mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 05:36:59 -04:00
added check_tagged function that verifies that a tagged string is correct, this helps with debugging.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1302 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -571,6 +571,38 @@ String simplify_tagged_overlap(const String& str) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Verification
|
||||||
|
|
||||||
|
void check_tagged(const String& str) {
|
||||||
|
for (size_t i = 0 ; i < str.size() ; ) {
|
||||||
|
if (str.GetChar(i) == _('<')) {
|
||||||
|
size_t end = skip_tag(str,i);
|
||||||
|
if (end == String::npos) {
|
||||||
|
handle_warning(_("Invalid tagged string: missing '>'"),false);
|
||||||
|
}
|
||||||
|
for (size_t j = i + 1 ; j + 1 < end ; ++j) {
|
||||||
|
Char c = str.GetChar(j);
|
||||||
|
if (c == _(' ') || c == _('<')) {
|
||||||
|
handle_warning(_("Invalid character in tag"),false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (str.GetChar(i+1) == _('/')) {
|
||||||
|
// close tag, don't check
|
||||||
|
} else if (is_substr(str,i,_("<hint"))) {
|
||||||
|
// no close tag for <hint> tags
|
||||||
|
} else {
|
||||||
|
size_t close = match_close_tag(str,i);
|
||||||
|
if (close == String::npos) {
|
||||||
|
handle_warning(_("Invalid tagged string: missing close tag for <") + tag_at(str,i) + _(">"),false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i = end;
|
||||||
|
} else {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Other utilities
|
// ----------------------------------------------------------------------------- : Other utilities
|
||||||
|
|
||||||
String curly_quotes(String str, bool curl) {
|
String curly_quotes(String str, bool curl) {
|
||||||
|
|||||||
@@ -175,12 +175,20 @@ String tagged_substr_replace(const String& input, size_t start, size_t end, cons
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Simplification
|
// ----------------------------------------------------------------------------- : Simplification
|
||||||
|
|
||||||
/// Verify that a string is correctly tagged, if it is not, change it so it is
|
/// Verify that a string is correctly tagged
|
||||||
/** Ensures that:
|
/** Ensures that:
|
||||||
* - All tags end, i.e. for each '<' there is a matching '>'
|
* - All tags end, i.e. for each '<' there is a matching '>'
|
||||||
* - There are no tags containing '<'
|
* - There are no tags containing '<' or whitespace
|
||||||
|
* - For each open tag there is a matching close tag.
|
||||||
|
*
|
||||||
|
* In case of an error, throws an exception.
|
||||||
*/
|
*/
|
||||||
String verify_tagged(const String& str);
|
void check_tagged(const String& str);
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define assert_tagged check_tagged
|
||||||
|
#else
|
||||||
|
#define assert_tagged(_)
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Simplify a tagged string
|
/// Simplify a tagged string
|
||||||
/** - merges adjecent open/close tags: "<tag></tag>" --> ""
|
/** - merges adjecent open/close tags: "<tag></tag>" --> ""
|
||||||
|
|||||||
Reference in New Issue
Block a user