I've uploaded another new version of ustring:
http://irrlicht.suckerfreegames.com/irrUString.h
Changes in this version:
- Renamed the class to ustring16, added custom allocators back in, and added a ustring typedef.
- Renamed all the byte order mark constants in the unicode namespace to better convey their functions.
- Added endianness conversion features.
- The class checks for byte order marks when you construct a new string.
- Ability to add byte order marks and specify endianness when using the string conversion functions.
- Various bugs fixed.
The big new features are the byte order marks and the endianness features. When you construct a new string, it will check to see if a byte order mark is present. If one is, it will correctly construct the string, taking into account the endianness specified by the mark. The byte order mark will NOT be saved into the string, however.
The string now saves its EUTF_ENCODE type. The encoding of the string can be retrieved via the getEncoding() member function. Currently, the only valid return values you should get are EUTFE_UTF16_LE and EUTFE_UTF16_BE.
I added a new enum, EUTF_ENDIAN. The getEndianness() member function will also return the endianness of the ustring.
I also updated all the unicode conversion routines (the toUTF8, toUTF16, toUTF32 member functions.) You can choose whether or not the function adds the appropriate byte order mark to the output string by passing true to the addBOM argument. Also, for the toUTF16 and toUTF32 functions, you can specify which endianness you wish the resulting string to have: EUTFEE_NATIVE, EUTFEE_LITTLE, or EUTFEE_BIG.
These new changes make it very easy to read/write proper Unicode formatted files complete with appropriate byte order marks. The class will take care of all the necessary endian conversions for you.
Code: Select all
// Passing true tells the class to include the byte order mark.
core::array<uchar8_t> utf8 = mystring.toUTF8(true);
io::IWriteFile* f = device->getFileSystem()->createAndWriteFile("mysettings.txt");
f->write(utf8.pointer(), utf8.size());
f->drop();
Code: Select all
// Passing true tells the class to include the byte order mark, and passing core::unicode::EUTFEE_BIG says that we want to save it as big-endian, for whatever reason.
core::array<uchar16_t> utf16be = mystring.toUTF16(core::unicode::EUTFEE_BIG, true);
io::IWriteFile* f = device->getFileSystem()->createAndWriteFile("mysettings.txt");
f->write(utf16be.pointer(), utf16be.size() * sizeof(uchar16_t));
f->drop();