Implemented CardList

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@23 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-18 17:48:14 +00:00
parent 7504e0540f
commit 29d072e949
29 changed files with 762 additions and 63 deletions
+39
View File
@@ -61,6 +61,45 @@ String trim_left(const String& s) {
}
}
bool smart_less(const String& as, const String& bs) {
bool in_num = false; // are we inside a number?
bool lt = false; // is as less than bs?
bool eq = true; // so far is everything equal?
FOR_EACH_2_CONST(a, as, b, bs) {
bool na = isDigit(a), nb = isDigit(b);
Char la = toLower(a), lb = toLower(b);
if (na && nb) {
// compare numbers
in_num = true;
if (eq && a != b) {
eq = false;
lt = a < b;
}
} else if (in_num && na) {
// comparing numbers, one is longer, therefore it is greater
return false;
} else if (in_num && nb) {
return true;
} else if (in_num && !eq) {
// two numbers of the same length, but not equal
return lt;
} else {
// compare characters
if (la < lb) return true;
if (la > lb) return false;
}
in_num = na && nb;
}
// When we are at the end; shorter strings come first
// This is true for normal string collation
// and also when both end in a number and another digit follows
if (as.size() != bs.size()) {
return as.size() < bs.size();
} else {
return lt;
}
}
// ----------------------------------------------------------------------------- : Words
String last_word(const String& s) {