MCPcopy Create free account
hub / github.com/crawl/crawl / mb_to_utf8

Function mb_to_utf8

crawl-ref/source/unicode.cc:218–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218string mb_to_utf8(const char *s)
219{
220#ifdef __ANDROID__
221 // Paranoia; all consumers already use the same code so this won't do
222 // anything new.
223 return utf8_validate(s);
224#else
225 string d;
226 wchar_t c;
227 int l;
228 mbstate_t ps;
229
230 memset(&ps, 0, sizeof(ps));
231 // the input is zero-terminated, so third argument doesn't matter
232 while ((l = mbrtowc(&c, s, MB_LEN_MAX, &ps)))
233 {
234 if (l > 0)
235 s += l;
236 else
237 { // invalid input, mark it and try to recover
238 s++;
239 c = 0xFFFD;
240 }
241
242 char buf[4];
243 int r = wctoutf8(buf, c);
244 for (int i = 0; i < r; i++)
245 d.push_back(buf[i]);
246 }
247 return d;
248#endif
249}
250
251static bool _check_trail(FILE *f, const char* bytes, int len)
252{

Callers 1

get_lineMethod · 0.70

Calls 3

wctoutf8Function · 0.85
utf8_validateFunction · 0.70
push_backMethod · 0.45

Tested by

no test coverage detected