Skip to content

Commit

Permalink
* oniguruma.h: updated to Oniguruma 5.7.0.
Browse files Browse the repository at this point in the history
* regsyntax.c, unicode.c: new files along with Oniguruma 5.x.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed May 23, 2007
1 parent 2cdb1c3 commit 6ee2e54
Show file tree
Hide file tree
Showing 19 changed files with 13,885 additions and 5,503 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Wed May 23 10:31:53 2007 Yukihiro Matsumoto <matz@ruby-lang.org>

* oniguruma.h: updated to Oniguruma 5.7.0.

* regsyntax.c, unicode.c: new files along with Oniguruma 5.x.

Wed May 23 05:49:49 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>

* ext/extmk.rb, ext/purelib.rb, lib/mkmf.rb, runruby.rb: clear default
Expand Down
19 changes: 5 additions & 14 deletions ascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ascii.c - Oniguruma (regular expression library)
**********************************************************************/
/*-
* Copyright (c) 2002-2004 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
* Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -43,23 +43,14 @@ OnigEncodingType OnigEncodingASCII = {
"US-ASCII", /* name */
1, /* max byte length */
1, /* min byte length */
ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE,
{
(OnigCodePoint )'\\' /* esc */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar '.' */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anytime '*' */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* zero or one time '?' */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* one or more time '+' */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar anytime */
},
onigenc_is_mbc_newline_0x0a,
onigenc_single_byte_mbc_to_code,
onigenc_single_byte_code_to_mbclen,
onigenc_single_byte_code_to_mbc,
onigenc_ascii_mbc_to_normalize,
onigenc_ascii_is_mbc_ambiguous,
onigenc_ascii_get_all_pair_ambig_codes,
onigenc_nothing_get_all_comp_ambig_codes,
onigenc_ascii_mbc_case_fold,
onigenc_ascii_apply_all_case_fold,
onigenc_ascii_get_case_fold_codes_by_str,
onigenc_minimum_property_name_to_ctype,
ascii_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
Expand Down
3 changes: 3 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ OBJS = array.$(OBJEXT) \
string.$(OBJEXT) \
struct.$(OBJEXT) \
time.$(OBJEXT) \
unicode.$(OBJEXT) \
utf8.$(OBJEXT) \
util.$(OBJEXT) \
variable.$(OBJEXT) \
Expand Down Expand Up @@ -520,6 +521,8 @@ thread.$(OBJEXT): {$(VPATH)}thread.c {$(VPATH)}eval_intern.h \
{$(VPATH)}rubysig.h {$(VPATH)}st.h {$(VPATH)}dln.h
time.$(OBJEXT): {$(VPATH)}time.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
unicode.$(OBJEXT): {$(VPATH)}unicode.c {$(VPATH)}regenc.h \
{$(VPATH)}oniguruma.h config.h
utf8.$(OBJEXT): {$(VPATH)}utf8.c {$(VPATH)}regenc.h \
{$(VPATH)}oniguruma.h config.h
util.$(OBJEXT): {$(VPATH)}util.c {$(VPATH)}ruby.h config.h \
Expand Down
1 change: 1 addition & 0 deletions defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#define RUBY

#include <stdlib.h>
#ifdef __cplusplus
# ifndef HAVE_PROTOTYPES
# define HAVE_PROTOTYPES 1
Expand Down
186 changes: 121 additions & 65 deletions euc_jp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
euc_jp.c - Oniguruma (regular expression library)
**********************************************************************/
/*-
* Copyright (c) 2002-2005 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
* Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -27,7 +27,7 @@
* SUCH DAMAGE.
*/

#include "regenc.h"
#include "regint.h"

#define eucjp_islead(c) ((UChar )((c) - 0xa1) > 0xfe - 0xa1)

Expand All @@ -51,13 +51,13 @@ static const int EncLen_EUCJP[] = {
};

static int
eucjp_mbc_enc_len(const UChar* p)
mbc_enc_len(const UChar* p)
{
return EncLen_EUCJP[*p];
}

static OnigCodePoint
eucjp_mbc_to_code(const UChar* p, const UChar* end)
mbc_to_code(const UChar* p, const UChar* end)
{
int c, i, len;
OnigCodePoint n;
Expand All @@ -75,7 +75,7 @@ eucjp_mbc_to_code(const UChar* p, const UChar* end)
}

static int
eucjp_code_to_mbclen(OnigCodePoint code)
code_to_mbclen(OnigCodePoint code)
{
if (ONIGENC_IS_CODE_ASCII(code)) return 1;
else if ((code & 0xff0000) != 0) return 3;
Expand All @@ -85,7 +85,7 @@ eucjp_code_to_mbclen(OnigCodePoint code)

#if 0
static int
eucjp_code_to_mbc_first(OnigCodePoint code)
code_to_mbc_first(OnigCodePoint code)
{
int first;

Expand All @@ -103,7 +103,7 @@ eucjp_code_to_mbc_first(OnigCodePoint code)
#endif

static int
eucjp_code_to_mbc(OnigCodePoint code, UChar *buf)
code_to_mbc(OnigCodePoint code, UChar *buf)
{
UChar *p = buf;

Expand All @@ -119,59 +119,31 @@ eucjp_code_to_mbc(OnigCodePoint code, UChar *buf)
}

static int
eucjp_mbc_to_normalize(OnigAmbigType flag,
const UChar** pp, const UChar* end, UChar* lower)
mbc_case_fold(OnigCaseFoldType flag,
const UChar** pp, const UChar* end, UChar* lower)
{
int len;
const UChar* p = *pp;

if (ONIGENC_IS_MBC_ASCII(p)) {
if ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0) {
*lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
}
else {
*lower = *p;
}

*lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
(*pp)++;
return 1;
}
else {
int i;

len = enc_len(ONIG_ENCODING_EUC_JP, p);
if (lower != p) {
int i;
for (i = 0; i < len; i++) {
*lower++ = *p++;
}
for (i = 0; i < len; i++) {
*lower++ = *p++;
}
(*pp) += len;
return len; /* return byte length of converted char to lower */
}
}

static int
eucjp_is_mbc_ambiguous(OnigAmbigType flag, const UChar** pp, const UChar* end)
{
return onigenc_mbn_is_mbc_ambiguous(ONIG_ENCODING_EUC_JP, flag, pp, end);
}

static int
eucjp_is_code_ctype(OnigCodePoint code, unsigned int ctype)
{
if (code < 128)
return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
else {
if ((ctype & (ONIGENC_CTYPE_WORD |
ONIGENC_CTYPE_GRAPH | ONIGENC_CTYPE_PRINT)) != 0) {
return (eucjp_code_to_mbclen(code) > 1 ? TRUE : FALSE);
}
}

return FALSE;
}

static UChar*
eucjp_left_adjust_char_head(const UChar* start, const UChar* s)
left_adjust_char_head(const UChar* start, const UChar* s)
{
/* In this encoding
mb-trail bytes doesn't mix with single bytes.
Expand All @@ -190,7 +162,7 @@ eucjp_left_adjust_char_head(const UChar* start, const UChar* s)
}

static int
eucjp_is_allowed_reverse_match(const UChar* s, const UChar* end)
is_allowed_reverse_match(const UChar* s, const UChar* end)
{
const UChar c = *s;
if (c <= 0x7e || c == 0x8e || c == 0x8f)
Expand All @@ -199,30 +171,114 @@ eucjp_is_allowed_reverse_match(const UChar* s, const UChar* end)
return FALSE;
}


static int PropertyInited = 0;
static const OnigCodePoint** PropertyList;
static int PropertyListNum;
static int PropertyListSize;
static hash_table_type* PropertyNameTable;

static const OnigCodePoint CR_Hiragana[] = {
1,
0xa4a1, 0xa4f3
}; /* CR_Hiragana */

static const OnigCodePoint CR_Katakana[] = {
3,
0xa5a1, 0xa5f6,
0xaaa6, 0xaaaf,
0xaab1, 0xaadd
}; /* CR_Katakana */

static int
init_property_list(void)
{
int r;

PROPERTY_LIST_ADD_PROP("Hiragana", CR_Hiragana);
PROPERTY_LIST_ADD_PROP("Katakana", CR_Katakana);
PropertyInited = 1;

end:
return r;
}

static int
property_name_to_ctype(OnigEncoding enc, UChar* p, UChar* end)
{
int ctype;

PROPERTY_LIST_INIT_CHECK;

if (onig_st_lookup_strend(PropertyNameTable, p, end, (void*)&ctype) == 0) {
return onigenc_minimum_property_name_to_ctype(enc, p, end);
}

return ctype;
}

static int
is_code_ctype(OnigCodePoint code, unsigned int ctype)
{
if (ctype <= ONIGENC_MAX_STD_CTYPE) {
if (code < 128)
return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
else {
if (CTYPE_IS_WORD_GRAPH_PRINT(ctype)) {
return (code_to_mbclen(code) > 1 ? TRUE : FALSE);
}
}
}
else {
PROPERTY_LIST_INIT_CHECK;

ctype -= (ONIGENC_MAX_STD_CTYPE + 1);
if (ctype >= (unsigned int )PropertyListNum)
return ONIGENCERR_TYPE_BUG;

return onig_is_in_code_range((UChar* )PropertyList[ctype], code);
}

return FALSE;
}

static int
get_ctype_code_range(int ctype, OnigCodePoint* sb_out,
const OnigCodePoint* ranges[])
{
if (ctype <= ONIGENC_MAX_STD_CTYPE) {
return ONIG_NO_SUPPORT_CONFIG;
}
else {
*sb_out = 0x80;

PROPERTY_LIST_INIT_CHECK;

ctype -= (ONIGENC_MAX_STD_CTYPE + 1);
if (ctype >= PropertyListNum)
return ONIGENCERR_TYPE_BUG;

*ranges = PropertyList[ctype];
return 0;
}
}


OnigEncodingType OnigEncodingEUC_JP = {
eucjp_mbc_enc_len,
mbc_enc_len,
"EUC-JP", /* name */
3, /* max enc length */
1, /* min enc length */
ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE,
{
(OnigCodePoint )'\\' /* esc */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar '.' */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anytime '*' */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* zero or one time '?' */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* one or more time '+' */
, (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar anytime */
},
onigenc_is_mbc_newline_0x0a,
eucjp_mbc_to_code,
eucjp_code_to_mbclen,
eucjp_code_to_mbc,
eucjp_mbc_to_normalize,
eucjp_is_mbc_ambiguous,
onigenc_ascii_get_all_pair_ambig_codes,
onigenc_nothing_get_all_comp_ambig_codes,
eucjp_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
eucjp_left_adjust_char_head,
eucjp_is_allowed_reverse_match
mbc_to_code,
code_to_mbclen,
code_to_mbc,
mbc_case_fold,
onigenc_ascii_apply_all_case_fold,
onigenc_ascii_get_case_fold_codes_by_str,
property_name_to_ctype,
is_code_ctype,
get_ctype_code_range,
left_adjust_char_head,
is_allowed_reverse_match
};
Loading

0 comments on commit 6ee2e54

Please sign in to comment.