Commit 17cfc132 authored by twanvl's avatar twanvl

- 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.
parent 7285deb2
...@@ -404,6 +404,7 @@ String KeywordDatabase::expand(const String& text, ...@@ -404,6 +404,7 @@ String KeywordDatabase::expand(const String& text,
const ScriptValueP& combine_script, const ScriptValueP& combine_script,
Context& ctx) const { Context& ctx) const {
assert(combine_script); assert(combine_script);
assert_tagged(text);
// Clean up usage statistics // Clean up usage statistics
KeywordUsageStatistics* stat = keyword_usage_statistics(); KeywordUsageStatistics* stat = keyword_usage_statistics();
...@@ -505,6 +506,7 @@ String KeywordDatabase::expand(const String& text, ...@@ -505,6 +506,7 @@ String KeywordDatabase::expand(const String& text,
matched_keyword:; matched_keyword:;
} }
assert_tagged(result);
return result; return result;
} }
......
...@@ -324,25 +324,29 @@ SCRIPT_FUNCTION(sort_text) { ...@@ -324,25 +324,29 @@ SCRIPT_FUNCTION(sort_text) {
/// Replace the contents of a specific tag with the value of a script function /// 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) { String replace_tag_contents(String input, const String& tag, const ScriptValueP& contents, Context& ctx) {
assert_tagged(input);
String ret; String ret;
size_t pos = input.find(tag); size_t start = 0, pos = input.find(tag);
while (pos != String::npos) { while (pos != String::npos) {
// find end of tag and contents // 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 if (end == String::npos) break; // missing close tag
// prepare for call // prepare for call
String old_contents = input.substr(pos + tag.size(), end - (pos + tag.size())); String old_contents = input.substr(after, end - after);
ctx.setVariable(_("contents"), to_script(old_contents)); ctx.setVariable(SCRIPT_VAR_input, to_script(old_contents));
// replace // replace
ret += input.substr(0, pos); // before tag ret.append(input, start, after-start); // before and including tag
ret += tag;
ret += contents->eval(ctx)->toString();// new contents (call) ret += contents->eval(ctx)->toString();// new contents (call)
ret += close_tag(tag); ret.append(input, end, after_end-end); // close tag
// next // next
input = input.substr(skip_tag(input,end)); start = after_end;
pos = input.find(tag); 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 // Replace the contents of a specific tag
...@@ -356,11 +360,13 @@ SCRIPT_FUNCTION(tag_contents) { ...@@ -356,11 +360,13 @@ SCRIPT_FUNCTION(tag_contents) {
SCRIPT_FUNCTION(remove_tag) { SCRIPT_FUNCTION(remove_tag) {
SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(String, input);
SCRIPT_PARAM_C(String, tag); SCRIPT_PARAM_C(String, tag);
assert_tagged(input);
SCRIPT_RETURN(remove_tag(input, tag)); SCRIPT_RETURN(remove_tag(input, tag));
} }
SCRIPT_FUNCTION(remove_tags) { SCRIPT_FUNCTION(remove_tags) {
SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(String, input);
assert_tagged(input);
SCRIPT_RETURN(untag_no_escape(input)); SCRIPT_RETURN(untag_no_escape(input));
} }
......
...@@ -310,6 +310,7 @@ String process_english_hints(const String& str) { ...@@ -310,6 +310,7 @@ String process_english_hints(const String& str) {
SCRIPT_FUNCTION(process_english_hints) { SCRIPT_FUNCTION(process_english_hints) {
SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(String, input);
assert_tagged(input);
SCRIPT_RETURN(process_english_hints(input)); SCRIPT_RETURN(process_english_hints(input));
} }
......
...@@ -91,6 +91,7 @@ void check_word(const String& tag, const String& input, String& out, Char sep, s ...@@ -91,6 +91,7 @@ void check_word(const String& tag, const String& input, String& out, Char sep, s
SCRIPT_FUNCTION(check_spelling) { SCRIPT_FUNCTION(check_spelling) {
SCRIPT_PARAM_C(String,language); SCRIPT_PARAM_C(String,language);
SCRIPT_PARAM_C(String,input); SCRIPT_PARAM_C(String,input);
assert_tagged(input);
SCRIPT_OPTIONAL_PARAM_N_(String,_("extra dictionary"),extra_dictionary); SCRIPT_OPTIONAL_PARAM_N_(String,_("extra dictionary"),extra_dictionary);
SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP,_("extra match"),extra_match); SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP,_("extra match"),extra_match);
// remove old spelling error tags // remove old spelling error tags
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment