From 52a46c915a090b3f6e4e56b7b68afc0c426fea98 Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Sun, 11 Sep 2016 12:06:58 +0900 Subject: [PATCH] implement is_valid_mbc_string() in euc_jp --- src/euc_jp.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/euc_jp.c b/src/euc_jp.c index 19422ce..3b54e95 100644 --- a/src/euc_jp.c +++ b/src/euc_jp.c @@ -57,9 +57,39 @@ 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_JP, s, end); + while (p < end) { + if (*p < 0x80) { + p++; + } + else if (*p > 0xa0) { + if (*p == 0xff) return FALSE; + p++; + if (p >= end) return FALSE; + if (*p < 0xa1 || *p == 0xff) return FALSE; + p++; + } + else if (*p == 0x8e) { + p++; + if (p >= end) return FALSE; + if (*p < 0xa1 || *p > 0xdf) return FALSE; + p++; + } + else if (*p == 0x8f) { + 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; + } + + return TRUE; } static OnigCodePoint -- 2.40.0