| 98 | |
| 99 | |
| 100 | std::string truncatePrefix(const std::string& s, size_t maxCodepoints) { |
| 101 | if (s.empty() || maxCodepoints == 0) |
| 102 | return ""; |
| 103 | |
| 104 | size_t pos = s.size(); |
| 105 | for (size_t i = 0; i < maxCodepoints; i++) { |
| 106 | // If remaining bytes are less than remaining codepoints, the string can't possibly be truncated. |
| 107 | if (pos <= maxCodepoints - i) |
| 108 | return s; |
| 109 | |
| 110 | pos = UTF8PrevCodepoint(s, pos); |
| 111 | // Check if at beginning |
| 112 | if (pos == 0) |
| 113 | return s; |
| 114 | } |
| 115 | |
| 116 | return s.substr(pos); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | std::string ellipsize(const std::string& s, size_t maxCodepoints) { |
no test coverage detected