moriyoshi               Sun Oct  6 11:38:34 2002 EDT

  Modified files:              (Branch: PHP_4_3)
    /php4/ext/mbstring  php_mbregex.c 
  Log:
  Added support for aliases of the encoding names. 
  
  
  
Index: php4/ext/mbstring/php_mbregex.c
diff -u php4/ext/mbstring/php_mbregex.c:1.5 php4/ext/mbstring/php_mbregex.c:1.5.2.1
--- php4/ext/mbstring/php_mbregex.c:1.5 Tue Aug 27 11:32:04 2002
+++ php4/ext/mbstring/php_mbregex.c     Sun Oct  6 11:38:33 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_mbregex.c,v 1.5 2002/08/27 15:32:04 helly Exp $ */
+/* $Id: php_mbregex.c,v 1.5.2.1 2002/10/06 15:38:33 moriyoshi Exp $ */
 
 
 #ifdef HAVE_CONFIG_H
@@ -90,22 +90,23 @@
 
        mbctype = -1;
        if (pname != NULL) {
-               if (strcasecmp("EUC-JP", pname) == 0) {
+               if (strcasecmp("EUC-JP", pname) == 0
+                   || strcasecmp("X-EUC-JP", pname) == 0
+                   || strcasecmp("UJIS", pname) == 0
+                   || strcasecmp("EUCJP", pname) == 0
+                   || strcasecmp("EUC_JP", pname) == 0) {
                        mbctype = MBCTYPE_EUC;
-               } else if (strcasecmp("UTF-8", pname) == 0) {
+               } else if (strcasecmp("UTF-8", pname) == 0
+                          || strcasecmp("UTF8", pname) == 0) {
                        mbctype = MBCTYPE_UTF8;
-               } else if (strcasecmp("SJIS", pname) == 0) {
+               } else if (strcasecmp("SJIS", pname) == 0
+                          || strcasecmp("CP932", pname) == 0
+                          || strcasecmp("MS932", pname) == 0
+                          || strcasecmp("SHIFT_JIS", pname) == 0 ) {
                        mbctype = MBCTYPE_SJIS;
-               } else if (strcasecmp("ascii", pname) == 0) {
+               } else if (strcasecmp("ASCII", pname) == 0) {
                        mbctype = MBCTYPE_ASCII;
-               } else if (strcasecmp("euc", pname) == 0) {
                        mbctype = MBCTYPE_EUC;
-               } else if (strcasecmp("eucJP", pname) == 0) {
-                       mbctype = MBCTYPE_EUC;
-               } else if (strcasecmp("EUC_JP", pname) == 0) {
-                       mbctype = MBCTYPE_EUC;
-               } else if (strcasecmp("Shift_JIS", pname) == 0) {
-                       mbctype = MBCTYPE_SJIS;
                }
        }
 
@@ -115,7 +116,7 @@
 static const char*
 php_mbregex_mbctype2name(int mbctype)
 {
-       const char *p;
+       const char *p = NULL;
 
        if (mbctype == MBCTYPE_EUC) {
                p = "EUC-JP";
@@ -125,8 +126,6 @@
                p = "SJIS";
        } else if(mbctype == MBCTYPE_ASCII) {
                p = "ascii";
-       } else {
-               p = "unknown";
        }
 
        return p;
@@ -224,12 +223,18 @@
        int mbctype;
 
        if (ZEND_NUM_ARGS() == 0) {
-               
RETVAL_STRING((char*)php_mbregex_mbctype2name(MBSTRG(current_mbctype)), 1);
-       } else if (ZEND_NUM_ARGS() == 1 && zend_get_parameters_ex(1, &arg1) != 
FAILURE) {
+               const char *retval = php_mbregex_mbctype2name(MBSTRG(current_mbctype));
+               if ( retval != NULL ) {
+                       RETVAL_STRING((char *)retval);
+               } else {
+                       RETVAL_FALSE;
+               }
+       } else if (ZEND_NUM_ARGS() == 1 &&
+                  zend_get_parameters_ex(1, &arg1) != FAILURE) {
                convert_to_string_ex(arg1);
                mbctype = php_mbregex_name2mbctype(Z_STRVAL_PP(arg1));
                if (mbctype < 0) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "unknown encoding 
\"%s\"", Z_STRVAL_PP(arg1));
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown encoding 
+\"%s\"", Z_STRVAL_PP(arg1));
                        RETVAL_FALSE;
                } else {
                        MBSTRG(current_mbctype) = mbctype;
@@ -307,7 +312,9 @@
                mbre_free_registers(&regs);
                RETURN_FALSE;
        }
