From 9d214f419dfaa30b10296c12989b0e5d887f5d8f Mon Sep 17 00:00:00 2001 From: Clemens Zeidler Date: Wed, 23 Mar 2011 21:22:42 +0000 Subject: [PATCH] Switch back to isspace for now. Have to read some utf8 stuff first. Feel free to fix it, though! will not do it in the near future... Fix header order, ups never changed a libbe file before ;) thx Oliver. Add small optimization as pointed out by Ingo. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41093 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/support/String.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/kits/support/String.cpp b/src/kits/support/String.cpp index ffa7e58190..e17c17cc34 100644 --- a/src/kits/support/String.cpp +++ b/src/kits/support/String.cpp @@ -14,14 +14,14 @@ /*! String class supporting common string operations. */ +#include + #include #include #include #include -#include #include -#include #include @@ -1970,22 +1970,20 @@ BString::Trim() const char* string = String(); // string is \0 terminated thus we don't need to check if we reached the end - uint32 startCount = 0; - while (iswspace(string[startCount])) + int32 startCount = 0; + while (isspace(string[startCount])) startCount++; - uint32 endCount = 0; - while (endCount < originalLength - startCount - && iswspace(string[originalLength - endCount - 1])) { - endCount++; - } + int32 endIndex = Length() - 1; + while (endIndex >= startCount && isspace(string[endIndex])) + endIndex--; - if (startCount == 0 && endCount == 0) + if (startCount == 0 && endIndex == Length() - 1) return *this; // We actually need to trim - ssize_t length = originalLength - startCount - endCount; + ssize_t length = endIndex + 1 - startCount; ASSERT(length >= 0); if (startCount == 0 || length == 0) { _MakeWritable(length, true);