mirror of
https://github.com/php/php-src.git
synced 2024-12-27 02:39:39 +08:00
added mb_language to ext/mbstring.
This commit is contained in:
parent
da0162a9de
commit
0a452b2ff2
@ -1779,6 +1779,13 @@ mbfl_name2language(const char *name)
|
||||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while ((language = mbfl_language_ptr_table[i++]) != NULL){
|
||||
if (strcasecmp(language->short_name, name) == 0) {
|
||||
return language;
|
||||
}
|
||||
}
|
||||
|
||||
/* serch aliases */
|
||||
i = 0;
|
||||
while ((language = mbfl_language_ptr_table[i++]) != NULL) {
|
||||
@ -1825,6 +1832,20 @@ mbfl_name2no_language(const char *name)
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
mbfl_no_language2name(enum mbfl_no_language no_language)
|
||||
{
|
||||
mbfl_language *language;
|
||||
|
||||
language = mbfl_no2language(no_language);
|
||||
if (language == NULL) {
|
||||
return "";
|
||||
} else {
|
||||
return language->name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* encoding resolver */
|
||||
mbfl_encoding *
|
||||
|
@ -255,6 +255,7 @@ void mbfl_string_init(mbfl_string *string);
|
||||
mbfl_language * mbfl_name2language(const char *name);
|
||||
mbfl_language * mbfl_no2language(enum mbfl_no_language no_language);
|
||||
enum mbfl_no_language mbfl_name2no_language(const char *name);
|
||||
const char * mbfl_no_language2name(enum mbfl_no_language no_language);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -84,6 +84,7 @@ static sapi_post_entry mbstr_post_entries[] = {
|
||||
#endif
|
||||
|
||||
function_entry mbstring_functions[] = {
|
||||
PHP_FE(mb_language, NULL)
|
||||
PHP_FE(mb_internal_encoding, NULL)
|
||||
PHP_FE(mb_http_input, NULL)
|
||||
PHP_FE(mb_http_output, NULL)
|
||||
@ -509,6 +510,40 @@ PHP_MINFO_FUNCTION(mbstring)
|
||||
|
||||
|
||||
|
||||
/* {{{ proto string mb_language([string language])
|
||||
Sets the current language or Returns the current language as a string. */
|
||||
PHP_FUNCTION(mb_language)
|
||||
{
|
||||
pval **arg1;
|
||||
char *name;
|
||||
enum mbfl_no_language no_language;
|
||||
MBSTRLS_FETCH();
|
||||
|
||||
if (ZEND_NUM_ARGS() == 0) {
|
||||
name = (char *)mbfl_no_language2name(MBSTRG(current_language));
|
||||
if (name != NULL) {
|
||||
RETURN_STRING(name, 1);
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
} else if (ZEND_NUM_ARGS() == 1 && zend_get_parameters_ex(1, &arg1) != FAILURE) {
|
||||
convert_to_string_ex(arg1);
|
||||
no_language = mbfl_name2no_language(Z_STRVAL_PP(arg1));
|
||||
if (no_language == mbfl_no_language_invalid) {
|
||||
php_error(E_WARNING, "unknown language \"%s\"", Z_STRVAL_PP(arg1));
|
||||
RETURN_FALSE;
|
||||
} else {
|
||||
MBSTRG(current_language) = no_language;
|
||||
RETURN_TRUE;
|
||||
}
|
||||
} else {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
|
||||
/* {{{ proto string mb_internal_encoding([string encoding])
|
||||
Sets the current internal encoding or Returns the current internal encoding as a string. */
|
||||
PHP_FUNCTION(mb_internal_encoding)
|
||||
|
Loading…
Reference in New Issue
Block a user