Strings in Tahiti
From version 6.0 Tahiti is compiled as a Unicode application. Two approaches are used:
our own string types defined in
TahitiBasefor the Tahiti core and multiplatform compatibility,CStringfor the user interface on the Windows platform.
TahitiBase string types
TahitiBase/TahitiString.h provides three types, all deriving from a std
string type:
Tahiti::u8stringUTF-8 string, derived from
std::string. The type for core and portable code. Itsconst char*constructor isexplicit; build literals with theTU8("...")macro.Tahiti::pstringPlatform dependent Unicode string for OS and filesystem APIs. On Windows derived from
std::wstring(UTF-16), on Linux fromstd::string(UTF-8).Tahiti::astringThe UI string. In Unicode builds (all current builds) it is derived from
std::wstring(UTF-16) and matchesCString; in non-Unicode builds it was derived fromstd::stringin the user’s OEM code page; on Linux it isstd::string(UTF-8).
Related macro:
Tahiti::u8string someText;
someText = TU8("Description of something ...");
Conversions
Convert between the Tahiti::XXXstring types with the constructor of the
target type:
Tahiti::u8string str(TU8("My data"));
Tahiti::pstring str2(str);
Build messages with Tahiti::U8StringBuilder().append(...).
User interface
MFC and ATL use CString. As the application is compiled as Unicode,
CString is based on wchar_t. In UI classes that are Windows specific we
prefer CString for storing data. For input parameters we use LPCTSTR,
which is const wchar_t * in a Unicode application.
FAQ
How do I set text from a Tahiti::u8string into a control?
Use Tahiti::astring, which in a Unicode build is UTF-16 like CString:
Tahiti::u8string data(TU8("some text in UTF-8"));
Tahiti::astring strForUI(data);
m_ctrl.SetWindowText(strForUI.c_str());
How do I read text from a control into a Tahiti::u8string ?
Read it into a CString and convert through Tahiti::astring:
CString strFromUI;
m_ctrl.GetWindowText(strFromUI);
Tahiti::u8string data;
data = Tahiti::astring(CSTRING_TO_ASTRING(strFromUI));