// Now check the decoded byte for an overlong encoding
if ( (bits >= 2 && ch < 0x80) ||
- (bits >= 3 && ch < 0x800) ||
- (bits >= 4 && ch < 0x10000) ||
- ch >= 0x10FFFF // RFC 3629
- )
+ (bits >= 3 && ch < 0x800) ||
+ (bits >= 4 && ch < 0x10000) ||
+ ch >= 0x10FFFF // RFC 3629
+ )
{
i += bits;
//fprintf(stderr, "overlong: %i bytes for %x\n", bits, ch);
cstr[p++] = (0x80 | ((point >> 0) & 0x3f));
}
else
- #if U32
+ #if WTF8U32
if (point < 0x10000)
#endif
{
cstr[p++] = (0x80 | ((point >> 6) & 0x3f));
cstr[p++] = (0x80 | ((point >> 0) & 0x3f));
}
- #if U32
+ #if WTF8U32
else
- #if CHECKS
+ #if WTF8CHECKS
if (point < 0x110000)
#endif
{
wchar point = byte;
int length = 1;
if (p + 1 >= maxwlen) break;
- #if CHECKS
+ #if WTF8CHECKS
if ((byte & 0xf8) == 0xf8)
return -1;
#endif
length = 2;
point = byte & 0x1f;
}
- #if CHECKS
+ #if WTF8CHECKS
else if ((byte & 0xc0) == 0x80)
{
return -1;
while (--length)
{
byte = cstr[i++];
- #if CHECKS
+ #if WTF8CHECKS
if (byte == -1) return -1;
else if ((byte & 0xc0) != 0x80) return -1;
#endif
// WTF-8 encoding to circumvent Windows encodings, be it UTF-16 or random codepages
// https://simonsapin.github.io/wtf-8/
-#define U32 0
-#define CHECKS 1
+#define WTF8U32 0 // whether to regard wchar as utf-32
+#define WTF8CHECKS 1 // check for extra sanity in conversion steps
typedef wchar_t wchar;
int towtf8(const wchar* wstr, int wlen, char* cstr, int maxclen);