mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
apply spelling corrections from the context menu.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1274 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : Functions
|
||||
|
||||
inline bool spelled_correctly(const String& input, size_t start, size_t end, SpellChecker** checkers, const ScriptValueP& extra_test, Context& ctx) {
|
||||
inline size_t spelled_correctly(const String& input, size_t start, size_t end, SpellChecker** checkers, const ScriptValueP& extra_test, Context& ctx) {
|
||||
// untag
|
||||
String word = untag(input.substr(start,end-start));
|
||||
if (word.empty()) return true;
|
||||
@@ -36,8 +36,8 @@ inline bool spelled_correctly(const String& input, size_t start, size_t end, Spe
|
||||
// run through spellchecker(s)
|
||||
word.erase(end_u,String::npos);
|
||||
word.erase(0,start_u);
|
||||
for (SpellChecker** c = checkers ; *c ; ++c) {
|
||||
if ((*c)->spell(word)) {
|
||||
for (size_t i = 0 ; checkers[i] ; ++i) {
|
||||
if (checkers[i]->spell(word)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -51,12 +51,12 @@ inline bool spelled_correctly(const String& input, size_t start, size_t end, Spe
|
||||
return false;
|
||||
}
|
||||
|
||||
void check_word(const String& input, String& out, size_t start, size_t end, SpellChecker** checkers, const ScriptValueP& extra_test, Context& ctx) {
|
||||
void check_word(const String& tag, const String& input, String& out, size_t start, size_t end, SpellChecker** checkers, const ScriptValueP& extra_test, Context& ctx) {
|
||||
if (start >= end) return;
|
||||
bool good = spelled_correctly(input, start, end, checkers, extra_test, ctx);
|
||||
if (!good) out += _("<error-spelling>");
|
||||
if (!good) out += _("<") + tag;
|
||||
out.append(input, start, end-start);
|
||||
if (!good) out += _("</error-spelling>");
|
||||
if (!good) out += _("</") + tag;
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(check_spelling) {
|
||||
@@ -75,6 +75,13 @@ SCRIPT_FUNCTION(check_spelling) {
|
||||
if (!extra_dictionary.empty()) {
|
||||
checkers[1] = &SpellChecker::get(extra_dictionary,language);
|
||||
}
|
||||
// what will the missspelling tag be?
|
||||
String tag = _("error-spelling:");
|
||||
tag += language;
|
||||
if (!extra_dictionary.empty()) {
|
||||
tag += _(":") + extra_dictionary;
|
||||
}
|
||||
tag += _(">");
|
||||
// now walk over the words in the input, and mark misspellings
|
||||
String result;
|
||||
size_t word_start = 0, word_end = 0, pos = 0;
|
||||
@@ -91,7 +98,7 @@ SCRIPT_FUNCTION(check_spelling) {
|
||||
}
|
||||
} else if (isSpace(c) || c == EM_DASH || c == EN_DASH) {
|
||||
// word boundary -> check word
|
||||
check_word(input, result, word_start, word_end, checkers, extra_match, ctx);
|
||||
check_word(tag, input, result, word_start, word_end, checkers, extra_match, ctx);
|
||||
// non-word characters
|
||||
result.append(input, word_end, pos - word_end + 1);
|
||||
// next
|
||||
@@ -101,7 +108,7 @@ SCRIPT_FUNCTION(check_spelling) {
|
||||
}
|
||||
}
|
||||
// last word
|
||||
check_word(input, result, word_start, word_end, checkers, extra_match, ctx);
|
||||
check_word(tag, input, result, word_start, word_end, checkers, extra_match, ctx);
|
||||
result.append(input, word_end, String::npos);
|
||||
// done
|
||||
SCRIPT_RETURN(result);
|
||||
|
||||
Reference in New Issue
Block a user