Newer
Older
libj / j / lang / src / main.cpp
#include <iostream>
#include <cerrno>

#include <j/lang/string.hpp>
#include <j/lang/throwable.hpp>
#include <j/lang/errno.hpp>
#include <j/lang/error.hpp>

using namespace j;
using namespace j::lang;

class X : public Object
{
public:
	String toString() const noexcept override
	{
		String str("This is X");
		return str;
	}
};

int main(int, char **)
{
	/*
	String str = "AbcdefAbaBcdefGhI";
	bool ret = str.startsWith("Abc");
	std::cout << "startsWith:[ok] " << ret << std::endl;

	ret = str.startsWith("Abd");
	std::cout << "startsWith:[ng] " << ret << std::endl;

	ret = str.endsWith("GhI");
	std::cout << "endsWith:[ok] " << ret << std::endl;

	ret = str.endsWith("xGhi");
	std::cout << "endsWith:[ng] " << ret << std::endl;

	std::cout << str.toLowerCase() << std::endl;
	std::cout << str.toUpperCase() << std::endl;

	String str2 = " a a daf\t";
	std::cout << str2 << std::endl;
	std::cout << str2.trim() << std::endl;

	std::cout << str << std::endl;
	std::cout << str.replace('A', '-') << std::endl;
	std::cout << str.replace("Ab", "--") << std::endl;
	std::cout << str.replaceAll("Ab", "--") << std::endl;
	*/
	String t1 = "Hello";
	String t2 = "World";
	String t3 = t1 + " " + t2;
	for (int i = 0; i < 100; i++)
	{
		t3 += "!";
	}

	std::cout << t3 << std::endl;

	std::cout << t1.equals(t2) << std::endl;

	String t4 = "World";
	String t5 = t2;
	std::cout << "t2:hash=" << t2.hashCode() << std::endl;
	std::cout << "t4:hash=" << t4.hashCode() << std::endl;
	std::cout << t2.equals(t4) << std::endl;
	std::cout << t5.equals(t2) << std::endl;

	Errno::set(EINVAL);
	Throwable tt1;
	Throwable tt2("MSG");
	Throwable tt3 = tt1;
	Object *tt4 = &tt1;

	std::cout << tt1 << std::endl;
	std::cout << tt2 << std::endl;
	std::cout << tt1.equals(tt2) << std::endl;
	std::cout << tt1.equals(tt3) << std::endl;
	std::cout << "tt1 == tt4 : " << tt1.equals(*tt4) << std::endl;
	std::cout << "tt4 == tt1 : " << tt4->equals(tt1) << std::endl;

	String str4 = tt3.getMessage();
	std::cout << str4 << std::endl;

	Error err("Error");
	Error err2 = err;
	std::cout << err2 << std::endl;
	return 0;
}