mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
Added 'filter' support to position function; Made sure sort script can depend on the value of the field itself.
Cleaned up some things, why is a blank image not thread safe? git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@548 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -19,8 +19,10 @@ template <typename T>
|
||||
class OrderCache : public IntrusivePtrBase<OrderCache<T> > {
|
||||
public:
|
||||
/// Initialize the order cache, ordering the keys by their string values from the other vector
|
||||
/** @pre keys.size() == values.size() */
|
||||
OrderCache(const vector<T>& keys, const vector<String>& values);
|
||||
/** Optionally filter the list using a vector of booleans of items to keep (note: vector<bool> is evil)
|
||||
* @pre keys.size() == values.size()
|
||||
*/
|
||||
OrderCache(const vector<T>& keys, const vector<String>& values, vector<int>* keep = nullptr);
|
||||
|
||||
/// Find the position of the given key in the cache, returns -1 if not found
|
||||
int find(const T& key) const;
|
||||
@@ -52,13 +54,16 @@ struct OrderCache<T>::CompareValues {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
OrderCache<T>::OrderCache(const vector<T>& keys, const vector<String>& values) {
|
||||
OrderCache<T>::OrderCache(const vector<T>& keys, const vector<String>& values, vector<int>* keep) {
|
||||
assert(keys.size() == values.size());
|
||||
assert(!keep || keep->size() == keys.size());
|
||||
// initialize positions, use pos to point back to the values vector
|
||||
positions.reserve(keys.size());
|
||||
int i = 0;
|
||||
for (typename vector<T>::const_iterator it = keys.begin() ; it != keys.end() ; ++it, ++i) {
|
||||
positions.push_back(KV(&**it, i));
|
||||
if (!keep || (*keep)[i]) {
|
||||
positions.push_back(KV(&**it, i));
|
||||
}
|
||||
}
|
||||
// sort the KVs by the values
|
||||
sort(positions.begin(), positions.end(), CompareValues(values));
|
||||
|
||||
+9
-7
@@ -68,6 +68,7 @@ void writeUTF8(wxTextOutputStream& stream, const String& str);
|
||||
#define RIGHT_SINGLE_QUOTE _('\x2019')
|
||||
#define LEFT_DOUBLE_QUOTE _('\x201C')
|
||||
#define RIGHT_DOUBLE_QUOTE _('\x201D')
|
||||
#define CONNECTION_SPACE _('\xEB00') // in private use are, untags to ' '
|
||||
#else
|
||||
#define LEFT_ANGLE_BRACKET _("<")
|
||||
#define RIGHT_ANGLE_BRACKET _(">")
|
||||
@@ -75,18 +76,19 @@ void writeUTF8(wxTextOutputStream& stream, const String& str);
|
||||
#define RIGHT_SINGLE_QUOTE _('\'')
|
||||
#define LEFT_DOUBLE_QUOTE _('\"')
|
||||
#define RIGHT_DOUBLE_QUOTE _('\"')
|
||||
#define CONNECTION_SPACE _(' ') // too bad
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------- : Char functions
|
||||
|
||||
// Character set tests
|
||||
inline bool isSpace(Char c) { return IF_UNICODE( iswspace(c) , isspace(c) ); }
|
||||
inline bool isAlpha(Char c) { return IF_UNICODE( iswalpha(c) , isalpha(c) ); }
|
||||
inline bool isDigit(Char c) { return IF_UNICODE( iswdigit(c) , isdigit(c) ); }
|
||||
inline bool isAlnum(Char c) { return IF_UNICODE( iswalnum(c) , isalnum(c) ); }
|
||||
inline bool isUpper(Char c) { return IF_UNICODE( iswupper(c) , isupper(c) ); }
|
||||
inline bool isLower(Char c) { return IF_UNICODE( iswlower(c) , islower(c) ); }
|
||||
inline bool isPunct(Char c) { return IF_UNICODE( iswpunct(c) , ispunct(c) ); }
|
||||
inline bool isSpace(Char c) { return IF_UNICODE( iswspace(c) , isspace((unsigned char)c) ) || c == CONNECTION_SPACE; }
|
||||
inline bool isAlpha(Char c) { return IF_UNICODE( iswalpha(c) , isalpha((unsigned char)c) ); }
|
||||
inline bool isDigit(Char c) { return IF_UNICODE( iswdigit(c) , isdigit((unsigned char)c) ); }
|
||||
inline bool isAlnum(Char c) { return IF_UNICODE( iswalnum(c) , isalnum((unsigned char)c) ); }
|
||||
inline bool isUpper(Char c) { return IF_UNICODE( iswupper(c) , isupper((unsigned char)c) ); }
|
||||
inline bool isLower(Char c) { return IF_UNICODE( iswlower(c) , islower((unsigned char)c) ); }
|
||||
inline bool isPunct(Char c) { return IF_UNICODE( iswpunct(c) , ispunct((unsigned char)c) ); }
|
||||
// Character conversions
|
||||
#ifdef _MSC_VER
|
||||
#define CHAR_FUNCTIONS_ARE_SLOW
|
||||
|
||||
@@ -11,12 +11,24 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : Conversion to/from normal string
|
||||
|
||||
Char untag_char(Char c) {
|
||||
if (c == _('\1')) return _('<');
|
||||
else if (c == CONNECTION_SPACE) return _(' ');
|
||||
else return c;
|
||||
}
|
||||
|
||||
Char tag_char(Char c) {
|
||||
if (c == _('<')) return _('\1');
|
||||
else return c;
|
||||
}
|
||||
|
||||
|
||||
String untag(const String& str) {
|
||||
bool intag = false;
|
||||
String ret; ret.reserve(str.size());
|
||||
FOR_EACH_CONST(c, str) {
|
||||
if (c==_('<')) intag = true;
|
||||
if (!intag) ret += c==_('\1') ? _('<') : c;
|
||||
if (!intag) ret += untag_char(c);
|
||||
if (c==_('>')) intag = false;
|
||||
}
|
||||
return ret;
|
||||
@@ -40,8 +52,7 @@ String untag_hide_sep(const String& str) {
|
||||
String escape(const String& str) {
|
||||
String ret; ret.reserve(str.size());
|
||||
FOR_EACH_CONST(c, str) {
|
||||
if (c==_('<')) ret += _('\1');
|
||||
else ret += c;
|
||||
ret += tag_char(c);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : Conversion to/from normal string
|
||||
|
||||
Char untag_char(Char c);
|
||||
Char tag_char(Char c);
|
||||
|
||||
/// Remove all tags from a string and convert escaped '<' back to normal '<'
|
||||
/** e.g. "<sym>R</> something <i>(note)</>"
|
||||
* becomes "R something (note)"
|
||||
|
||||
Reference in New Issue
Block a user