mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-14 17:36:31 +01:00
provide Glib::ustring() variant of strip_whitespace_edges
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@6541 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
db70bc225d
commit
1c26bd74d7
2 changed files with 49 additions and 34 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (isgraph (str[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == len) {
|
||||
/* it's all whitespace, not much we can do */
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue