New version:
http://irrlicht.pastebin.com/f90b1b63
I finished implementing split() and started testing the class, fixing bugs as I came across them.
I also implemented toUTF8_s() and toWCHAR_s(), which return a stringc and a stringw. I also implemented a toUTF16_s() and a toUTF32_s() function, which is only turned on for C++0x compatible compilers (it will only work with GCC 4.5 at the moment, as that is the only compiler with the new unicode string data types.) This is the only solution I can come up with currently because of the issues with the string class. Also, I added a couple C++0x move semantics for fun.
I have attached the code I used to test the class with. It shows all of the functions that I have currently tested. I think there is only a few I haven't tested yet. And I still need to test the correctness of my UTF-8 conversion functions.
EDIT: I got around to testing all the last bits of code, including the UTF-8 conversion functions. It all worked perfectly. Here are the updated tests:
Code: Select all
core::ustring test(L"This is a test: ");
core::ustring test2(test);
test.append((uchar32_t)0x10405);
test += " - ???";
core::ustring::iterator i = test.begin();
i += 3;
*i = 0x10400;
++i;
*i = 0x10401;
test.erase(3);
s32 loc1 = test.find(L"is");
s32 loc2 = test.findLast((uchar32_t)'e');
s32 loc3 = test.findFirst((uchar32_t)0x10401);
uchar32_t buf[3] = {0x10400, 0x10401, 0x10405};
s32 loc4 = test.findFirstChar(buf, 3);
s32 loc5 = test.findFirstCharNotInList(buf, 3);
s32 loc6 = test.findLastChar(buf, 3);
s32 loc7 = test.findLastCharNotInList(buf, 3);
uchar32_t lc = test.lastChar();
test.replace('s', 'S');
bool e1 = test.equalsn(test2, 5);
bool e2 = test.equalsn(test2, 3);
bool e3 = test.equalsn(test2, 4);
bool e4 = (test == test2);
bool e5 = (test != test2);
uchar32_t ct1 = test[3];
uchar32_t ct2 = test[4];
test[4] = (uchar32_t)'I';
core::ustring test3 = test.subString(3, 6);
uchar32_t splitPos = 'S';
core::list<core::ustring> sstrings;
test.split<core::list<core::ustring> >(sstrings, &splitPos, 1);
i.toStart();
while (!i.atEnd())
{
uchar32_t c = *i;
device->getLogger()->log(core::stringw(c).c_str());
++i;
}
core::stringw t2 = test.toWCHAR_s();
core::stringc t3 = test.toUTF8_s();
io::IWriteFile* f1 = device->getFileSystem()->createAndWriteFile("test.txt");
f1->write(t3.c_str(), t3.size());
f1->drop();
io::IReadFile* f2 = device->getFileSystem()->createAndOpenFile("test.txt");
c8* fbuf = new c8[f2->getSize() + 1];
f2->read(fbuf, f2->getSize());
fbuf[f2->getSize()] = 0;
core::ustring test4(fbuf);
delete[] fbuf;
f2->drop();
bool u8test = (test == test4);
core::ustring bigunicode;
bigunicode.append(0x10401);
test2.removeChars("s");
test.removeChars(bigunicode);