| 251 | //========================================================================== |
| 252 | |
| 253 | const char* FResourceFile::NormalizeFileName(const char* fn, int fallbackcp) |
| 254 | { |
| 255 | if (!fn || !*fn) return ""; |
| 256 | auto norm = tolower_normalize(fn); |
| 257 | if (!norm) |
| 258 | { |
| 259 | if (fallbackcp == 437) |
| 260 | { |
| 261 | std::vector<char> buffer; |
| 262 | ibm437_to_utf8(fn, buffer); |
| 263 | norm = tolower_normalize(buffer.data()); |
| 264 | } |
| 265 | // maybe handle other codepages |
| 266 | else |
| 267 | { |
| 268 | // if the filename is not valid UTF-8, nuke all bytes larger than 0x80 so that we still got something semi-usable |
| 269 | std::string ffn = fn; |
| 270 | for (auto& c : ffn) |
| 271 | { |
| 272 | if (c & 0x80) c = '@'; |
| 273 | } |
| 274 | norm = tolower_normalize(&ffn.front()); |
| 275 | } |
| 276 | } |
| 277 | FixPathSeparator(norm); |
| 278 | auto pooled = stringpool->Strdup(norm); |
| 279 | free(norm); |
| 280 | return pooled; |
| 281 | |
| 282 | } |
| 283 | |
| 284 | //========================================================================== |
| 285 | // |
no test coverage detected