made a start with script functions

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@62 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-31 12:17:36 +00:00
parent 0caaf01a78
commit 1ffaa5bd58
20 changed files with 372 additions and 29 deletions
+10 -1
View File
@@ -37,7 +37,8 @@ void handle_error(const String& e, bool allow_duplicate = true, bool now = true)
}
// Only show errors in the main thread
if (!now || !wxThread::IsMain()) {
pending_error = e;
if (!pending_error.empty()) pending_error += _("\n\n");
pending_error += e;
return;
}
// show message
@@ -47,3 +48,11 @@ void handle_error(const String& e, bool allow_duplicate = true, bool now = true)
void handle_error(const Error& e, bool allow_duplicate, bool now) {
handle_error(e.what(), allow_duplicate, now);
}
void handle_pending_errors() {
assert(wxThread::IsMain());
if (!pending_error.empty()) {
handle_error(pending_error);
pending_error.clear();
}
}
+1 -1
View File
@@ -65,7 +65,7 @@ void Reader::showWarnings() {
bool Reader::enterBlock(const Char* name) {
if (just_opened) moveNext(); // on the key of the parent block, first move inside it
if (indent != expected_indent) return false; // not enough indentation
if (name == key) {
if (cannocial_name_compare(key, name)) {
just_opened = true;
expected_indent += 1; // the indent inside the block must be at least this much
return true;
+1 -1
View File
@@ -134,7 +134,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(value);
reader.handle(v);
moveNext();
+1 -3
View File
@@ -35,7 +35,7 @@ void Writer::enterBlock(const Char* name) {
}
// don't write the key yet
indentation += 1;
opened_key = name;
opened_key = cannocial_name_form(name);
just_opened = true;
}
@@ -47,8 +47,6 @@ void Writer::exitBlock() {
void Writer::writeKey() {
writeIndentation();
// Use ' ' instead of '_' because it is more human readable
FOR_EACH(c, opened_key) if (c == _('_')) c = _(' ');
writeUTF8(stream, opened_key);
}
void Writer::writeIndentation() {
+10 -1
View File
@@ -123,7 +123,7 @@ String cannocial_name_form(const String& str) {
bool leading = true;
FOR_EACH_CONST(c, str) {
if ((c == _('_') || c == _(' ')) && !leading) {
ret += _('_');
ret += _(' ');
} else if (isAlnum(c)) {
ret += toLower(c);
leading = false;
@@ -195,3 +195,12 @@ bool is_substr(const String& str, size_t pos, const Char* cmp) {
}
return *cmp == _('\0');
}
bool cannocial_name_compare(const String& as, const Char* b) {
const Char* a = as.c_str();
while (true) {
if (*a != *b && !(*a == _(' ') && *b == _('_'))) return false;
if (*a == _('\0')) return true;
a++; b++;
}
}
+4 -1
View File
@@ -100,7 +100,7 @@ String capitalize(const String&);
String capitalize_sentence(const String&);
/// Convert a field name to cannocial form
/** - lower case and '_' instead of ' '.
/** - lower case and ' ' instead of '_'.
* - non alphanumeric characters are droped
* - "camalCase" is converted to words "camel case" (TODO)
*/
@@ -127,5 +127,8 @@ bool starts_with(const String& str, const String& start);
/// Return whether str contains the string cmp at position pos
bool is_substr(const String& str, size_t pos, const Char* cmp);
/// Compare two strings for equality, b may contain '_' where a contains ' '
bool cannocial_name_compare(const String& a, const Char* b);
// ----------------------------------------------------------------------------- : EOF
#endif