| 207 | } |
| 208 | |
| 209 | uint8_t convertUnicodeToLoco(utf32_t unicode) |
| 210 | { |
| 211 | auto tableLookup = [unicode](auto&& table) { |
| 212 | auto it = std::ranges::lower_bound( |
| 213 | table, |
| 214 | unicode, |
| 215 | {}, |
| 216 | &EncodingConvertEntry::unicode); |
| 217 | |
| 218 | // Handle edge case where iterator is valid, but mismatches the input |
| 219 | return it != table.end() && it->unicode == unicode ? it : table.end(); |
| 220 | }; |
| 221 | |
| 222 | // Extended Latin characters that are supported by Locomotion as-is |
| 223 | if (auto it = tableLookup(kUnicodeToLocoTable); it != kUnicodeToLocoTable.end()) |
| 224 | { |
| 225 | return it->locoCode; |
| 226 | } |
| 227 | |
| 228 | // Remove diacritics from letters that don't have an associated glyph yet |
| 229 | if (auto it = tableLookup(kUnicodeTemporaryStrip); it != kUnicodeTemporaryStrip.end()) |
| 230 | { |
| 231 | return it->locoCode; |
| 232 | } |
| 233 | |
| 234 | // Basic Latin characters |
| 235 | if (unicode < 256) |
| 236 | { |
| 237 | return static_cast<uint8_t>(unicode); |
| 238 | } |
| 239 | |
| 240 | return LocoChar::replacement_character; |
| 241 | } |
| 242 | |
| 243 | std::string convertUnicodeToLoco(const std::string& unicodeString) |
| 244 | { |
no test coverage detected