summaryrefslogtreecommitdiff
path: root/src/gb18030.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gb18030.c')
-rw-r--r--src/gb18030.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/gb18030.c b/src/gb18030.c
index 1385a7f..7409d3e 100644
--- a/src/gb18030.c
+++ b/src/gb18030.c
@@ -89,15 +89,25 @@ gb18030_mbc_enc_len(const UChar* p)
static int
gb18030_code_to_mbclen(OnigCodePoint code)
{
- if ((code & 0xff000000) != 0) return 4;
- else if ((code & 0xff0000) != 0) return ONIGERR_INVALID_CODE_POINT_VALUE;
- else if ((code & 0xff00) != 0) return 2;
+ if ((code & 0xff000000) != 0) {
+ if (GB18030_MAP[(int )(code >> 24) & 0xff] == CM)
+ if (GB18030_MAP[(int )(code >> 16) & 0xff] == C4)
+ return 4;
+ }
+ else if ((code & 0xff0000) != 0) return ONIGERR_INVALID_CODE_POINT_VALUE;
+ else if ((code & 0xff00) != 0) {
+ if (GB18030_MAP[(int )(code >> 8) & 0xff] == CM) {
+ char c = GB18030_MAP[(int )code & 0xff];
+ if (c == CM || c == C2)
+ return 2;
+ }
+ }
else {
- if (GB18030_MAP[(int )(code & 0xff)] == CM)
- return ONIGERR_INVALID_CODE_POINT_VALUE;
-
- return 1;
+ if (GB18030_MAP[(int )(code & 0xff)] != CM)
+ return 1;
}
+
+ return ONIGERR_INVALID_CODE_POINT_VALUE;
}
static int