mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
CMake file
Update to C++ 11: std::shared_ptr, for each loops Update to wxWidgets 3.0+
This commit is contained in:
@@ -316,11 +316,18 @@ SCRIPT_FUNCTION(to_title) {
|
||||
SCRIPT_RETURN(capitalize(input.Lower()));
|
||||
}
|
||||
|
||||
String reverse_string(String const& input) {
|
||||
// Note: std::reverse doesn't work because of unicode encoding stuff
|
||||
String reversed;
|
||||
for (auto it = input.rbegin(); it != input.rend(); ++it) {
|
||||
reversed += *it;
|
||||
}
|
||||
return reversed;
|
||||
}
|
||||
// reverse a string
|
||||
SCRIPT_FUNCTION(reverse) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
reverse(input.begin(), input.end());
|
||||
SCRIPT_RETURN(input);
|
||||
SCRIPT_RETURN(reverse_string(input));
|
||||
}
|
||||
|
||||
// remove leading and trailing whitespace from a string
|
||||
@@ -370,12 +377,19 @@ SCRIPT_FUNCTION(regex_escape) {
|
||||
}
|
||||
|
||||
// sort/filter characters
|
||||
void sort_string(String& input) {
|
||||
vector<wxUniChar> chars;
|
||||
copy(input.begin(), input.end(), back_inserter(chars));
|
||||
sort(chars.begin(), chars.end());
|
||||
input.clear();
|
||||
for (auto c : chars) input += c;
|
||||
}
|
||||
SCRIPT_FUNCTION(sort_text) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
SCRIPT_OPTIONAL_PARAM_C(String, order) {
|
||||
SCRIPT_RETURN(spec_sort(order, input));
|
||||
} else {
|
||||
sort(input.begin(), input.end());
|
||||
sort_string(input);
|
||||
SCRIPT_RETURN(input);
|
||||
}
|
||||
}
|
||||
@@ -432,7 +446,6 @@ SCRIPT_FUNCTION(remove_tags) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Collection stuff
|
||||
|
||||
|
||||
/// position of some element in a vector
|
||||
/** 0 based index, -1 if not found */
|
||||
int position_in_vector(const ScriptValueP& of, const ScriptValueP& in, const ScriptValueP& order_by, const ScriptValueP& filter) {
|
||||
@@ -450,7 +463,7 @@ int position_in_vector(const ScriptValueP& of, const ScriptValueP& in, const Scr
|
||||
}
|
||||
} else {
|
||||
// unordered position
|
||||
ScriptValueP it = in->makeIterator(in);
|
||||
ScriptValueP it = in->makeIterator();
|
||||
int i = 0;
|
||||
while (ScriptValueP v = it->next()) {
|
||||
if (equal(of, v)) return i;
|
||||
@@ -473,7 +486,7 @@ ScriptValueP sort_script(Context& ctx, const ScriptValueP& list, ScriptValue& or
|
||||
if (list_t == SCRIPT_STRING) {
|
||||
// sort a string
|
||||
String s = list->toString();
|
||||
sort(s.begin(), s.end());
|
||||
sort_string(s);
|
||||
if (remove_duplicates) {
|
||||
s.erase( unique(s.begin(), s.end()), s.end() );
|
||||
}
|
||||
@@ -483,7 +496,7 @@ ScriptValueP sort_script(Context& ctx, const ScriptValueP& list, ScriptValue& or
|
||||
ScriptObject<Set*>* set = dynamic_cast<ScriptObject<Set*>*>(list.get());
|
||||
// sort a collection
|
||||
vector<pair<String,ScriptValueP> > values;
|
||||
ScriptValueP it = list->makeIterator(list);
|
||||
ScriptValueP it = list->makeIterator();
|
||||
while (ScriptValueP v = it->next()) {
|
||||
ctx.setVariable(set ? _("card") : _("input"), v);
|
||||
values.push_back(make_pair(order_by.eval(ctx)->toString(), v));
|
||||
@@ -558,7 +571,7 @@ SCRIPT_FUNCTION(filter_list) {
|
||||
SCRIPT_PARAM_C(ScriptValueP, filter);
|
||||
// filter a collection
|
||||
ScriptCustomCollectionP ret(new ScriptCustomCollection());
|
||||
ScriptValueP it = input->makeIterator(input);
|
||||
ScriptValueP it = input->makeIterator();
|
||||
while (ScriptValueP v = it->next()) {
|
||||
ctx.setVariable(SCRIPT_VAR_input, v);
|
||||
if (*filter->eval(ctx)) {
|
||||
@@ -581,7 +594,7 @@ SCRIPT_FUNCTION(random_shuffle) {
|
||||
SCRIPT_PARAM_C(ScriptValueP, input);
|
||||
// convert to CustomCollection
|
||||
ScriptCustomCollectionP ret(new ScriptCustomCollection());
|
||||
ScriptValueP it = input->makeIterator(input);
|
||||
ScriptValueP it = input->makeIterator();
|
||||
while (ScriptValueP v = it->next()) {
|
||||
ret->value.push_back(v);
|
||||
}
|
||||
@@ -620,7 +633,7 @@ SCRIPT_FUNCTION(random_select_many) {
|
||||
throw ScriptError(String::Format(_("Can not select %d items from a collection conaining only %d items"), count, input->itemCount()));
|
||||
}
|
||||
// transfer all to ret and shuffle
|
||||
ScriptValueP it = input->makeIterator(input);
|
||||
ScriptValueP it = input->makeIterator();
|
||||
while (ScriptValueP v = it->next()) {
|
||||
ret->value.push_back(v);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user