MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / pop_back_utf8_char

Function pop_back_utf8_char

smallthinker/common/console.cpp:339–353  ·  view source on GitHub ↗

Helper function to remove the last UTF-8 character from a string

Source from the content-addressed store, hash-verified

337
338 // Helper function to remove the last UTF-8 character from a string
339 static void pop_back_utf8_char(std::string & line) {
340 if (line.empty()) {
341 return;
342 }
343
344 size_t pos = line.length() - 1;
345
346 // Find the start of the last UTF-8 character (checking up to 4 bytes back)
347 for (size_t i = 0; i < 3 && pos > 0; ++i, --pos) {
348 if ((line[pos] & 0xC0) != 0x80) {
349 break; // Found the start of the character
350 }
351 }
352 line.erase(pos);
353 }
354
355 static bool readline_advanced(std::string & line, bool multiline_input) {
356 if (out != stdout) {

Callers 1

readline_advancedFunction · 0.70

Calls 2

lengthMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected