From ddcc92302dd6e09d87aadc0e91d2ee2e8a05b619 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 11 Oct 2008 20:07:50 +0000 Subject: 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 --- src/Path.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/Path.cpp') 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& 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') { -- cgit v1.2.1