diff options
-rw-r--r-- | src/BString.cc | 9 | ||||
-rw-r--r-- | tests/test-String.cc | 5 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/BString.cc b/src/BString.cc index 74d033e..262a9fa 100644 --- a/src/BString.cc +++ b/src/BString.cc @@ -48,16 +48,19 @@ Balau::String & Balau::String::do_ltrim() { } Balau::String & Balau::String::do_rtrim() { - unsigned int l = length(), p = l; + unsigned int i, l = length(), p = l; const char * buffer = data(); - for (unsigned int i = l - 1; i >= 0; i--) + for (i = l - 1; i > 0; i--) if (isspace(buffer[i])) p--; else break; - erase(p); + if ((i == 0) && isspace(buffer[0])) + assign("", 0); + else + erase(p); return *this; } diff --git a/tests/test-String.cc b/tests/test-String.cc index 8e6eacb..1f7efc0 100644 --- a/tests/test-String.cc +++ b/tests/test-String.cc @@ -27,6 +27,11 @@ void MainTask::Do() { x = y; x.do_rtrim(); Assert(x == " foo bar"); x = y; x.do_trim(); Assert(x == "foo bar"); + y = " "; + x = y; x.do_ltrim(); Assert(x == ""); + x = y; x.do_rtrim(); Assert(x == ""); + x = y; x.do_trim(); Assert(x == ""); + x = "42"; Assert(x.to_int() == 42); x = "0x42"; Assert(x.to_int() == 0x42); x = "42"; Assert(x.to_int(16) == 0x42); |