mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
Fix in_tag and is_tag calls, fixes #47
This commit is contained in:
@@ -23,6 +23,12 @@ wxUniChar tag_char(wxUniChar c) {
|
||||
else return c;
|
||||
}
|
||||
|
||||
// Is a character the "end" of the tag name?
|
||||
// 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 == ' ';
|
||||
}
|
||||
|
||||
|
||||
String untag(const String& str) {
|
||||
bool in_tag = false;
|
||||
@@ -156,6 +162,14 @@ String fix_old_tags(const String& str) {
|
||||
return skip_all_tags(it, end, after_open, after_close);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool is_tag(String::const_iterator it, String::const_iterator end, const char* tag) {
|
||||
for (; *tag; ++it, ++tag) {
|
||||
if (it == end || *it != *tag) return false;
|
||||
}
|
||||
if (it == end || !is_tag_end_char(*it)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
// Does the string [it..end) contain the matching close tag for [tag..tag_end)?
|
||||
bool is_close_tag(String::const_iterator it, String::const_iterator end, String::const_iterator tag, String::const_iterator tag_end) {
|
||||
@@ -253,11 +267,6 @@ 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()]);
|
||||
}
|
||||
|
||||
@@ -119,6 +119,12 @@ String anti_tag(const String& tag);
|
||||
// If not found, returns end
|
||||
[[nodiscard]] String::const_iterator find_close_tag(String::const_iterator it, String::const_iterator end);
|
||||
|
||||
/// Does a string contain a tag at the given location?
|
||||
/** Only matches if the tag in the text ends one of ">-: "
|
||||
* tag should be "<tag" or "</tag"
|
||||
*/
|
||||
[[nodiscard]] bool is_tag(String::const_iterator it, String::const_iterator end, const char* tag);
|
||||
|
||||
// Length of a string when not counting tags
|
||||
// For example: untagged_length("<b>abc</b>",_) = 3
|
||||
[[nodiscard]] size_t untagged_length(String::const_iterator it, String::const_iterator end);
|
||||
|
||||
Reference in New Issue
Block a user