com php-src: added various encoding support other than unicode: ext/mbstring/mbstring.c
| From: | Yasuo Ohgaki | Date: | Sat, 07 Mar 2015 17:03:44 +0000 |
| Subject: | com php-src: added various encoding support other than unicode: ext/mbstring/mbstring.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93706@lists.php.net to get a copy of this message | ||
Commit: ae838e6e4c53013469c5a1c2b0c540cf150c66be
Author: Masaki Kagaya <masakielastic@gmail.com> Thu, 19 Feb 2015 18:59:13 +0900
Parents: 09b5bfc71a7e4199295a48e75ef220aa34376cd5
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ae838e6e4c53013469c5a1c2b0c540cf150c66be
Log:
added various encoding support other than unicode
Changed paths:
M ext/mbstring/mbstring.c
Diff:
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 5ef6eca..47143b6 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -4737,8 +4737,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;
@@ -4752,6 +4751,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
@@ -4770,19 +4774,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) {
@@ -4791,18 +4782,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)