| 230 | } |
| 231 | |
| 232 | std::u16string StringUtils::removeForbiddenCharacters(std::u16string src) |
| 233 | { |
| 234 | static const std::u16string illegalChars = StringUtils::UTF8toUTF16(".,!\\/:?*\"<>|"); |
| 235 | for (size_t i = 0; i < src.length(); i++) { |
| 236 | if (illegalChars.find(src[i]) != std::string::npos) { |
| 237 | src[i] = ' '; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // Trim trailing spaces. find_last_not_of handles the empty / all-spaces cases |
| 242 | // (npos) without the size()-1 underflow of a reverse index loop. |
| 243 | size_t end = src.find_last_not_of(u' '); |
| 244 | if (end == std::u16string::npos) { |
| 245 | src.clear(); |
| 246 | } |
| 247 | else { |
| 248 | src.erase(end + 1); |
| 249 | } |
| 250 | |
| 251 | return src; |
| 252 | } |
| 253 | |
| 254 | // One decoder and one glyph-width cache for every text-measuring path. |
| 255 | namespace { |