]> granicus.if.org Git - php/commitdiff
Simplify php_u_trim().
authorAndrei Zmievski <andrei@php.net>
Wed, 16 Aug 2006 18:07:22 +0000 (18:07 +0000)
committerAndrei Zmievski <andrei@php.net>
Wed, 16 Aug 2006 18:07:22 +0000 (18:07 +0000)
ext/standard/string.c

index 418a4ef836086ecb8f25b9ddfc21adb150ca14cf..d0c453498c983275ec2b9a40d9da97261f9d937e 100644 (file)
@@ -709,10 +709,6 @@ static UChar *php_u_trim(UChar *c, int len, UChar *what, int what_len, zval *ret
        UChar   ch = 0, wh = 0;
        int32_t start = 0, end = len;
 
-       /*
-        * UTODO
-        * fix trim("a") results in ""
-        */
        if ( what ) {
                what = eustrndup(what, what_len);
                php_expand_u_trim_range(&what, &what_len TSRMLS_CC);
@@ -722,11 +718,9 @@ static UChar *php_u_trim(UChar *c, int len, UChar *what, int what_len, zval *ret
                for ( i = k = 0 ; i < end ; ) {
                        U16_NEXT(c, k, end, ch);
                        if ( what ) {
-                               for ( j = 0 ; j < what_len ;  ) {
-                                       U16_NEXT(what, j, what_len, wh);
-                                       if ( wh == ch ) break;
+                               if (u_memchr32(what, ch, what_len) == NULL) {
+                                       break;
                                }
-                               if ( wh != ch ) break;
                        } else {
                                if ( u_isWhitespace(ch) == FALSE ) {
                                        break;
@@ -740,11 +734,9 @@ static UChar *php_u_trim(UChar *c, int len, UChar *what, int what_len, zval *ret
                for ( i = k = end ; i > start ; ) {
                        U16_PREV(c, 0, k, ch);
                        if ( what ) {
-                               for ( j = 0 ; j < what_len ; ) {
-                                       U16_NEXT(what, j, what_len, wh);
-                                       if ( wh == ch ) break;
+                               if (u_memchr32(what, ch, what_len) == NULL) {
+                                       break;
                                }
-                               if ( wh != ch ) break;
                        } else {
                                if ( u_isWhitespace(ch) == FALSE ) {
                                        break;