diff options
Diffstat (limited to 'libs/pbd/whitespace.cc')
-rw-r--r-- | libs/pbd/whitespace.cc | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/libs/pbd/whitespace.cc b/libs/pbd/whitespace.cc index 7f74940457..e35a8a8c0e 100644 --- a/libs/pbd/whitespace.cc +++ b/libs/pbd/whitespace.cc @@ -7,9 +7,11 @@ strip_whitespace_edges (string& str) { string::size_type i; string::size_type len; - string::size_type s; + string::size_type s; len = str.length(); + + /* strip front */ for (i = 0; i < len; ++i) { if (isgraph (str[i])) { @@ -17,14 +19,26 @@ strip_whitespace_edges (string& str) } } - s = i; + /* strip back */ + + if (len > 1) { + + s = i; + i = len - 1; + + do { + if (isgraph (str[i]) || i == 0) { + break; + } - for (i = len - 1; i >= 0; --i) { - if (isgraph (str[i])) { - break; - } - } + --i; + + } while (true); + + str = str.substr (s, (i - s) + 1); - str = str.substr (s, (i - s) + 1); + } else { + str = str.substr (s); + } } |