diff options
author | Masaki Kagaya <masakielastic@gmail.com> | 2015-02-19 18:59:13 +0900 |
---|---|---|
committer | Masaki Kagaya <masakielastic@gmail.com> | 2015-02-19 18:59:13 +0900 |
commit | f10a182674475b200c67f651aa8fd0d90891368a (patch) | |
tree | 1bcfd8a7595ed8eaccd704bcdcaa84cd6dfac04f /ext/mbstring/mbstring.c | |
parent | a8ef8a25e5ebf03bfb6092ab24fbbe1a0f56e162 (diff) | |
download | php-git-f10a182674475b200c67f651aa8fd0d90891368a.tar.gz |
added various encoding support other than unicode
Diffstat (limited to 'ext/mbstring/mbstring.c')
-rw-r--r-- | ext/mbstring/mbstring.c | 73 |
1 files changed, 51 insertions, 22 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 78ffd5cd98..03ed229381 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -4744,8 +4744,7 @@ PHP_FUNCTION(mb_ord) static inline char* php_mb_chr(long cp, const char* enc) { enum mbfl_no_encoding no_enc; - zend_bool supported = false; - zend_string *buf = zend_string_alloc(4, 0); + zend_string *buf; char* ret; size_t ret_len; @@ -4759,6 +4758,11 @@ static inline char* php_mb_chr(long cp, const char* enc) } } + if (php_mb_check_forbidden_encoding(no_enc)) { + php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc); + return NULL; + } + if (no_enc == mbfl_no_encoding_utf8 || no_enc == mbfl_no_encoding_utf8_docomo || no_enc == mbfl_no_encoding_utf8_kddi_a @@ -4777,19 +4781,6 @@ static inline char* php_mb_chr(long cp, const char* enc) || no_enc == mbfl_no_encoding_utf16be || no_enc == mbfl_no_encoding_utf16le ) { - supported = true; - } - - if (!supported || php_mb_check_forbidden_encoding(no_enc)) { - php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc); - return NULL; - } - - 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 - ) { if (0 > cp || (cp > 0xd7ff && 0xe000 > cp) || 0x10ffff < cp) { if (no_enc == MBSTRG(current_internal_encoding)->no_encoding) { @@ -4798,18 +4789,56 @@ static inline char* php_mb_chr(long cp, const char* enc) cp = 0x3f; } } + + buf = zend_string_alloc(4, 0); + buf->val[0] = (cp >> 24) & 0xff; + buf->val[1] = (cp >> 16) & 0xff; + buf->val[2] = (cp >> 8) & 0xff; + buf->val[3] = cp & 0xff; + buf->val[4] = 0; + + ret = php_mb_convert_encoding(buf->val, buf->len, enc, "UCS-4BE", &ret_len); + zend_string_release(buf); + + return ret; + } + + if (0 > cp || cp > 0x100000000) { + if (no_enc == MBSTRG(current_internal_encoding)->no_encoding) { + cp = MBSTRG(current_filter_illegal_substchar); + } else { + cp = 0x3f; + } } - buf->val[0] = (cp >> 24) & 0xff; - buf->val[1] = (cp >> 16) & 0xff; - buf->val[2] = (cp >> 8) & 0xff; - buf->val[3] = cp & 0xff; - buf->val[4] = 0; + if (cp < 0x100) { + buf = zend_string_alloc(1, 0); + buf->val[0] = cp; + buf->val[1] = 0; + } else if (cp < 0x10000) { + buf = zend_string_alloc(2, 0); + buf->val[0] = cp >> 8; + buf->val[1] = cp & 0xff; + buf->val[2] = 0; + } else if (cp < 0x1000000) { + buf = zend_string_alloc(3, 0); + buf->val[0] = cp >> 16; + buf->val[1] = (cp >> 8) & 0xff; + buf->val[2] = cp & 0xff; + buf->val[3] = 0; + } else { + buf = zend_string_alloc(4, 0); + buf->val[0] = cp >> 24; + buf->val[1] = (cp >> 16) & 0xff; + buf->val[2] = (cp >> 8) & 0xff; + buf->val[3] = cp & 0xff; + buf->val[4] = 0; + } - ret = php_mb_convert_encoding(buf->val, buf->len, enc, "UCS-4BE", &ret_len); + ret = php_mb_convert_encoding(buf->val, buf->len, enc, enc, &ret_len); zend_string_release(buf); - return ret; + return ret; } /* {{{ proto bool mb_ord([int cp[, string encoding]]) */ PHP_FUNCTION(mb_chr) |