mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
More strict matching of tags: <blah> doesn't count as <b> anymore
This commit is contained in:
@@ -253,6 +253,15 @@ String::const_iterator find_close_tag(String::const_iterator tag, String::const_
|
||||
return String::npos;
|
||||
}
|
||||
|
||||
// don't mistake <tag> as <t>, only <t>, <t-stuff> and <t:stuff> are considered <t>
|
||||
bool is_tag_end_char(Char c) {
|
||||
return c == '>' || c == '-' || c == ':' || c == ' ';
|
||||
}
|
||||
|
||||
bool is_tag(const String& str, size_t pos, const String& tag) {
|
||||
return is_substr(str, pos, tag) && pos+tag.size() < str.size() && is_tag_end_char(str[pos+tag.size()]);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t in_tag(const String& str, const String& tag, size_t start, size_t end) {
|
||||
size_t last_start = String::npos;
|
||||
size_t size = str.size();
|
||||
@@ -261,10 +270,10 @@ String::const_iterator find_close_tag(String::const_iterator tag, String::const_
|
||||
for (size_t pos = 0 ; pos < end ; ) {
|
||||
Char c = str.GetChar(pos);
|
||||
if (c == _('<')) {
|
||||
if (is_substr(str, pos + 1, static_cast<const Char*>(tag.c_str())+1)) {
|
||||
if (is_substr(str, pos + 1, static_cast<const Char*>(tag.c_str())+1) && pos+tag.size() < str.size() && is_tag_end_char(str[pos+tag.size()])) {
|
||||
if (pos < start) last_start = pos;
|
||||
++taglevel;
|
||||
} else if (pos + 2 < size && str.GetChar(pos+1) == _('/') && is_substr(str, pos + 2, static_cast<const Char*>(tag.c_str())+1)) {
|
||||
} else if (pos + 2 < size && str.GetChar(pos+1) == _('/') && is_substr(str, pos + 2, static_cast<const Char*>(tag.c_str())+1) && pos+1+tag.size() < str.size() && is_tag_end_char(str[pos+1+tag.size()])) {
|
||||
--taglevel; // close tag
|
||||
}
|
||||
pos = skip_tag(str,pos);
|
||||
|
||||
@@ -72,6 +72,10 @@ String fix_old_tags(const String&);
|
||||
/** If not found returns String::npos */
|
||||
[[nodiscard]] size_t last_start_tag_before(const String& str, const String& tag, size_t start);
|
||||
|
||||
/// Does a string contain a tag at the given location?
|
||||
/** Only matches if the tag ends one of ">-: " */
|
||||
[[nodiscard]] bool is_tag(const String& str, size_t pos, const String& tag);
|
||||
|
||||
/// Is the given range entirely contained in a given tagged block?
|
||||
/** If so: return the start position of that tag, otherwise returns String::npos
|
||||
* A tagged block is everything between <tag>...</tag>
|
||||
|
||||
Reference in New Issue
Block a user