moriyoshi               Sat Sep 13 00:30:51 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/mbstring/tests mb_encoding_aliases.phpt 
                                mb_list_encodings.phpt 

  Modified files:              
    /php-src/ext/mbstring       mbstring.c mbstring.h 
  Log:
  - MFH: mb_list_*() issue settlements
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/mbstring.c?r1=1.224.2.22.2.25.2.33&r2=1.224.2.22.2.25.2.34&diff_format=u
Index: php-src/ext/mbstring/mbstring.c
diff -u php-src/ext/mbstring/mbstring.c:1.224.2.22.2.25.2.33 
php-src/ext/mbstring/mbstring.c:1.224.2.22.2.25.2.34
--- php-src/ext/mbstring/mbstring.c:1.224.2.22.2.25.2.33        Fri Sep 12 
23:35:01 2008
+++ php-src/ext/mbstring/mbstring.c     Sat Sep 13 00:30:51 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mbstring.c,v 1.224.2.22.2.25.2.33 2008/09/12 23:35:01 moriyoshi Exp $ 
*/
+/* $Id: mbstring.c,v 1.224.2.22.2.25.2.34 2008/09/13 00:30:51 moriyoshi Exp $ 
*/
 
 /*
  * PHP 4 Multibyte String module "mbstring"
@@ -401,6 +401,11 @@
 ZEND_END_ARG_INFO()
 
 static
+ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_encoding_aliases, 0, 0, 1)
+       ZEND_ARG_INFO(0, encoding)
+ZEND_END_ARG_INFO()
+
+static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_encode_mimeheader, 0, 0, 1)
        ZEND_ARG_INFO(0, str)
        ZEND_ARG_INFO(0, charset)
@@ -585,6 +590,7 @@
        PHP_FE(mb_convert_encoding,             arginfo_mb_convert_encoding)
        PHP_FE(mb_detect_encoding,              arginfo_mb_detect_encoding)
        PHP_FE(mb_list_encodings,               arginfo_mb_list_encodings)
+       PHP_FE(mb_encoding_aliases,             arginfo_mb_encoding_aliases)
        PHP_FE(mb_convert_kana,                 arginfo_mb_convert_kana)
        PHP_FE(mb_encode_mimeheader,    arginfo_mb_encode_mimeheader)
        PHP_FE(mb_decode_mimeheader,    arginfo_mb_decode_mimeheader)
@@ -3298,117 +3304,29 @@
 }
 /* }}} */
 
-/* {{{ proto array mb_list_encodings_alias_names([string encoding])
-   Returns an array of all supported alias encodings */
-PHP_FUNCTION(mb_list_encodings_alias_names)
+/* {{{ proto array mb_encoding_aliases(string encoding)
+   Returns an array of the aliases of a given encoding name */
+PHP_FUNCTION(mb_encoding_aliases)
 {
-       const mbfl_encoding **encodings;
        const mbfl_encoding *encoding;
-       enum mbfl_no_encoding no_encoding;
-       int i, j;
-       zval *row;
        char *name = NULL;
        int name_len;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, 
&name_len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, 
&name_len) == FAILURE) {
                RETURN_FALSE;
        }
 
-       if (name == NULL) {
-               array_init(return_value);
-               i = 0;
-               encodings = mbfl_get_supported_encodings();
-               while ((encoding = encodings[i++]) != NULL) {
-                       MAKE_STD_ZVAL(row);
-                       array_init(row);
-                       if (encoding->aliases != NULL) {
-                               j = 0;
-                               while ((*encoding->aliases)[j] != NULL) {
-                                       add_next_index_string(row, (char 
*)(*encoding->aliases)[j], 1);
-                                       j++;
-                               }
-                       }
-                       add_assoc_zval(return_value, (char *) encoding->name, 
row);
-               }
-       } else {
-               no_encoding = mbfl_name2no_encoding(name);
-               if (no_encoding == mbfl_no_encoding_invalid) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown 
encoding \"%s\"", name);
-                       RETURN_FALSE;
-               }
-
-               name = (char *)mbfl_no_encoding2name(no_encoding);
-               if (name != NULL) {
-                       i = 0;
-                       encodings = mbfl_get_supported_encodings();
-                       while ((encoding = encodings[i++]) != NULL) {
-                               if (strcmp(encoding->name, name) != 0){ 
continue; }
-
-                               array_init(return_value);
-                               if (encoding->aliases != NULL) {
-                                       j = 0;
-                                       while ((*encoding->aliases)[j] != NULL) 
{
-                                               
add_next_index_string(return_value, (char *)(*encoding->aliases)[j], 1);
-                                               j++;
-                                       }
-                               }
-
-                               break;
-                       }
-               } else {
-                       RETURN_FALSE;
-               }
-       }
-}
-/* }}} */
-
-/* {{{ proto mixed mb_list_mime_names([string encoding])
-   Returns an array or string of all supported mime names */
-PHP_FUNCTION(mb_list_mime_names)
-{
-       const mbfl_encoding **encodings;
-       const mbfl_encoding *encoding;
-       enum mbfl_no_encoding no_encoding;
-       int i;
-       char *name = NULL;
-       int name_len;
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, 
&name_len) == FAILURE) {
+       encoding = mbfl_name2encoding(name);
+       if (!encoding) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown encoding 
\"%s\"", name);
                RETURN_FALSE;
        }
 
