diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-01-22 16:57:30 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-01-22 16:57:30 +0000 |
commit | 1c26bd74d7ff2a4ee0fde76adc2cdc0d11548cfd (patch) | |
tree | b61a606c3ea32a9a7395090f609e2c1668fc8e03 | |
parent | db70bc225de7bac876f312de17fa2b991d4b2cdf (diff) |
provide Glib::ustring() variant of strip_whitespace_edges
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@6541 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | libs/pbd/pbd/whitespace.h | 5 | ||||
-rw-r--r-- | libs/pbd/whitespace.cc | 80 |
2 files changed, 50 insertions, 35 deletions
diff --git a/libs/pbd/pbd/whitespace.h b/libs/pbd/pbd/whitespace.h index 444be112b0..dcdb4e5f27 100644 --- a/libs/pbd/pbd/whitespace.h +++ b/libs/pbd/pbd/whitespace.h @@ -22,11 +22,16 @@ #include <string> +namespace Glib { + class ustring; +} + namespace PBD { // returns the empty string if the entire string is whitespace // so check length after calling. extern void strip_whitespace_edges (std::string& str); +extern void strip_whitespace_edges (Glib::ustring& str); } // namespace PBD diff --git a/libs/pbd/whitespace.cc b/libs/pbd/whitespace.cc index b09d830103..126039842e 100644 --- a/libs/pbd/whitespace.cc +++ b/libs/pbd/whitespace.cc @@ -18,6 +18,7 @@ */ #include <pbd/whitespace.h> +#include <glibmm/ustring.h> using namespace std; @@ -26,55 +27,64 @@ namespace PBD { void strip_whitespace_edges (string& str) { - string::size_type i; - string::size_type len; - string::size_type s = 0; + string::size_type i; + string::size_type len; + string::size_type s = 0; - len = str.length(); + len = str.length(); - if (len == 1) { - return; - } + if (len == 1) { + return; + } - /* strip front */ + /* strip front */ - for (i = 0; i < len; ++i) { - if (isgraph (str[i])) { - break; - } - } - - if (i == len) { - /* it's all whitespace, not much we can do */ + for (i = 0; i < len; ++i) { + if (isgraph (str[i])) { + break; + } + } + + if (i == len) { + /* it's all whitespace, not much we can do */ str = ""; - return; - } + return; + } - /* strip back */ + /* strip back */ - if (len > 1) { + if (len > 1) { - s = i; - i = len - 1; + s = i; + i = len - 1; - if (s == i) { - return; - } + if (s == i) { + return; + } - do { - if (isgraph (str[i]) || i == 0) { - break; - } + do { + if (isgraph (str[i]) || i == 0) { + break; + } - --i; + --i; - } while (true); + } while (true); - str = str.substr (s, (i - s) + 1); + str = str.substr (s, (i - s) + 1); - } else { - str = str.substr (s); - } + } else { + str = str.substr (s); + } } +void +strip_whitespace_edges (Glib::ustring& str) +{ + string copy (str.raw()); + strip_whitespace_edges (copy); + str = copy; +} + + } // namespace PBD |