From 713a9e4a404385ba0c37452ffd418810900906f9 Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Wed, 22 Apr 2020 23:33:06 +0200 Subject: [PATCH] Use underscores instead of spaces for all internal names. And renamed some script functions at the same time. * cannocial_name_form now outputs "_", where it used to use " " * this simplifies reflectio and scripting code, because now C++ names are also MSE internal names * added 'caption' property to fields. This is used instead of the name in NativeLookEditor, since the latter will now contain underscores. * renamed text related script functions for consistency, since we were touching that part of the code anyway. --- src/data/field.cpp | 4 +- src/data/field.hpp | 3 +- src/data/field/choice.cpp | 5 +- src/data/field/information.cpp | 2 +- src/data/field/multiple_choice.cpp | 2 +- src/data/format/apprentice.cpp | 10 +-- src/data/game.cpp | 2 +- src/data/installer.cpp | 2 +- src/data/keyword.cpp | 4 +- src/data/locale.cpp | 7 +- src/data/set.cpp | 6 +- src/data/settings.cpp | 10 +-- src/data/settings.hpp | 2 +- src/data/stylesheet.cpp | 14 ++-- src/data/symbol_font.cpp | 10 +-- src/gui/control/card_list.cpp | 2 +- src/gui/control/card_list_column_select.cpp | 4 +- src/gui/control/native_look_editor.cpp | 4 +- src/render/symbol/filter.cpp | 2 +- src/script/functions/basic.cpp | 90 ++++++++++----------- src/script/functions/construction.cpp | 2 +- src/script/functions/editor.cpp | 26 +++--- src/script/functions/english.cpp | 14 ++-- src/script/functions/export.cpp | 22 ++--- src/script/functions/image.cpp | 82 +++++++++---------- src/script/functions/regex.cpp | 30 +++---- src/script/functions/spelling.cpp | 8 +- src/script/script.cpp | 4 +- src/util/io/package.cpp | 2 +- src/util/io/reader.hpp | 2 +- src/util/locale.hpp | 2 + src/util/string.cpp | 44 +++++++--- src/util/string.hpp | 14 +++- 33 files changed, 240 insertions(+), 197 deletions(-) diff --git a/src/data/field.cpp b/src/data/field.cpp index f6d0f611..3facdfcc 100644 --- a/src/data/field.cpp +++ b/src/data/field.cpp @@ -51,6 +51,7 @@ IMPLEMENT_REFLECTION(Field) { } REFLECT(name); REFLECT_IF_READING name = canonical_name_form(name); + REFLECT(caption); REFLECT(description); REFLECT_N("icon", icon_filename); REFLECT(editable); @@ -64,9 +65,10 @@ IMPLEMENT_REFLECTION(Field) { REFLECT(card_list_allow); REFLECT(card_list_name); REFLECT(sort_script); - REFLECT_IF_READING if(card_list_name.empty()) card_list_name = name; REFLECT_N("card_list_alignment", card_list_align); REFLECT(tab_index); + REFLECT_IF_READING if(caption.empty()) caption = name_to_caption(name); + REFLECT_IF_READING if(card_list_name.empty()) card_list_name = capitalize(caption); } template <> diff --git a/src/data/field.hpp b/src/data/field.hpp index 9e746e9b..5ec5a826 100644 --- a/src/data/field.hpp +++ b/src/data/field.hpp @@ -44,8 +44,9 @@ class Field : public IntrusivePtrVirtualBase { size_t index; ///< Used by IndexMap String name; ///< Name of the field, for refering to it from scripts and files + String caption; ///< Caption for NativeLookEditor String description; ///< Description, used in status bar - String icon_filename; ///< Filename for an icon (for list of fields) + String icon_filename; ///< Filename for an icon (for list of fields) bool editable; ///< Can values of this field be edited? bool save_value; ///< Should values of this field be written to files? Can be false for script generated fields. bool show_statistics; ///< Should this field appear as a group by choice in the statistics panel? diff --git a/src/data/field/choice.cpp b/src/data/field/choice.cpp index 1a0f7e43..12ee814f 100644 --- a/src/data/field/choice.cpp +++ b/src/data/field/choice.cpp @@ -192,7 +192,8 @@ void ChoiceStyle::initImage() { // OR_ELSE ScriptCustomCollectionP lookup(new ScriptCustomCollection()); FOR_EACH(ci, choice_images) { - lookup->key_value[ci.first] = ci.second.getValidScriptP(); + lookup->key_value[uncanonical_name_form(ci.first)] = + lookup->key_value[ci.first] = ci.second.getValidScriptP(); } Script& script = image.getMutableScript(); script.addInstruction(I_PUSH_CONST, lookup); @@ -270,7 +271,7 @@ template <> void reflect_content(GetMember& tag, const ChoiceStyle& cs } IMPLEMENT_REFLECTION(ChoiceStyle) { - REFLECT_ALIAS(300, "card list colors", "colors card list"); + REFLECT_ALIAS(300, "card_list_colors", "colors_card_list"); REFLECT_BASE(Style); REFLECT(popup_style); REFLECT(render_style); diff --git a/src/data/field/information.cpp b/src/data/field/information.cpp index 8908de70..1e6b38e0 100644 --- a/src/data/field/information.cpp +++ b/src/data/field/information.cpp @@ -63,7 +63,7 @@ String InfoValue::toString() const { return value; } bool InfoValue::update(Context& ctx) { - if (value.empty()) value = field().name; + if (value.empty()) value = field().caption; bool change = field().script.invokeOn(ctx, value); Value::update(ctx); return change; diff --git a/src/data/field/multiple_choice.cpp b/src/data/field/multiple_choice.cpp index d14c6f35..6fad986c 100644 --- a/src/data/field/multiple_choice.cpp +++ b/src/data/field/multiple_choice.cpp @@ -53,7 +53,7 @@ IMPLEMENT_REFLECTION_NAMELESS(MultipleChoiceValue) { bool MultipleChoiceValue::update(Context& ctx) { String old_value = value(); - ctx.setVariable(_("last change"), to_script(last_change)); + ctx.setVariable(_("last_change"), to_script(last_change)); ChoiceValue::update(ctx); normalForm(); return value() != old_value; diff --git a/src/data/format/apprentice.cpp b/src/data/format/apprentice.cpp index 3a89d708..15ad2c2c 100644 --- a/src/data/format/apprentice.cpp +++ b/src/data/format/apprentice.cpp @@ -423,12 +423,12 @@ class ApprCardRecord : public IntrusivePtrBase { ApprCardRecord::ApprCardRecord(const Card& card, const String& sets_) { name = untag_appr(card.value(_("name")).value); sets = sets_ + _("-") + card_rarity_code(card.value(_("rarity")).value); - cc = untag_appr(card.value(_("casting cost")).value); - type = untag_appr(card.value(_("super type")).value); - String subType = untag(card.value(_("sub type")).value); + cc = untag_appr(card.value(_("casting_cost")).value); + type = untag_appr(card.value(_("super_type")).value); + String subType = untag(card.value(_("sub_type")).value); if (!subType.empty()) type += _(" - ") + subType; - text = untag_appr(card.value(_("rule text")).value); - flavor = untag_appr(card.value(_("flavor text")).value); + text = untag_appr(card.value(_("rule_text")).value); + flavor = untag_appr(card.value(_("flavor_text")).value); pt = untag_appr(card.value(_("pt")).value); } diff --git a/src/data/game.cpp b/src/data/game.cpp index 2097539c..57fed495 100644 --- a/src/data/game.cpp +++ b/src/data/game.cpp @@ -54,7 +54,7 @@ IMPLEMENT_REFLECTION(Game) { REFLECT_NO_SCRIPT(card_list_color_script); REFLECT_NO_SCRIPT(statistics_dimensions); REFLECT_NO_SCRIPT(statistics_categories); - REFLECT_ALIAS(308, "pack item", "pack type"); + REFLECT_ALIAS(308, "pack_item", "pack_type"); REFLECT_NO_SCRIPT(pack_types); REFLECT_NO_SCRIPT(keyword_match_script); REFLECT(has_keywords); diff --git a/src/data/installer.cpp b/src/data/installer.cpp index 21e0ad23..da93981e 100644 --- a/src/data/installer.cpp +++ b/src/data/installer.cpp @@ -248,7 +248,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(PackageDescription) { REFLECT(installer_group); REFLECT(position_hint); REFLECT(description); - REFLECT_N("depends ons", dependencies); + REFLECT_N("depends_ons", dependencies); } void PackageDescription::merge(const PackageDescription& p2) { diff --git a/src/data/keyword.cpp b/src/data/keyword.cpp index 5ddeecd3..05dfac10 100644 --- a/src/data/keyword.cpp +++ b/src/data/keyword.cpp @@ -675,8 +675,8 @@ bool KeywordDatabase::tryExpand(const Keyword& kw, part_start = part_end; } ctx.setVariable(_("mode"), to_script(kw.mode)); - ctx.setVariable(_("correct case"), to_script(correct_case)); - ctx.setVariable(_("used placeholders"), to_script(used_placeholders)); + ctx.setVariable(_("correct_case"), to_script(correct_case)); + ctx.setVariable(_("used_placeholders"), to_script(used_placeholders)); // Final check whether the keyword matches if (match_condition && (bool)*match_condition->eval(ctx) == false) { diff --git a/src/data/locale.cpp b/src/data/locale.cpp index ffabaa1b..f9272dab 100644 --- a/src/data/locale.cpp +++ b/src/data/locale.cpp @@ -89,9 +89,12 @@ String warn_and_identity(const String& key) { queue_message(MESSAGE_WARNING, _("Missing key in locale: ") + key); return key; } +String identity(const String& key) { + return key; +} String SubLocale::tr(const String& key, DefaultLocaleFun def) { - map::const_iterator it = translations.find(key); + map::const_iterator it = translations.find(canonical_name_form(key)); if (it == translations.end()) { return def(key); } else { @@ -99,7 +102,7 @@ String SubLocale::tr(const String& key, DefaultLocaleFun def) { } } String SubLocale::tr(const String& subcat, const String& key, DefaultLocaleFun def) { - map::const_iterator it = translations.find(subcat + _(" ") + key); + map::const_iterator it = translations.find(subcat + _("_") + canonical_name_form(key)); if (it == translations.end()) { return def(key); } else { diff --git a/src/data/set.cpp b/src/data/set.cpp index 904d4714..254891b8 100644 --- a/src/data/set.cpp +++ b/src/data/set.cpp @@ -171,7 +171,7 @@ void Set::validate(Version file_app_version) { IMPLEMENT_REFLECTION(Set) { REFLECT_ALIAS(300, "style", "stylesheet"); // < 0.3.0 used style instead of stylesheet - REFLECT_ALIAS(300, "extra set info", "styling"); + REFLECT_ALIAS(300, "extra_set_info", "styling"); REFLECT(game); if (game) { REFLECT_IF_READING { @@ -190,7 +190,7 @@ IMPLEMENT_REFLECTION(Set) { REFLECT(pack_types); } reflect_set_info_get_member(tag,data); - REFLECT_NO_SCRIPT_N("version control", vcs); + REFLECT_NO_SCRIPT_N("version_control", vcs); REFLECT(apprentice_code); } @@ -226,7 +226,7 @@ void Set::reflect_cards (Writer& tag) { Writer writer(openOut(full_name), app_version); writer.handle(_("card"), card); referenceFile(full_name); - REFLECT_N("include file", full_name); + REFLECT_N("include_file", full_name); } } } diff --git a/src/data/settings.cpp b/src/data/settings.cpp index c9c55464..767db060 100644 --- a/src/data/settings.cpp +++ b/src/data/settings.cpp @@ -109,7 +109,7 @@ void GameSettings::initDefaults(const Game& game) { IMPLEMENT_REFLECTION_NO_SCRIPT(GameSettings) { REFLECT(default_stylesheet); REFLECT(default_export); - REFLECT_N("cardlist columns", columns); + REFLECT(cardlist_columns); REFLECT(sort_cards_by); REFLECT(sort_cards_ascending); REFLECT(images_export_filename); @@ -211,7 +211,7 @@ ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field // Get game info GameSettings& gs = gameSettingsFor(game); // Get column info - ColumnSettings& cs = gs.columns[field.name]; + ColumnSettings& cs = gs.cardlist_columns[field.name]; if (cs.position == COLUMN_NOT_INITIALIZED) { // column info not set, initialize based on the game cs.visible = field.card_list_visible; @@ -244,8 +244,8 @@ String Settings::settingsFile() { } IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) { - REFLECT_ALIAS(300, "style settings", "stylesheet settings"); - REFLECT_ALIAS(300, "default style settings", "default stylesheet settings"); + REFLECT_ALIAS(300, "style_settings", "stylesheet_settings"); + REFLECT_ALIAS(300, "default_style_settings", "default_stylesheet_settings"); REFLECT(locale); REFLECT(recent_sets); REFLECT(default_set_dir); @@ -266,7 +266,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) { #if USE_OLD_STYLE_UPDATE_CHECKER REFLECT(updates_url); #else - REFLECT_IGNORE(306,"updates url"); + REFLECT_IGNORE(306,"updates_url"); #endif REFLECT(package_versions_url); REFLECT(installer_list_url); diff --git a/src/data/settings.hpp b/src/data/settings.hpp index f90613a8..895d6aae 100644 --- a/src/data/settings.hpp +++ b/src/data/settings.hpp @@ -76,7 +76,7 @@ class GameSettings : public IntrusivePtrBase { String default_stylesheet; String default_export; - map columns; + map cardlist_columns; String sort_cards_by; bool sort_cards_ascending; String images_export_filename; diff --git a/src/data/stylesheet.cpp b/src/data/stylesheet.cpp index 864467c3..80e1288c 100644 --- a/src/data/stylesheet.cpp +++ b/src/data/stylesheet.cpp @@ -95,14 +95,14 @@ void mark_dependency_value(const StyleSheet& stylesheet, const Dependency& dep) IMPLEMENT_REFLECTION(StyleSheet) { // < 0.3.0 didn't use card_ prefix - REFLECT_ALIAS(300, "width", "card width"); - REFLECT_ALIAS(300, "height", "card height"); - REFLECT_ALIAS(300, "dpi", "card dpi"); - REFLECT_ALIAS(300, "background", "card background"); - REFLECT_ALIAS(300, "info style", "set info style"); + REFLECT_ALIAS(300, "width", "card_width"); + REFLECT_ALIAS(300, "height", "card_height"); + REFLECT_ALIAS(300, "dpi", "card_dpi"); + REFLECT_ALIAS(300, "background", "card_background"); + REFLECT_ALIAS(300, "info_style", "set_info_style"); REFLECT_ALIAS(300, "align", "alignment"); - REFLECT_ALIAS(300, "extra field", "styling field"); - REFLECT_ALIAS(300, "extra style", "styling style"); + REFLECT_ALIAS(300, "extra_field", "styling_field"); + REFLECT_ALIAS(300, "extra_style", "styling_style"); REFLECT(game); REFLECT_BASE(Packaged); diff --git a/src/data/symbol_font.cpp b/src/data/symbol_font.cpp index 1f4fa3b4..2ccfe2bd 100644 --- a/src/data/symbol_font.cpp +++ b/src/data/symbol_font.cpp @@ -51,11 +51,11 @@ SymbolFontP SymbolFont::byName(const String& name) { IMPLEMENT_REFLECTION(SymbolFont) { REFLECT_BASE(Packaged); - REFLECT_ALIAS(300, "text align", "text alignment"); + REFLECT_ALIAS(300, "text_align", "text_alignment"); - REFLECT_N("image font size", img_size); - REFLECT_N("horizontal space", spacing.width); - REFLECT_N("vertical space", spacing.height); + REFLECT_N("image_font_size", img_size); + REFLECT_N("horizontal_space", spacing.width); + REFLECT_N("vertical_space", spacing.height); WITH_DYNAMIC_ARG(symbol_font_for_reading, this); REFLECT(symbols); REFLECT(scale_text); @@ -189,7 +189,7 @@ IMPLEMENT_REFLECTION(SymbolInFont) { REFLECT(text_margin_bottom); REFLECT(image); REFLECT(enabled); - REFLECT_N("image font size", img_size); + REFLECT_N("image_font_size", img_size); } // ----------------------------------------------------------------------------- : SymbolFont : splitting diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index 73e2d5c1..cfb8edf3 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -237,7 +237,7 @@ void CardListBase::rebuild() { else if (f.second->card_list_align & ALIGN_CENTER) align = wxLIST_FORMAT_CENTRE; else align = wxLIST_FORMAT_LEFT; InsertColumn((long)column_fields.size(), - tr(*set->game, f.second->card_list_name, capitalize), + tr(*set->game, f.second->card_list_name, identity), align, cs.width); column_fields.push_back(f.second); } diff --git a/src/gui/control/card_list_column_select.cpp b/src/gui/control/card_list_column_select.cpp index ecd25afb..1438a9e8 100644 --- a/src/gui/control/card_list_column_select.cpp +++ b/src/gui/control/card_list_column_select.cpp @@ -76,7 +76,7 @@ void CardListColumnSelectDialog::initList() { // Init items Color window_color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); FOR_EACH(c, columns) { - list->Append(tr(*game, c.field->card_list_name, capitalize)); + list->Append(tr(*game, c.field->card_list_name, identity)); // check int i = list->GetCount() - 1; list->Check(i, c.settings.visible); @@ -89,7 +89,7 @@ void CardListColumnSelectDialog::initList() { void CardListColumnSelectDialog::refreshItem(int i) { list->Check (i, columns[i].settings.visible); - list->SetString(i, tr(*game, columns[i].field->card_list_name, capitalize) ); + list->SetString(i, tr(*game, columns[i].field->card_list_name, identity) ); } // ----------------------------------------------------------------------------- : Events diff --git a/src/gui/control/native_look_editor.cpp b/src/gui/control/native_look_editor.cpp index ca2b53a8..d2b57564 100644 --- a/src/gui/control/native_look_editor.cpp +++ b/src/gui/control/native_look_editor.cpp @@ -44,7 +44,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) { dc.SetFont(*wxNORMAL_FONT); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); // TODO : tr using stylesheet or using game? - dc.DrawText(tr(getStylePackage(), s.fieldP->name, capitalize_sentence), + dc.DrawText(tr(getStylePackage(), s.fieldP->caption, identity), RealPoint(margin_left - s.left, 1)); } // draw viewer @@ -68,7 +68,7 @@ void NativeLookEditor::resizeViewers() { // width of the label string int w; Style& s = *v->getStyle(); - String text = tr(getStylePackage(), s.fieldP->name, capitalize_sentence); + String text = tr(getStylePackage(), s.fieldP->caption, identity); dc.GetTextExtent(text,&w,nullptr); label_width = max(label_width, w + label_margin); } diff --git a/src/render/symbol/filter.cpp b/src/render/symbol/filter.cpp index 8e92608b..3b9aec01 100644 --- a/src/render/symbol/filter.cpp +++ b/src/render/symbol/filter.cpp @@ -70,7 +70,7 @@ template <> intrusive_ptr read_new(Reader& reader) { // there must be a fill type specified String fill_type; - reader.handle(_("fill type"), fill_type); + reader.handle(_("fill_type"), fill_type); if (fill_type == _("solid")) return intrusive(new SolidFillSymbolFilter); else if (fill_type == _("linear gradient")) return intrusive(new LinearGradientSymbolFilter); else if (fill_type == _("radial gradient")) return intrusive(new RadialGradientSymbolFilter); diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index 8310d69f..000545be 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -516,7 +516,7 @@ ScriptValueP sort_script(Context& ctx, const ScriptValueP& list, ScriptValue& or SCRIPT_FUNCTION_WITH_DEP(position_of) { ScriptValueP of = ctx.getVariable(_("of")); ScriptValueP in = ctx.getVariable(_("in")); - ScriptValueP order_by = ctx.getVariableOpt(_("order by")); + ScriptValueP order_by = ctx.getVariableOpt(_("order_by")); ScriptValueP filter = ctx.getVariableOpt(_("filter")); if (filter == script_nil) filter = ScriptValueP(); SCRIPT_RETURN(position_in_vector(of, in, order_by, filter)); @@ -524,7 +524,7 @@ SCRIPT_FUNCTION_WITH_DEP(position_of) { SCRIPT_FUNCTION_DEPENDENCIES(position_of) { ScriptValueP of = ctx.getVariable(_("of")); ScriptValueP in = ctx.getVariable(_("in")); - ScriptValueP order_by = ctx.getVariableOpt(_("order by")); + ScriptValueP order_by = ctx.getVariableOpt(_("order_by")); ScriptValueP filter = ctx.getVariableOpt(_("filter")); ScriptObject* s = dynamic_cast* >(in.get()); ScriptObject* c = dynamic_cast*>(of.get()); @@ -581,8 +581,8 @@ SCRIPT_FUNCTION(filter_list) { SCRIPT_FUNCTION(sort_list) { SCRIPT_PARAM_C(ScriptValueP, input); - SCRIPT_PARAM_DEFAULT_N(ScriptValueP, _("order by"), order_by, script_nil); - SCRIPT_PARAM_DEFAULT_N(bool, _("remove duplicates"), remove_duplicates, false); + SCRIPT_PARAM_DEFAULT(ScriptValueP, order_by, script_nil); + SCRIPT_PARAM_DEFAULT(bool, remove_duplicates, false); return sort_script(ctx, input, *order_by, remove_duplicates); } @@ -648,8 +648,8 @@ SCRIPT_FUNCTION_WITH_DEP(expand_keywords) { SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(Set*, set); SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("condition"), match_condition); - SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("default expand"), default_expand); - SCRIPT_PARAM_N(ScriptValueP, _("combine"), combine); + SCRIPT_OPTIONAL_PARAM_(ScriptValueP, default_expand); + SCRIPT_PARAM(ScriptValueP, combine); KeywordDatabase& db = set->keyword_db; if (db.empty()) { db.prepare_parameters(set->game->keyword_parameter_types, set->keywords); @@ -668,8 +668,8 @@ SCRIPT_FUNCTION_WITH_DEP(expand_keywords) { SCRIPT_FUNCTION_DEPENDENCIES(expand_keywords) { SCRIPT_PARAM_C(Set*, set); SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("condition"), match_condition); - SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("default expand"), default_expand); - SCRIPT_PARAM_N(ScriptValueP, _("combine"), combine); + SCRIPT_OPTIONAL_PARAM_(ScriptValueP, default_expand); + SCRIPT_PARAM(ScriptValueP, combine); if (match_condition) match_condition->dependencies(ctx,dep); default_expand ->dependencies(ctx,dep); combine ->dependencies(ctx,dep); @@ -715,62 +715,62 @@ void init_script_basic_functions(Context& ctx) { // debugging ctx.setVariable(_("trace"), script_trace); // conversion - ctx.setVariable(_("to string"), script_to_string); - ctx.setVariable(_("to int"), script_to_int); - ctx.setVariable(_("to real"), script_to_real); - ctx.setVariable(_("to number"), script_to_number); - ctx.setVariable(_("to boolean"), script_to_boolean); - ctx.setVariable(_("to color"), script_to_color); - ctx.setVariable(_("to date"), script_to_date); - ctx.setVariable(_("to code"), script_to_code); - ctx.setVariable(_("type name"), script_type_name); + ctx.setVariable(_("to_string"), script_to_string); + ctx.setVariable(_("to_int"), script_to_int); + ctx.setVariable(_("to_real"), script_to_real); + ctx.setVariable(_("to_number"), script_to_number); + ctx.setVariable(_("to_boolean"), script_to_boolean); + ctx.setVariable(_("to_color"), script_to_color); + ctx.setVariable(_("to_date"), script_to_date); + ctx.setVariable(_("to_code"), script_to_code); + ctx.setVariable(_("type_name"), script_type_name); // math ctx.setVariable(_("abs"), script_abs); - ctx.setVariable(_("random real"), script_random_real); - ctx.setVariable(_("random int"), script_random_int); - ctx.setVariable(_("random boolean"), script_random_boolean); + ctx.setVariable(_("random_real"), script_random_real); + ctx.setVariable(_("random_int"), script_random_int); + ctx.setVariable(_("random_boolean"), script_random_boolean); ctx.setVariable(_("sin"), script_sin); ctx.setVariable(_("cos"), script_cos); ctx.setVariable(_("tan"), script_tan); - ctx.setVariable(_("sin deg"), script_sin_deg); - ctx.setVariable(_("cos deg"), script_cos_deg); - ctx.setVariable(_("tan deg"), script_tan_deg); + ctx.setVariable(_("sin_deg"), script_sin_deg); + ctx.setVariable(_("cos_deg"), script_cos_deg); + ctx.setVariable(_("tan_deg"), script_tan_deg); ctx.setVariable(_("exp"), script_exp); ctx.setVariable(_("log"), script_log); ctx.setVariable(_("log10"), script_log10); ctx.setVariable(_("sqrt"), script_sqrt); ctx.setVariable(_("pow"), script_pow); // string - ctx.setVariable(_("to upper"), script_to_upper); - ctx.setVariable(_("to lower"), script_to_lower); - ctx.setVariable(_("to title"), script_to_title); + ctx.setVariable(_("to_upper"), script_to_upper); + ctx.setVariable(_("to_lower"), script_to_lower); + ctx.setVariable(_("to_title"), script_to_title); ctx.setVariable(_("reverse"), script_reverse); ctx.setVariable(_("trim"), script_trim); ctx.setVariable(_("substring"), script_substring); ctx.setVariable(_("contains"), script_contains); ctx.setVariable(_("format"), script_format); - ctx.setVariable(_("format rule"), intrusive(new ScriptRule(script_format))); - ctx.setVariable(_("curly quotes"), script_curly_quotes); - ctx.setVariable(_("regex escape"), script_regex_escape); - ctx.setVariable(_("sort text"), script_sort_text); - ctx.setVariable(_("sort rule"), intrusive(new ScriptRule(script_sort_text))); + ctx.setVariable(_("format_rule"), intrusive(new ScriptRule(script_format))); + ctx.setVariable(_("curly_quotes"), script_curly_quotes); + ctx.setVariable(_("regex_escape"), script_regex_escape); + ctx.setVariable(_("sort_text"), script_sort_text); + ctx.setVariable(_("sort_rule"), intrusive(new ScriptRule(script_sort_text))); // tagged string - ctx.setVariable(_("tag contents"), script_tag_contents); - ctx.setVariable(_("remove tag"), script_remove_tag); - ctx.setVariable(_("remove tags"), script_remove_tags); - ctx.setVariable(_("tag contents rule"), intrusive(new ScriptRule(script_tag_contents))); - ctx.setVariable(_("tag remove rule"), intrusive(new ScriptRule(script_remove_tag))); + ctx.setVariable(_("tag_contents"), script_tag_contents); + ctx.setVariable(_("remove_tag"), script_remove_tag); + ctx.setVariable(_("remove_tags"), script_remove_tags); + ctx.setVariable(_("tag_contents_rule"), intrusive(new ScriptRule(script_tag_contents))); + ctx.setVariable(_("tag_remove_rule"), intrusive(new ScriptRule(script_remove_tag))); // collection ctx.setVariable(_("position"), script_position_of); ctx.setVariable(_("length"), script_length); - ctx.setVariable(_("number of items"), script_number_of_items); - ctx.setVariable(_("filter list"), script_filter_list); - ctx.setVariable(_("sort list"), script_sort_list); - ctx.setVariable(_("random shuffle"), script_random_shuffle); - ctx.setVariable(_("random select"), script_random_select); - ctx.setVariable(_("random select many"), script_random_select_many); + ctx.setVariable(_("number_of_items"), script_number_of_items); // deprecated + ctx.setVariable(_("filter_list"), script_filter_list); + ctx.setVariable(_("sort_list"), script_sort_list); + ctx.setVariable(_("random_shuffle"), script_random_shuffle); + ctx.setVariable(_("random_select"), script_random_select); + ctx.setVariable(_("random_select_many"), script_random_select_many); // keyword - ctx.setVariable(_("expand keywords"), script_expand_keywords); - ctx.setVariable(_("expand keywords rule"), intrusive(new ScriptRule(script_expand_keywords))); - ctx.setVariable(_("keyword usage"), script_keyword_usage); + ctx.setVariable(_("expand_keywords"), script_expand_keywords); + ctx.setVariable(_("expand_keywords_rule"), intrusive(new ScriptRule(script_expand_keywords))); + ctx.setVariable(_("keyword_usage"), script_keyword_usage); } diff --git a/src/script/functions/construction.cpp b/src/script/functions/construction.cpp index a3fe972c..446ee477 100644 --- a/src/script/functions/construction.cpp +++ b/src/script/functions/construction.cpp @@ -55,5 +55,5 @@ SCRIPT_FUNCTION(new_card) { // ----------------------------------------------------------------------------- : Init void init_script_construction_functions(Context& ctx) { - ctx.setVariable(_("new card"), script_new_card); + ctx.setVariable(_("new_card"), script_new_card); } diff --git a/src/script/functions/editor.cpp b/src/script/functions/editor.cpp index 3fb15135..3933e7bc 100644 --- a/src/script/functions/editor.cpp +++ b/src/script/functions/editor.cpp @@ -99,8 +99,8 @@ SCRIPT_FUNCTION_WITH_DEP(combined_editor) { nv.second = index_to_untagged(nv.first, nv.first.size()) == 0; } // options - SCRIPT_PARAM_DEFAULT_N(bool, _("hide when empty"), hide_when_empty, false); - SCRIPT_PARAM_DEFAULT_N(bool, _("soft before empty"), soft_before_empty, false); + SCRIPT_PARAM_DEFAULT(bool, hide_when_empty, false); + SCRIPT_PARAM_DEFAULT(bool, soft_before_empty, false); // recombine the parts String new_value = value_parts.front().first; bool new_value_empty = value_parts.front().second; @@ -336,7 +336,7 @@ void read_choices_param(Context& ctx, vector& choices_out) { // add the given choice if it is not already active SCRIPT_FUNCTION(require_choice) { SCRIPT_PARAM_C(String,input); - SCRIPT_OPTIONAL_PARAM_N_(String,_("last change"),last_change); + SCRIPT_OPTIONAL_PARAM_(String, last_change); vector choices; read_choices_param(ctx, choices); SCRIPT_RETURN(filter_choices(input, choices, 1, (int)choices.size(), last_change)); @@ -345,7 +345,7 @@ SCRIPT_FUNCTION(require_choice) { // make sure at most one of the choices is active SCRIPT_FUNCTION(exclusive_choice) { SCRIPT_PARAM_C(String,input); - SCRIPT_OPTIONAL_PARAM_N_(String,_("last change"),last_change); + SCRIPT_OPTIONAL_PARAM_(String, last_change); vector choices; read_choices_param(ctx, choices); SCRIPT_RETURN(filter_choices(input, choices, 0, 1, last_change)); @@ -354,7 +354,7 @@ SCRIPT_FUNCTION(exclusive_choice) { // make sure exactly one of the choices is active SCRIPT_FUNCTION(require_exclusive_choice) { SCRIPT_PARAM_C(String,input); - SCRIPT_OPTIONAL_PARAM_N_(String,_("last change"),last_change); + SCRIPT_OPTIONAL_PARAM_(String, last_change); vector choices; read_choices_param(ctx, choices); SCRIPT_RETURN(filter_choices(input, choices, 1, 1, last_change)); @@ -393,13 +393,13 @@ SCRIPT_FUNCTION(count_chosen) { // ----------------------------------------------------------------------------- : Init void init_script_editor_functions(Context& ctx) { - ctx.setVariable(_("forward editor"), script_combined_editor); // compatability - ctx.setVariable(_("combined editor"), script_combined_editor); - ctx.setVariable(_("primary choice"), script_primary_choice); + ctx.setVariable(_("forward_editor"), script_combined_editor); // compatability + ctx.setVariable(_("combined_editor"), script_combined_editor); + ctx.setVariable(_("primary_choice"), script_primary_choice); ctx.setVariable(_("chosen"), script_chosen); - ctx.setVariable(_("count chosen"), script_count_chosen); - ctx.setVariable(_("require choice"), script_require_choice); - ctx.setVariable(_("exclusive choice"), script_exclusive_choice); - ctx.setVariable(_("require exclusive choice"), script_require_exclusive_choice); - ctx.setVariable(_("remove choice"), script_remove_choice); + ctx.setVariable(_("count_chosen"), script_count_chosen); + ctx.setVariable(_("require_choice"), script_require_choice); + ctx.setVariable(_("exclusive_choice"), script_exclusive_choice); + ctx.setVariable(_("require_exclusive_choice"), script_require_exclusive_choice); + ctx.setVariable(_("remove_choice"), script_remove_choice); } diff --git a/src/script/functions/english.cpp b/src/script/functions/english.cpp index 117220d9..946a0a97 100644 --- a/src/script/functions/english.cpp +++ b/src/script/functions/english.cpp @@ -334,11 +334,11 @@ SCRIPT_FUNCTION(process_english_hints) { // ----------------------------------------------------------------------------- : Init void init_script_english_functions(Context& ctx) { - ctx.setVariable(_("english number"), script_english_number); - ctx.setVariable(_("english number a"), script_english_number_a); - ctx.setVariable(_("english number multiple"), script_english_number_multiple); - ctx.setVariable(_("english number ordinal"), script_english_number_ordinal); - ctx.setVariable(_("english singular"), script_english_singular); - ctx.setVariable(_("english plural"), script_english_plural); - ctx.setVariable(_("process english hints"), script_process_english_hints); + ctx.setVariable(_("english_number"), script_english_number); + ctx.setVariable(_("english_number_a"), script_english_number_a); + ctx.setVariable(_("english_number_multiple"), script_english_number_multiple); + ctx.setVariable(_("english_number_ordinal"), script_english_number_ordinal); + ctx.setVariable(_("english_singular"), script_english_singular); + ctx.setVariable(_("english_plural"), script_english_plural); + ctx.setVariable(_("process_english_hints"), script_process_english_hints); } diff --git a/src/script/functions/export.cpp b/src/script/functions/export.cpp index 0acb0482..3d4e7a96 100644 --- a/src/script/functions/export.cpp +++ b/src/script/functions/export.cpp @@ -278,11 +278,11 @@ SCRIPT_FUNCTION(to_html) { SCRIPT_PARAM_C(String, input); // symbol font? SymbolFontP symbol_font; - SCRIPT_OPTIONAL_PARAM_N(String, _("symbol font"), font_name) { + SCRIPT_OPTIONAL_PARAM_N(String, _("symbol_font"), font_name) { symbol_font = SymbolFont::byName(font_name); symbol_font->update(ctx); } - SCRIPT_OPTIONAL_PARAM_N_(double, _("symbol font size"), symbol_font_size); + SCRIPT_OPTIONAL_PARAM_(double, symbol_font_size); if (symbol_font_size <= 0) symbol_font_size = 12; // a default SCRIPT_RETURN(to_html(input, symbol_font, symbol_font_size)); } @@ -290,8 +290,8 @@ SCRIPT_FUNCTION(to_html) { // convert a symbol string to html SCRIPT_FUNCTION(symbols_to_html) { SCRIPT_PARAM_C(String, input); - SCRIPT_PARAM_N(String, _("symbol font"), font_name); - SCRIPT_OPTIONAL_PARAM_N_(double, _("symbol font size"), symbol_font_size); + SCRIPT_PARAM_N(String, _("symbol_font"), font_name); + SCRIPT_OPTIONAL_PARAM_(double, symbol_font_size); SymbolFontP symbol_font = SymbolFont::byName(font_name); symbol_font->update(ctx); if (symbol_font_size <= 0) symbol_font_size = 12; // a default @@ -451,12 +451,12 @@ SCRIPT_FUNCTION(sanitize) { // ----------------------------------------------------------------------------- : Init void init_script_export_functions(Context& ctx) { - ctx.setVariable(_("to html"), script_to_html); - ctx.setVariable(_("symbols to html"), script_symbols_to_html); - ctx.setVariable(_("to text"), script_to_text); - ctx.setVariable(_("copy file"), script_copy_file); - ctx.setVariable(_("write text file"), script_write_text_file); - ctx.setVariable(_("write image file"), script_write_image_file); - ctx.setVariable(_("write set file"), script_write_set_file); + ctx.setVariable(_("to_html"), script_to_html); + ctx.setVariable(_("symbols_to_html"), script_symbols_to_html); + ctx.setVariable(_("to_text"), script_to_text); + ctx.setVariable(_("copy_file"), script_copy_file); + ctx.setVariable(_("write_text_file"), script_write_text_file); + ctx.setVariable(_("write_image_file"), script_write_image_file); + ctx.setVariable(_("write_set_file"), script_write_set_file); ctx.setVariable(_("sanitize"), script_sanitize); } diff --git a/src/script/functions/image.cpp b/src/script/functions/image.cpp index ac6ed7a4..bdad8c1d 100644 --- a/src/script/functions/image.cpp +++ b/src/script/functions/image.cpp @@ -106,16 +106,16 @@ SCRIPT_FUNCTION(recolor_image) { SCRIPT_FUNCTION(enlarge) { SCRIPT_PARAM_C(GeneratedImageP, input); - SCRIPT_PARAM_N(double, _("border size"), border_size); + SCRIPT_PARAM(double, border_size); return intrusive(new EnlargeImage(input, border_size)); } SCRIPT_FUNCTION(crop) { SCRIPT_PARAM_C(GeneratedImageP, input); - SCRIPT_PARAM_N(int, _("width"), width); - SCRIPT_PARAM_N(int, _("height"), height); - SCRIPT_PARAM_N(double, _("offset x"), offset_x); - SCRIPT_PARAM_N(double, _("offset y"), offset_y); + SCRIPT_PARAM(int, width); + SCRIPT_PARAM(int, height); + SCRIPT_PARAM(double, offset_x); + SCRIPT_PARAM(double, offset_y); return intrusive(new CropImage(input, width, height, offset_x, offset_y)); } @@ -131,17 +131,17 @@ SCRIPT_FUNCTION(flip_vertical) { SCRIPT_FUNCTION(rotate) { SCRIPT_PARAM_C(GeneratedImageP, input); - SCRIPT_PARAM_N(Degrees, _("angle"), angle); + SCRIPT_PARAM(Degrees, angle); return intrusive(new RotateImage(input,deg_to_rad(angle))); } SCRIPT_FUNCTION(drop_shadow) { SCRIPT_PARAM_C(GeneratedImageP, input); - SCRIPT_OPTIONAL_PARAM_N_(double, _("offset x"), offset_x); - SCRIPT_OPTIONAL_PARAM_N_(double, _("offset y"), offset_y); - SCRIPT_OPTIONAL_PARAM_N_(double, _("alpha"), alpha); - SCRIPT_OPTIONAL_PARAM_N_(double, _("blur radius"), blur_radius); - SCRIPT_OPTIONAL_PARAM_N_(Color, _("color"), color); + SCRIPT_OPTIONAL_PARAM_(double, offset_x); + SCRIPT_OPTIONAL_PARAM_(double, offset_y); + SCRIPT_OPTIONAL_PARAM_(double, alpha); + SCRIPT_OPTIONAL_PARAM_(double, blur_radius); + SCRIPT_OPTIONAL_PARAM_(Color, color); return intrusive(new DropShadowImage(input, offset_x, offset_y, alpha, blur_radius, color)); } @@ -176,30 +176,30 @@ SCRIPT_FUNCTION(symbol_variation) { throw ScriptError(_("Variation of symbol not found ('") + variation + _("')")); } else { // custom variation - SCRIPT_PARAM_N(double, _("border radius"), border_radius); - SCRIPT_OPTIONAL_PARAM_N_(String, _("fill type"), fill_type); + SCRIPT_PARAM(double, border_radius); + SCRIPT_OPTIONAL_PARAM_(String, fill_type); SymbolVariationP var(new SymbolVariation); var->border_radius = border_radius; if (fill_type == _("solid") || fill_type.empty()) { - SCRIPT_PARAM_N(Color, _("fill color"), fill_color); - SCRIPT_PARAM_N(Color, _("border color"), border_color); + SCRIPT_PARAM(Color, fill_color); + SCRIPT_PARAM(Color, border_color); var->filter = intrusive(new SolidFillSymbolFilter(fill_color, border_color)); } else if (fill_type == _("linear gradient")) { - SCRIPT_PARAM_N(Color, _("fill color 1"), fill_color_1); - SCRIPT_PARAM_N(Color, _("border color 1"), border_color_1); - SCRIPT_PARAM_N(Color, _("fill color 2"), fill_color_2); - SCRIPT_PARAM_N(Color, _("border color 2"), border_color_2); - SCRIPT_PARAM_N(double, _("center x"), center_x); - SCRIPT_PARAM_N(double, _("center y"), center_y); - SCRIPT_PARAM_N(double, _("end x"), end_x); - SCRIPT_PARAM_N(double, _("end y"), end_y); + SCRIPT_PARAM(Color, fill_color_1); + SCRIPT_PARAM(Color, border_color_1); + SCRIPT_PARAM(Color, fill_color_2); + SCRIPT_PARAM(Color, border_color_2); + SCRIPT_PARAM(double, center_x); + SCRIPT_PARAM(double, center_y); + SCRIPT_PARAM(double, end_x); + SCRIPT_PARAM(double, end_y); var->filter = intrusive(new LinearGradientSymbolFilter(fill_color_1, border_color_1, fill_color_2, border_color_2 ,center_x, center_y, end_x, end_y)); } else if (fill_type == _("radial gradient")) { - SCRIPT_PARAM_N(Color, _("fill color 1"), fill_color_1); - SCRIPT_PARAM_N(Color, _("border color 1"), border_color_1); - SCRIPT_PARAM_N(Color, _("fill color 2"), fill_color_2); - SCRIPT_PARAM_N(Color, _("border color 2"), border_color_2); + SCRIPT_PARAM(Color, fill_color_1); + SCRIPT_PARAM(Color, border_color_1); + SCRIPT_PARAM(Color, fill_color_2); + SCRIPT_PARAM(Color, border_color_2); var->filter = intrusive(new RadialGradientSymbolFilter(fill_color_1, border_color_1, fill_color_2, border_color_2)); } else { throw ScriptError(_("Unknown fill type for symbol_variation: ") + fill_type); @@ -216,22 +216,22 @@ SCRIPT_FUNCTION(built_in_image) { // ----------------------------------------------------------------------------- : Init void init_script_image_functions(Context& ctx) { - ctx.setVariable(_("to image"), script_to_image); - ctx.setVariable(_("linear blend"), script_linear_blend); - ctx.setVariable(_("masked blend"), script_masked_blend); - ctx.setVariable(_("combine blend"), script_combine_blend); - ctx.setVariable(_("set mask"), script_set_mask); - ctx.setVariable(_("set alpha"), script_set_alpha); - ctx.setVariable(_("set combine"), script_set_combine); + ctx.setVariable(_("to_image"), script_to_image); + ctx.setVariable(_("linear_blend"), script_linear_blend); + ctx.setVariable(_("masked_blend"), script_masked_blend); + ctx.setVariable(_("combine_blend"), script_combine_blend); + ctx.setVariable(_("set_mask"), script_set_mask); + ctx.setVariable(_("set_alpha"), script_set_alpha); + ctx.setVariable(_("set_combine"), script_set_combine); ctx.setVariable(_("saturate"), script_saturate); - ctx.setVariable(_("invert image"), script_invert_image); - ctx.setVariable(_("recolor image"), script_recolor_image); + ctx.setVariable(_("invert_image"), script_invert_image); + ctx.setVariable(_("recolor_image"), script_recolor_image); ctx.setVariable(_("enlarge"), script_enlarge); ctx.setVariable(_("crop"), script_crop); - ctx.setVariable(_("flip horizontal"), script_flip_horizontal); - ctx.setVariable(_("flip vertical"), script_flip_vertical); + ctx.setVariable(_("flip_horizontal"), script_flip_horizontal); + ctx.setVariable(_("flip_vertical"), script_flip_vertical); ctx.setVariable(_("rotate"), script_rotate); - ctx.setVariable(_("drop shadow"), script_drop_shadow); - ctx.setVariable(_("symbol variation"), script_symbol_variation); - ctx.setVariable(_("built in image"), script_built_in_image); + ctx.setVariable(_("drop_shadow"), script_drop_shadow); + ctx.setVariable(_("symbol_variation"), script_symbol_variation); + ctx.setVariable(_("built_in_image"), script_built_in_image); } diff --git a/src/script/functions/regex.cpp b/src/script/functions/regex.cpp index 213a0693..f8603b79 100644 --- a/src/script/functions/regex.cpp +++ b/src/script/functions/regex.cpp @@ -105,7 +105,7 @@ struct RegexReplacer { } }; -SCRIPT_FUNCTION_WITH_SIMPLIFY(replace) { +SCRIPT_FUNCTION_WITH_SIMPLIFY(replace_text) { // construct replacer RegexReplacer replacer; replacer.match = from_script(ctx.getVariable(SCRIPT_VAR_match), SCRIPT_VAR_match); @@ -131,7 +131,7 @@ SCRIPT_FUNCTION_WITH_SIMPLIFY(replace) { SCRIPT_RETURN(replacer.match->replace_all(input, replacer.replacement_string)); } } -SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(replace) { +SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(replace_text) { FOR_EACH(b, closure.bindings) { if (b.first == SCRIPT_VAR_match || b.first == SCRIPT_VAR_in_context) { b.second = regex_from_script(b.second); // pre-compile @@ -198,7 +198,7 @@ SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(break_text) { SCRIPT_FUNCTION_WITH_SIMPLIFY(split_text) { SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(ScriptRegexP, match); - SCRIPT_PARAM_DEFAULT_N(bool, _("include empty"), include_empty, true); + SCRIPT_PARAM_DEFAULT(bool, include_empty, true); ScriptCustomCollectionP ret(new ScriptCustomCollection); // find all matches String::const_iterator start = input.begin(); @@ -227,12 +227,12 @@ SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(split_text) { // ----------------------------------------------------------------------------- : Rules : regex match -SCRIPT_FUNCTION_WITH_SIMPLIFY(match) { +SCRIPT_FUNCTION_WITH_SIMPLIFY(match_text) { SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(ScriptRegexP, match); SCRIPT_RETURN(match->matches(input)); } -SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(match) { +SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(match_text) { FOR_EACH(b, closure.bindings) { if (b.first == SCRIPT_VAR_match) { b.second = regex_from_script(b.second); // pre-compile @@ -244,13 +244,15 @@ SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(match) { // ----------------------------------------------------------------------------- : Init void init_script_regex_functions(Context& ctx) { - ctx.setVariable(_("replace"), script_replace); - ctx.setVariable(_("filter text"), script_filter_text); - ctx.setVariable(_("break text"), script_break_text); - ctx.setVariable(_("split text"), script_split_text); - ctx.setVariable(_("match"), script_match); - ctx.setVariable(_("replace rule"), intrusive(new ScriptRule(script_replace))); - ctx.setVariable(_("filter rule"), intrusive(new ScriptRule(script_filter_text))); - ctx.setVariable(_("break rule"), intrusive(new ScriptRule(script_break_text))); - ctx.setVariable(_("match rule"), intrusive(new ScriptRule(script_match))); + ctx.setVariable(_("replace_text"), script_replace_text); + ctx.setVariable(_("replace"), script_replace_text); // old name + ctx.setVariable(_("filter_text"), script_filter_text); + ctx.setVariable(_("break_text"), script_break_text); + ctx.setVariable(_("split_text"), script_split_text); + ctx.setVariable(_("match_text"), script_match_text); + ctx.setVariable(_("match"), script_match_text); // old name + ctx.setVariable(_("replace_rule"), intrusive(new ScriptRule(script_replace_text))); + ctx.setVariable(_("filter_rule"), intrusive(new ScriptRule(script_filter_text))); + ctx.setVariable(_("break_rule"), intrusive(new ScriptRule(script_break_text))); + ctx.setVariable(_("match_rule"), intrusive(new ScriptRule(script_match_text))); } diff --git a/src/script/functions/spelling.cpp b/src/script/functions/spelling.cpp index 45457d20..09afce98 100644 --- a/src/script/functions/spelling.cpp +++ b/src/script/functions/spelling.cpp @@ -96,8 +96,8 @@ SCRIPT_FUNCTION(check_spelling) { assert_tagged(input); if (!settings.stylesheetSettingsFor(*stylesheet).card_spellcheck_enabled) SCRIPT_RETURN(input); - SCRIPT_OPTIONAL_PARAM_N_(String,_("extra dictionary"),extra_dictionary); - SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP,_("extra match"),extra_match); + SCRIPT_OPTIONAL_PARAM_(String, extra_dictionary); + SCRIPT_OPTIONAL_PARAM_(ScriptValueP, extra_match); // remove old spelling error tags input = remove_tag(input, _(" spelling checking @@ -176,6 +176,6 @@ SCRIPT_FUNCTION(check_spelling_word) { // ----------------------------------------------------------------------------- : Init void init_script_spelling_functions(Context& ctx) { - ctx.setVariable(_("check spelling"), script_check_spelling); - ctx.setVariable(_("check spelling word"), script_check_spelling_word); + ctx.setVariable(_("check_spelling"), script_check_spelling); + ctx.setVariable(_("check_spelling_word"), script_check_spelling_word); } diff --git a/src/script/script.cpp b/src/script/script.cpp index 907800c7..04cac23a 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -58,7 +58,7 @@ void init_script_variables() { Var(in); Var(match); Var(replace); - VarN(in_context,_("in context")); + Var(in_context); Var(recursive); Var(order); Var(begin); @@ -72,7 +72,7 @@ void init_script_variables() { Var(set); Var(game); Var(stylesheet); - VarN(card_style,_("card style")); + Var(card_style); Var(card); Var(styling); Var(value); diff --git a/src/util/io/package.cpp b/src/util/io/package.cpp index dc248974..aeaa09e6 100644 --- a/src/util/io/package.cpp +++ b/src/util/io/package.cpp @@ -495,7 +495,7 @@ IMPLEMENT_REFLECTION(Packaged) { REFLECT(installer_group); REFLECT(version); REFLECT(compatible_version); - REFLECT_NO_SCRIPT_N("depends ons", dependencies); // hack for singular_form + REFLECT_NO_SCRIPT_N("depends_ons", dependencies); // hack for singular_form } Packaged::Packaged() diff --git a/src/util/io/reader.hpp b/src/util/io/reader.hpp index 299591ed..a4a6a466 100644 --- a/src/util/io/reader.hpp +++ b/src/util/io/reader.hpp @@ -181,7 +181,7 @@ class Reader { /** Maybe the key is "include file" */ template void unknownKey(T& v) { - if (key == _("include file")) { + if (key == _("include_file")) { Reader reader(this, package, value, ignore_invalid); reader.handle_greedy(v); moveNext(); diff --git a/src/util/locale.hpp b/src/util/locale.hpp index 24384269..3f66b1fc 100644 --- a/src/util/locale.hpp +++ b/src/util/locale.hpp @@ -43,6 +43,8 @@ enum LocaleCategory typedef String (*DefaultLocaleFun)(const String&); /// Return the input and issue a warning String warn_and_identity(const String&); +/// Return the input and don't issue a warning +String identity(const String&); /// Translate 'key' in the category 'cat' using the current locale String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and_identity); diff --git a/src/util/string.cpp b/src/util/string.cpp index cc6694c9..3c675325 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -168,22 +168,47 @@ String capitalize_sentence(const String& s) { return ret; } +wxUniChar canonical_name_form(wxUniChar c) { + if (c == _(' ')) return _('_'); + return c; +} String canonical_name_form(const String& str) { String ret; ret.reserve(str.size()); - bool leading = true; + FOR_EACH_CONST(c, str) { + ret += canonical_name_form(c); + } + return ret; +} + +wxUniChar uncanonical_name_form(wxUniChar c) { + if (c == _('_')) return _(' '); + return c; +} +String uncanonical_name_form(const String& str) { + String ret; + ret.reserve(str.size()); + FOR_EACH_CONST(c, str) { + ret += uncanonical_name_form(c); + } + return ret; +} + +String name_to_caption(const String& str) { + String ret; + ret.reserve(str.size()); + bool leading = true, first = true; FOR_EACH_CONST(c, str) { if ((c == _('_') || c == _(' '))) { - ret += leading ? c : wxUniChar(' '); + ret += leading ? c : _(' '); + } else if (first) { + // capitalize_sentence + ret += toUpper(c); + leading = false; + first = false; } else { ret += c; leading = false; -/* - } else if (isAlnum(c) || c == _('-')) { - ret += toLower(c); - leading = false; - } else { - // ignore non alpha numeric*/ } } return ret; @@ -392,9 +417,10 @@ bool is_substr_i(const String& str, size_t pos, const String& cmp) { } bool canonical_name_compare(const String& as, const Char* b) { + assert(canonical_name_form(b) == b); const Char* a = as.c_str(); while (true) { - if (*a != *b && !(*a == _(' ') && *b == _('_'))) return false; + if (*a != *b && !(*a == _('_') && *b == _(' '))) return false; if (*a == _('\0')) return true; a++; b++; } diff --git a/src/util/string.hpp b/src/util/string.hpp index 039f044b..906da627 100644 --- a/src/util/string.hpp +++ b/src/util/string.hpp @@ -160,11 +160,14 @@ String capitalize(const String&); String capitalize_sentence(const String&); /// Convert a field name to canonical form -/** - lower case and ' ' instead of '_'. - * - non alphanumeric characters are droped - * - "camalCase" is converted to words "camel case" (TODO) +/** - converts ' ' to '_' */ String canonical_name_form(const String&); +/// Undo canonical_name_form: replace '_' by ' ' +String uncanonical_name_form(const String&); + +/// Convert a field name to a string that can be shown to the user +String name_to_caption(const String&); /// Returns the singular form of a string /** Used for reflection, for example "vector apples" is written with keys @@ -209,7 +212,10 @@ bool is_substr_i(const String& str, size_t pos, const String& cmp); /// Case insensitive string search, returns String::npos if not found size_t find_i(const String& heystack, const String& needle); -/// Compare two strings for equality, b may contain '_' where a contains ' ' +/// Compare two strings for equality, a may contain '_' where b contains ' ' +/** canoncial_name_compare(a,b) == (cannocial_name_form(a) == b) + * b should already be in cannonical name form + */ bool canonical_name_compare(const String& a, const Char* b); // ----------------------------------------------------------------------------- : Regular expressions