]> granicus.if.org Git - php/commitdiff
- The mb_list_* issue has been resolved in the following way:
authorMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 12 Sep 2008 23:59:51 +0000 (23:59 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 12 Sep 2008 23:59:51 +0000 (23:59 +0000)
  - Keep the same prototype as 5.2 for mb_list_encodings().
  - Add mb_list_encoding_aliases() with the mandatory parameter.
  - Remove mb_list_mime_names() as the list can be made from iteration
    on mb_list_encodings() with mb_preferred_mime_name().

ext/mbstring/mbstring.c

index cc861d0e50880c199e15874c03b31c1d02da4e89..bcc573f5bd87bb284cc284c9ddf9f147177c3a9c 100644 (file)
@@ -390,16 +390,10 @@ ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_list_encodings, 0, 0, 0)
-       ZEND_ARG_INFO(0, alias_encoding)
 ZEND_END_ARG_INFO()
 
 static
-ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_list_encodings_alias_names, 0, 0, 0)
-       ZEND_ARG_INFO(0, encoding)
-ZEND_END_ARG_INFO()
-
-static
-ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_list_mime_names, 0, 0, 0)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_list_encoding_aliases, 0, 0, 1)
        ZEND_ARG_INFO(0, encoding)
 ZEND_END_ARG_INFO()
 
@@ -588,8 +582,7 @@ const zend_function_entry mbstring_functions[] = {
        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_list_encodings_alias_names,           arginfo_mb_list_encodings_alias_names)
-       PHP_FE(mb_list_mime_names,              arginfo_mb_list_mime_names)
+       PHP_FE(mb_list_encoding_aliases,                arginfo_mb_list_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)
@@ -3125,156 +3118,51 @@ PHP_FUNCTION(mb_detect_encoding)
 }
 /* }}} */
 
-/* {{{ proto mixed mb_list_encodings([string alias_encoding])
+/* {{{ proto mixed mb_list_encodings()
    Returns an array of all supported entity encodings or Returns the entity encoding as a string */
 PHP_FUNCTION(mb_list_encodings)
 {
        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) {
-               RETURN_FALSE;
+       if (ZEND_NUM_ARGS() != 0) {
+               RETVAL_FALSE;
+               ZEND_WRONG_PARAM_COUNT();
        }
 
-       if (name == NULL) {
-               array_init(return_value);
-               i = 0;
-               encodings = mbfl_get_supported_encodings();
-               while ((encoding = encodings[i++]) != NULL) {
-                       add_next_index_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) {
-                       RETURN_STRING(name, 1);
-               } else {
-                       RETURN_FALSE;
-               }
+       array_init(return_value);
+       i = 0;
+       encodings = mbfl_get_supported_encodings();
+       while ((encoding = encodings[i++]) != NULL) {
+               add_next_index_string(return_value, (char *) encoding->name, 1);
        }
 }
 /* }}} */
 
-/* {{{ 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_list_encoding_aliases(string encoding)
+   Returns an array of the aliases of a given encoding name */
+PHP_FUNCTION(mb_list_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);
                }
        }
 }