MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / collectUniqueCodepoints

Function collectUniqueCodepoints

lib/EpdFont/SdCardFont.cpp:48–66  ·  view source on GitHub ↗

Walks a null-terminated UTF-8 string and appends each unique codepoint to codepoints[0..cpCount-1] via O(n²) dedup. Returns true if the buffer reached maxCount (cap hit), false if all codepoints fit.

Source from the content-addressed store, hash-verified

46// codepoints[0..cpCount-1] via O(n²) dedup. Returns true if the buffer
47// reached maxCount (cap hit), false if all codepoints fit.
48bool collectUniqueCodepoints(const char* text, uint32_t* codepoints, uint32_t& cpCount, uint32_t maxCount) {
49 const unsigned char* p = reinterpret_cast<const unsigned char*>(text);
50 while (*p) {
51 uint32_t cp = utf8NextCodepoint(&p);
52 if (cp == 0) break;
53 bool found = false;
54 for (uint32_t i = 0; i < cpCount; i++) {
55 if (codepoints[i] == cp) {
56 found = true;
57 break;
58 }
59 }
60 if (!found) {
61 if (cpCount >= maxCount) return true;
62 codepoints[cpCount++] = cp;
63 }
64 }
65 return false;
66}
67
68const char* asCStr(const std::string& s) { return s.c_str(); }
69const char* asCStr(const char* s) { return s; }

Callers 1

Calls 1

utf8NextCodepointFunction · 0.85

Tested by

no test coverage detected