summaryrefslogtreecommitdiff
path: root/libs/pbd/whitespace.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/pbd/whitespace.cc')
-rw-r--r--libs/pbd/whitespace.cc80
1 files changed, 45 insertions, 35 deletions
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