decode_utf8_to_wchar.c 555 B

12345678910111213141516171819202122
  1. /*
  2. * Decode a single UTF-8 character to the platform's local wchar_t.
  3. */
  4. #include "putty.h"
  5. #include "misc.h"
  6. size_t decode_utf8_to_wchar(BinarySource *src, wchar_t *out,
  7. DecodeUTF8Failure *err)
  8. {
  9. size_t outlen = 0;
  10. unsigned wc = decode_utf8(src, err);
  11. if (sizeof(wchar_t) > 2 || wc < 0x10000) {
  12. out[outlen++] = wc;
  13. } else {
  14. unsigned wcoff = wc - 0x10000;
  15. out[outlen++] = 0xD800 | (0x3FF & (wcoff >> 10));
  16. out[outlen++] = 0xDC00 | (0x3FF & wcoff);
  17. }
  18. return outlen;
  19. }