From 692c7a768ddbbd3bbf45ec8ee97b96c9dbacad39 Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Sun, 18 Sep 2016 18:04:21 +0900 Subject: [PATCH] implement is_valid_mbc_string() in Shift_jis --- src/sjis.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/sjis.c b/src/sjis.c index a607b3d..3378474 100644 --- a/src/sjis.c +++ b/src/sjis.c @@ -77,9 +77,36 @@ 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_SJIS, s, end); + while (p < end) { + if (*p < 0x80) { + p++; + } + else if (*p < 0xa1) { + if (*p == 0xa0 || *p == 0x80) + return FALSE; + p++; + if (p >= end) return FALSE; + if (*p < 0x40 || *p > 0xfc || *p == 0x7f) + return FALSE; + p++; + } + else if (*p < 0xe0) { + p++; + } + else if (*p < 0xfd) { + p++; + if (p >= end) return FALSE; + if (*p < 0x40 || *p > 0xfc || *p == 0x7f) + return FALSE; + p++; + } + else + return FALSE; + } + + return TRUE; } static int -- 2.40.0