2006-01-13 14:48:55 -05:00
|
|
|
#include <pbd/whitespace.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2006-12-01 01:01:30 -05:00
|
|
|
namespace PBD {
|
|
|
|
|
2006-01-13 14:48:55 -05:00
|
|
|
void
|
|
|
|
strip_whitespace_edges (string& str)
|
|
|
|
{
|
|
|
|
string::size_type i;
|
|
|
|
string::size_type len;
|
2007-01-16 21:35:16 -05:00
|
|
|
string::size_type s = 0;
|
2006-01-13 14:48:55 -05:00
|
|
|
|
|
|
|
len = str.length();
|
2006-07-27 12:52:14 -04:00
|
|
|
|
2006-11-12 22:11:32 -05:00
|
|
|
if (len == 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-27 12:52:14 -04:00
|
|
|
/* strip front */
|
2006-01-13 14:48:55 -05:00
|
|
|
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
if (isgraph (str[i])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-12 22:11:32 -05:00
|
|
|
if (i == len) {
|
2006-12-01 01:01:30 -05:00
|
|
|
/* it's all whitespace, not much we can do */
|
|
|
|
str = "";
|
2006-11-12 22:11:32 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-27 12:52:14 -04:00
|
|
|
/* strip back */
|
|
|
|
|
|
|
|
if (len > 1) {
|
|
|
|
|
|
|
|
s = i;
|
|
|
|
i = len - 1;
|
2006-11-12 22:11:32 -05:00
|
|
|
|
|
|
|
if (s == i) {
|
|
|
|
return;
|
|
|
|
}
|
2006-07-27 12:52:14 -04:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (isgraph (str[i]) || i == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2006-01-13 14:48:55 -05:00
|
|
|
|
2006-07-27 12:52:14 -04:00
|
|
|
--i;
|
|
|
|
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
str = str.substr (s, (i - s) + 1);
|
2006-01-13 14:48:55 -05:00
|
|
|
|
2006-07-27 12:52:14 -04:00
|
|
|
} else {
|
|
|
|
str = str.substr (s);
|
|
|
|
}
|
2006-01-13 14:48:55 -05:00
|
|
|
}
|
|
|
|
|
2006-12-01 01:01:30 -05:00
|
|
|
} // namespace PBD
|