-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpellChecker.h
55 lines (39 loc) · 1.48 KB
/
SpellChecker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2015-2017 mogemimi. Distributed under the MIT license.
#pragma once
#include <cstdint>
#include <unordered_map>
#include <string>
#include <vector>
namespace typopoi {
struct SpellCheckResult {
std::vector<std::string> suggestions;
///@brief `true` if the word is correctly spelled; `false` otherwise.
bool correctlySpelled;
};
class SpellChecker {
public:
///@brief Add a word to dictionary.
///@param word UTF-8 encoded string
SpellCheckResult Suggest(const std::string& word);
///@brief Add a word to dictionary.
///@param word UTF-8 encoded string
void AddWord(const std::string& word);
///@brief Remove a word from dictionary.
///@param word UTF-8 encoded string
void RemoveWord(const std::string& word);
private:
std::unordered_map<uint32_t, std::vector<std::u32string>> hashedDictionary;
};
///@brief Convert a UTF-8 encoded string into a UTF-32 encoded string.
std::u32string ToUtf32(const std::string& utf8);
///@brief Convert a UTF-32 encoded string into a UTF-8 encoded string.
std::string ToUtf8(const std::u32string& utf32);
///@brief islower() function for UTF-32 encoding.
bool IsLowerUtf32(char32_t c) noexcept;
///@brief isupper() function for UTF-32 encoding.
bool IsUpperUtf32(char32_t c) noexcept;
///@brief tolower() function for UTF-32 encoding.
char32_t ToLowerUtf32(char32_t c) noexcept;
///@brief toupper() function for UTF-32 encoding.
char32_t ToUpperUtf32(char32_t c) noexcept;
} // namespace typopoi