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

Function utf16_to_8

crawl-ref/source/unicode.cc:141–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139static
140#endif
141string utf16_to_8(const utf16_t *s)
142{
143 string d;
144 char32_t c;
145
146 while (*s)
147 {
148 if (*s >= 0xD800 && *s <= 0xDBFF)
149 if (s[1] >= 0xDC00 && s[1] <= 0xDFFF)
150 {
151 c = (((char32_t)s[0]) << 10) + s[1] - 0x35fdc00;
152 s++;
153 }
154 else
155 c = 0xFFFD; // leading surrogate without its tail
156 else if (*s >= 0xDC00 && *s <= 0xDFFF)
157 c = 0xFFFD; // unpaired trailing surrogate
158 else
159 c = *s;
160 s++;
161
162 char buf[4];
163 int l = wctoutf8(buf, c);
164 for (int i = 0; i < l; i++)
165 d.push_back(buf[i]);
166 }
167
168 return d;
169}
170
171string utf8_to_mb(const char *s)
172{

Callers 1

get_lineMethod · 0.70

Calls 2

wctoutf8Function · 0.85
push_backMethod · 0.45

Tested by

no test coverage detected