2022-03-12 15:53:04 +00:00
|
|
|
/*
|
|
|
|
* Decode a single UTF-8 character to the platform's local wchar_t.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
2022-11-09 19:01:04 +00:00
|
|
|
size_t decode_utf8_to_wchar(BinarySource *src, wchar_t *out)
|
2022-03-12 15:53:04 +00:00
|
|
|
{
|
|
|
|
size_t outlen = 0;
|
2022-11-09 19:01:04 +00:00
|
|
|
unsigned wc = decode_utf8(src);
|
2022-03-12 15:53:04 +00:00
|
|
|
if (sizeof(wchar_t) > 2 || wc < 0x10000) {
|
|
|
|
out[outlen++] = wc;
|
|
|
|
} else {
|
|
|
|
unsigned wcoff = wc - 0x10000;
|
|
|
|
out[outlen++] = 0xD800 | (0x3FF & (wcoff >> 10));
|
|
|
|
out[outlen++] = 0xDC00 | (0x3FF & wcoff);
|
|
|
|
}
|
|
|
|
return outlen;
|
|
|
|
}
|