summaryrefslogtreecommitdiff
path: root/libs/ardour/utils.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ardour/utils.cc')
-rw-r--r--libs/ardour/utils.cc43
1 files changed, 42 insertions, 1 deletions
diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc
index 8c990a5e88..d9310c958a 100644
--- a/libs/ardour/utils.cc
+++ b/libs/ardour/utils.cc
@@ -60,12 +60,23 @@ using namespace ARDOUR;
using namespace std;
using namespace PBD;
+/** take an arbitrary string as an argument, and return a version of it
+ * suitable for use as a path (directory/folder name). This is the Ardour 3.X
+ * and later version of this code. It defines a very small number
+ * of characters that are not allowed in a path on any of our target
+ * filesystems, and replaces any instances of them with an underscore.
+ */
+
string
legalize_for_path (const string& str)
{
string::size_type pos;
string illegal_chars = "/\\"; /* DOS, POSIX. Yes, we're going to ignore HFS */
- string legal;
+ Glib::ustring legal;
+
+ /* this is the one place in Ardour where we need to iterate across
+ * potential multibyte characters, and thus we need Glib::ustring
+ */
legal = str;
pos = 0;
@@ -78,6 +89,36 @@ legalize_for_path (const string& str)
return string (legal);
}
+/** take an arbitrary string as an argument, and return a version of it
+ * suitable for use as a path (directory/folder name). This is the Ardour 2.X
+ * version of this code, which used an approach that came to be seen as
+ * problematic: defining the characters that were allowed and replacing all
+ * others with underscores. See legalize_for_path() for the 3.X and later
+ * version.
+ */
+
+string
+legalize_for_path_2X (const string& str)
+{
+ string::size_type pos;
+ string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=: ";
+ Glib::ustring legal;
+
+ /* this is the one place in Ardour where we need to iterate across
+ * potential multibyte characters, and thus we need Glib::ustring
+ */
+
+ legal = str;
+ pos = 0;
+
+ while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
+ legal.replace (pos, 1, "_");
+ pos += 1;
+ }
+
+ return string (legal);
+}
+
string
bump_name_once (const std::string& name, char delimiter)
{