2 char16_t *restrict pc16,
\r
3 const char *restrict s,
\r
5 mbstate_t *restrict ps);
\r
7 This file is part of the Public Domain C Library (PDCLib).
\r
8 Permission is granted to use, modify, and / or redistribute at will.
\r
16 #include <_PDCLIB_encoding.h>
\r
17 #include <_PDCLIB_locale.h>
\r
20 char16_t *restrict pc16,
\r
21 const char *restrict s,
\r
23 mbstate_t *restrict ps,
\r
30 if(!l->_Codec->__mbstoc16s) {
\r
31 // No UTF-16 support in codec. Must synthesize on top of UCS-4 support.
\r
33 if(ps->_Surrogate) {
\r
34 // If a pending surrogate is stored in the state
\r
35 *pc16 = ps->_Surrogate;
\r
41 size_t res = mbrtoc32_l(&c32, s, n, ps, l);
\r
42 if(res != (size_t) -1) {
\r
43 // Conversion was successful. Check for surrogates
\r
48 // Supplementary char
\r
49 *pc16 = 0xD800 | (c32 >> 10);
\r
50 ps->_Surrogate = 0xDC00 | (c32 & 0x3FF);
\r
54 } else if(l->_Codec->__mbstoc16s(&pc16, &dstlen, &s, &nr, ps)) {
\r
55 // Successful conversion
\r
57 // A character was output
\r
59 // The output character resulted entirely from stored state
\r
61 } else if(pc16[-1] == 0) {
\r
62 // Was null character
\r
65 // Count of processed characters
\r
69 assert(nr == 0 && "Must have processed whole input");
\r
73 // Failed conversion
\r
80 char16_t *restrict pc16,
\r
81 const char *restrict s,
\r
83 mbstate_t *restrict ps
\r
86 return mbrtoc16_l(pc16, s, n, ps, _PDCLIB_threadlocale());
\r
92 #include <_PDCLIB_test.h>
\r
96 TESTCASE( NO_TESTDRIVER );
\r
97 return TEST_RESULTS;
\r