MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / validate_utf8

Function validate_utf8

tools/server/server-common.cpp:677–702  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

675}
676
677size_t validate_utf8(const std::string& text) {
678 size_t len = text.size();
679 if (len == 0) return 0;
680
681 // Check the last few bytes to see if a multi-byte character is cut off
682 for (size_t i = 1; i <= 4 && i <= len; ++i) {
683 unsigned char c = text[len - i];
684 // Check for start of a multi-byte sequence from the end
685 if ((c & 0xE0) == 0xC0) {
686 // 2-byte character start: 110xxxxx
687 // Needs at least 2 bytes
688 if (i < 2) return len - i;
689 } else if ((c & 0xF0) == 0xE0) {
690 // 3-byte character start: 1110xxxx
691 // Needs at least 3 bytes
692 if (i < 3) return len - i;
693 } else if ((c & 0xF8) == 0xF0) {
694 // 4-byte character start: 11110xxx
695 // Needs at least 4 bytes
696 if (i < 4) return len - i;
697 }
698 }
699
700 // If no cut-off multi-byte character is found, return full length
701 return len;
702}
703
704// Computes FNV-1a hash of the data
705static std::string fnv_hash(const uint8_t * data, size_t len) {

Callers 3

process_tokenMethod · 0.85
to_jsonMethod · 0.85
probs_vector_to_jsonMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected