1 /* size_t mbrtoc16( char16_t *, const char *, size_t, mbstate_t * )
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
12 #include "_PDCLIB_encoding.h"
13 #include "_PDCLIB_locale.h"
16 char16_t *restrict pc16,
17 const char *restrict s,
19 mbstate_t *restrict ps,
26 if(!l->_Codec->__mbstoc16s) {
27 // No UTF-16 support in codec. Must synthesize on top of UCS-4 support.
30 // If a pending surrogate is stored in the state
31 *pc16 = ps->_Surrogate;
37 size_t res = mbrtoc32_l(&c32, s, n, ps, l);
38 if(res != (size_t) -1) {
39 // Conversion was successful. Check for surrogates
45 *pc16 = 0xD800 | (c32 >> 10);
46 ps->_Surrogate = 0xDC00 | (c32 & 0x3FF);
50 } else if(l->_Codec->__mbstoc16s(&pc16, &dstlen, &s, &nr, ps)) {
51 // Successful conversion
53 // A character was output
55 // The output character resulted entirely from stored state
57 } else if(pc16[-1] == 0) {
61 // Count of processed characters
65 assert(nr == 0 && "Must have processed whole input");
76 char16_t *restrict pc16,
77 const char *restrict s,
79 mbstate_t *restrict ps
82 return mbrtoc16_l(pc16, s, n, ps, _PDCLIB_threadlocale());
88 #include "_PDCLIB_test.h"
92 TESTCASE( NO_TESTDRIVER );