some cleanup
[squirrelmail.git] / functions / strings.php
index 00557ae498fbf1b8c789be19076fd725ef8054fe..23f1b1814ccaf9d36e1574fd2f279da7c8db9aa9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-/**
+/** 
  * strings.php
  *
  * Copyright (c) 1999-2002 The SquirrelMail Project Team
@@ -32,7 +32,7 @@
  * SquirrelMail version number -- DO NOT CHANGE
  */
 global $version;
-$version = '1.2.2 [cvs]';
+$version = '1.2.3 [cvs]';
 
 /**
  * If $haystack is a full mailbox name and $needle is the mailbox
@@ -66,18 +66,25 @@ function readMailboxParent($haystack, $needle) {
 }
 
 /**
- * Searches for the next position in a string minus white space.
+ * Returns the index of the first chunk of string $haystack that
+ * starts with non-white-space character, starting at position $pos.
+ * If there is no such chunk, returns -1.
  */
 function next_pos_minus_white ($haystack, $pos) {
-    while (substr($haystack, $pos, 1) == ' ' ||
-           substr($haystack, $pos, 1) == "\t" ||
-           substr($haystack, $pos, 1) == "\n" ||
-           substr($haystack, $pos, 1) == "\r") {
-        if ($pos >= strlen($haystack))
-            return -1;
-        $pos++;
-    }
-    return $pos;
+    $len = strlen($haystack);
+    while ($pos < $len) {
+        /* Get the next character. */
+        $c = substr($haystack, $pos, 1);
+        
+        /* Check the next character. */
+        if (($c != ' ') && ($c != "\t") && ($c != "\n") && ($c != "\r")) {
+            return $pos;
+        }
+
+        /* Increment position in string. */
+        ++$pos;
+    }
+    return -1;
 }
 
 /**