diff --git a/src/data/format/apprentice.cpp b/src/data/format/apprentice.cpp index 49992185..92f89ad3 100644 --- a/src/data/format/apprentice.cpp +++ b/src/data/format/apprentice.cpp @@ -358,7 +358,7 @@ void ApprDistro::writeD(wxTextOutputStream& tout, const String& name, int c, int /// Untag function for apprentice, replaces newlines with \r\n String untag_appr(const String& s) { - return replace_all(untag(s), _("\n"), _("\r\n")); + return replace_all(untag(curly_quotes(s,false)), _("\n"), _("\r\n")); } DECLARE_POINTER_TYPE(ApprCardRecord); diff --git a/src/data/format/mws.cpp b/src/data/format/mws.cpp index 249d6212..07a3eb57 100644 --- a/src/data/format/mws.cpp +++ b/src/data/format/mws.cpp @@ -23,7 +23,8 @@ DECLARE_TYPEOF_COLLECTION(CardP); /// Convert a tagged string to MWS format: \t\t before each line beyond the first String untag_mws(const String& str) { - return replace_all(untag(str), _("\n"), _("\n\t\t") ); + // TODO : em dashes? + return replace_all(untag(curly_quotes(str,false)), _("\n"), _("\n\t\t") ); } //String untag_mws(const Defaultable& str) { // str. @@ -36,6 +37,7 @@ String card_color_mws(const String& col) { if (col == _("black")) return _("B"); if (col == _("red")) return _("R"); if (col == _("green")) return _("G"); + if (col == _("artifact")) return _("Art"); if (col == _("colorless")) return _("Art"); if (col.find(_("land")) != String::npos) { return _("Lnd"); // land diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index b7adb3f8..195cfb03 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -267,22 +267,7 @@ SCRIPT_FUNCTION(format) { SCRIPT_FUNCTION(curly_quotes) { SCRIPT_PARAM_C(String, input); - bool open = true, in_tag = false; - FOR_EACH(c, input) { - if (c == _('\'') || c == LEFT_SINGLE_QUOTE || c == RIGHT_SINGLE_QUOTE) { - c = open ? LEFT_SINGLE_QUOTE : RIGHT_SINGLE_QUOTE; - } else if (c == _('\"') || c == LEFT_DOUBLE_QUOTE || c == RIGHT_DOUBLE_QUOTE) { - c = open ? LEFT_DOUBLE_QUOTE : RIGHT_DOUBLE_QUOTE; - } else if (c == _('<')) { - in_tag = true; - } else if (c == _('>')) { - in_tag = false; - } else if (!in_tag) { - // Also allow double-nesting of quotes - open = isSpace(c) || c == _('(') || c == _('['); - } - } - SCRIPT_RETURN(input); + SCRIPT_RETURN(curly_quotes(input,true)); } // regex escape a string diff --git a/src/util/tagged_string.cpp b/src/util/tagged_string.cpp index 6daa010e..112357db 100644 --- a/src/util/tagged_string.cpp +++ b/src/util/tagged_string.cpp @@ -567,3 +567,24 @@ String simplify_tagged_overlap(const String& str) { } return ret; } + +// ----------------------------------------------------------------------------- : Other utilities + +String curly_quotes(String str, bool curl) { + bool open = true, in_tag = false; + FOR_EACH(c, str) { + if (c == _('\'') || c == LEFT_SINGLE_QUOTE || c == RIGHT_SINGLE_QUOTE) { + c = curl ? (open ? LEFT_SINGLE_QUOTE : RIGHT_SINGLE_QUOTE) : _('\''); + } else if (c == _('\"') || c == LEFT_DOUBLE_QUOTE || c == RIGHT_DOUBLE_QUOTE) { + c = curl ? (open ? LEFT_DOUBLE_QUOTE : RIGHT_DOUBLE_QUOTE) : _('\"'); + } else if (c == _('<')) { + in_tag = true; + } else if (c == _('>')) { + in_tag = false; + } else if (!in_tag) { + // Also allow double-nesting of quotes + open = isSpace(c) || c == _('(') || c == _('['); + } + } + return str; +} diff --git a/src/util/tagged_string.hpp b/src/util/tagged_string.hpp index 138edcbf..eaf8d6c6 100644 --- a/src/util/tagged_string.hpp +++ b/src/util/tagged_string.hpp @@ -198,5 +198,10 @@ String simplify_tagged_merge(const String& str, bool all = false); */ String simplify_tagged_overlap(const String& str); +// ----------------------------------------------------------------------------- : Other utilities + +/// Turn straight quotes into curly ones or vice-versa +String curly_quotes(String str, bool curl); + // ----------------------------------------------------------------------------- : EOF #endif