File: decode_utf8_to_wchar.c

package info (click to toggle)
putty 0.83-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,216 kB
  • sloc: ansic: 148,476; python: 8,466; perl: 1,830; makefile: 128; sh: 117
file content (21 lines) | stat: -rw-r--r-- 555 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Decode a single UTF-8 character to the platform's local wchar_t.
 */

#include "putty.h"
#include "misc.h"

size_t decode_utf8_to_wchar(BinarySource *src, wchar_t *out,
                            DecodeUTF8Failure *err)
{
    size_t outlen = 0;
    unsigned wc = decode_utf8(src, err);
    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;
}