From: Arcady G. <ant...@us...> - 2001-12-30 15:35:26
|
Update of /cvsroot/squirrelmail/squirrelmail/functions In directory usw-pr-cvs1:/tmp/cvs-serv28478 Modified Files: strings.php Log Message: Rewrote next_pos_minus_white() to fix correctness and efficiency problems. Rewrote comment for the function. Index: strings.php =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/functions/strings.php,v retrieving revision 1.127 retrieving revision 1.128 diff -u -w -r1.127 -r1.128 --- strings.php 2001/12/30 15:02:39 1.127 +++ strings.php 2001/12/30 15:35:23 1.128 @@ -66,18 +66,19 @@ } /** - * 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++; - } + $len = strlen($haystack); + for ( ; $pos < $len; $pos++ ) { + $char = substr($haystack, $pos, 1); + if ( $char != ' ' && $char != "\t" && $char != "\n" && $char != "\r" ) { return $pos; + } + } + return -1; } /** |