mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 21:27:01 -04:00
slightly less tagged string checking
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1304 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -324,7 +324,7 @@ 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);
|
assert_tagged(input, false);
|
||||||
String ret;
|
String ret;
|
||||||
size_t start = 0, pos = input.find(tag);
|
size_t start = 0, pos = input.find(tag);
|
||||||
while (pos != String::npos) {
|
while (pos != String::npos) {
|
||||||
@@ -345,7 +345,7 @@ String replace_tag_contents(String input, const String& tag, const ScriptValueP&
|
|||||||
pos = input.find(tag, start);
|
pos = input.find(tag, start);
|
||||||
}
|
}
|
||||||
ret.append(input, start, pos-start);
|
ret.append(input, start, pos-start);
|
||||||
assert_tagged(ret);
|
assert_tagged(ret, false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,13 +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);
|
assert_tagged(input, false);
|
||||||
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);
|
assert_tagged(input, false);
|
||||||
SCRIPT_RETURN(untag_no_escape(input));
|
SCRIPT_RETURN(untag_no_escape(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -573,7 +573,7 @@ String simplify_tagged_overlap(const String& str) {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Verification
|
// ----------------------------------------------------------------------------- : Verification
|
||||||
|
|
||||||
void check_tagged(const String& str) {
|
void check_tagged(const String& str, bool check_balance) {
|
||||||
for (size_t i = 0 ; i < str.size() ; ) {
|
for (size_t i = 0 ; i < str.size() ; ) {
|
||||||
if (str.GetChar(i) == _('<')) {
|
if (str.GetChar(i) == _('<')) {
|
||||||
size_t end = skip_tag(str,i);
|
size_t end = skip_tag(str,i);
|
||||||
@@ -586,14 +586,16 @@ void check_tagged(const String& str) {
|
|||||||
handle_warning(_("Invalid character in tag"),false);
|
handle_warning(_("Invalid character in tag"),false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (str.GetChar(i+1) == _('/')) {
|
if (check_balance) {
|
||||||
// close tag, don't check
|
if (str.GetChar(i+1) == _('/')) {
|
||||||
} else if (is_substr(str,i,_("<hint"))) {
|
// close tag, don't check
|
||||||
// no close tag for <hint> tags
|
} else if (is_substr(str,i,_("<hint"))) {
|
||||||
} else {
|
// no close tag for <hint> tags
|
||||||
size_t close = match_close_tag(str,i);
|
} else {
|
||||||
if (close == String::npos) {
|
size_t close = match_close_tag(str,i);
|
||||||
handle_warning(_("Invalid tagged string: missing close tag for <") + tag_at(str,i) + _(">"),false);
|
if (close == String::npos) {
|
||||||
|
handle_warning(_("Invalid tagged string: missing close tag for <") + tag_at(str,i) + _(">"),false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i = end;
|
i = end;
|
||||||
|
|||||||
@@ -183,11 +183,11 @@ String tagged_substr_replace(const String& input, size_t start, size_t end, cons
|
|||||||
*
|
*
|
||||||
* In case of an error, throws an exception.
|
* In case of an error, throws an exception.
|
||||||
*/
|
*/
|
||||||
void check_tagged(const String& str);
|
void check_tagged(const String& str, bool check_balance = true);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define assert_tagged check_tagged
|
#define assert_tagged check_tagged
|
||||||
#else
|
#else
|
||||||
#define assert_tagged(_)
|
#define assert_tagged(_,_)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Simplify a tagged string
|
/// Simplify a tagged string
|
||||||
|
|||||||
Reference in New Issue
Block a user