[haiku-commits] r41093 - haiku/trunk/src/kits/support

  • From: clemens.zeidler@xxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 23 Mar 2011 22:22:42 +0100 (CET)

Author: czeidler
Date: 2011-03-23 22:22:42 +0100 (Wed, 23 Mar 2011)
New Revision: 41093
Changeset: https://dev.haiku-os.org/changeset/41093

Modified:
   haiku/trunk/src/kits/support/String.cpp
Log:
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.



Modified: haiku/trunk/src/kits/support/String.cpp
===================================================================
--- haiku/trunk/src/kits/support/String.cpp     2011-03-23 19:13:21 UTC (rev 
41092)
+++ haiku/trunk/src/kits/support/String.cpp     2011-03-23 21:22:42 UTC (rev 
41093)
@@ -14,14 +14,14 @@
 
 /*! String class supporting common string operations. */
 
+#include <String.h>
+
 #include <ctype.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <wctype.h>
 
 #include <Debug.h>
-#include <String.h>
 
 #include <utf8_functions.h>
 
@@ -1970,22 +1970,20 @@
        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);


Other related posts: