#pragma once #include "platform.h" #include #include #include #include namespace ks { struct AutoSuggestion { int source{-1}, target{-1}; std::wstring text; }; std::wstring layoutLanguage(const Layout &); bool safeAutoWord(const std::wstring &, int minimumLength = 3); bool autoClosingSelection(const std::wstring &, const Settings & = {}); int matchAutoInput(const Run &, const std::wstring &, const std::vector &, const Layout &, const Settings & = {}); bool autoCorrectionAllowed(HWND, const Settings &); class AutoCorrector { friend struct AutoCorrectorRegressionAccess; struct Dictionary { // Front-coded UTF-8 words in independently searchable blocks of 32. // Prefix/suffix lengths share a byte (15 escapes to a full byte length). // Ranks use two bytes; 65535 escapes to a varint for larger custom ranks. std::string bytes; std::vector offsets; std::string_view word(size_t) const; explicit Dictionary(const std::filesystem::path &); int rank(const std::wstring &) const; }; std::map> dictionaries; std::vector languages; std::set rejected; public: void configure(const std::filesystem::path &, const std::vector &); // Share immutable dictionary storage, keeping each consumer's undo rejections private. void shareDictionaries(const AutoCorrector &); std::optional suggest(const std::wstring &, int source, const std::vector &, const Settings &) const; void reject(std::wstring word, const Settings & = {}); // Referenced dictionary payload, including shared storage (do not sum across consumers). size_t memoryBytes() const; }; } // namespace ks