MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / append_cp_utf8

Function append_cp_utf8

tests/src/Base/Reader.cpp:506–526  ·  view source on GitHub ↗

Minimal UTF-8 encoder -- not valid for full production use, test suite only!

Source from the content-addressed store, hash-verified

504
505// Minimal UTF-8 encoder -- not valid for full production use, test suite only!
506static void append_cp_utf8(std::string& s, char32_t cp)
507{
508 if (cp <= 0x7F) {
509 s.push_back(static_cast<char>(cp));
510 }
511 else if (cp <= 0x7FF) {
512 s.push_back(static_cast<char>(0xC0 | (cp >> 6)));
513 s.push_back(static_cast<char>(0x80 | (cp & 0x3F)));
514 }
515 else if (cp <= 0xFFFF) {
516 s.push_back(static_cast<char>(0xE0 | (cp >> 12)));
517 s.push_back(static_cast<char>(0x80 | ((cp >> 6) & 0x3F)));
518 s.push_back(static_cast<char>(0x80 | (cp & 0x3F)));
519 }
520 else {
521 s.push_back(static_cast<char>(0xF0 | (cp >> 18)));
522 s.push_back(static_cast<char>(0x80 | ((cp >> 12) & 0x3F)));
523 s.push_back(static_cast<char>(0x80 | ((cp >> 6) & 0x3F)));
524 s.push_back(static_cast<char>(0x80 | (cp & 0x3F)));
525 }
526}
527
528static std::string make_utf8(std::initializer_list<char32_t> cps)
529{

Callers 1

make_utf8Function · 0.85

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected