Regexp supports Unicoe 9.0.0's \X

* meta character \X matches Unicode 9.0.0 characters with some workarounds
  for UTR #51 Unicode Emoji, Version 4.0 emoji zwj sequences.
  [Feature #12831] [ruby-core:77586]

The term "character" can have many meanings bytes, codepoints, combined
characters, and so on. "grapheme cluster" is highest one of such words,
which means user-perceived characters.
Unicode Standard Annex #29 UNICODE TEXT SEGMENTATION specifies how to
handle grapheme clusters (extended grapheme cluster).
But some specs aren't updated to current situation because Unicode Emoji
is rapidly extended without well definition.
It breaks the precondition of UTR#29 "Grapheme cluster boundaries can be
easily tested by looking at immediately adjacent characters". (the
sentence will be removed in the next version)
Though some of its detail are described in Unicode Technical Report #51
UNICODE EMOJI but it is not merged into UTR#29 yet.

http://unicode.org/reports/tr29/
http://unicode.org/reports/tr51/
http://unicode.org/Public/emoji/4.0/

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2016-11-30 17:29:19 +00:00
Родитель e680bfb1ab
Коммит c11e648799
8 изменённых файлов: 4210 добавлений и 2254 удалений

3
NEWS
Просмотреть файл

@ -132,6 +132,9 @@ with all sufficient information, see the ChangeLog file or Redmine
* Regexp#match? [Feature #8110]
This returns bool and doesn't save backref.
* meta character \X matches Unicode 9.0 characters with some workarounds
for UTR #51 Unicode Emoji, Version 4.0 emoji zwj sequences.
* Regexp/String: Updated Unicode version from 8.0.0 to 9.0.0 [Feature #12513]
* RubyVM::Env

Просмотреть файл

@ -1064,6 +1064,7 @@ UNICODE_PROPERTY_FILES = \
$(UNICODE_SRC_DATA_DIR)/PropertyAliases.txt \
$(UNICODE_SRC_DATA_DIR)/PropertyValueAliases.txt \
$(UNICODE_SRC_DATA_DIR)/Scripts.txt \
$(UNICODE_SRC_DATA_DIR)/auxiliary/GraphemeBreakProperty.txt \
$(empty)
update-unicode: $(UNICODE_FILES)
@ -1076,7 +1077,7 @@ UNICODE_DOWNLOAD = \
$(UNICODE_PROPERTY_FILES):
$(ECHO) Downloading Unicode $(UNICODE_VERSION) property files...
$(Q) $(MAKEDIRS) "$(UNICODE_SRC_DATA_DIR)"
$(Q) $(MAKEDIRS) "$(UNICODE_SRC_DATA_DIR)/auxiliary"
$(Q) $(UNICODE_DOWNLOAD) $(UNICODE_PROPERTY_FILES)
$(UNICODE_FILES):

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -6572,7 +6572,7 @@ print_compiled_byte_code_list(FILE* f, regex_t* reg)
#endif /* ONIG_DEBUG_COMPILE */
#ifdef ONIG_DEBUG_PARSE_TREE
static void
void
print_indent_tree(FILE* f, Node* node, int indent)
{
int i, type, container_p = 0;
@ -6618,12 +6618,15 @@ print_indent_tree(FILE* f, Node* node, int indent)
case NT_CCLASS:
fprintf(f, "<cclass:%"PRIxPTR">", (intptr_t )node);
if (IS_NCCLASS_NOT(NCCLASS(node))) fputs(" not", f);
if (IS_NCCLASS_NOT(NCCLASS(node))) fputs("not ", f);
if (NCCLASS(node)->mbuf) {
BBuf* bbuf = NCCLASS(node)->mbuf;
for (i = 0; i < (int )bbuf->used; i++) {
if (i > 0) fprintf(f, ",");
fprintf(f, "%0x", bbuf->p[i]);
OnigCodePoint* data = (OnigCodePoint*)bbuf->p;
OnigCodePoint* end = (OnigCodePoint*)(bbuf->p + bbuf->used);
fprintf(f, "%d", *data++);
for (; data < end; data+=2) {
fprintf(f, ",");
fprintf(f, "%04x-%04x", data[0], data[1]);
}
}
break;

Просмотреть файл

@ -5784,61 +5784,703 @@ node_linebreak(Node** np, ScanEnv* env)
return ONIGERR_MEMORY;
}
static int
propname2ctype(ScanEnv* env, const char* propname)
{
UChar* name = (UChar*)propname;
int ctype = env->enc->property_name_to_ctype(ONIG_ENCODING_ASCII,
name, name + strlen(propname));
return ctype;
}
static int
node_extended_grapheme_cluster(Node** np, ScanEnv* env)
{
/* same as (?>\P{M}\p{M}*) */
Node* np1 = NULL;
Node* np2 = NULL;
Node* qn = NULL;
Node* list1 = NULL;
Node* list = NULL;
Node* list2 = NULL;
Node* alt = NULL;
Node* alt2 = NULL;
int r = 0;
#ifdef USE_UNICODE_PROPERTIES
if (ONIGENC_IS_UNICODE(env->enc)) {
/* UTF-8, UTF-16BE/LE, UTF-32BE/LE */
CClassNode* cc1;
CClassNode* cc2;
UChar* propname = (UChar* )"M";
int ctype = env->enc->property_name_to_ctype(ONIG_ENCODING_ASCII,
propname, propname + 1);
if (ctype >= 0) {
/* \P{M} */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc1 = NCCLASS(np1);
r = add_ctype_to_cc(cc1, ctype, 0, 0, env);
if (r != 0) goto err;
NCCLASS_SET_NOT(cc1);
Node* tmp = NULL;
int num1, num2;
UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN * 2];
CClassNode* cc;
OnigOptionType option;
int extend = propname2ctype(env, "Grapheme_Cluster_Break=Extend");
/* \p{M}* */
np2 = node_new_cclass();
if (IS_NULL(np2)) goto err;
cc2 = NCCLASS(np2);
r = add_ctype_to_cc(cc2, ctype, 0, 0, env);
if (r != 0) goto err;
/* Prepend*
* ( RI-sequence | Hangul-Syllable | !Control )
* ( Grapheme_Extend | SpacingMark )* */
qn = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(qn)) goto err;
NQTFR(qn)->target = np2;
np2 = NULL;
/* ( Grapheme_Extend | SpacingMark )* */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, extend, 0, 0, env);
if (r != 0) goto err;
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=SpacingMark"), 0, 0, env);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x200D, 0x200D);
if (r != 0) goto err;
/* \P{M}\p{M}* */
list2 = node_new_list(qn, NULL_NODE);
if (IS_NULL(list2)) goto err;
qn = NULL;
list1 = node_new_list(np1, list2);
if (IS_NULL(list1)) goto err;
np1 = NULL;
list2 = NULL;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
/* (?>...) */
*np = node_new_enclose(ENCLOSE_STOP_BACKTRACK);
if (IS_NULL(*np)) goto err;
NENCLOSE(*np)->target = list1;
return ONIG_NORMAL;
}
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list = tmp;
np1 = NULL;
/* ( RI-sequence | Hangul-Syllable | !Control ) */
/* !Control */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=Control"), 1, 0, env);
if (r != 0) goto err;
BITSET_CLEAR_BIT(cc->bs, 0x0a);
BITSET_CLEAR_BIT(cc->bs, 0x0d);
tmp = onig_node_new_alt(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
alt = tmp;
np1 = NULL;
/* Hangul-Syllable
* := L* V+ T*
* | L* LV V* T*
* | L* LVT T*
* | L+
* | T+ */
/* T+ */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=T"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(1, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = onig_node_new_alt(np1, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
np1 = NULL;
/* L+ */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=L"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(1, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = onig_node_new_alt(np1, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
np1 = NULL;
/* L* LVT T* */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=T"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=LVT"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=L"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
list2 = NULL;
/* L* LV V* T* */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=T"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=V"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=LV"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=L"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
list2 = NULL;
/* L* V+ T* */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=T"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=V"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(1, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=L"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
list2 = NULL;
/* Emoji sequence := (E_Base | EBG) Extend* E_Modifier?
* (ZWJ (Glue_After_Zwj | EBG Extend* E_Modifier?) )* */
/* ZWJ (Glue_After_Zwj | E_Base_GAZ Extend* E_Modifier?) */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=E_Modifier"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, 1, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, extend, 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=E_Base_GAZ"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, NULL_NODE);
if (IS_NULL(tmp)) goto err;
alt2 = tmp;
list2 = NULL;
/* Glue_After_Zwj */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, extend, 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_code_range(&(cc->mbuf), env, 0x1F308, 0x1F308);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F33E, 0x1F33E);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F373, 0x1F373);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F393, 0x1F393);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F3A4, 0x1F3A4);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F3A8, 0x1F3A8);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F3EB, 0x1F3EB);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F3ED, 0x1F3ED);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F4BB, 0x1F4BC);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F527, 0x1F527);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F52C, 0x1F52C);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F680, 0x1F680);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F692, 0x1F692);
if (r != 0) goto err;
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=Glue_After_Zwj"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, alt2);
if (IS_NULL(tmp)) goto err;
alt2 = tmp;
list2 = NULL;
/* Emoji variation sequence
* http://unicode.org/Public/emoji/4.0/emoji-zwj-sequences.txt
*/
np1 = node_new_cclass();
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;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_code_range(&(cc->mbuf), env, 0x2640, 0x2640);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x2642, 0x2642);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x2695, 0x2696);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x2708, 0x2708);
if (r != 0) goto err;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, alt2);
if (IS_NULL(tmp)) goto err;
alt2 = tmp;
list2 = NULL;
tmp = node_new_list(alt2, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
alt2 = NULL;
/* ZWJ */
np1 = node_new_cclass();
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;
list2 = tmp;
np1 = NULL;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = list2;
np1 = tmp;
list2 = NULL;
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
/* E_Modifier? */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=E_Modifier"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, 1, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
/* Extend* */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, extend, 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
/* (E_Base | EBG) */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_code_range(&(cc->mbuf), env, 0x1F3C2, 0x1F3C2);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F3C7, 0x1F3C7);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F3CC, 0x1F3CC);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F3F3, 0x1F3F3);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F441, 0x1F441);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F46F, 0x1F46F);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F574, 0x1F574);
if (r != 0) goto err;
r = add_code_range(&(cc->mbuf), env, 0x1F6CC, 0x1F6CC);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=E_Base"), 0, 0, env);
if (r != 0) goto err;
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=E_Base_GAZ"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
list2 = NULL;
/* ZWJ (E_Base_GAZ | Glue_After_Zwj) E_Modifier? */
/* a sequence starting with ZWJ seems artificial, but GraphemeBreakTest
* has such examples.
* http://www.unicode.org/Public/9.0.0/ucd/auxiliary/GraphemeBreakTest.html
*/
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=E_Modifier"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, 1, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=Glue_After_Zwj"), 0, 0, env);
if (r != 0) goto err;
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=E_Base_GAZ"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
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;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
list2 = NULL;
/* RI-Sequence := Regional_Indicator{2} */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_code_range(&(cc->mbuf), env, 0x1F1E6, 0x1F1FF);
if (r != 0) goto err;
tmp = node_new_quantifier(2, 2, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
list2 = NULL;
tmp = node_new_list(alt, list);
if (IS_NULL(tmp)) goto err;
list = tmp;
alt = NULL;
/* Prepend* */
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=Prepend"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(0, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list);
if (IS_NULL(tmp)) goto err;
list = tmp;
np1 = NULL;
/* PerlSyntax: (?s:.), RubySyntax: (?m:.) */
np1 = node_new_anychar();
if (IS_NULL(np1)) goto err;
option = env->option;
ONOFF(option, ONIG_OPTION_MULTILINE, 0);
tmp = node_new_option(option);
if (IS_NULL(tmp)) goto err;
NENCLOSE(tmp)->target = np1;
np1 = tmp;
tmp = onig_node_new_alt(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
alt = tmp;
np1 = NULL;
/* Prepend+ */
np1 = node_new_cclass();
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;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, NULL_NODE);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
np1 = node_new_cclass();
if (IS_NULL(np1)) goto err;
cc = NCCLASS(np1);
r = add_ctype_to_cc(cc, propname2ctype(env, "Grapheme_Cluster_Break=Prepend"), 0, 0, env);
if (r != 0) goto err;
tmp = node_new_quantifier(1, REPEAT_INFINITE, 0);
if (IS_NULL(tmp)) goto err;
NQTFR(tmp)->target = np1;
np1 = tmp;
tmp = node_new_list(np1, list2);
if (IS_NULL(tmp)) goto err;
list2 = tmp;
np1 = NULL;
tmp = onig_node_new_alt(list2, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
list2 = NULL;
tmp = onig_node_new_alt(list, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
list = NULL;
/* \x0D\x0A */
num1 = ONIGENC_CODE_TO_MBC(env->enc, 0x0D, buf);
if (num1 < 0) return num1;
num2 = ONIGENC_CODE_TO_MBC(env->enc, 0x0A, buf + num1);
if (num2 < 0) return num2;
np1 = node_new_str_raw(buf, buf + num1 + num2);
if (IS_NULL(np1)) goto err;
tmp = onig_node_new_alt(np1, alt);
if (IS_NULL(tmp)) goto err;
alt = tmp;
np1 = NULL;
/* (?>...) */
*np = node_new_enclose(ENCLOSE_STOP_BACKTRACK);
if (IS_NULL(*np)) goto err;
NENCLOSE(*np)->target = alt;
return ONIG_NORMAL;
}
#endif /* USE_UNICODE_PROPERTIES */
if (IS_NULL(*np)) {
@ -5857,10 +6499,10 @@ node_extended_grapheme_cluster(Node** np, ScanEnv* env)
err:
onig_node_free(np1);
onig_node_free(np2);
onig_node_free(qn);
onig_node_free(list1);
onig_node_free(list);
onig_node_free(list2);
onig_node_free(alt);
onig_node_free(alt2);
return (r == 0) ? ONIGERR_MEMORY : r;
}

Просмотреть файл

@ -900,6 +900,27 @@ class TestRegexp < Test::Unit::TestCase
assert_no_match(/[[:ascii:]]/, "\x80\xFF")
end
def test_cclass_R
assert_match /\A\R\z/, "\r"
assert_match /\A\R\z/, "\n"
assert_match /\A\R\z/, "\r\n"
end
def test_cclass_X
assert_match /\A\X\z/, "\u{20 200d}"
assert_match /\A\X\z/, "\u{600 600}"
assert_match /\A\X\z/, "\u{600 20}"
assert_match /\A\X\z/, "\u{261d 1F3FB}"
assert_match /\A\X\z/, "\u{1f600}"
assert_match /\A\X\z/, "\u{20 308}"
assert_match /\A\X\X\z/, "\u{a 308}"
assert_match /\A\X\X\z/, "\u{d 308}"
assert_match /\A\X\z/, "\u{1F477 1F3FF 200D 2640 FE0F}"
assert_match /\A\X\z/, "\u{1F468 200D 1F393}"
assert_match /\A\X\z/, "\u{1F46F 200D 2642 FE0F}"
assert_match /\A\X\z/, "\u{1f469 200d 2764 fe0f 200d 1f469}"
end
def test_backward
assert_equal(3, "foobar".rindex(/b.r/i))
assert_equal(nil, "foovar".rindex(/b.r/i))

Просмотреть файл

@ -228,7 +228,13 @@ if $0 == __FILE__
dl = Downloader.const_get(dl)
ARGV.shift
ARGV.each do |name|
name = "#{prefix}/#{File.basename(name)}" if prefix
if prefix
if name.include?('/auxiliary/')
name = "#{prefix}/auxiliary/#{File.basename(name)}"
else
name = "#{prefix}/#{File.basename(name)}"
end
end
dl.download(name, destdir, since, options)
end
else

Просмотреть файл

@ -144,7 +144,7 @@ def parse_scripts(data, categories)
categories[current] = file[:title]
(names[file[:title]] ||= []) << current
cps = []
elsif /^([0-9a-fA-F]+)(?:..([0-9a-fA-F]+))?\s*;\s*(\w+)/ =~ line
elsif /^([0-9a-fA-F]+)(?:\.\.([0-9a-fA-F]+))?\s*;\s*(\w+)/ =~ line
current = $3
$2 ? cps.concat(($1.to_i(16)..$2.to_i(16)).to_a) : cps.push($1.to_i(16))
end
@ -199,7 +199,26 @@ def parse_age(data)
ages << current
last_constname = constname
cps = []
elsif /^([0-9a-fA-F]+)(?:..([0-9a-fA-F]+))?\s*;\s*(\d+\.\d+)/ =~ line
elsif /^([0-9a-fA-F]+)(?:\.\.([0-9a-fA-F]+))?\s*;\s*(\d+\.\d+)/ =~ line
current = $3
$2 ? cps.concat(($1.to_i(16)..$2.to_i(16)).to_a) : cps.push($1.to_i(16))
end
end
ages
end
def parse_GraphemeBreakProperty(data)
current = nil
cps = []
ages = []
data_foreach('GraphemeBreakProperty.txt') do |line|
if /^# Total code points: / =~ line
constname = constantize_Grapheme_Cluster_Break(current)
data[constname] = cps
make_const(constname, cps, "Grapheme_Cluster_Break=#{current}")
ages << current
cps = []
elsif /^([0-9a-fA-F]+)(?:\.\.([0-9a-fA-F]+))?\s*;\s*(\w+)/ =~ line
current = $3
$2 ? cps.concat(($1.to_i(16)..$2.to_i(16)).to_a) : cps.push($1.to_i(16))
end
@ -209,7 +228,6 @@ end
def parse_block(data)
current = nil
last_constname = nil
cps = []
blocks = []
data_foreach('Blocks.txt') do |line|
@ -269,6 +287,10 @@ def constantize_agename(name)
"Age_#{name.sub(/\./, '_')}"
end
def constantize_Grapheme_Cluster_Break(name)
"Grapheme_Cluster_Break_#{name}"
end
def constantize_blockname(name)
"In_#{name.gsub(/\W/, '_')}"
end
@ -381,6 +403,7 @@ end
output.ifdef :USE_UNICODE_AGE_PROPERTIES
ages = parse_age(data)
output.endif :USE_UNICODE_AGE_PROPERTIES
graphemeBreaks = parse_GraphemeBreakProperty(data)
blocks = parse_block(data)
output.endif :USE_UNICODE_PROPERTIES
puts(<<'__HEREDOC')
@ -393,6 +416,7 @@ props.each{|name| puts" CR_#{name},"}
output.ifdef :USE_UNICODE_AGE_PROPERTIES
ages.each{|name| puts" CR_#{constantize_agename(name)},"}
output.endif :USE_UNICODE_AGE_PROPERTIES
graphemeBreaks.each{|name| puts" CR_#{constantize_Grapheme_Cluster_Break(name)},"}
blocks.each{|name|puts" CR_#{name},"}
output.endif :USE_UNICODE_PROPERTIES
@ -437,6 +461,12 @@ ages.each do |name|
puts "%-40s %3d" % [name + ',', i]
end
output.endif :USE_UNICODE_AGE_PROPERTIES
graphemeBreaks.each do |name|
i += 1
name = "graphemeclusterbreak=#{name.delete('_').downcase}"
name_to_index[name] = i
puts "%-40s %3d" % [name + ',', i]
end
blocks.each do |name|
i += 1
name = normalize_propname(name)