Strings in OMGUI

Index

Unicode

OMGUI is a Unicode library, which is supported by all modern platforms. This creates some complications when it comes to portable string handling. For example, the Windows system uses UTF-16 for its unicode representation, meaning its strings use wide characters (wchar_t). However, GTK+ uses UTF-8 for its unicode representation, meaning its strings use normal chars (char). To allow for efficient implementations on both platforms, string objects in OMGUI will use wchar_t on systems using UTF-16 and char on systems that use UTF-8. This is handled with the omgui::string typedef, which will be std::wstring on UTF-16 platforms and std::string on UTF-8 platforms.

Back to top

Unicode gotchas

While the interface provided by omgui::string will be identical regardless of what encoding is being used, other tasks may be complicated by having to deal with std::wstring. For example, std::stringstream does not accept std::wstrings; std::wstringstream must be used instead. This is provided for with the omgui::stringstream typedef, which is std::wstringstream or std::stringstream based on the encoding being used.

Additionally, string literals in your source code need to be handled specially, as std::wstring cannot be initialized from a plain string literal, such as "hello world". It requires a wide string literal: L"hello world". OMGUI proviedes a macro to deal with this, OMGUI_STR, which will evaluate to the string literal on UTF-8 platforms, and a wide string literal on UTF-16 platforms.

Back to top

Encoding type mappings

This set of tables outline what encoding is used on which platform and what the various typedefs evaluate to on these platforms.

Platform Encoding
Windows UTF-16
GTK+ UTF-8
Cocoa*
*: Cocoa itself UTF-16 (right?), but the implementation currently uses UTF-8.

Encoding typedefs and macros
UTF-16 typedef std::wstring omgui::string
typedef std::wstringstream omgui::stringstream
#define OMGUI_STR(s) L##s
UTF8 typedef std::string omgui::string
typedef std::stringstream omgui::stringstream
#define OMGUI_STR(s) s

Back to top

Additional references

See also:
omgui::string, omgui::stringstream, OMGUI_STR
Back to top

doxygen SourceForge.net Logo