From d3a6585330d53a1c93b2164d0872a43267f14b6f Mon Sep 17 00:00:00 2001 From: "K.Takata" Date: Thu, 1 Dec 2016 21:32:02 +0900 Subject: [PATCH] Use raw string if a cclass contains only one character (Issue #46) --- regparse.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/regparse.c b/regparse.c index cda37f19..ebca4604 100644 --- a/regparse.c +++ b/regparse.c @@ -6084,11 +6084,10 @@ node_extended_grapheme_cluster(Node** np, ScanEnv* env) /* Emoji variation sequence * http://unicode.org/Public/emoji/4.0/emoji-zwj-sequences.txt */ - np1 = node_new_cclass(); + num1 = ONIGENC_CODE_TO_MBC(env->enc, 0xfe0f, buf); + if (num1 < 0) return num1; + np1 = node_new_str_raw(buf, buf + num1); if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_code_range(&(cc->mbuf), env, 0xfe0f, 0xfe0f); - if (r != 0) goto err; tmp = node_new_quantifier(0, 1, 0); if (IS_NULL(tmp)) goto err; @@ -6131,11 +6130,10 @@ node_extended_grapheme_cluster(Node** np, ScanEnv* env) alt2 = NULL; /* ZWJ */ - np1 = node_new_cclass(); + num1 = ONIGENC_CODE_TO_MBC(env->enc, 0x200D, buf); + if (num1 < 0) return num1; + np1 = node_new_str_raw(buf, buf + num1); if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_code_range(&(cc->mbuf), env, 0x200D, 0x200D); - if (r != 0) goto err; tmp = node_new_list(np1, list2); if (IS_NULL(tmp)) goto err; @@ -6255,11 +6253,10 @@ node_extended_grapheme_cluster(Node** np, ScanEnv* env) list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); + num1 = ONIGENC_CODE_TO_MBC(env->enc, 0x200D, buf); + if (num1 < 0) return num1; + np1 = node_new_str_raw(buf, buf + num1); if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_code_range(&(cc->mbuf), env, 0x200D, 0x200D); - if (r != 0) goto err; tmp = node_new_list(np1, list2); if (IS_NULL(tmp)) goto err; @@ -6332,11 +6329,10 @@ node_extended_grapheme_cluster(Node** np, ScanEnv* env) np1 = NULL; /* Prepend+ */ - np1 = node_new_cclass(); + num1 = ONIGENC_CODE_TO_MBC(env->enc, 0x200D, buf); + if (num1 < 0) return num1; + np1 = node_new_str_raw(buf, buf + num1); if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_code_range(&(cc->mbuf), env, 0x200D, 0x200D); - if (r != 0) goto err; tmp = node_new_quantifier(0, 1, 0); if (IS_NULL(tmp)) goto err;