49 lines
1.9 KiB
C++
49 lines
1.9 KiB
C++
#pragma once
|
|
#include "platform.h"
|
|
#include <map>
|
|
#include <memory>
|
|
#include <set>
|
|
#include <string_view>
|
|
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<Layout> &, 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<uint32_t> offsets;
|
|
std::string_view word(size_t) const;
|
|
explicit Dictionary(const std::filesystem::path &);
|
|
int rank(const std::wstring &) const;
|
|
};
|
|
std::map<std::wstring, std::shared_ptr<const Dictionary>> dictionaries;
|
|
std::vector<std::wstring> languages;
|
|
std::set<std::wstring> rejected;
|
|
|
|
public:
|
|
void configure(const std::filesystem::path &, const std::vector<std::wstring> &);
|
|
// Share immutable dictionary storage, keeping each consumer's undo rejections private.
|
|
void shareDictionaries(const AutoCorrector &);
|
|
std::optional<AutoSuggestion> suggest(const std::wstring &, int source, const std::vector<Layout> &,
|
|
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
|