MCPcopy Create free account
hub / github.com/axmolengine/axmol / getUTF8ByteOffset

Function getUTF8ByteOffset

core/base/UTF8.cpp:432–450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430}
431
432size_t getUTF8ByteOffset(std::string_view utf8, size_t utf8CharOffset)
433{
434 if (utf8CharOffset >= utf8.length())
435 return std::string_view::npos;
436
437 const UTF8* source = (const UTF8*)utf8.data();
438 const UTF8* sourceEnd = source + utf8.length();
439 for (size_t i = 0; i < utf8CharOffset; ++i)
440 {
441 auto size = getUTF8SequenceSize(source, sourceEnd);
442 if (size == 0)
443 {
444 // Invalid UTF-8 sequence found
445 return std::string_view::npos;
446 }
447 source += size;
448 }
449 return static_cast<unsigned int>(source - (const UTF8*)utf8.data());
450}
451
452size_t eraseUTF8CharAt(std::string& str, size_t utf8CharOffset)
453{

Callers 3

insertTextMethod · 0.85
eraseUTF8CharAtFunction · 0.85

Calls 3

getUTF8SequenceSizeFunction · 0.85
lengthMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected