MCPcopy Create free account
hub / github.com/brofield/simpleini / SystemDecode

Function SystemDecode

tests/ts-utf8-conversion.cpp:95–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95bool SystemDecode(const char *buf, size_t len, char32_t &cp, size_t &consumed) {
96 iconv_t cd = iconv_open("UTF-32LE", "UTF-8");
97 if (cd == (iconv_t)-1) {
98 return false;
99 }
100
101 unsigned char out[4] = {};
102 char *inbuf = (char *)buf;
103 size_t inleft = len;
104 char *outbuf = (char *)out;
105 size_t outleft = sizeof(out);
106
107 if (iconv(cd, &inbuf, &inleft, &outbuf, &outleft) == (size_t)-1) {
108 iconv_close(cd);
109 return false;
110 }
111
112 iconv_close(cd);
113 consumed = len - inleft;
114 cp = (char32_t)out[0] | ((char32_t)out[1] << 8) | ((char32_t)out[2] << 16) |
115 ((char32_t)out[3] << 24);
116 return true;
117}
118
119#elif defined(SI_TEST_UTF8_REF_UCHAR)
120

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected