This source file includes following definitions.
- Init
- OnCustomDictionaryChanged
- SpellCheckWord
#include "chrome/renderer/spellchecker/custom_dictionary_engine.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
CustomDictionaryEngine::CustomDictionaryEngine() {
}
CustomDictionaryEngine::~CustomDictionaryEngine() {
}
void CustomDictionaryEngine::Init(const std::set<std::string>& custom_words) {
for (std::set<std::string>::const_iterator it = custom_words.begin();
it != custom_words.end();
++it) {
dictionary_.insert(base::UTF8ToUTF16(*it));
}
}
void CustomDictionaryEngine::OnCustomDictionaryChanged(
const std::vector<std::string>& words_added,
const std::vector<std::string>& words_removed) {
for (std::vector<std::string>::const_iterator it = words_added.begin();
it != words_added.end();
++it) {
dictionary_.insert(base::UTF8ToUTF16(*it));
}
for (std::vector<std::string>::const_iterator it = words_removed.begin();
it != words_removed.end();
++it) {
dictionary_.erase(base::UTF8ToUTF16(*it));
}
}
bool CustomDictionaryEngine::SpellCheckWord(
const base::string16& text,
int misspelling_start,
int misspelling_len) {
return
misspelling_start >= 0 &&
misspelling_len > 0 &&
size_t(misspelling_start + misspelling_len) <= text.length() &&
dictionary_.count(text.substr(misspelling_start, misspelling_len)) > 0;
}