summaryrefslogtreecommitdiff
path: root/ext/mysqlnd/mysqlnd_charset.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2014-07-01 09:10:36 +0200
committerAnatol Belski <ab@php.net>2014-07-01 09:10:36 +0200
commit1a50c27f998769c5b3472d35c39852286900db69 (patch)
tree3c83075a87d566d3d2cac23523ce3f737805aa32 /ext/mysqlnd/mysqlnd_charset.c
parentd4cfc15514285d42f113facc1c296d32a818ccf2 (diff)
parent2330be5641c907b7edd7cffdd3074e85d0091df5 (diff)
downloadphp-git-1a50c27f998769c5b3472d35c39852286900db69.tar.gz
Merge remote-tracking branch 'origin/PHP-5.6' into str_size_and_int64_56_backport
* origin/PHP-5.6: (170 commits) Fixed possible crash because of race conditions on modifying constants in shared memory remove the NEWS entry for the reverted fpm fix remove the NEWS entry for the reverted fpm fix remove the NEWS entry for the reverted fpm fix Revert "Fix Bug #67530 error_log=syslog ignored" --enable-fpm for the travis build fix the last fpm NEWS entry, the other bug is related, but not the same what we fixed here NEWS NEWS Fix bug #67091: make install fails to install libphp5.so on FreeBSD 10.0 adding NEWS entry for the fix for bug #65641 Updated NEWS file for recent phpdbg fixes Fixed issue krakjoe/phpdbg#94 - List behavior is inconsistent Fix issue krakjoe/phpdbg#97 - list now appends a newline if there is none The prompt should always ensure it is on a newline Fixed test Inform about back command existence in help - Fixes krakjoe/phpdbg#100 No way to list the current stack/frames Fix issue krakjoe/phpdbg#98 break if does not seem to work Fix issue krakjoe/phpdbg#99 register function has the same behavior as run Fix readline/libedit (Thanks to @remicollet) Replace incorrect `E` command with `ev` in watch help ... Conflicts: Zend/zend_compile.c ext/standard/basic_functions.c ext/standard/http_fopen_wrapper.c ext/standard/var.c ext/tokenizer/tokenizer_data.c sapi/phpdbg/phpdbg_list.c
Diffstat (limited to 'ext/mysqlnd/mysqlnd_charset.c')
-rw-r--r--ext/mysqlnd/mysqlnd_charset.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/ext/mysqlnd/mysqlnd_charset.c b/ext/mysqlnd/mysqlnd_charset.c
index 41b0f33894..fa97b877e5 100644
--- a/ext/mysqlnd/mysqlnd_charset.c
+++ b/ext/mysqlnd/mysqlnd_charset.c
@@ -418,20 +418,60 @@ static uint mysqlnd_mbcharlen_utf16(unsigned int utf16)
/* {{{ utf32 functions */
-static uint
-check_mb_utf32(const char *start __attribute((unused)), const char *end __attribute((unused)))
+static unsigned int check_mb_utf32(const char *start __attribute((unused)), const char *end __attribute((unused)))
{
return 4;
}
-static uint
-mysqlnd_mbcharlen_utf32(unsigned int utf32 __attribute((unused)))
+static unsigned int mysqlnd_mbcharlen_utf32(unsigned int utf32 __attribute((unused)))
{
return 4;
}
/* }}} */
+
+/* {{{ gb18030 functions */
+#define is_gb18030_odd(c) (0x81 <= (zend_uchar) (c) && (zend_uchar) (c) <= 0xFE)
+#define is_gb18030_even_2(c) ((0x40 <= (zend_uchar) (c) && (zend_uchar) (c) <= 0x7E) || (0x80 <= (zend_uchar) (c) && (zend_uchar) (c) <= 0xFE))
+#define is_gb18030_even_4(c) (0x30 <= (zend_uchar) (c) && (zend_uchar) (c) <= 0x39)
+
+
+static unsigned int mysqlnd_mbcharlen_gb18030(unsigned int c)
+{
+ if (c <= 0xFF) {
+ return !is_gb18030_odd(c);
+ }
+ if (c > 0xFFFF || !is_gb18030_odd((c >> 8) & 0xFF)) {
+ return 0;
+ }
+ if (is_gb18030_even_2((c & 0xFF))) {
+ return 2;
+ }
+ if (is_gb18030_even_4((c & 0xFF))) {
+ return 4;
+ }
+
+ return 0;
+}
+
+
+static unsigned int my_ismbchar_gb18030(const char * start, const char * end)
+{
+ if (end - start <= 1 || !is_gb18030_odd(start[0])) {
+ return 0;
+ }
+
+ if (is_gb18030_even_2(start[1])) {
+ return 2;
+ } else if (end - start > 3 && is_gb18030_even_4(start[1]) && is_gb18030_odd(start[2]) && is_gb18030_even_4(start[3])) {
+ return 4;
+ }
+
+ return 0;
+}
+/* }}} */
+
/*
The server compiles sometimes the full utf-8 (the mb4) as utf8m4, and the old as utf8,
for BC reasons. Sometimes, utf8mb4 is just utf8 but the old charsets are utf8mb3.
@@ -643,6 +683,8 @@ const MYSQLND_CHARSET mysqlnd_charsets[] =
{ 245, UTF8_MB4, UTF8_MB4"_croatian_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
{ 246, UTF8_MB4, UTF8_MB4"_unicode_520_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
{ 247, UTF8_MB4, UTF8_MB4"_vietnamese_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
+ { 248, "gb18030", "gb18030_chinese_ci", 1, 4, "", mysqlnd_mbcharlen_gb18030, my_ismbchar_gb18030},
+ { 249, "gb18030", "gb18030_bin", 1, 4, "", mysqlnd_mbcharlen_gb18030, my_ismbchar_gb18030},
{ 254, UTF8_MB3, UTF8_MB3"_general_cs", 1, 3, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
{ 0, NULL, NULL, 0, 0, NULL, NULL, NULL}