Commit 7285deb2 authored by twanvl's avatar twanvl

added check_tagged function that verifies that a tagged string is correct,...

added check_tagged function that verifies that a tagged string is correct, this helps with debugging.
parent 23976ea1
......@@ -571,6 +571,38 @@ String simplify_tagged_overlap(const String& str) {
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
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
/// 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:
* - 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
/** - merges adjecent open/close tags: "<tag></tag>" --> ""
......
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