summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-09-06 22:07:53 +0000
committerDavid Robillard <d@drobilla.net>2006-09-06 22:07:53 +0000
commit445b55c6d13db5fffe18113cd6664e7923f8251b (patch)
tree86d4fcb6b18e49ef3bd1c9e28334a365d9d3931e /src
parent80923fdb966c74263a723f2ac6a39ea44efb07b2 (diff)
downloadingen-445b55c6d13db5fffe18113cd6664e7923f8251b.tar.gz
ingen-445b55c6d13db5fffe18113cd6664e7923f8251b.tar.bz2
ingen-445b55c6d13db5fffe18113cd6664e7923f8251b.zip
Another fix for port names (mangling for port name clashes)
git-svn-id: http://svn.drobilla.net/lad/ingen@116 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/common/util/Path.h66
-rw-r--r--src/libs/engine/LADSPANode.cpp4
2 files changed, 35 insertions, 35 deletions
diff --git a/src/common/util/Path.h b/src/common/util/Path.h
index 353ecaca..2c4d58b1 100644
--- a/src/common/util/Path.h
+++ b/src/common/util/Path.h
@@ -48,6 +48,7 @@ public:
assert(is_valid(path));
}
+
/** Construct a Path from a C string.
*
* It is a fatal error to construct a Path from an invalid string,
@@ -59,6 +60,7 @@ public:
assert(is_valid(cpath));
}
+
static bool is_valid(const std::basic_string<char>& path)
{
if (path.length() == 0)
@@ -94,7 +96,8 @@ public:
return true;
}
- /** Convert a string in to a valid full path.
+
+ /** Convert a string to a valid full path.
*
* This will make a best effort at turning @a str into a complete, valid
* Path, and will always return one.
@@ -116,28 +119,14 @@ public:
assert(path.find_last_of("/") != string::npos);
- // Replace any invalid characters with "." (for lack of a better idea)
- for (size_t i=0; i < path.length(); ++i) {
- if (path.at(i) < 32 || path.at(i) > 126
- || path.at(i) == ' '
- || path.at(i) == '#'
- || path.at(i) == '*'
- || path.at(i) == ','
- || path.at(i) == '?'
- || path.at(i) == '['
- || path.at(i) == ']'
- || path.at(i) == '{'
- || path.at(i) == '}') {
- path[i] = '.';
- }
- }
+ replace_invalid_chars(path, false);
assert(is_valid(path));
return path;
}
- /** Convert a string into a valid name (or "method" - tokens between slashes)
+ /** Convert a string to a valid name (or "method" - tokens between slashes)
*
* This will strip all slashes and always return a valid name/method.
*/
@@ -148,26 +137,37 @@ public:
if (name.length() == 0)
return "."; // this might not be wise
- // Replace any invalid characters with "." (for lack of a better idea)
- for (size_t i=0; i < name.length(); ++i) {
- if (name.at(i) < 32 || name.at(i) > 126
- || name.at(i) == ' '
- || name.at(i) == '#'
- || name.at(i) == '*'
- || name.at(i) == ','
- || name.at(i) == '?'
- || name.at(i) == '['
- || name.at(i) == ']'
- || name.at(i) == '{'
- || name.at(i) == '}'
- || name.at(i) == '/') {
- name[i] = '.';
- }
- }
+ replace_invalid_chars(name, true);
+
+ assert(is_valid(string("/") + name));
return name;
}
+
+ /** Replace any invalid characters in @a str with a suitable replacement.
+ */
+ 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] = '_';
+ } 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] == ','
+ || str[i] == '?'
+ || (replace_slash && str[i] == '/')) {
+ str[i] = '.';
+ }
+ }
+ }
+
/** Return the name of this object (everything after the last '/').
* This is the "method name" for OSC paths.
diff --git a/src/libs/engine/LADSPANode.cpp b/src/libs/engine/LADSPANode.cpp
index 0be82819..96be6771 100644
--- a/src/libs/engine/LADSPANode.cpp
+++ b/src/libs/engine/LADSPANode.cpp
@@ -83,9 +83,9 @@ LADSPANode::instantiate()
assert(_descriptor->PortNames[k] != NULL);
if (k != j && port_name == _descriptor->PortNames[k]) { // clash
if (LADSPA_IS_PORT_CONTROL(_descriptor->PortDescriptors[j]))
- port_name += " (CR)";
+ port_name += "_(CR)";
else
- port_name += " (AR)";
+ port_name += "_(AR)";
}
// Replace all slashes with "-" (so they don't screw up paths)
while ((slash_index = port_name.find("/")) != string::npos)