mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Fix in_tag and is_tag calls, fixes #47
This commit is contained in:
@@ -203,7 +203,7 @@ unique_ptr<TextValueAction> typing_action(const TextValueP& value, size_t start_
|
||||
TextToggleReminderAction::TextToggleReminderAction(const TextValueP& value, size_t pos_in)
|
||||
: ValueAction(value)
|
||||
{
|
||||
pos = in_tag(value->value(), _("<kw-"), pos_in, pos_in);
|
||||
pos = in_tag(value->value(), _("<kw"), pos_in, pos_in);
|
||||
if (pos == String::npos) {
|
||||
throw InternalError(_("TextToggleReminderAction: not in <kw- tag"));
|
||||
}
|
||||
|
||||
@@ -531,9 +531,9 @@ String expand_keywords(const String& tagged_str, vector<KeywordMatch> const& mat
|
||||
} else {
|
||||
bool is_close = (it+1) != end && *(it+1) == '/';
|
||||
if (is_close && !close || !is_close && !open) return;
|
||||
if (is_substr(it, end, "<atom")) {
|
||||
if (is_tag(it, end, "<atom")) {
|
||||
atom++;
|
||||
} else if (is_substr(it, end, "</atom")) {
|
||||
} else if (is_tag(it, end, "</atom")) {
|
||||
atom++;
|
||||
}
|
||||
// keep tag in output
|
||||
@@ -602,7 +602,7 @@ String::const_iterator keyword_match_detail(String::const_iterator it, String::c
|
||||
// The even captures are parameter values, the odd ones are the plain text in between
|
||||
// submatch 0 is the whole match
|
||||
assert(match.size() - 1 == 1 + 2 * keyword.parameters.size());
|
||||
for (int sub = 1; sub < match.size(); ++sub) {
|
||||
for (int sub = 1; sub < (int)match.size(); ++sub) {
|
||||
// The matched part, indices in untagged string. We only need the length
|
||||
size_t part_len_untagged = match.length(sub);
|
||||
// Translate back to tagged position
|
||||
|
||||
@@ -553,7 +553,7 @@ void TextValueEditor::onLoseFocus() {
|
||||
|
||||
bool TextValueEditor::onContextMenu(wxMenu& m, wxContextMenuEvent& ev) {
|
||||
// in a keword? => "reminder text" option
|
||||
size_t kwpos = in_tag(value().value(), _("<kw-"), selection_start_i, selection_start_i);
|
||||
size_t kwpos = in_tag(value().value(), _("<kw"), selection_start_i, selection_start_i);
|
||||
if (kwpos != String::npos) {
|
||||
m.InsertSeparator(0);
|
||||
m.Insert(0, make_menu_item_tr(&m, ID_FORMAT_REMINDER, "reminder", "reminder_text", wxITEM_CHECK));
|
||||
|
||||
@@ -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