]> granicus.if.org Git - onig/commitdiff
implement is_valid_mbc_string() in euc_kr
authorK.Kosako <kkosako0@gmail.com>
Sun, 18 Sep 2016 09:25:54 +0000 (18:25 +0900)
committerK.Kosako <kkosako0@gmail.com>
Sun, 18 Sep 2016 09:25:54 +0000 (18:25 +0900)
src/euc_kr.c

index 12803cdbd8c139933d631e52516cca9bc267e335..450caf146ffc8677e22b8f3286ac9d5eeff5f0a9 100644 (file)
@@ -55,9 +55,27 @@ euckr_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_KR, s, end);
+  while (p < end) {
+    if (*p < 0x80) {
+      p++;
+    }
+    else if (*p < 0xa1) {
+      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