From eed4c5301e66fa6e24b20f90d0772f4c228407ea Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 8 Jan 2009 17:14:20 +0000 Subject: [PATCH] - Added some calls to assert_tagged - The tag_contents script function now works as advertised: - uses 'input' script variable instead of 'contents' - keeps the full old tag, not the one from 'tag' - no template code in svn breaks. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1303 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/keyword.cpp | 2 ++ src/script/functions/basic.cpp | 26 ++++++++++++++++---------- src/script/functions/english.cpp | 1 + src/script/functions/spelling.cpp | 1 + 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/data/keyword.cpp b/src/data/keyword.cpp index bdc9ab4f..1dc898e3 100644 --- a/src/data/keyword.cpp +++ b/src/data/keyword.cpp @@ -404,6 +404,7 @@ String KeywordDatabase::expand(const String& text, const ScriptValueP& combine_script, Context& ctx) const { assert(combine_script); + assert_tagged(text); // Clean up usage statistics KeywordUsageStatistics* stat = keyword_usage_statistics(); @@ -505,6 +506,7 @@ String KeywordDatabase::expand(const String& text, matched_keyword:; } + assert_tagged(result); return result; } diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index d7f9ba3a..fe25e939 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -324,25 +324,29 @@ SCRIPT_FUNCTION(sort_text) { /// Replace the contents of a specific tag with the value of a script function String replace_tag_contents(String input, const String& tag, const ScriptValueP& contents, Context& ctx) { + assert_tagged(input); String ret; - size_t pos = input.find(tag); + size_t start = 0, pos = input.find(tag); while (pos != String::npos) { // find end of tag and contents - size_t end = match_close_tag(input, pos); + size_t after = skip_tag(input, pos); + size_t end = match_close_tag(input, pos); + size_t after_end = skip_tag(input, end); if (end == String::npos) break; // missing close tag // prepare for call - String old_contents = input.substr(pos + tag.size(), end - (pos + tag.size())); - ctx.setVariable(_("contents"), to_script(old_contents)); + String old_contents = input.substr(after, end - after); + ctx.setVariable(SCRIPT_VAR_input, to_script(old_contents)); // replace - ret += input.substr(0, pos); // before tag - ret += tag; + ret.append(input, start, after-start); // before and including tag ret += contents->eval(ctx)->toString();// new contents (call) - ret += close_tag(tag); + ret.append(input, end, after_end-end); // close tag // next - input = input.substr(skip_tag(input,end)); - pos = input.find(tag); + start = after_end; + pos = input.find(tag, start); } - return ret + input; + ret.append(input, start, pos-start); + assert_tagged(ret); + return ret; } // Replace the contents of a specific tag @@ -356,11 +360,13 @@ SCRIPT_FUNCTION(tag_contents) { SCRIPT_FUNCTION(remove_tag) { SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(String, tag); + assert_tagged(input); SCRIPT_RETURN(remove_tag(input, tag)); } SCRIPT_FUNCTION(remove_tags) { SCRIPT_PARAM_C(String, input); + assert_tagged(input); SCRIPT_RETURN(untag_no_escape(input)); } diff --git a/src/script/functions/english.cpp b/src/script/functions/english.cpp index 9d1f7cb4..e561e1f2 100644 --- a/src/script/functions/english.cpp +++ b/src/script/functions/english.cpp @@ -310,6 +310,7 @@ String process_english_hints(const String& str) { SCRIPT_FUNCTION(process_english_hints) { SCRIPT_PARAM_C(String, input); + assert_tagged(input); SCRIPT_RETURN(process_english_hints(input)); } diff --git a/src/script/functions/spelling.cpp b/src/script/functions/spelling.cpp index 0e2babc7..a046210b 100644 --- a/src/script/functions/spelling.cpp +++ b/src/script/functions/spelling.cpp @@ -91,6 +91,7 @@ void check_word(const String& tag, const String& input, String& out, Char sep, s SCRIPT_FUNCTION(check_spelling) { SCRIPT_PARAM_C(String,language); SCRIPT_PARAM_C(String,input); + assert_tagged(input); SCRIPT_OPTIONAL_PARAM_N_(String,_("extra dictionary"),extra_dictionary); SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP,_("extra match"),extra_match); // remove old spelling error tags