Browse Source
added simplified chinese, traditional chinese, korean support to mbstring. Note that this feature is experimental.
experimental/new_ui_api
added simplified chinese, traditional chinese, korean support to mbstring. Note that this feature is experimental.
experimental/new_ui_api
14 changed files with 26336 additions and 9 deletions
-
25ext/mbstring/config.m4
-
647ext/mbstring/mbfilter.c
-
16ext/mbstring/mbfilter.h
-
263ext/mbstring/mbfilter_cn.c
-
30ext/mbstring/mbfilter_cn.h
-
15ext/mbstring/mbfilter_ja.c
-
324ext/mbstring/mbfilter_kr.c
-
30ext/mbstring/mbfilter_kr.h
-
336ext/mbstring/mbfilter_tw.c
-
30ext/mbstring/mbfilter_tw.h
-
66ext/mbstring/mbstring.c
-
6414ext/mbstring/unicode_table_cn.h
-
6934ext/mbstring/unicode_table_kr.h
-
11215ext/mbstring/unicode_table_tw.h
@ -0,0 +1,263 @@ |
|||
/* |
|||
+----------------------------------------------------------------------+ |
|||
| PHP Version 4 | |
|||
+----------------------------------------------------------------------+ |
|||
| Copyright (c) 2001 The PHP Group | |
|||
+----------------------------------------------------------------------+ |
|||
| This source file is subject to version 2.02 of the PHP license, | |
|||
| that is bundled with this package in the file LICENSE, and is | |
|||
| available at through the world-wide-web at | |
|||
| http://www.php.net/license/2_02.txt. | |
|||
| If you did not receive a copy of the PHP license and are unable to | |
|||
| obtain it through the world-wide-web, please send a note to | |
|||
| license@php.net so we can mail you a copy immediately. | |
|||
+----------------------------------------------------------------------+ |
|||
| Author: Rui Hirokawa <hirokawa@php.net> | |
|||
+----------------------------------------------------------------------+ |
|||
*/ |
|||
|
|||
/* |
|||
* "streamable simplified chinese code filter and converter" |
|||
*/ |
|||
|
|||
/* $Id$ */ |
|||
|
|||
#ifdef HAVE_CONFIG_H |
|||
#include "config.h" |
|||
#endif |
|||
|
|||
#include "php.h" |
|||
#include "php_globals.h" |
|||
|
|||
#if defined(HAVE_MBSTR_CN) |
|||
#include "mbfilter.h" |
|||
#include "mbfilter_cn.h" |
|||
|
|||
#include "unicode_table_cn.h" |
|||
|
|||
#define CK(statement) do { if ((statement) < 0) return (-1); } while (0) |
|||
|
|||
|
|||
/* |
|||
* EUC-CN => wchar |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_euccn_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, s1, s2, w; |
|||
|
|||
switch (filter->status) { |
|||
case 0: |
|||
if (c >= 0 && c < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else if (c > 0xa0 && c < 0xff) { /* dbcs lead byte */ |
|||
filter->status = 1; |
|||
filter->cache = c; |
|||
} else { |
|||
w = c & MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
case 1: /* dbcs second byte */ |
|||
filter->status = 0; |
|||
c1 = filter->cache; |
|||
if (c1 > 0xa0 && c1 < 0xff && c > 0xa0 && c < 0xff) { |
|||
w = (c1 - 0x81)*192 + (c - 0x40); |
|||
if (w >= 0 && w < cp936_ucs_table_size) { |
|||
w = cp936_ucs_table[w]; |
|||
} else { |
|||
w = 0; |
|||
} |
|||
if (w <= 0) { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSPLANE_MASK; |
|||
w |= MBFL_WCSPLANE_GB2312; |
|||
} |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} else if ((c >= 0 && c < 0x21) || c == 0x7f) { /* CTLs */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
default: |
|||
filter->status = 0; |
|||
break; |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
/* |
|||
* wchar => EUC-CN |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_wchar_euccn(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, c2, s; |
|||
|
|||
s = 0; |
|||
if (c >= ucs_a1_cp936_table_min && c < ucs_a1_cp936_table_max) { |
|||
s = ucs_a1_cp936_table[c - ucs_a1_cp936_table_min]; |
|||
} else if (c >= ucs_a2_cp936_table_min && c < ucs_a2_cp936_table_max) { |
|||
s = ucs_a2_cp936_table[c - ucs_a2_cp936_table_min]; |
|||
} else if (c >= ucs_a3_cp936_table_min && c < ucs_a3_cp936_table_max) { |
|||
s = ucs_a3_cp936_table[c - ucs_a3_cp936_table_min]; |
|||
} else if (c >= ucs_i_cp936_table_min && c < ucs_i_cp936_table_max) { |
|||
s = ucs_i_cp936_table[c - ucs_i_cp936_table_min]; |
|||
} else if (c >= ucs_r_cp936_table_min && c < ucs_r_cp936_table_max) { |
|||
s = ucs_r_cp936_table[c - ucs_r_cp936_table_min]; |
|||
} |
|||
c1 = (s >> 8) & 0xff; |
|||
c2 = s & 0xff; |
|||
|
|||
if (c1 < 0xa1 || c2 < 0xa1) { /* exclude CP932 extension */ |
|||
s = 0; |
|||
} |
|||
|
|||
if (s <= 0) { |
|||
c1 = c & ~MBFL_WCSPLANE_MASK; |
|||
if (c1 == MBFL_WCSPLANE_GB2312) { |
|||
s = c & MBFL_WCSPLANE_MASK; |
|||
} |
|||
if (c == 0) { |
|||
s = 0; |
|||
} else if (s <= 0) { |
|||
s = -1; |
|||
} |
|||
} |
|||
if (s >= 0) { |
|||
if (s < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(s, filter->data TSRMLS_CC)); |
|||
} else { |
|||
CK((*filter->output_function)((s >> 8) & 0xff, filter->data TSRMLS_CC)); |
|||
CK((*filter->output_function)(s & 0xff, filter->data TSRMLS_CC)); |
|||
} |
|||
} else { |
|||
if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) { |
|||
CK(mbfl_filt_conv_illegal_output(c, filter TSRMLS_CC)); |
|||
} |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
/* |
|||
* CP936 => wchar |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_cp936_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, s1, s2, w; |
|||
|
|||
switch (filter->status) { |
|||
case 0: |
|||
if (c >= 0 && c < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else if (c == 0x80) { /* euro sign */ |
|||
CK((*filter->output_function)(0x20ac, filter->data TSRMLS_CC)); |
|||
} else if (c > 0x80 && c < 0xff) { /* dbcs lead byte */ |
|||
filter->status = 1; |
|||
filter->cache = c; |
|||
} else { |
|||
w = c & MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
case 1: /* dbcs second byte */ |
|||
filter->status = 0; |
|||
c1 = filter->cache; |
|||
if ( c1 < 0xff && c1 > 0x80 && c > 0x39 && c < 0xff && c != 0x7f) { |
|||
w = (c1 - 0x81)*192 + (c - 0x40); |
|||
if (w >= 0 && w < cp936_ucs_table_size) { |
|||
w = cp936_ucs_table[w]; |
|||
} else { |
|||
w = 0; |
|||
} |
|||
if (w <= 0) { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSPLANE_MASK; |
|||
w |= MBFL_WCSPLANE_WINCP936; |
|||
} |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} else if ((c >= 0 && c < 0x21) || c == 0x7f) { /* CTLs */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
default: |
|||
filter->status = 0; |
|||
break; |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
/* |
|||
* wchar => CP936 |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_wchar_cp936(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, c2, s; |
|||
|
|||
s = 0; |
|||
if (c >= ucs_a1_cp936_table_min && c < ucs_a1_cp936_table_max) { |
|||
s = ucs_a1_cp936_table[c - ucs_a1_cp936_table_min]; |
|||
} else if (c >= ucs_a2_cp936_table_min && c < ucs_a2_cp936_table_max) { |
|||
s = ucs_a2_cp936_table[c - ucs_a2_cp936_table_min]; |
|||
} else if (c >= ucs_a3_cp936_table_min && c < ucs_a3_cp936_table_max) { |
|||
s = ucs_a3_cp936_table[c - ucs_a3_cp936_table_min]; |
|||
} else if (c >= ucs_i_cp936_table_min && c < ucs_i_cp936_table_max) { |
|||
s = ucs_i_cp936_table[c - ucs_i_cp936_table_min]; |
|||
} else if (c >= ucs_r_cp936_table_min && c < ucs_r_cp936_table_max) { |
|||
s = ucs_r_cp936_table[c - ucs_r_cp936_table_min]; |
|||
} |
|||
if (s <= 0) { |
|||
c1 = c & ~MBFL_WCSPLANE_MASK; |
|||
if (c1 == MBFL_WCSPLANE_WINCP936) { |
|||
s = c & MBFL_WCSPLANE_MASK; |
|||
} |
|||
if (c == 0) { |
|||
s = 0; |
|||
} else if (s <= 0) { |
|||
s = -1; |
|||
} |
|||
} |
|||
if (s >= 0) { |
|||
if (s < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(s, filter->data TSRMLS_CC)); |
|||
} else { |
|||
CK((*filter->output_function)((s >> 8) & 0xff, filter->data TSRMLS_CC)); |
|||
CK((*filter->output_function)(s & 0xff, filter->data TSRMLS_CC)); |
|||
} |
|||
} else { |
|||
if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) { |
|||
CK(mbfl_filt_conv_illegal_output(c, filter TSRMLS_CC)); |
|||
} |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
#endif /* HAVE_MBSTR_CN */ |
|||
|
|||
/* |
|||
* Local variables: |
|||
* tab-width: 4 |
|||
* c-basic-offset: 4 |
|||
* End: |
|||
*/ |
|||
@ -0,0 +1,30 @@ |
|||
/* |
|||
+----------------------------------------------------------------------+ |
|||
| PHP Version 4 | |
|||
+----------------------------------------------------------------------+ |
|||
| Copyright (c) 2001 The PHP Group | |
|||
+----------------------------------------------------------------------+ |
|||
| This source file is subject to version 2.02 of the PHP license, | |
|||
| that is bundled with this package in the file LICENSE, and is | |
|||
| available at through the world-wide-web at | |
|||
| http://www.php.net/license/2_02.txt. | |
|||
| If you did not receive a copy of the PHP license and are unable to | |
|||
| obtain it through the world-wide-web, please send a note to | |
|||
| license@php.net so we can mail you a copy immediately. | |
|||
+----------------------------------------------------------------------+ |
|||
| Author: Rui Hirokawa <hirokawa@php.net> | |
|||
+----------------------------------------------------------------------+ |
|||
*/ |
|||
|
|||
|
|||
/* $Id$ */ |
|||
|
|||
#ifndef MBFL_MBFILTER_CN_H |
|||
#define MBFL_MBFILTER_CN_H |
|||
|
|||
int mbfl_filt_conv_euccn_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
int mbfl_filt_conv_wchar_euccn(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
int mbfl_filt_conv_cp936_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
int mbfl_filt_conv_wchar_cp936(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
|
|||
#endif /* MBFL_MBFILTER_CN_H */ |
|||
@ -0,0 +1,324 @@ |
|||
/* |
|||
+----------------------------------------------------------------------+ |
|||
| PHP Version 4 | |
|||
+----------------------------------------------------------------------+ |
|||
| Copyright (c) 2001 The PHP Group | |
|||
+----------------------------------------------------------------------+ |
|||
| This source file is subject to version 2.02 of the PHP license, | |
|||
| that is bundled with this package in the file LICENSE, and is | |
|||
| available at through the world-wide-web at | |
|||
| http://www.php.net/license/2_02.txt. | |
|||
| If you did not receive a copy of the PHP license and are unable to | |
|||
| obtain it through the world-wide-web, please send a note to | |
|||
| license@php.net so we can mail you a copy immediately. | |
|||
+----------------------------------------------------------------------+ |
|||
| Author: Rui Hirokawa <hirokawa@php.net> | |
|||
+----------------------------------------------------------------------+ |
|||
*/ |
|||
|
|||
/* |
|||
* "streamable korean code filter and converter" |
|||
*/ |
|||
|
|||
/* $Id$ */ |
|||
|
|||
#ifdef HAVE_CONFIG_H |
|||
#include "config.h" |
|||
#endif |
|||
|
|||
#include "php.h" |
|||
#include "php_globals.h" |
|||
|
|||
#if defined(HAVE_MBSTR_KR) |
|||
#include "mbfilter.h" |
|||
#include "mbfilter_cn.h" |
|||
|
|||
#include "unicode_table_kr.h" |
|||
|
|||
#define CK(statement) do { if ((statement) < 0) return (-1); } while (0) |
|||
|
|||
|
|||
/* |
|||
* EUC-KR => wchar |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_euckr_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, s1, s2, w, flag; |
|||
|
|||
switch (filter->status) { |
|||
case 0: |
|||
if (c >= 0 && c < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else if (c > 0xa0 && c < 0xff && c != 0xc9) { /* dbcs lead byte */ |
|||
filter->status = 1; |
|||
filter->cache = c; |
|||
} else { |
|||
w = c & MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
case 1: /* dbcs second byte */ |
|||
filter->status = 0; |
|||
c1 = filter->cache; |
|||
flag = 0; |
|||
if (c1 >= 0xa1 && c1 <= 0xc6) { |
|||
flag = 1; |
|||
} else if (c1 >= 0xc7 && c1 <= 0xfe && c1 != 0xc9) { |
|||
flag = 2; |
|||
} |
|||
if (flag > 0 && c >= 0xa1 && c <= 0xfe) { |
|||
if (flag == 1){ |
|||
w = (c1 - 0xa1)*178 + (c - 0xa1) + 0x54; |
|||
if (w >= 0 && w < uhc2_ucs_table_size) { |
|||
w = uhc2_ucs_table[w]; |
|||
} else { |
|||
w = 0; |
|||
} |
|||
} else { |
|||
if (c1 < 0xc9){ |
|||
w = (c1 - 0xc7)*94 + c - 0xa1; |
|||
} else { |
|||
w = (c1 - 0xc8)*94 + c - 0xa1; |
|||
} |
|||
if (w >= 0 && w < uhc3_ucs_table_size) { |
|||
w = uhc3_ucs_table[w]; |
|||
} else { |
|||
w = 0; |
|||
} |
|||
} |
|||
|
|||
if (w <= 0) { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSPLANE_MASK; |
|||
w |= MBFL_WCSPLANE_KSC5601; |
|||
} |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} else if ((c >= 0 && c < 0x21) || c == 0x7f) { /* CTLs */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
default: |
|||
filter->status = 0; |
|||
break; |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
/* |
|||
* wchar => EUC-KR |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_wchar_euckr(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, c2, s; |
|||
|
|||
s = 0; |
|||
|
|||
if (c >= ucs_a1_uhc_table_min && c < ucs_a1_uhc_table_max) { |
|||
s = ucs_a1_uhc_table[c - ucs_a1_uhc_table_min]; |
|||
} else if (c >= ucs_a2_uhc_table_min && c < ucs_a2_uhc_table_max) { |
|||
s = ucs_a2_uhc_table[c - ucs_a2_uhc_table_min]; |
|||
} else if (c >= ucs_a3_uhc_table_min && c < ucs_a3_uhc_table_max) { |
|||
s = ucs_a3_uhc_table[c - ucs_a3_uhc_table_min]; |
|||
} else if (c >= ucs_i_uhc_table_min && c < ucs_i_uhc_table_max) { |
|||
s = ucs_i_uhc_table[c - ucs_i_uhc_table_min]; |
|||
} else if (c >= ucs_r1_uhc_table_min && c < ucs_r1_uhc_table_max) { |
|||
s = ucs_r1_uhc_table[c - ucs_r1_uhc_table_min]; |
|||
} else if (c >= ucs_r2_uhc_table_min && c < ucs_r2_uhc_table_max) { |
|||
s = ucs_r2_uhc_table[c - ucs_r2_uhc_table_min]; |
|||
} |
|||
|
|||
c1 = (s >> 8) & 0xff; |
|||
c2 = s & 0xff; |
|||
/* exclude UHC extension area */ |
|||
if (c1 < 0xa1 || c1 > 0xfe || c2 < 0xa1 && c2 > 0xfe){ |
|||
s = 0; |
|||
} |
|||
|
|||
if (s <= 0) { |
|||
c1 = c & ~MBFL_WCSPLANE_MASK; |
|||
if (c1 == MBFL_WCSPLANE_KSC5601) { |
|||
s = c & MBFL_WCSPLANE_MASK; |
|||
} |
|||
if (c == 0) { |
|||
s = 0; |
|||
} else if (s <= 0) { |
|||
s = -1; |
|||
} |
|||
} |
|||
if (s >= 0) { |
|||
if (s < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(s, filter->data TSRMLS_CC)); |
|||
} else { |
|||
CK((*filter->output_function)((s >> 8) & 0xff, filter->data TSRMLS_CC)); |
|||
CK((*filter->output_function)(s & 0xff, filter->data TSRMLS_CC)); |
|||
} |
|||
} else { |
|||
if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) { |
|||
CK(mbfl_filt_conv_illegal_output(c, filter)); |
|||
} |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
/* |
|||
* UHC => wchar |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, s1, s2, w, flag; |
|||
const short ofst1[] = { 0x41, 0x61, 0x81, 0xa1}; |
|||
const short ofst2[] = { 0x0, 0x1a, 0x34, 0x54}; |
|||
|
|||
switch (filter->status) { |
|||
case 0: |
|||
if (c >= 0 && c < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else if (c > 0x80 && c < 0xff && c != 0xc9) { /* dbcs lead byte */ |
|||
filter->status = 1; |
|||
filter->cache = c; |
|||
} else { |
|||
w = c & MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
case 1: /* dbcs second byte */ |
|||
filter->status = 0; |
|||
c1 = filter->cache; |
|||
|
|||
flag = 0; |
|||
if ( c >= 0x41 && c <= 0x5a){ |
|||
flag = 1; |
|||
} else if (c >= 0x61 && c <= 0x7a){ |
|||
flag = 2; |
|||
} else if (c >= 0x81 && c <= 0xa0){ |
|||
flag = 3; |
|||
} else if (c >= 0xa1 && c <= 0xfe){ |
|||
flag = 4; |
|||
} |
|||
if ( c1 >= 0x81 && c1 <= 0xa0 && flag > 0){ |
|||
w = (c1 - 0x81)*178 + (c - ofst1[flag-1] + ofst2[flag-1]); |
|||
if (w >= 0 && w < uhc1_ucs_table_size) { |
|||
w = uhc1_ucs_table[w]; |
|||
} else { |
|||
w = 0; |
|||
} |
|||
} else if ( c1 >= 0xa1 && c1 <= 0xc6 && flag > 0){ |
|||
w = (c1 - 0xa1)*178 + (c - ofst1[flag-1] + ofst2[flag-1]); |
|||
if (w >= 0 && w < uhc2_ucs_table_size) { |
|||
w = uhc2_ucs_table[w]; |
|||
} else { |
|||
w = 0; |
|||
} |
|||
} else if ( c1 >= 0xc7 && c1 <= 0xfe && flag == 4){ |
|||
if (c1 < 0xc9){ |
|||
w = (c1 - 0xc7)*94 + (c - ofst1[flag-1]); |
|||
} else { |
|||
w = (c1 - 0xc8)*94 + (c - ofst1[flag-1]); |
|||
} |
|||
if (w >= 0 && w < uhc3_ucs_table_size) { |
|||
w = uhc3_ucs_table[w]; |
|||
} else { |
|||
w = 0; |
|||
} |
|||
} |
|||
if (flag > 0){ |
|||
if (w <= 0) { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSPLANE_MASK; |
|||
w |= MBFL_WCSPLANE_UHC; |
|||
} |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} else { |
|||
if ((c >= 0 && c < 0x21) || c == 0x7f) { /* CTLs */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
} |
|||
break; |
|||
|
|||
default: |
|||
filter->status = 0; |
|||
break; |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
/* |
|||
* wchar => UHC |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, c2, s; |
|||
|
|||
s = 0; |
|||
if (c >= ucs_a1_uhc_table_min && c < ucs_a1_uhc_table_max) { |
|||
s = ucs_a1_uhc_table[c - ucs_a1_uhc_table_min]; |
|||
} else if (c >= ucs_a2_uhc_table_min && c < ucs_a2_uhc_table_max) { |
|||
s = ucs_a2_uhc_table[c - ucs_a2_uhc_table_min]; |
|||
} else if (c >= ucs_a3_uhc_table_min && c < ucs_a3_uhc_table_max) { |
|||
s = ucs_a3_uhc_table[c - ucs_a3_uhc_table_min]; |
|||
} else if (c >= ucs_i_uhc_table_min && c < ucs_i_uhc_table_max) { |
|||
s = ucs_i_uhc_table[c - ucs_i_uhc_table_min]; |
|||
} else if (c >= ucs_s_uhc_table_min && c < ucs_s_uhc_table_max) { |
|||
s = ucs_s_uhc_table[c - ucs_s_uhc_table_min]; |
|||
} else if (c >= ucs_r1_uhc_table_min && c < ucs_r1_uhc_table_max) { |
|||
s = ucs_r1_uhc_table[c - ucs_r1_uhc_table_min]; |
|||
} else if (c >= ucs_r2_uhc_table_min && c < ucs_r2_uhc_table_max) { |
|||
s = ucs_r2_uhc_table[c - ucs_r2_uhc_table_min]; |
|||
} |
|||
if (s <= 0) { |
|||
c1 = c & ~MBFL_WCSPLANE_MASK; |
|||
if (c1 == MBFL_WCSPLANE_UHC) { |
|||
s = c & MBFL_WCSPLANE_MASK; |
|||
} |
|||
if (c == 0) { |
|||
s = 0; |
|||
} else if (s <= 0) { |
|||
s = -1; |
|||
} |
|||
} |
|||
if (s >= 0) { |
|||
if (s < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(s, filter->data TSRMLS_CC)); |
|||
} else { |
|||
CK((*filter->output_function)((s >> 8) & 0xff, filter->data TSRMLS_CC)); |
|||
CK((*filter->output_function)(s & 0xff, filter->data TSRMLS_CC)); |
|||
} |
|||
} else { |
|||
if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) { |
|||
CK(mbfl_filt_conv_illegal_output(c, filter TSRMLS_CC)); |
|||
} |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
#endif /* HAVE_MBSTR_KR */ |
|||
|
|||
/* |
|||
* Local variables: |
|||
* tab-width: 4 |
|||
* c-basic-offset: 4 |
|||
* End: |
|||
*/ |
|||
@ -0,0 +1,30 @@ |
|||
/* |
|||
+----------------------------------------------------------------------+ |
|||
| PHP Version 4 | |
|||
+----------------------------------------------------------------------+ |
|||
| Copyright (c) 2001 The PHP Group | |
|||
+----------------------------------------------------------------------+ |
|||
| This source file is subject to version 2.02 of the PHP license, | |
|||
| that is bundled with this package in the file LICENSE, and is | |
|||
| available at through the world-wide-web at | |
|||
| http://www.php.net/license/2_02.txt. | |
|||
| If you did not receive a copy of the PHP license and are unable to | |
|||
| obtain it through the world-wide-web, please send a note to | |
|||
| license@php.net so we can mail you a copy immediately. | |
|||
+----------------------------------------------------------------------+ |
|||
| Author: Rui Hirokawa <hirokawa@php.net> | |
|||
+----------------------------------------------------------------------+ |
|||
*/ |
|||
|
|||
|
|||
/* $Id$ */ |
|||
|
|||
#ifndef MBFL_MBFILTER_KR_H |
|||
#define MBFL_MBFILTER_KR_H |
|||
|
|||
int mbfl_filt_conv_euckr_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
int mbfl_filt_conv_wchar_euckr(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
int mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
int mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
|
|||
#endif /* MBFL_MBFILTER_KR_H */ |
|||
@ -0,0 +1,336 @@ |
|||
/* |
|||
+----------------------------------------------------------------------+ |
|||
| PHP Version 4 | |
|||
+----------------------------------------------------------------------+ |
|||
| Copyright (c) 2001 The PHP Group | |
|||
+----------------------------------------------------------------------+ |
|||
| This source file is subject to version 2.02 of the PHP license, | |
|||
| that is bundled with this package in the file LICENSE, and is | |
|||
| available at through the world-wide-web at | |
|||
| http://www.php.net/license/2_02.txt. | |
|||
| If you did not receive a copy of the PHP license and are unable to | |
|||
| obtain it through the world-wide-web, please send a note to | |
|||
| license@php.net so we can mail you a copy immediately. | |
|||
+----------------------------------------------------------------------+ |
|||
| Author: Rui Hirokawa <hirokawa@php.net> | |
|||
+----------------------------------------------------------------------+ |
|||
*/ |
|||
|
|||
/* |
|||
* "streamable traditional chinese code filter and converter" |
|||
*/ |
|||
|
|||
/* $Id$ */ |
|||
|
|||
#ifdef HAVE_CONFIG_H |
|||
#include "config.h" |
|||
#endif |
|||
|
|||
#include "php.h" |
|||
#include "php_globals.h" |
|||
|
|||
#if defined(HAVE_MBSTR_TW) |
|||
#include "mbfilter.h" |
|||
#include "mbfilter_tw.h" |
|||
|
|||
#include "unicode_table_tw.h" |
|||
|
|||
#define CK(statement) do { if ((statement) < 0) return (-1); } while (0) |
|||
|
|||
/* |
|||
* EUC-TW => wchar |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_euctw_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, s, w, plane; |
|||
|
|||
switch (filter->status) { |
|||
case 0: |
|||
if (c >= 0 && c < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else if (c > 0xa0 && c < 0xff) { /* dbcs first byte */ |
|||
filter->status = 1; |
|||
filter->cache = c; |
|||
} else if (c == 0x8e) { /* mbcs first byte */ |
|||
filter->status = 2; |
|||
filter->cache = c; |
|||
} else { |
|||
w = c & MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
case 1: /* mbcs second byte */ |
|||
filter->status = 0; |
|||
c1 = filter->cache; |
|||
if (c > 0xa0 && c < 0xff) { |
|||
w = (c1 - 0xa1)*94 + (c - 0xa1); |
|||
if (w >= 0 && w < cns11643_1_ucs_table_size) { |
|||
w = cns11643_1_ucs_table[w]; |
|||
} else { |
|||
w = 0; |
|||
} |
|||
if (w <= 0) { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSPLANE_MASK; |
|||
w |= MBFL_WCSPLANE_CNS11643; |
|||
} |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} else if ((c >= 0 && c < 0x21) || c == 0x7f) { /* CTLs */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
case 2: /* got 0x8e, first char */ |
|||
if ((c >= 0 && c < 0x21) || c == 0x7f) { /* CTLs */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
filter->status = 0; |
|||
} else if (c > 0xa0 && c < 0xaf) { |
|||
filter->status = 3; |
|||
filter->cache = c - 0xa1; |
|||
} else { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
case 3: /* got 0x8e, third char */ |
|||
filter->status = 0; |
|||
c1 = filter->cache; |
|||
if ((c >= 0 && c < 0x21) || c == 0x7f) { /* CTLs */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
filter->status = 0; |
|||
} else if (c > 0xa0 && c < 0xff) { |
|||
filter->status = 4; |
|||
filter->cache = (c1 << 8) + c - 0xa1; |
|||
} else { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
case 4: /* mbcs fourth char */ |
|||
filter->status = 0; |
|||
c1 = filter->cache; |
|||
if (c1 >= 0x100 && c1 <= 0xdff && c > 0xa0 && c < 0xff) { |
|||
plane = (c1 & 0xf00) >> 8; |
|||
s = (c1 & 0xff)*94 + c - 0xa1; |
|||
w = 0; |
|||
if (s >= 0) { |
|||
if (plane == 1 & s < cns11643_2_ucs_table_size) { |
|||
w = cns11643_2_ucs_table[s]; |
|||
} |
|||
if (plane == 13 & s < cns11643_14_ucs_table_size) { |
|||
w = cns11643_14_ucs_table[s]; |
|||
} |
|||
} |
|||
if (w <= 0) { |
|||
w = ((c1 & 0x7f) << 8) | (c & 0x7f); |
|||
w &= MBFL_WCSPLANE_MASK; |
|||
w |= MBFL_WCSPLANE_CNS11643; |
|||
} |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} else if ((c >= 0 && c < 0x21) || c == 0x7f) { /* CTLs */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else { |
|||
w = (c1 << 8) | c | 0x8e0000; |
|||
w &= MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
default: |
|||
filter->status = 0; |
|||
break; |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
/* |
|||
* wchar => EUC-TW |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_wchar_euctw(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c0, c1, c2, s, plane; |
|||
|
|||
s = 0; |
|||
if (c >= ucs_a1_cns11643_table_min && c < ucs_a1_cns11643_table_max) { |
|||
s = ucs_a1_cns11643_table[c - ucs_a1_cns11643_table_min]; |
|||
} else if (c >= ucs_a2_cns11643_table_min && c < ucs_a2_cns11643_table_max) { |
|||
s = ucs_a2_cns11643_table[c - ucs_a2_cns11643_table_min]; |
|||
} else if (c >= ucs_a3_cns11643_table_min && c < ucs_a3_cns11643_table_max) { |
|||
s = ucs_a3_cns11643_table[c - ucs_a3_cns11643_table_min]; |
|||
} else if (c >= ucs_i_cns11643_table_min && c < ucs_i_cns11643_table_max) { |
|||
s = ucs_i_cns11643_table[c - ucs_i_cns11643_table_min]; |
|||
} else if (c >= ucs_r_cns11643_table_min && c < ucs_r_cns11643_table_max) { |
|||
s = ucs_r_cns11643_table[c - ucs_r_cns11643_table_min]; |
|||
} |
|||
if (s <= 0) { |
|||
c1 = c & ~MBFL_WCSPLANE_MASK; |
|||
if (c1 == MBFL_WCSPLANE_CNS11643) { |
|||
s = c & MBFL_WCSPLANE_MASK; |
|||
} |
|||
if (c == 0) { |
|||
s = 0; |
|||
} else if (s <= 0) { |
|||
s = -1; |
|||
} |
|||
} |
|||
if (s >= 0) { |
|||
plane = (s & 0x1f0000) >> 16; |
|||
if (plane <= 1){ |
|||
if (s < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(s, filter->data TSRMLS_CC)); |
|||
} else { |
|||
s = (s & 0xffff) | 0x8080; |
|||
CK((*filter->output_function)((s >> 8) & 0xff, filter->data TSRMLS_CC)); |
|||
CK((*filter->output_function)(s & 0xff, filter->data TSRMLS_CC)); |
|||
} |
|||
} else { |
|||
s = (0x8ea00000 + (plane << 16)) | ((s & 0xffff) | 0x8080); |
|||
CK((*filter->output_function)(0x8e , filter->data TSRMLS_CC)); |
|||
CK((*filter->output_function)((s >> 16) & 0xff, filter->data TSRMLS_CC)); |
|||
CK((*filter->output_function)((s >> 8) & 0xff, filter->data TSRMLS_CC)); |
|||
CK((*filter->output_function)(s & 0xff, filter->data TSRMLS_CC)); |
|||
} |
|||
} else { |
|||
if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) { |
|||
CK(mbfl_filt_conv_illegal_output(c, filter TSRMLS_CC)); |
|||
} |
|||
} |
|||
return c; |
|||
} |
|||
|
|||
/* |
|||
* Big5 => wchar |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_big5_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, s1, s2, w; |
|||
|
|||
switch (filter->status) { |
|||
case 0: |
|||
if (c >= 0 && c < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else if (c > 0xa0 && c < 0xff) { /* dbcs lead byte */ |
|||
filter->status = 1; |
|||
filter->cache = c; |
|||
} else { |
|||
w = c & MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
case 1: /* dbcs second byte */ |
|||
filter->status = 0; |
|||
c1 = filter->cache; |
|||
if ((c > 0x39 && c < 0x7f) | (c > 0xa0 && c < 0xff)) { |
|||
if (c < 0x7f){ |
|||
w = (c1 - 0xa1)*157 + (c - 0x40); |
|||
} else { |
|||
w = (c1 - 0xa1)*157 + (c - 0xa1) + 0x3f; |
|||
} |
|||
if (w >= 0 && w < big5_ucs_table_size) { |
|||
w = big5_ucs_table[w]; |
|||
} else { |
|||
w = 0; |
|||
} |
|||
if (w <= 0) { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSPLANE_MASK; |
|||
w |= MBFL_WCSPLANE_BIG5; |
|||
} |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} else if ((c >= 0 && c < 0x21) || c == 0x7f) { /* CTLs */ |
|||
CK((*filter->output_function)(c, filter->data TSRMLS_CC)); |
|||
} else { |
|||
w = (c1 << 8) | c; |
|||
w &= MBFL_WCSGROUP_MASK; |
|||
w |= MBFL_WCSGROUP_THROUGH; |
|||
CK((*filter->output_function)(w, filter->data TSRMLS_CC)); |
|||
} |
|||
break; |
|||
|
|||
default: |
|||
filter->status = 0; |
|||
break; |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
/* |
|||
* wchar => Big5 |
|||
*/ |
|||
int |
|||
mbfl_filt_conv_wchar_big5(int c, mbfl_convert_filter *filter TSRMLS_DC) |
|||
{ |
|||
int c1, c2, s; |
|||
|
|||
s = 0; |
|||
if (c >= ucs_a1_big5_table_min && c < ucs_a1_big5_table_max) { |
|||
s = ucs_a1_big5_table[c - ucs_a1_big5_table_min]; |
|||
} else if (c >= ucs_a2_big5_table_min && c < ucs_a2_big5_table_max) { |
|||
s = ucs_a2_big5_table[c - ucs_a2_big5_table_min]; |
|||
} else if (c >= ucs_a3_big5_table_min && c < ucs_a3_big5_table_max) { |
|||
s = ucs_a3_big5_table[c - ucs_a3_big5_table_min]; |
|||
} else if (c >= ucs_i_big5_table_min && c < ucs_i_big5_table_max) { |
|||
s = ucs_i_big5_table[c - ucs_i_big5_table_min]; |
|||
} else if (c >= ucs_pua_big5_table_min && c < ucs_pua_big5_table_max) { |
|||
s = ucs_pua_big5_table[c - ucs_pua_big5_table_min]; |
|||
} else if (c >= ucs_r1_big5_table_min && c < ucs_r1_big5_table_max) { |
|||
s = ucs_r1_big5_table[c - ucs_r1_big5_table_min]; |
|||
} else if (c >= ucs_r2_big5_table_min && c < ucs_r2_big5_table_max) { |
|||
s = ucs_r2_big5_table[c - ucs_r2_big5_table_min]; |
|||
} |
|||
if (s <= 0) { |
|||
c1 = c & ~MBFL_WCSPLANE_MASK; |
|||
if (c1 == MBFL_WCSPLANE_BIG5) { |
|||
s = c & MBFL_WCSPLANE_MASK; |
|||
} |
|||
if (c == 0) { |
|||
s = 0; |
|||
} else if (s <= 0) { |
|||
s = -1; |
|||
} |
|||
} |
|||
if (s >= 0) { |
|||
if (s < 0x80) { /* latin */ |
|||
CK((*filter->output_function)(s, filter->data TSRMLS_CC)); |
|||
} else { |
|||
CK((*filter->output_function)((s >> 8) & 0xff, filter->data TSRMLS_CC)); |
|||
CK((*filter->output_function)(s & 0xff, filter->data TSRMLS_CC)); |
|||
} |
|||
} else { |
|||
if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) { |
|||
CK(mbfl_filt_conv_illegal_output(c, filter TSRMLS_CC)); |
|||
} |
|||
} |
|||
|
|||
return c; |
|||
} |
|||
|
|||
#endif /* HAVE_MBSTR_TW */ |
|||
|
|||
/* |
|||
* Local variables: |
|||
* tab-width: 4 |
|||
* c-basic-offset: 4 |
|||
* End: |
|||
*/ |
|||
@ -0,0 +1,30 @@ |
|||
/* |
|||
+----------------------------------------------------------------------+ |
|||
| PHP Version 4 | |
|||
+----------------------------------------------------------------------+ |
|||
| Copyright (c) 2001 The PHP Group | |
|||
+----------------------------------------------------------------------+ |
|||
| This source file is subject to version 2.02 of the PHP license, | |
|||
| that is bundled with this package in the file LICENSE, and is | |
|||
| available at through the world-wide-web at | |
|||
| http://www.php.net/license/2_02.txt. | |
|||
| If you did not receive a copy of the PHP license and are unable to | |
|||
| obtain it through the world-wide-web, please send a note to | |
|||
| license@php.net so we can mail you a copy immediately. | |
|||
+----------------------------------------------------------------------+ |
|||
| Author: Rui Hirokawa <hirokawa@php.net> | |
|||
+----------------------------------------------------------------------+ |
|||
*/ |
|||
|
|||
|
|||
/* $Id$ */ |
|||
|
|||
#ifndef MBFL_MBFILTER_TW_H |
|||
#define MBFL_MBFILTER_TW_H |
|||
|
|||
int mbfl_filt_conv_euctw_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
int mbfl_filt_conv_wchar_euctw(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
int mbfl_filt_conv_big5_wchar(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
int mbfl_filt_conv_wchar_big5(int c, mbfl_convert_filter *filter TSRMLS_DC); |
|||
|
|||
#endif /* MBFL_MBFILTER_TW_H */ |
|||
6414
ext/mbstring/unicode_table_cn.h
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
6934
ext/mbstring/unicode_table_kr.h
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
11215
ext/mbstring/unicode_table_tw.h
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue