Beast uses strings for several purposes, typically for resource names and messages.
The Beast API can handle string input and output using any of the following encodings:
The Beast API will attempt to detect automatically the string encoding used by the host application with the pre-processor. You can override the auto-detection by setting one of the following defines to specify the kind of encoding you want to use:
#define ILB_STRING_ANSI #define ILB_STRING_UTF8 #define ILB_STRING_UTF16
If you choose to specify an encoding using one of those defines, make sure that you do this for all files that directly or indirectly use the Beast headers in order to avoid conflicts. See the beastapitypes.h file for the auto-detection and setup for strings.
When you provide a string to the Beast API, you provide it as an ILBConstString object. This is a pointer to a zero-terminated string of characters. Depending on the string encoding being used, the character type will be different. If you use ANSI or UTF-8 encodings, you can build the ILBConstString from a string of char* characters; if you use UTF-16, you can build the ILBConstString from a string of wchar_t* characters.
Beast also provides strings as output in some cases. This requires some memory management to ensure that the memory allocated for the string is released properly.
When a function in the Beast API provides a string as output, it provides it through an ILBStringHandle. You need to use this handle as follows:
The typical way of handling return strings is to create a function that converts the string to the format used in the host application. For example, the following code block creates an std::string from an ILBStringHandle in C++:
std::string convertBeastString(ILBStringHandle h) { int32 len; ILBGetLength(h, &len); // Note that Beast strings give their length // including zero termination. We need to // make the std::string 1 character shorter // since std::string expects sizes without zero // termination. std::string result(len - 1, 0); ILBCopy(h, &result[0], len); ILBReleaseString(h); return result; }