From 35c6b52c36ca047ada5b1b127128c03049ebfc89 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 23 Oct 2012 14:52:26 +0000 Subject: probable fix for not being able to find audio files in a 2.X session that had "illegal" characters in the session name - adds the 2.X version of the search path to the audio file search path, if it exists git-svn-id: svn://localhost/ardour2/branches/3.0@13321 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/utils.cc | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'libs/ardour/utils.cc') 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) { -- cgit v1.2.3