MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / EncodeUtf8Codepoint

Function EncodeUtf8Codepoint

engine/Poseidon/Foundation/Strings/Mbcs.cpp:300–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298}
299
300int EncodeUtf8Codepoint(uint32_t codepoint, char* out, size_t outSize)
301{
302 if (!out || outSize == 0)
303 return 0;
304
305 if (codepoint <= 0x7F)
306 {
307 if (outSize < 2)
308 return 0;
309 out[0] = static_cast<char>(codepoint);
310 out[1] = 0;
311 return 1;
312 }
313 if (codepoint <= 0x7FF)
314 {
315 if (outSize < 3)
316 return 0;
317 out[0] = static_cast<char>(0xC0 | (codepoint >> 6));
318 out[1] = static_cast<char>(0x80 | (codepoint & 0x3F));
319 out[2] = 0;
320 return 2;
321 }
322 if (codepoint <= 0xFFFF)
323 {
324 if (outSize < 4)
325 return 0;
326 out[0] = static_cast<char>(0xE0 | (codepoint >> 12));
327 out[1] = static_cast<char>(0x80 | ((codepoint >> 6) & 0x3F));
328 out[2] = static_cast<char>(0x80 | (codepoint & 0x3F));
329 out[3] = 0;
330 return 3;
331 }
332 if (codepoint <= 0x10FFFF)
333 {
334 if (outSize < 5)
335 return 0;
336 out[0] = static_cast<char>(0xF0 | (codepoint >> 18));
337 out[1] = static_cast<char>(0x80 | ((codepoint >> 12) & 0x3F));
338 out[2] = static_cast<char>(0x80 | ((codepoint >> 6) & 0x3F));
339 out[3] = static_cast<char>(0x80 | (codepoint & 0x3F));
340 out[4] = 0;
341 return 4;
342 }
343
344 return EncodeUtf8Codepoint(0xFFFD, out, outSize);
345}
346
347} // namespace Poseidon::Foundation

Callers 2

DoCharMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected