mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 05:36:59 -04:00
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.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -181,7 +181,7 @@ class Reader {
|
||||
/** Maybe the key is "include file" */
|
||||
template <typename T>
|
||||
void unknownKey(T& v) {
|
||||
if (key == _("include file")) {
|
||||
if (key == _("include_file")) {
|
||||
Reader reader(this, package, value, ignore_invalid);
|
||||
reader.handle_greedy(v);
|
||||
moveNext();
|
||||
|
||||
@@ -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);
|
||||
|
||||
+35
-9
@@ -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++;
|
||||
}
|
||||
|
||||
+10
-4
@@ -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<T> 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
|
||||
|
||||
Reference in New Issue
Block a user