Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5f41bff
added php_mb_check_encoding
masakielastic Feb 19, 2015
f6be936
added mb_ord
masakielastic Feb 19, 2015
f008db6
added utf32 and ucs4 for available encodings
masakielastic Feb 19, 2015
c55dea0
added check for forbidden encodings
masakielastic Feb 19, 2015
590e6f0
added utf16 and ucs2 for supported encodings
masakielastic Feb 19, 2015
1c1c64a
added support for various encodings other than unicode
masakielastic Feb 19, 2015
421f7fc
added php_mb_check_forbidden_encoding
masakielastic Feb 19, 2015
3238311
added mb_chr
masakielastic Feb 19, 2015
09b5bfc
added check by php_mb_check_forbidden_encoding
masakielastic Feb 19, 2015
ae838e6
added various encoding support other than unicode
masakielastic Feb 19, 2015
08443b2
use php_mb_convert_encoding instead of php_mb_check_encoding
masakielastic Feb 19, 2015
2e97d7b
changed the position of calling php_mb_check_forbidden_encoding
masakielastic Feb 19, 2015
325faea
rename php_mb_check_forbidden_encoding to php_mb_check_unsupported_en…
masakielastic Feb 20, 2015
00324a3
add test for mb_chr and mb_ord
masakielastic Feb 20, 2015
1033bad
add php_mb_check_unicode_encoding
masakielastic Feb 21, 2015
2a3c08b
fix php_mb_ord for better handling the value of MBSTRG(current_filter…
masakielastic Feb 21, 2015
bdb7a59
fix memory leak
masakielastic Feb 21, 2015
8410027
fix memory leak in php_mb_check_encoding
masakielastic Feb 21, 2015
29d09b7
update the functions for checking the names of encodings
masakielastic Feb 27, 2015
70e241f
replace zend_string_alloc with safe_emalloc
masakielastic Mar 1, 2015
905dfb9
add argument for output_len
masakielastic Mar 1, 2015
d24dacc
replace AND operator with OR operator
masakielastic Mar 1, 2015
b8468ad
introduce fast zpp
masakielastic Mar 2, 2015
15e32fd
generate utf-8 string directly instead of using php_mb_convert_encoding
masakielastic Mar 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added mb_ord
  • Loading branch information
masakielastic committed Mar 7, 2015
commit f6be936e103e2b673a8580bb3e2659929becda4b
73 changes: 73 additions & 0 deletions ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_check_encoding, 0, 0, 0)
ZEND_ARG_INFO(0, encoding)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_ord, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_ARG_INFO(0, encoding)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_regex_encoding, 0, 0, 0)
ZEND_ARG_INFO(0, encoding)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -555,6 +560,7 @@ const zend_function_entry mbstring_functions[] = {
PHP_FE(mb_send_mail, arginfo_mb_send_mail)
PHP_FE(mb_get_info, arginfo_mb_get_info)
PHP_FE(mb_check_encoding, arginfo_mb_check_encoding)
PHP_FE(mb_ord, arginfo_mb_ord)
#if HAVE_MBREGEX
PHP_MBREGEX_FUNCTION_ENTRIES
#endif
Expand Down Expand Up @@ -4578,6 +4584,73 @@ PHP_FUNCTION(mb_check_encoding)
}
/* }}} */

static inline long php_mb_ord(const char* str, size_t str_len, const char* enc)
{
enum mbfl_no_encoding no_enc;
zend_bool supported = false;
char* ret;
size_t ret_len;

if (enc == NULL) {
no_enc = MBSTRG(current_internal_encoding)->no_encoding;
} else {
no_enc = mbfl_name2no_encoding(enc);

if (no_enc == mbfl_no_encoding_invalid) {
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", enc);
return -1;
}
}

if (no_enc == mbfl_no_encoding_utf8
|| no_enc == mbfl_no_encoding_utf8_docomo
|| no_enc == mbfl_no_encoding_utf8_kddi_a
|| no_enc == mbfl_no_encoding_utf8_kddi_b
|| no_enc == mbfl_no_encoding_utf8_sb
) {
supported = true;
}

if (!supported) {
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc);
return -1;
}

ret = php_mb_convert_encoding(str, str_len, "UCS-4BE", enc, &ret_len);

if (ret == NULL) {
return -1;
}

return (unsigned char) ret[0] << 24 |
(unsigned char) ret[1] << 16 |
(unsigned char) ret[2] << 8 |
(unsigned char) ret[3];
}

/* {{{ proto bool mb_ord([string str[, string encoding]]) */
PHP_FUNCTION(mb_ord)
{
char* str;
size_t str_len;
char* enc = NULL;
size_t enc_len;
long cp;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &str, &str_len, &enc, &enc_len) == FAILURE) {
return;
}

cp = php_mb_ord(str, str_len, enc);

if (0 > cp) {
RETURN_FALSE;
}

RETURN_LONG(cp);
}
/* }}} */

/* {{{ php_mb_populate_current_detect_order_list */
static void php_mb_populate_current_detect_order_list(void)
{
Expand Down
1 change: 1 addition & 0 deletions ext/mbstring/mbstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ PHP_FUNCTION(mb_decode_numericentity);
PHP_FUNCTION(mb_send_mail);
PHP_FUNCTION(mb_get_info);
PHP_FUNCTION(mb_check_encoding);
PHP_FUNCTION(mb_ord);

MBSTRING_API char *php_mb_safe_strrchr_ex(const char *s, unsigned int c,
size_t nbytes, const mbfl_encoding *enc);
Expand Down