diff options
author | Remi Collet <remi@php.net> | 2012-11-25 08:21:10 +0100 |
---|---|---|
committer | Remi Collet <remi@php.net> | 2012-11-25 08:21:10 +0100 |
commit | f4a8612561b5b446d563901a3f13edf9e6298267 (patch) | |
tree | 98804a9ba33e795a12c7d821a5eba719a1ab3a6a /ext | |
parent | c5d4ee9bed992e1ac7f74be8ddfc0ae0c510df1e (diff) | |
parent | 289bb339c9e722ff3017ec58fdef7300f39b8e6d (diff) | |
download | php-git-f4a8612561b5b446d563901a3f13edf9e6298267.tar.gz |
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4:
Fixed bug #63588 Duplicate implementation of php_next_utf8_char
Diffstat (limited to 'ext')
-rw-r--r-- | ext/json/config.m4 | 2 | ||||
-rw-r--r-- | ext/json/config.w32 | 2 | ||||
-rw-r--r-- | ext/json/json.c | 32 | ||||
-rw-r--r-- | ext/json/utf8_to_utf16.c | 59 | ||||
-rw-r--r-- | ext/json/utf8_to_utf16.h | 3 |
5 files changed, 31 insertions, 67 deletions
diff --git a/ext/json/config.m4 b/ext/json/config.m4 index b62e938421..26c43a0e3f 100644 --- a/ext/json/config.m4 +++ b/ext/json/config.m4 @@ -9,7 +9,7 @@ if test "$PHP_JSON" != "no"; then AC_DEFINE([HAVE_JSON],1 ,[whether to enable JavaScript Object Serialization support]) AC_HEADER_STDC - PHP_NEW_EXTENSION(json, json.c utf8_to_utf16.c utf8_decode.c JSON_parser.c, $ext_shared) + PHP_NEW_EXTENSION(json, json.c utf8_decode.c JSON_parser.c, $ext_shared) PHP_INSTALL_HEADERS([ext/json], [php_json.h]) PHP_SUBST(JSON_SHARED_LIBADD) fi diff --git a/ext/json/config.w32 b/ext/json/config.w32 index 06a48e05ed..cedbf42829 100644 --- a/ext/json/config.w32 +++ b/ext/json/config.w32 @@ -5,7 +5,7 @@ ARG_ENABLE("json", "JavaScript Object Serialization support", "yes"); if (PHP_JSON != "no") { EXTENSION('json', 'json.c', PHP_JSON_SHARED, ""); - ADD_SOURCES(configure_module_dirname, "JSON_parser.c utf8_decode.c utf8_to_utf16.c", "json"); + ADD_SOURCES(configure_module_dirname, "JSON_parser.c utf8_decode.c", "json"); PHP_INSTALL_HEADERS("ext/json/", "php_json.h"); } diff --git a/ext/json/json.c b/ext/json/json.c index e4bb8a5d4b..0393be3fc1 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -25,8 +25,8 @@ #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" +#include "ext/standard/html.h" #include "ext/standard/php_smart_str.h" -#include "utf8_to_utf16.h" #include "JSON_parser.h" #include "php_json.h" #include <zend_exceptions.h> @@ -358,6 +358,32 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC) } /* }}} */ +static int json_utf8_to_utf16(unsigned short *utf16, char utf8[], int len) /* {{{ */ +{ + size_t pos = 0, us; + int j, status; + + for (j=0 ; pos < len ; j++) { + us = php_next_utf8_char((const unsigned char *)utf8, len, &pos, &status); + if (status != SUCCESS) { + return -1; + } + if (utf16) { + /* From http://en.wikipedia.org/wiki/UTF16 */ + if (us >= 0x10000) { + us -= 0x10000; + utf16[j++] = (unsigned short)((us >> 10) | 0xd800); + utf16[j] = (unsigned short)((us & 0x3ff) | 0xdc00); + } else { + utf16[j] = (unsigned short)us; + } + } + } + return j; +} +/* }}} */ + + #define REVERSE16(us) (((us & 0xf) << 12) | (((us >> 4) & 0xf) << 8) | (((us >> 8) & 0xf) << 4) | ((us >> 12) & 0xf)) static void json_escape_string(smart_str *buf, char *s, int len, int options TSRMLS_DC) /* {{{ */ @@ -397,7 +423,7 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR } utf16 = (options & PHP_JSON_UNESCAPED_UNICODE) ? NULL : (unsigned short *) safe_emalloc(len, sizeof(unsigned short), 0); - ulen = utf8_to_utf16(utf16, s, len); + ulen = json_utf8_to_utf16(utf16, s, len); if (ulen <= 0) { if (utf16) { efree(utf16); @@ -639,7 +665,7 @@ PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, int str_len, utf16 = (unsigned short *) safe_emalloc((str_len+1), sizeof(unsigned short), 1); - utf16_len = utf8_to_utf16(utf16, str, str_len); + utf16_len = json_utf8_to_utf16(utf16, str, str_len); if (utf16_len <= 0) { if (utf16) { efree(utf16); diff --git a/ext/json/utf8_to_utf16.c b/ext/json/utf8_to_utf16.c deleted file mode 100644 index 508bc9368a..0000000000 --- a/ext/json/utf8_to_utf16.c +++ /dev/null @@ -1,59 +0,0 @@ -/* utf8_to_utf16.c */ - -/* 2005-12-25 */ - -/* -Copyright (c) 2005 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "utf8_to_utf16.h" -#include "utf8_decode.h" - -int -utf8_to_utf16(unsigned short *w, char p[], int length) -{ - int c; - int the_index = 0; - json_utf8_decode utf8; - - utf8_decode_init(&utf8, p, length); - for (;;) { - c = utf8_decode_next(&utf8); - if (c < 0) { - return (c == UTF8_END) ? the_index : UTF8_ERROR; - } - if (c < 0x10000) { - if (w) { - w[the_index] = (unsigned short)c; - } - the_index += 1; - } else { - c -= 0x10000; - if (w) { - w[the_index] = (unsigned short)(0xD800 | (c >> 10)); - w[the_index + 1] = (unsigned short)(0xDC00 | (c & 0x3FF)); - } - the_index += 2; - } - } -} diff --git a/ext/json/utf8_to_utf16.h b/ext/json/utf8_to_utf16.h deleted file mode 100644 index 5c9685a991..0000000000 --- a/ext/json/utf8_to_utf16.h +++ /dev/null @@ -1,3 +0,0 @@ -/* utf8_to_utf16.h */ - -extern int utf8_to_utf16(unsigned short *w, char p[], int length); |