41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
#pragma once
|
|
#include "platform.h"
|
|
#include <map>
|
|
#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
|
|
{
|
|
struct Dictionary
|
|
{
|
|
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, Dictionary> dictionaries;
|
|
std::vector<std::wstring> languages;
|
|
std::set<std::wstring> rejected;
|
|
|
|
public:
|
|
void configure(const std::filesystem::path &, const std::vector<std::wstring> &);
|
|
std::optional<AutoSuggestion> suggest(const std::wstring &, int source, const std::vector<Layout> &,
|
|
const Settings &) const;
|
|
void reject(std::wstring word, const Settings & = {});
|
|
size_t memoryBytes() const;
|
|
};
|
|
} // namespace ks
|