added mb_list_mime_names( ).

This commit is contained in:
Seiji Masugata 2006-03-27 15:20:02 +00:00
parent d1d9ce8fed
commit d28ec107ac
2 changed files with 54 additions and 0 deletions

View file

@ -214,6 +214,7 @@ zend_function_entry mbstring_functions[] = {
PHP_FE(mb_detect_encoding, NULL) PHP_FE(mb_detect_encoding, NULL)
PHP_FE(mb_list_encodings, NULL) PHP_FE(mb_list_encodings, NULL)
PHP_FE(mb_list_encodings_alias_names, 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_convert_kana, NULL)
PHP_FE(mb_encode_mimeheader, NULL) PHP_FE(mb_encode_mimeheader, NULL)
PHP_FE(mb_decode_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]]]]) /* {{{ 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?= */ Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= */
PHP_FUNCTION(mb_encode_mimeheader) PHP_FUNCTION(mb_encode_mimeheader)

View file

@ -113,6 +113,7 @@ PHP_FUNCTION(mb_convert_encoding);
PHP_FUNCTION(mb_detect_encoding); PHP_FUNCTION(mb_detect_encoding);
PHP_FUNCTION(mb_list_encodings); PHP_FUNCTION(mb_list_encodings);
PHP_FUNCTION(mb_list_encodings_alias_names); PHP_FUNCTION(mb_list_encodings_alias_names);
PHP_FUNCTION(mb_list_mime_names);
PHP_FUNCTION(mb_convert_kana); PHP_FUNCTION(mb_convert_kana);
PHP_FUNCTION(mb_encode_mimeheader); PHP_FUNCTION(mb_encode_mimeheader);
PHP_FUNCTION(mb_decode_mimeheader); PHP_FUNCTION(mb_decode_mimeheader);