mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Added regex_escape script function (was already used by keyword code);
Added icons for 'sort special rarity' choice. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@625 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+50
-1
@@ -384,4 +384,53 @@ String clean_filename(const String& name) {
|
||||
clean = _("no-name") + clean;
|
||||
}
|
||||
return clean;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Regular expressions
|
||||
|
||||
/// Escape a single character for use in regular expressions
|
||||
String regex_escape(Char c) {
|
||||
if (c == _('(') || c == _(')') || c == _('[') || c == _(']') || c == _('{') ||
|
||||
c == _('.') || c == _('^') || c == _('$') || c == _('#') || c == _('\\') ||
|
||||
c == _('|') || c == _('+') || c == _('*') || c == _('?')) {
|
||||
// c needs to be escaped
|
||||
return _("\\") + String(1,c);
|
||||
} else {
|
||||
return String(1,c);
|
||||
}
|
||||
}
|
||||
/// Escape a string for use in regular expressions
|
||||
String regex_escape(const String& s) {
|
||||
String ret;
|
||||
FOR_EACH_CONST(c,s) ret += regex_escape(c);
|
||||
return ret;
|
||||
}
|
||||
|
||||
String make_non_capturing(const String& re) {
|
||||
String ret;
|
||||
bool escape = false, bracket = false, capture = false;
|
||||
FOR_EACH_CONST(c, re) {
|
||||
if (capture && c != _('?')) {
|
||||
// change this capture into a non-capturing "(" by appending "?:"
|
||||
ret += _("?:");
|
||||
capture = false;
|
||||
}
|
||||
if (escape) { // second char of escape sequence
|
||||
escape = false;
|
||||
} else if (c == _('\\')) { // start of escape sequence
|
||||
escape = true;
|
||||
} else if (c == _('[')) { // start of [...]
|
||||
bracket = true;
|
||||
} else if (c == _(']')) { // end of [...]
|
||||
bracket = false;
|
||||
} else if (bracket && c == _('(')) {
|
||||
// wx has a bug, it counts the '(' in "[(]" as a matching group
|
||||
// escape it so wx doesn't see it
|
||||
ret += _('\\');
|
||||
} else if (c == _('(')) { // start of capture?
|
||||
capture = true;
|
||||
}
|
||||
ret += c;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user