-
+       if (regs.beg[0] == regs.end[0]) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty regular 
+expression");
+       }
        match_len = 1;
        str = Z_STRVAL_PP(arg_string);
        if (array) {
@@ -423,6 +430,10 @@
        pos = 0;
        while (err >= 0) {
                err = mbre_search(&re, string, string_len, pos, string_len - pos, 
&regs);
+               if ( regs.beg[0] == regs.end[0] ) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty regular 
+expression");
+                       break;
+               }
                if (err <= -2) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "mbregex search 
failure in php_mbereg_replace_exec()");
                        break;
@@ -565,20 +576,19 @@
        /* churn through str, generating array entries as we go */
        while ((count != 0) &&
                   (err = mbre_search(&re, string, string_len, pos, string_len - pos, 
&regs)) >= 0) {
+               if ( regs.beg[0] == regs.end[0] ) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty regular 
+expression");
+                       break;
+               }
+
                n = regs.beg[0];
-               if (n == pos) {
-                       /* match is at start of string, return empty string */
-                       add_next_index_stringl(return_value, empty_string, 0, 1);
+               /* add it to the array */
+               if (n < string_len && n <= pos) {
+                       n -= pos;
+                       add_next_index_stringl(return_value, &string[pos], n, 1);
                } else {
-                       /* On a real match */
-                       /* add it to the array */
-                       if (n < string_len) {
-                               n -= pos;
-                               add_next_index_stringl(return_value, &string[pos], n, 
1);
-                       } else {
-                               err = -2;
-                               break;
-                       }
+                       err = -2;
+                       break;
                }
                /* point at our new starting point */
                n = regs.end[0];
@@ -721,11 +731,11 @@
        }
 
        if (!MBSTRG(search_re)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "no regex for search");
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "No regex given");
                RETURN_FALSE;
        }
        if (!str) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "no string for search");
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "No string given");
                RETURN_FALSE;
        }
        if (MBSTRG(search_regs)) {
@@ -736,7 +746,6 @@
        }
 
        err = mbre_search(MBSTRG(search_re), str, len, pos, len - pos, 
MBSTRG(search_regs));
-
        if (err <= -2) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "mbregex search failure in 
mbregex_search()");
                RETVAL_FALSE;
@@ -744,6 +753,9 @@
                MBSTRG(search_pos) = len;
                RETVAL_FALSE;
        } else {
+               if (MBSTRG(search_regs)->beg[0] == MBSTRG(search_regs)->end[0]) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty regular 
+expression");
+               }
                switch (mode) {
                case 1:
                        if (array_init(return_value) != FAILURE) {
@@ -955,8 +967,11 @@
        }
        convert_to_long_ex(arg_pos);
        n = Z_LVAL_PP(arg_pos);
-       if (n < 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "position is minus value");
+       if (n < 0
+           || ( MBSTRG(search_str) != NULL && *MBSTRG(search_str) != NULL &&
+                Z_TYPE_PP(MBSTRG(search_str)) == IS_STRING && 
+                n >= Z_STRLEN_PP(MBSTRG(search_str)) ) ) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Position is out of 
+range");
                MBSTRG(search_pos) = 0;
                RETVAL_FALSE;
        } else {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to