From 61136d79a858b5e7f4075ba4c3d8077f18f7cd21 Mon Sep 17 00:00:00 2001 From: twanvl Date: Fri, 24 Aug 2007 20:24:10 +0000 Subject: [PATCH] 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 --- data/magic.mse-game/game | 6 +++ .../icons/number_cards_after.png | Bin 0 -> 632 bytes .../icons/number_cards_mixed.png | Bin 0 -> 613 bytes .../icons/number_cards_separate.png | Bin 0 -> 628 bytes doc/function/index.txt | 1 + doc/type/style.txt | 5 +- src/data/keyword.cpp | 49 ----------------- src/script/functions/basic.cpp | 8 ++- src/util/string.cpp | 51 +++++++++++++++++- src/util/string.hpp | 11 ++++ .../drupal/mse-drupal-modules/highlight.inc | 1 + 11 files changed, 80 insertions(+), 52 deletions(-) create mode 100644 data/magic.mse-game/icons/number_cards_after.png create mode 100644 data/magic.mse-game/icons/number_cards_mixed.png create mode 100644 data/magic.mse-game/icons/number_cards_separate.png diff --git a/data/magic.mse-game/game b/data/magic.mse-game/game index 0cfc08f7..95e1c04d 100644 --- a/data/magic.mse-game/game +++ b/data/magic.mse-game/game @@ -598,6 +598,12 @@ default set style: automatic reminder text: render style: checklist direction: vertical + sort special rarity: + render style: both + choice images: + with the rest: /magic.mse-game/icons/number_cards_mixed.png + after other cards: /magic.mse-game/icons/number_cards_after.png + separate numbering: /magic.mse-game/icons/number_cards_separate.png use gradient multicolor: render style: both choice images: diff --git a/data/magic.mse-game/icons/number_cards_after.png b/data/magic.mse-game/icons/number_cards_after.png new file mode 100644 index 0000000000000000000000000000000000000000..180bc46eeab103b77faf1125cf00822592a67e27 GIT binary patch literal 632 zcmV-;0*C#HP)pF33NqRbVF}#ZDnqB004<9jRpV!0u@O_K~#90jZ$rE(@+%d&&pTJ z+TC_^e({6(Fpx3O3)4{)UzlP95ypn2W8K=diAj?*O>WYpW}WNQi7z-55y79+oO`{u zwW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V!0uf0>K~#90ty1r6(?A&RpOvqc zwYz3?e(}TdVIX6m2h&j$bxbjW2xG(1v2N|!#H2}@CYLseS?4-+;tw2(h~S^IzIWa= zbL*fE9UeT~-TS`x+;h*p8OB&<&zU9}u~?h2{ES~Opsqdz8SB;o+M4UoVaoG76vr_M zf?zNVh^(j|R`9{X7gM-S?2icuQW0#dWs$j& z!)_H34r-Khu(O&?3j_?qK$d0UR;%T495J0RUS+Xaq@*E(vo)DoQCrPQ`uc=oSMsX2BQt9=PqpV0u)T66 zbwYp;qKG+35*CIb_`VNZYR_RdEZuXRoSx;TL zX0Y;X8yYtfuoqva8s0qnDJ2iTC~oOc)$uNCmEO{L`3U+?f1GI$3}XHxgGi2L`0b>C zQO--&W)AW9EA3hVlSV-eHJL<4k##kh@_wOiwE%Wy68OJ?zMi9}P78w3_2~X0oZIlv zmbg`j`=^|EtMcaZxvxz0qwtnD8Ra#=YX_!j!g$sb1%IRB+=1lLS1DZjjJ&(=6>IST z>$s;@=Oa?N9LZPf#@g O0000 The script will be called with @input@ set to the value to determine an image for. | ^^^ @choice images@ [[type:map]] of [[type:image]]s An alternative way to specify what image to show.
For each [[type:choice]] a separate image is specified. +| ^^^ @content width@ [[type:double]] ''automatic'' When read from a script, gives the width of the current choice image in this box.
+ This is only useful when the alignment is changed, otherwise it is always equal the box size itself. +| ^^^ @content height@ [[type:double]] ''automatic'' When read from a script, gives the height of the current choice image in this box. | @"multiple choice"@ @direction@ [[type:direction]] @"left to right"@ Direction the items are layed out in, only when @render style@ is @list@. | ^^^ @spacing@ [[type:double]] @0@ Spacing between the items. diff --git a/src/data/keyword.cpp b/src/data/keyword.cpp index ca25a9e2..a86a28f6 100644 --- a/src/data/keyword.cpp +++ b/src/data/keyword.cpp @@ -157,55 +157,6 @@ size_t Keyword::findMode(const vector& modes) const { // ----------------------------------------------------------------------------- : Regex stuff -/// Make sure the given regex does no capturing -/** Basicly replaces "(" with "(?:" */ -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; -} - -/// 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; -} - void Keyword::prepare(const vector& param_types, bool force) { if (!force && match_re.IsValid()) return; parameters.clear(); diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index eb6079d2..926e65c6 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -114,6 +114,11 @@ SCRIPT_FUNCTION(curly_quotes) { SCRIPT_RETURN(input); } +// regex escape a string +SCRIPT_FUNCTION(regex_escape) { + SCRIPT_PARAM(String, input); + SCRIPT_RETURN(regex_escape(input)); +} // ----------------------------------------------------------------------------- : Tagged string @@ -593,6 +598,7 @@ void init_script_basic_functions(Context& ctx) { ctx.setVariable(_("format"), script_format); ctx.setVariable(_("format rule"), script_format_rule); ctx.setVariable(_("curly quotes"), script_curly_quotes); + ctx.setVariable(_("regex_escape"), script_regex_escape); // tagged string ctx.setVariable(_("tag contents"), script_tag_contents); ctx.setVariable(_("remove tag"), script_tag_remove); @@ -608,7 +614,7 @@ void init_script_basic_functions(Context& ctx) { ctx.setVariable(_("expand keywords"), script_expand_keywords); ctx.setVariable(_("expand keywords rule"), script_expand_keywords_rule); ctx.setVariable(_("keyword usage"), script_keyword_usage); - // advanced string rules + // advanced string rules/functions ctx.setVariable(_("replace"), script_replace); ctx.setVariable(_("filter text"), script_filter_text); ctx.setVariable(_("match"), script_match); diff --git a/src/util/string.cpp b/src/util/string.cpp index 5ae4036a..38def722 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -384,4 +384,53 @@ String clean_filename(const String& name) { clean = _("no-name") + clean; } return clean; -} \ No newline at end of file +} + +// ----------------------------------------------------------------------------- : 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; +} diff --git a/src/util/string.hpp b/src/util/string.hpp index 5b1c1f11..d6af3599 100644 --- a/src/util/string.hpp +++ b/src/util/string.hpp @@ -179,5 +179,16 @@ bool cannocial_name_compare(const String& a, const Char* b); /// Make sure a string is safe to use as a filename String clean_filename(const String& name); +// ----------------------------------------------------------------------------- : Regular expressions + +/// Escape a single character for use in regular expressions +String regex_escape(Char c); +/// Escape a string for use in regular expressions +String regex_escape(const String& s); + +/// Make sure the given regex does no capturing +/** Basicly replaces "(" with "(?:" */ +String make_non_capturing(const String& re); + // ----------------------------------------------------------------------------- : EOF #endif diff --git a/tools/website/drupal/mse-drupal-modules/highlight.inc b/tools/website/drupal/mse-drupal-modules/highlight.inc index 364c3130..dac6ea82 100644 --- a/tools/website/drupal/mse-drupal-modules/highlight.inc +++ b/tools/website/drupal/mse-drupal-modules/highlight.inc @@ -17,6 +17,7 @@ $built_in_functions = array( 'sort_text' =>'', 'sort_rule' => 'sort_text', 'contains' =>'', 'match' =>'', 'match_rule' => 'match', + 'regex_escape' =>'', // tags 'tag_contents' =>'', 'tag_contents_rule'=>'tag_contents', 'remove_tag' =>'', 'tag_remove_rule' =>'remove_tag',