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);