]> granicus.if.org Git - onig/commitdiff
implement is_valid_mbc_string() in euc_jp
authorK.Kosako <kkosako0@gmail.com>
Sun, 11 Sep 2016 03:06:58 +0000 (12:06 +0900)
committerK.Kosako <kkosako0@gmail.com>
Sun, 11 Sep 2016 03:06:58 +0000 (12:06 +0900)
src/euc_jp.c

index 19422ce702db584715b345beca65c5e6b0578868..3b54e958d9616928734f35c67d9c35fde1a16af8 100644 (file)
@@ -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