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.
| 46 | // codepoints[0..cpCount-1] via O(n²) dedup. Returns true if the buffer |
| 47 | // reached maxCount (cap hit), false if all codepoints fit. |
| 48 | bool 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 | |
| 68 | const char* asCStr(const std::string& s) { return s.c_str(); } |
| 69 | const char* asCStr(const char* s) { return s; } |
no test coverage detected