Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit ad3e2d9

Browse files
committed
Add windows impl for Spellchecker::CheckSpelling
1 parent 4e1592c commit ad3e2d9

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/spellchecker_win.cc

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ WindowsSpellchecker::~WindowsSpellchecker() {
7878
this->currentSpellchecker->Release();
7979
this->currentSpellchecker = NULL;
8080
}
81-
81+
8282
if (this->spellcheckerFactory) {
8383
this->spellcheckerFactory->Release();
8484
this->spellcheckerFactory = NULL;
@@ -187,6 +187,36 @@ bool WindowsSpellchecker::IsMisspelled(const std::string& word) {
187187
return ret;
188188
}
189189

190+
std::vector<MisspelledRange> WindowsSpellchecker::CheckSpelling(const char *text, size_t length) {
191+
std::vector<MisspelledRange> result;
192+
193+
if (this->currentSpellchecker == NULL) {
194+
return result;
195+
}
196+
197+
IEnumSpellingError* errors = NULL;
198+
std::wstring wtext = ToWString(text);
199+
if (FAILED(this->currentSpellchecker->Check(wtext.c_str(), &errors))) {
200+
return result;
201+
}
202+
203+
ISpellingError *error;
204+
while (errors->Next(&error) == S_OK) {
205+
ULONG start, length;
206+
error->get_StartIndex(&start);
207+
error->get_Length(&length);
208+
209+
MisspelledRange range;
210+
range.start = start;
211+
range.end = start + length;
212+
result.push_back(range);
213+
error->Release();
214+
}
215+
216+
errors->Release();
217+
return result;
218+
}
219+
190220
void WindowsSpellchecker::Add(const std::string& word) {
191221
if (this->currentSpellchecker == NULL) {
192222
return;

src/spellchecker_win.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class WindowsSpellchecker : public SpellcheckerImplementation {
1818

1919
std::vector<std::string> GetCorrectionsForMisspelling(const std::string& word);
2020
bool IsMisspelled(const std::string& word);
21+
std::vector<MisspelledRange> CheckSpelling(const char *text, size_t length);
2122
void Add(const std::string& word);
2223

2324
private:

0 commit comments

Comments
 (0)