The DECLARE_TYPEOF(()) calls don't work in MSVC, I changed it to use a COMMA macro instead of ,

If this doesn't work in GCC, the COMMA definition could be made only for MSVC, then GCC sees DECLARE_TYPEOF(map<int COMMA string>). GCC doesn't need DECLARE_TYPEOF anyway.

Keyword expansion now works, still todo:
 - marking parameters, e.g. "Cycling 2W" -> "Cycling <param-mana>2W</param-mana>"
 - user interface for toggling reminder text
 - user interface for keywords

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@210 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-03-17 23:58:16 +00:00
parent 83b6aa36f8
commit 0464f5f7fc
29 changed files with 560 additions and 161 deletions
+10 -3
View File
@@ -85,12 +85,19 @@
}
/// Declare typeof magic for a specific std::vector type
#define DECLARE_TYPEOF_COLLECTION(T) DECLARE_TYPEOF(vector<T>); \
// DECLARE_TYPEOF_CONST(set<T>)
#define DECLARE_TYPEOF_COLLECTION(T) DECLARE_TYPEOF(vector< T >); \
DECLARE_TYPEOF_CONST(set< T >)
#endif
/// Use for template classes
/** i.e.
* DECLARE_TYPEOF(pair<a COMMA b>);
* instead of
* DECLARE_TYPEOF(pair<a,b>);
*/
#define COMMA ,
// ----------------------------------------------------------------------------- : Looping macros with iterators
/// Iterate over a collection, using an iterator it of type Type
+2 -1
View File
@@ -97,8 +97,9 @@ String tr(const SymbolFont&, const String& key, const String& def);
inline String format_string(const String& format, ...) {
va_list args;
va_start(args, format);
return String::Format(format, args);
String res = String::Format(format, args);
va_end(args);
return res;
}
inline String format_string(const String& format, const String& a0) {
return String::Format(format, a0.c_str());
+12 -1
View File
@@ -9,7 +9,7 @@
/** @file util/platform.hpp
*
* @brief Platform specific hacks
* @brief Platform and compiler specific hacks.
*/
// ----------------------------------------------------------------------------- : Includes
@@ -23,11 +23,22 @@
#ifdef __linux__
/// wxMkDir as documented
inline void wxMkDir(const String& dir) {
wxMkDir(wxConvLocal.cWX2MB(dir), 0777);
}
#endif
// ----------------------------------------------------------------------------- : GCC
#ifdef __GNUC__
/// Absolute value of integers
template <typename T>
inline T abs(T a) { return a < 0 ? -a : a; }
#endif
// ----------------------------------------------------------------------------- : EOF
#endif
+2 -1
View File
@@ -113,7 +113,8 @@ String capitalize_sentence(const String&);
String cannocial_name_form(const String&);
/// Returns the singular form of a string
/** Used for reflection, for example "vector<T> apples" is written with keys "apple"
/** Used for reflection, for example "vector<T> apples" is written with keys
* singular_form("apples"), which is "apple"
*/
String singular_form(const String&);
+24 -2
View File
@@ -121,6 +121,10 @@ size_t match_close_tag(const String& str, size_t start) {
return String::npos;
}
size_t match_close_tag_end(const String& str, size_t start) {
return skip_tag(str, match_close_tag(str, start));
}
size_t last_start_tag_before(const String& str, const String& tag, size_t start) {
start = min(str.size(), start);
for (size_t pos = start ; pos > 0 ; --pos) {
@@ -178,7 +182,7 @@ size_t index_to_cursor(const String& str, size_t index, Movement dir) {
if (is_substr(str, i, _("<atom")) || is_substr(str, i, _("<sep"))) {
// skip tag contents, tag counts as a single 'character'
size_t before = i;
size_t after = skip_tag(str, match_close_tag(str, i));
size_t after = match_close_tag_end(str, i);
if (index > before && index < after) {
// index is inside an atom, determine on which side we want the cursor
if (dir == MOVE_RIGHT) {
@@ -215,7 +219,7 @@ void cursor_to_index_range(const String& str, size_t cursor, size_t& start, size
// a tag
if (is_substr(str, i, _("<atom")) || is_substr(str, i, _("<sep"))) {
// skip tag contents, tag counts as a single 'character'
i = skip_tag(str, match_close_tag(str, i));
i = match_close_tag_end(str, i);
} else {
i = skip_tag(str, i);
has_width = false;
@@ -259,6 +263,24 @@ size_t cursor_to_index(const String& str, size_t cursor, Movement dir) {
return dir == MOVE_RIGHT ? end - 1 : start;
}
// ----------------------------------------------------------------------------- : Untagged position
size_t untagged_to_index(const String& str, size_t pos, bool inside) {
size_t i = 0, p = 0;
while (i < str.size()) {
Char c = str.GetChar(i);
if (c == _('<')) {
bool is_close = is_substr(str, i, _("</"));
if (p == pos && is_close == inside) break;
i = skip_tag(str, i);
} else {
if (p == pos) break;
i++;
p++;
}
}
return i;
}
// ----------------------------------------------------------------------------- : Global operations
+14
View File
@@ -57,6 +57,12 @@ size_t skip_tag(const String& str, size_t start);
/** If not found returns String::npos */
size_t match_close_tag(const String& str, size_t start);
/// Find the position of the closing tag matching the tag at start
/** Returns the position just after that tag.
* match_close_tag_end(s,i) == skip_tag(s, match_close_tag(s,i) )
* If not found returns String::npos */
size_t match_close_tag_end(const String& str, size_t start);
/// Find the last start tag before position start
/** If not found returns String::npos */
size_t last_start_tag_before(const String& str, const String& tag, size_t start);
@@ -103,6 +109,14 @@ void cursor_to_index_range(const String& str, size_t cursor, size_t& begin, size
/// Find the character index corresponding to the given cursor position
size_t cursor_to_index(const String& str, size_t cursor, Movement dir = MOVE_MID);
// ----------------------------------------------------------------------------- : Untagged position
/// Find the tagged position corresponding to the given untagged position.
/** An untagged position in str is a position in untag(str).
* @param inside if inside then it prefers to find positions inside tags (after open tags, before close tags)
*/
size_t untagged_to_index(const String& str, size_t pos, bool inside);
// ----------------------------------------------------------------------------- : Global operations
/// Remove all instances of a tag and its close tag, but keep the contents.