summaryrefslogtreecommitdiffstats
path: root/src/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/util.cc b/src/util.cc
index 63bd2cd..f65dcb3 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -196,29 +196,35 @@ int64_t GetTimeMillis() {
#endif
}
-const char* SpellcheckString(const string& text, ...) {
+const char* SpellcheckStringV(const string& text,
+ const vector<const char*>& words) {
const bool kAllowReplacements = true;
const int kMaxValidEditDistance = 3;
- va_list ap;
- va_start(ap, text);
- const char* correct_spelling;
-
int min_distance = kMaxValidEditDistance + 1;
const char* result = NULL;
- while ((correct_spelling = va_arg(ap, const char*))) {
- int distance = EditDistance(
- correct_spelling, text, kAllowReplacements, kMaxValidEditDistance);
+ for (vector<const char*>::const_iterator i = words.begin();
+ i != words.end(); ++i) {
+ int distance = EditDistance(*i, text, kAllowReplacements,
+ kMaxValidEditDistance);
if (distance < min_distance) {
min_distance = distance;
- result = correct_spelling;
+ result = *i;
}
}
-
- va_end(ap);
return result;
}
+const char* SpellcheckString(const string& text, ...) {
+ va_list ap;
+ va_start(ap, text);
+ vector<const char*> words;
+ const char* word;
+ while ((word = va_arg(ap, const char*)))
+ words.push_back(word);
+ return SpellcheckStringV(text, words);
+}
+
#ifdef WIN32
string GetLastErrorString() {
DWORD err = GetLastError();