-       if (name == NULL) {
-               array_init(return_value);
-               i = 0;
-               encodings = mbfl_get_supported_encodings();
-               while ((encoding = encodings[i++]) != NULL) {
-                       if(encoding->mime_name != NULL) {
-                               add_assoc_string(return_value, (char *) 
encoding->name, (char *) encoding->mime_name, 1);
-                       } else{
-                               add_assoc_string(return_value, (char *) 
encoding->name, "", 1);
-                       }
-               }
-       } else {
-               no_encoding = mbfl_name2no_encoding(name);
-               if (no_encoding == mbfl_no_encoding_invalid) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown 
encoding \"%s\"", name);
-                       RETURN_FALSE;
-               }
-
-               name = (char *)mbfl_no_encoding2name(no_encoding);
-               if (name != NULL) {
-                       i = 0;
-                       encodings = mbfl_get_supported_encodings();
-                       while ((encoding = encodings[i++]) != NULL) {
-                               if (strcmp(encoding->name, name) != 0){ 
continue; }
-                               if(encoding->mime_name != NULL) {
-                                       RETURN_STRING((char *) 
encoding->mime_name, 1);
-                               }
-                               break;
-                       }
-                       RETURN_STRING("", 1);
-               } else {
-                       RETURN_FALSE;
+       array_init(return_value);
+       if (encoding->aliases != NULL) {
+               const char **alias;
+               for (alias = *encoding->aliases; *alias; ++alias) {
+                       add_next_index_string(return_value, (char *)*alias, 1);
                }
        }
 }
http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/mbstring.h?r1=1.66.2.4.2.5.2.7&r2=1.66.2.4.2.5.2.8&diff_format=u
Index: php-src/ext/mbstring/mbstring.h
diff -u php-src/ext/mbstring/mbstring.h:1.66.2.4.2.5.2.7 
php-src/ext/mbstring/mbstring.h:1.66.2.4.2.5.2.8
--- php-src/ext/mbstring/mbstring.h:1.66.2.4.2.5.2.7    Sat Aug  2 20:49:00 2008
+++ php-src/ext/mbstring/mbstring.h     Sat Sep 13 00:30:51 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mbstring.h,v 1.66.2.4.2.5.2.7 2008/08/02 20:49:00 moriyoshi Exp $ */
+/* $Id: mbstring.h,v 1.66.2.4.2.5.2.8 2008/09/13 00:30:51 moriyoshi Exp $ */
 
 /*
  * PHP 4 Multibyte String module "mbstring" (currently only for Japanese)
@@ -117,8 +117,7 @@
 PHP_FUNCTION(mb_convert_encoding);
 PHP_FUNCTION(mb_detect_encoding);
 PHP_FUNCTION(mb_list_encodings);
-PHP_FUNCTION(mb_list_encodings_alias_names);
-PHP_FUNCTION(mb_list_mime_names);
+PHP_FUNCTION(mb_encoding_aliases);
 PHP_FUNCTION(mb_convert_kana);
 PHP_FUNCTION(mb_encode_mimeheader);
 PHP_FUNCTION(mb_decode_mimeheader);

http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/tests/mb_encoding_aliases.phpt?view=markup&rev=1.1
Index: php-src/ext/mbstring/tests/mb_encoding_aliases.phpt
+++ php-src/ext/mbstring/tests/mb_encoding_aliases.phpt
--TEST--
mb_encoding_aliases()
--FILE--
<?php
mb_encoding_aliases();
$list = mb_encoding_aliases("ASCII");
sort($list);
var_dump($list);
var_dump(mb_encoding_aliases("7bit"));
var_dump(mb_encoding_aliases("8bit"));
?>
--EXPECTF--
Warning: mb_encoding_aliases() expects exactly 1 parameter, 0 given in %s on 
line 2
array(10) {
  [0]=>
  string(14) "ANSI_X3.4-1968"
  [1]=>
  string(14) "ANSI_X3.4-1986"
  [2]=>
  string(6) "IBM367"
  [3]=>
  string(9) "ISO646-US"
  [4]=>
  string(16) "ISO_646.irv:1991"
  [5]=>
  string(8) "US-ASCII"
  [6]=>
  string(5) "cp367"
  [7]=>
  string(7) "csASCII"
  [8]=>
  string(8) "iso-ir-6"
  [9]=>
  string(2) "us"
}
array(0) {
}
array(1) {
  [0]=>
  string(6) "binary"
}

http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/tests/mb_list_encodings.phpt?view=markup&rev=1.1
Index: php-src/ext/mbstring/tests/mb_list_encodings.phpt
+++ php-src/ext/mbstring/tests/mb_list_encodings.phpt
--TEST--
mb_list_encodings
--FILE--
<?php
var_dump(in_array("7bit", mb_list_encodings()));
var_dump(in_array("8bit", mb_list_encodings()));
var_dump(in_array("ASCII", mb_list_encodings()));
var_dump(in_array("non-existent", mb_list_encodings()));
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(false)



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

Reply via email to