From 6c33274a0a2bbee4da85729aa26e986b5ee6b057 Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Sun, 18 Sep 2016 18:38:21 +0900 Subject: [PATCH] implement is_valid_mbc_string() in euc_tw --- src/euc_tw.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/euc_tw.c b/src/euc_tw.c index 4e07567..b3ee628 100644 --- a/src/euc_tw.c +++ b/src/euc_tw.c @@ -55,9 +55,42 @@ euctw_mbc_enc_len(const UChar* p) } static int -is_valid_mbc_string(const UChar* s, const UChar* end) +is_valid_mbc_string(const UChar* p, const UChar* end) { - return onigenc_length_check_is_valid_mbc_string(ONIG_ENCODING_EUC_TW, s, end); + while (p < end) { + if (*p < 0x80) { + p++; + } + else if (*p < 0xa1) { + if (*p == 0x8e) { + p++; + if (p >= end) return FALSE; + if (*p < 0xa1 || *p > 0xb0) return FALSE; + p++; + if (p >= end) return FALSE; + if (*p < 0xa1 || *p == 0xff) + return FALSE; + p++; + if (p >= end) return FALSE; + if (*p < 0xa1 || *p == 0xff) + return FALSE; + p++; + } + else + return FALSE; + } + else if (*p < 0xff) { + p++; + if (p >= end) return FALSE; + if (*p < 0xa1 || *p == 0xff) + return FALSE; + p++; + } + else + return FALSE; + } + + return TRUE; } static OnigCodePoint -- 2.40.0