mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
MFH
This commit is contained in:
parent
8d012d041f
commit
e8d320dd77
3 changed files with 67 additions and 0 deletions
|
@ -335,6 +335,10 @@ int mbfl_buffer_illegalchars(mbfl_buffer_converter *convd)
|
|||
{
|
||||
int num_illegalchars = 0;
|
||||
|
||||
if (convd == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (convd->filter1 != NULL) {
|
||||
num_illegalchars += convd->filter1->num_illegalchar;
|
||||
}
|
||||
|
|
|
@ -220,6 +220,7 @@ zend_function_entry mbstring_functions[] = {
|
|||
PHP_FE(mb_decode_numericentity, NULL)
|
||||
PHP_FE(mb_send_mail, NULL)
|
||||
PHP_FE(mb_get_info, NULL)
|
||||
PHP_FE(mb_check_encoding, NULL)
|
||||
#if HAVE_MBREGEX
|
||||
PHP_MBREGEX_FUNCTION_ENTRIES
|
||||
#endif
|
||||
|
@ -3437,6 +3438,67 @@ PHP_FUNCTION(mb_get_info)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool mb_check_encoding([string var[, string encoding]])
|
||||
Check if the string is valid for the specified encoding */
|
||||
PHP_FUNCTION(mb_check_encoding)
|
||||
{
|
||||
char *var = NULL;
|
||||
int var_len;
|
||||
char *enc = NULL;
|
||||
int enc_len;
|
||||
char *name;
|
||||
mbfl_buffer_converter *convd;
|
||||
enum mbfl_no_encoding no_encoding = MBSTRG(current_internal_encoding);
|
||||
zval *row;
|
||||
mbfl_string string, result, *ret = NULL;
|
||||
long illegalchars = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &var, &var_len, &enc, &enc_len) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (var == NULL) {
|
||||
RETURN_BOOL(MBSTRG(illegalchars) == 0);
|
||||
}
|
||||
|
||||
if (enc != NULL) {
|
||||
no_encoding = mbfl_name2no_encoding(enc);
|
||||
if (no_encoding == mbfl_no_encoding_invalid || no_encoding == mbfl_no_encoding_pass) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid encoding \"%s\"", enc);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
convd = mbfl_buffer_converter_new(no_encoding, no_encoding, 0);
|
||||
if (convd == NULL) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create converter");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
|
||||
mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
|
||||
|
||||
/* initialize string */
|
||||
mbfl_string_init(&string);
|
||||
mbfl_string_init(&result);
|
||||
string.no_encoding = no_encoding;
|
||||
string.no_language = MBSTRG(current_language);
|
||||
|
||||
string.val = (unsigned char *)var;
|
||||
string.len = var_len;
|
||||
ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
|
||||
illegalchars = mbfl_buffer_illegalchars(convd);
|
||||
mbfl_buffer_converter_delete(convd);
|
||||
|
||||
if (ret != NULL) {
|
||||
MBSTRG(illegalchars) += illegalchars;
|
||||
efree(ret->val);
|
||||
RETURN_BOOL(illegalchars == 0);
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ MBSTRING_API int php_mb_encoding_translation() */
|
||||
MBSTRING_API int php_mb_encoding_translation(TSRMLS_D)
|
||||
{
|
||||
|
|
|
@ -120,6 +120,7 @@ PHP_FUNCTION(mb_encode_numericentity);
|
|||
PHP_FUNCTION(mb_decode_numericentity);
|
||||
PHP_FUNCTION(mb_send_mail);
|
||||
PHP_FUNCTION(mb_get_info);
|
||||
PHP_FUNCTION(mb_check_encoding);
|
||||
|
||||
MBSTRING_API int php_mb_encoding_translation(TSRMLS_D);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue