93 if(0xD800ul <= u && u <= 0xDFFFul)
99 if(u == 0xFFFEul || u == 0xFFFFul || (0xFDD0ul <= u && u <= 0xFDEFul))
116 *dstPos++ =
UTF8((u >> 6) | 0xC0);
117 *dstPos++ =
UTF8((u | 0x80u) & 0xBFu);
120 *dstPos++ =
UTF8((u >> 12) | 0xE0);
121 *dstPos++ =
UTF8(((u >> 6) | 0x80u) & 0xBFu);
122 *dstPos++ =
UTF8((u | 0x80u) & 0xBFu);
131 if(!
IsValid(srcPos, size, srcEnd))
138 for(
size_t i = 0; i < size-1; i++)
140 u +=
UTF32(*srcPos++);
143 u +=
UTF32(*srcPos++);
145 static const UTF32 offsets[1+4] = { 0, 0x00000000ul, 0x00003080ul, 0x000E2080ul, 0x03C82080UL };
177 if(src+size > srcEnd)
182 if(!(0xC2 <= src[0] && src[0] <= 0xF4))
186 if(src[0] == 0xE0 && src[1] < 0xA0)
188 if(src[0] == 0xED && src[1] > 0x9F)
190 if(src[0] == 0xF0 && src[1] < 0x90)
192 if(src[0] == 0xF4 && src[1] > 0x8F)
195 for(
size_t i = 1; i < size; i++)
197 if(!(0x80 <= src[i] && src[i] <= 0xBF))
213 std::string dst(src.size()*3+1,
' ');
215 for(
size_t i = 0; i < src.size(); i++)
220 dst.resize(dstPos - (
UTF8*)&dst[0]);
231 dst.reserve(src.size());
232 const UTF8* srcPos = (
const UTF8*)src.data();
233 const UTF8*
const srcEnd = srcPos + src.size();
234 while(srcPos < srcEnd)
const Status UTF8_INVALID_UTF8
std::string utf8_from_wstring(const std::wstring &src, Status *err)
opposite of wstring_from_utf8
static UTF32 Decode(const UTF8 *&srcPos, const UTF8 *const srcEnd, Status *err)
static size_t SizeFromFirstByte(UTF8 firstByte)
static UTF32 ReplaceIfInvalid(UTF32 u, Status *err)
static void Encode(UTF32 u, UTF8 *&dstPos)
i64 Status
Error handling system.
static bool IsValid(const UTF8 *const src, size_t size, const UTF8 *const srcEnd)
#define STATUS_ADD_DEFINITIONS(definitions)
add a module's array of StatusDefinition to the list.
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
std::wstring wstring_from_utf8(const std::string &src, Status *err)
convert UTF-8 to a wide string (UTF-16 or UCS-4, depending on the platform's wchar_t).
const Status UTF8_OUTSIDE_BMP
const Status UTF8_SURROGATE
static size_t Size(UTF32 u)
static const StatusDefinition utf8StatusDefinitions[]
static UTF32 RaiseError(Status err, Status *perr)
const Status UTF8_NONCHARACTER