| 450 | int historyIndex = 0; |
| 451 | |
| 452 | class DictionaryWindow : public PrettyWindow |
| 453 | { |
| 454 | public: |
| 455 | DictionaryWindow() : PrettyWindow("Dictionary Window") |
| 456 | { |
| 457 | ui.display->setSizePolicy({ QSizePolicy::Fixed, QSizePolicy::Minimum }); |
| 458 | } |
| 459 | |
| 460 | void UpdateDictionary() |
| 461 | { |
| 462 | try |
| 463 | { |
| 464 | if (dictionaryFileLastWrite == std::filesystem::last_write_time(DICTIONARY_SAVE_FILE)) return; |
| 465 | dictionaryFileLastWrite = std::filesystem::last_write_time(DICTIONARY_SAVE_FILE); |
| 466 | } |
| 467 | catch (std::filesystem::filesystem_error) { return; } |
| 468 | |
| 469 | dictionary.clear(); |
| 470 | charStorage.clear(); |
| 471 | |
| 472 | auto StoreCopy = [&](std::string_view string) |
| 473 | { |
| 474 | auto location = &*charStorage.insert(charStorage.end(), string.begin(), string.end()); |
| 475 | charStorage.push_back(0); |
| 476 | return location; |
| 477 | }; |
| 478 | |
| 479 | charStorage.reserve(std::filesystem::file_size(DICTIONARY_SAVE_FILE)); |
| 480 | std::ifstream stream(DICTIONARY_SAVE_FILE); |
| 481 | BlockMarkupIterator savedDictionary(stream, Array<std::string_view>{ "|TERM|", "|DEFINITION|" }); |
| 482 | while (auto read = savedDictionary.Next()) |
| 483 | { |
| 484 | const auto& [terms, definition] = read.value(); |
| 485 | auto storedDefinition = StoreCopy(definition); |
| 486 | std::string_view termsView = terms; |
| 487 | size_t start = 0, end = termsView.find("|TERM|"); |
| 488 | while (end != std::string::npos) |
| 489 | { |
| 490 | dictionary.push_back(DictionaryEntry{ StoreCopy(termsView.substr(start, end - start)), storedDefinition }); |
| 491 | start = end + 6; |
| 492 | end = termsView.find("|TERM|", start); |
| 493 | } |
| 494 | dictionary.push_back(DictionaryEntry{ StoreCopy(termsView.substr(start)), storedDefinition }); |
| 495 | } |
| 496 | std::stable_sort(dictionary.begin(), dictionary.end()); |
| 497 | |
| 498 | inflections.clear(); |
| 499 | stream.seekg(0); |
| 500 | BlockMarkupIterator savedInflections(stream, Array<std::string_view>{ "|ROOT|", "|INFLECTS TO|", "|NAME|" }); |
| 501 | while (auto read = savedInflections.Next()) |
| 502 | { |
| 503 | const auto& [root, inflectsTo, name] = read.value(); |
| 504 | if (!inflections.emplace_back(Inflection{ |
| 505 | S(root), |
| 506 | QRegularExpression(QRegularExpression::anchoredPattern(S(inflectsTo)), QRegularExpression::UseUnicodePropertiesOption), |
| 507 | S(name) |
| 508 | }).inflectsTo.isValid()) TEXTRACTOR_MESSAGE(L"Invalid regex: %s", StringToWideString(inflectsTo)); |
| 509 | } |
nothing calls this directly
no outgoing calls
no test coverage detected