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

Function SystemEncode

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

Source from the content-addressed store, hash-verified

66#if defined(SI_TEST_UTF8_REF_ICONV)
67
68bool SystemEncode(char32_t cp, char *buf, size_t cap, size_t &outLen) {
69 iconv_t cd = iconv_open("UTF-8", "UTF-32LE");
70 if (cd == (iconv_t)-1) {
71 return false;
72 }
73
74 unsigned char in[4] = {
75 (unsigned char)(cp & 0xFF),
76 (unsigned char)((cp >> 8) & 0xFF),
77 (unsigned char)((cp >> 16) & 0xFF),
78 (unsigned char)((cp >> 24) & 0xFF),
79 };
80 char *inbuf = (char *)in;
81 size_t inleft = sizeof(in);
82 char *outbuf = buf;
83 size_t outleft = cap;
84
85 if (iconv(cd, &inbuf, &inleft, &outbuf, &outleft) == (size_t)-1) {
86 iconv_close(cd);
87 return false;
88 }
89
90 iconv_close(cd);
91 outLen = cap - outleft;
92 return true;
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");

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected