summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-10-11 20:07:50 +0000
committerDavid Robillard <d@drobilla.net>2008-10-11 20:07:50 +0000
commitddcc92302dd6e09d87aadc0e91d2ee2e8a05b619 (patch)
tree5cd49b01d01e84e1826969e1f4df7ce25e396636 /src
parentc10bf72bee64ce87b8ed95a35568c2588ace66e8 (diff)
downloadraul-ddcc92302dd6e09d87aadc0e91d2ee2e8a05b619.tar.gz
raul-ddcc92302dd6e09d87aadc0e91d2ee2e8a05b619.tar.bz2
raul-ddcc92302dd6e09d87aadc0e91d2ee2e8a05b619.zip
Properly identify (and normalize) symbols that start with a number (illegal in C and LV2, among other things).
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@1644 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/Path.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Path.cpp b/src/Path.cpp
index 24ab2bd..435c452 100644
--- a/src/Path.cpp
+++ b/src/Path.cpp
@@ -42,16 +42,18 @@ Path::is_valid(const std::basic_string<char>& path)
if (path.find("//") != string::npos)
return false;
- // All characters must be _, a-z, A-Z, 0-9
+
for (size_t i=0; i < path.length(); ++i)
- if ( path[i] != '/' && path[i] != '_'
+ // All contained symbols must not start with a digit
+ if (i > 0 && path[i-1] == '/' && isdigit(path[i]))
+ return false;
+ // All characters must be _, a-z, A-Z, 0-9
+ else if ( path[i] != '/' && path[i] != '_'
&& (path[i] < 'a' || path[i] > 'z')
&& (path[i] < 'A' || path[i] > 'Z')
&& (path[i] < '0' || path[i] > '9') )
return false;
- // FIXME: first character can't be number?
-
#if 0
// Disallowed characters
if ( path.find(" ") != string::npos
@@ -155,9 +157,14 @@ Path::replace_invalid_chars(string& str, bool replace_slash)
str = str.substr(0, i) + '_' + str.substr(i);
}
#endif
+
+ if (isdigit(str[0]))
+ str = string("_").append(str);
for (size_t i=0; i < str.length(); ++i) {
- if (str[i] == '\'') {
+ if (i > 0 && str[i-1] == '/' && isdigit(str[i])) {
+ str = str.substr(0, i) + "_" + str.substr(i);
+ } else if (str[i] == '\'') {
str = str.substr(0, i) + str.substr(i+1);
#ifdef STRICT_SYMBOLS
} else if (str[i] >= 'A' && str[i] <= 'Z') {