- 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
This commit is contained in:
twanvl
2009-01-08 17:14:20 +00:00
parent f134edb09d
commit eed4c5301e
4 changed files with 20 additions and 10 deletions
+16 -10
View File
@@ -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));
}
+1
View File
@@ -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));
}
+1
View File
@@ -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