]> granicus.if.org Git - php/commitdiff
added mb_list_mime_names( ).
authorSeiji Masugata <masugata@php.net>
Mon, 27 Mar 2006 15:20:02 +0000 (15:20 +0000)
committerSeiji Masugata <masugata@php.net>
Mon, 27 Mar 2006 15:20:02 +0000 (15:20 +0000)
ext/mbstring/mbstring.c
ext/mbstring/mbstring.h

index a825859b6d0aa9712e804bbc4ca1f76a326ff9be..b63d82ac4dce93082a87e9c4cafbcd8057fbc662 100644 (file)
@@ -214,6 +214,7 @@ zend_function_entry mbstring_functions[] = {
        PHP_FE(mb_detect_encoding,              NULL)
        PHP_FE(mb_list_encodings,               NULL)
        PHP_FE(mb_list_encodings_alias_names,           NULL)
+       PHP_FE(mb_list_mime_names,              NULL)
        PHP_FE(mb_convert_kana,                 NULL)
        PHP_FE(mb_encode_mimeheader,    NULL)
        PHP_FE(mb_decode_mimeheader,    NULL)
@@ -2425,6 +2426,58 @@ PHP_FUNCTION(mb_list_encodings_alias_names)
 }
 /* }}} */
 
+/* {{{ 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) {
+               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;
+               }
+       }
+}
+/* }}} */
+
 /* {{{ proto string mb_encode_mimeheader(string str [, string charset [, string transfer-encoding [, string linefeed [, int indent]]]])
    Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= */
 PHP_FUNCTION(mb_encode_mimeheader)
index 525893a7dfe2e92d3e8304b94905295c727034d7..71628a02c3a25962d400f8f25ba83f4cee3e03cf 100644 (file)
@@ -113,6 +113,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_convert_kana);
 PHP_FUNCTION(mb_encode_mimeheader);
 PHP_FUNCTION(mb_decode_mimeheader);