summaryrefslogtreecommitdiffstats
path: root/src/common/util/Path.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-09-30 06:47:00 +0000
committerDavid Robillard <d@drobilla.net>2006-09-30 06:47:00 +0000
commit35a5d92cfcf6815553a0939c3e2bf77c1108fd31 (patch)
tree456351b4b18d48aba25a2db7218df9be09d4047e /src/common/util/Path.h
parentd82dcd232f201b531a0be165ee44aede1bc8a1df (diff)
downloadingen-35a5d92cfcf6815553a0939c3e2bf77c1108fd31.tar.gz
ingen-35a5d92cfcf6815553a0939c3e2bf77c1108fd31.tar.bz2
ingen-35a5d92cfcf6815553a0939c3e2bf77c1108fd31.zip
Work on RDF serialization (only (partial) saving so far).
git-svn-id: http://svn.drobilla.net/lad/ingen@146 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/common/util/Path.h')
-rw-r--r--src/common/util/Path.h28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/common/util/Path.h b/src/common/util/Path.h
index 2fcf5774..bcb047ad 100644
--- a/src/common/util/Path.h
+++ b/src/common/util/Path.h
@@ -17,6 +17,7 @@
#ifndef PATH_H
#define PATH_H
+#include <cctype>
#include <string>
#include <cassert>
using std::string;
@@ -137,7 +138,7 @@ public:
/** Convert a string to a valid name (or "method" - tokens between slashes)
*
- * This will strip all slashes and always return a valid name/method.
+ * This will strip all slashes, etc, and always return a valid name/method.
*/
static string nameify(const std::basic_string<char>& str)
{
@@ -155,18 +156,22 @@ public:
/** Replace any invalid characters in @a str with a suitable replacement.
+ *
+ * Makes a pretty name - underscores are a valid character, but this chops
+ * both spaces and underscores, uppercasing the next letter, to create
+ * uniform CamelCase names that look nice
*/
static void replace_invalid_chars(string& str, bool replace_slash = false)
{
for (size_t i=0; i < str.length(); ++i) {
- if (str[i] == ' ') {
- str[i] = '_';
+ if (str[i] == ' ' || str[i] == '_') {
+ str[i+1] = std::toupper(str[i+1]); // capitalize next char
+ str = str.substr(0, i) + str.substr(i+1); // chop space/underscore
} else if (str[i] == '[' || str[i] == '{') {
str[i] = '(';
} else if (str[i] == ']' || str[i] == '}') {
str[i] = ')';
} else if (str[i] < 32 || str.at(i) > 126
- || str[i] == ' '
|| str[i] == '#'
|| str[i] == '*'
|| str[i] == ','
@@ -175,6 +180,21 @@ public:
str[i] = '.';
}
}
+
+ // Chop brackets
+ while (true) {
+
+ const string::size_type open = str.find("(");
+ const string::size_type close = str.find(")");
+
+ if (open != string::npos) {
+ if (close != string::npos)
+ str.erase(open, (close - open) + 1);
+ } else {
+ break;
+ }
+
+ }
}