2004-03-05 18:31:51 +03:00
|
|
|
/**********************************************************************
|
2012-02-17 11:42:23 +04:00
|
|
|
regparse.c - Onigmo (Oniguruma-mod) (regular expression library)
|
2004-03-05 18:31:51 +03:00
|
|
|
**********************************************************************/
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
/*-
|
2010-03-02 00:54:59 +03:00
|
|
|
* Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
2016-12-10 20:47:04 +03:00
|
|
|
* Copyright (c) 2011-2016 K.Takata <kentkt AT csc DOT jp>
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#include "regparse.h"
|
2016-12-10 20:47:04 +03:00
|
|
|
#include <stdarg.h>
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
#define WARN_BUFSIZE 256
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#define CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS
|
|
|
|
|
|
|
|
|
2008-07-01 12:21:44 +04:00
|
|
|
const OnigSyntaxType OnigSyntaxRuby = {
|
2004-03-05 18:31:51 +03:00
|
|
|
(( SYN_GNU_REGEX_OP | ONIG_SYN_OP_QMARK_NON_GREEDY |
|
|
|
|
ONIG_SYN_OP_ESC_OCTAL3 | ONIG_SYN_OP_ESC_X_HEX2 |
|
|
|
|
ONIG_SYN_OP_ESC_X_BRACE_HEX8 | ONIG_SYN_OP_ESC_CONTROL_CHARS |
|
|
|
|
ONIG_SYN_OP_ESC_C_CONTROL )
|
|
|
|
& ~ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END )
|
|
|
|
, ( ONIG_SYN_OP2_QMARK_GROUP_EFFECT |
|
|
|
|
ONIG_SYN_OP2_OPTION_RUBY |
|
|
|
|
ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP | ONIG_SYN_OP2_ESC_K_NAMED_BACKREF |
|
|
|
|
ONIG_SYN_OP2_ESC_G_SUBEXP_CALL |
|
2007-05-23 05:32:08 +04:00
|
|
|
ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY |
|
|
|
|
ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT |
|
2004-03-05 18:31:51 +03:00
|
|
|
ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT |
|
|
|
|
ONIG_SYN_OP2_CCLASS_SET_OP | ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL |
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META | ONIG_SYN_OP2_ESC_V_VTAB |
|
2012-02-17 11:42:23 +04:00
|
|
|
ONIG_SYN_OP2_ESC_H_XDIGIT |
|
2016-12-10 20:47:04 +03:00
|
|
|
#ifndef RUBY
|
|
|
|
ONIG_SYN_OP2_ESC_U_HEX4 |
|
|
|
|
#endif
|
2012-02-17 11:42:23 +04:00
|
|
|
ONIG_SYN_OP2_ESC_CAPITAL_X_EXTENDED_GRAPHEME_CLUSTER |
|
|
|
|
ONIG_SYN_OP2_QMARK_LPAREN_CONDITION |
|
|
|
|
ONIG_SYN_OP2_ESC_CAPITAL_R_LINEBREAK |
|
2017-02-11 18:08:33 +03:00
|
|
|
ONIG_SYN_OP2_ESC_CAPITAL_K_KEEP |
|
|
|
|
ONIG_SYN_OP2_QMARK_TILDE_ABSENT )
|
2009-02-22 17:23:33 +03:00
|
|
|
, ( SYN_GNU_REGEX_BV |
|
2004-03-05 18:31:51 +03:00
|
|
|
ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV |
|
|
|
|
ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND |
|
|
|
|
ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP |
|
|
|
|
ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME |
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY |
|
2004-03-05 18:31:51 +03:00
|
|
|
ONIG_SYN_WARN_CC_OP_NOT_ESCAPED |
|
2009-08-04 08:14:38 +04:00
|
|
|
ONIG_SYN_WARN_CC_DUP |
|
2004-03-05 18:31:51 +03:00
|
|
|
ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT )
|
2012-02-17 11:42:23 +04:00
|
|
|
, ( ONIG_OPTION_ASCII_RANGE | ONIG_OPTION_POSIX_BRACKET_ALL_RANGE |
|
|
|
|
ONIG_OPTION_WORD_BOUND_ALL_RANGE )
|
2007-05-23 05:32:08 +04:00
|
|
|
,
|
|
|
|
{
|
|
|
|
(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 */
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
};
|
|
|
|
|
2008-07-01 12:21:44 +04:00
|
|
|
const OnigSyntaxType* OnigDefaultSyntax = ONIG_SYNTAX_RUBY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
extern void onig_null_warn(const char* s ARG_UNUSED) { }
|
2006-02-04 15:31:19 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef DEFAULT_WARN_FUNCTION
|
|
|
|
static OnigWarnFunc onig_warn = (OnigWarnFunc )DEFAULT_WARN_FUNCTION;
|
|
|
|
#else
|
|
|
|
static OnigWarnFunc onig_warn = onig_null_warn;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEFAULT_VERB_WARN_FUNCTION
|
|
|
|
static OnigWarnFunc onig_verb_warn = (OnigWarnFunc )DEFAULT_VERB_WARN_FUNCTION;
|
|
|
|
#else
|
|
|
|
static OnigWarnFunc onig_verb_warn = onig_null_warn;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern void onig_set_warn_func(OnigWarnFunc f)
|
|
|
|
{
|
|
|
|
onig_warn = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void onig_set_verb_warn_func(OnigWarnFunc f)
|
|
|
|
{
|
|
|
|
onig_verb_warn = f;
|
|
|
|
}
|
|
|
|
|
2018-10-15 15:31:22 +03:00
|
|
|
static void CC_DUP_WARN(ScanEnv *env, OnigCodePoint from, OnigCodePoint to);
|
2009-08-04 08:14:38 +04:00
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
|
|
|
|
static unsigned int ParseDepthLimit = DEFAULT_PARSE_DEPTH_LIMIT;
|
|
|
|
|
|
|
|
extern unsigned int
|
|
|
|
onig_get_parse_depth_limit(void)
|
|
|
|
{
|
|
|
|
return ParseDepthLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onig_set_parse_depth_limit(unsigned int depth)
|
|
|
|
{
|
|
|
|
if (depth == 0)
|
|
|
|
ParseDepthLimit = DEFAULT_PARSE_DEPTH_LIMIT;
|
|
|
|
else
|
|
|
|
ParseDepthLimit = depth;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static void
|
|
|
|
bbuf_free(BBuf* bbuf)
|
|
|
|
{
|
|
|
|
if (IS_NOT_NULL(bbuf)) {
|
|
|
|
if (IS_NOT_NULL(bbuf->p)) xfree(bbuf->p);
|
|
|
|
xfree(bbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bbuf_clone(BBuf** rto, BBuf* from)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
BBuf *to;
|
|
|
|
|
|
|
|
*rto = to = (BBuf* )xmalloc(sizeof(BBuf));
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(to);
|
2004-03-05 18:31:51 +03:00
|
|
|
r = BBUF_INIT(to, from->alloc);
|
|
|
|
if (r != 0) return r;
|
|
|
|
to->used = from->used;
|
|
|
|
xmemcpy(to->p, from->p, from->used);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#define BACKREF_REL_TO_ABS(rel_no, env) \
|
|
|
|
((env)->num_mem + 1 + (rel_no))
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#define ONOFF(v,f,negative) (negative) ? ((v) &= ~(f)) : ((v) |= (f))
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#define MBCODE_START_POS(enc) \
|
|
|
|
(OnigCodePoint )(ONIGENC_MBC_MINLEN(enc) > 1 ? 0 : 0x80)
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#define SET_ALL_MULTI_BYTE_RANGE(enc, pbuf) \
|
2012-02-17 11:42:23 +04:00
|
|
|
add_code_range_to_buf(pbuf, env, MBCODE_START_POS(enc), ONIG_LAST_CODE_POINT)
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
|
|
|
#define ADD_ALL_MULTI_BYTE_RANGE(enc, mbuf) do {\
|
|
|
|
if (! ONIGENC_IS_SINGLEBYTE(enc)) {\
|
|
|
|
r = SET_ALL_MULTI_BYTE_RANGE(enc, &(mbuf));\
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r) return r;\
|
|
|
|
}\
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2009-08-04 08:14:38 +04:00
|
|
|
#define BITSET_SET_BIT_CHKDUP(bs, pos) do { \
|
2018-10-15 15:31:22 +03:00
|
|
|
if (BITSET_AT(bs, pos)) CC_DUP_WARN(env, pos, pos); \
|
2009-08-04 08:14:38 +04:00
|
|
|
BS_ROOM(bs, pos) |= BS_BIT(pos); \
|
|
|
|
} while (0)
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#define BITSET_IS_EMPTY(bs,empty) do {\
|
|
|
|
int i;\
|
|
|
|
empty = 1;\
|
2013-03-01 20:36:37 +04:00
|
|
|
for (i = 0; i < BITSET_SIZE; i++) {\
|
2004-03-05 18:31:51 +03:00
|
|
|
if ((bs)[i] != 0) {\
|
|
|
|
empty = 0; break;\
|
|
|
|
}\
|
|
|
|
}\
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void
|
2009-08-04 08:14:38 +04:00
|
|
|
bitset_set_range(ScanEnv *env, BitSetRef bs, int from, int to)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = from; i <= to && i < SINGLE_BYTE_SIZE; i++) {
|
2009-08-04 08:14:38 +04:00
|
|
|
BITSET_SET_BIT_CHKDUP(bs, i);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static void
|
|
|
|
bitset_set_all(BitSetRef bs)
|
|
|
|
{
|
|
|
|
int i;
|
2007-05-23 05:32:08 +04:00
|
|
|
for (i = 0; i < BITSET_SIZE; i++) { bs[i] = ~((Bits )0); }
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
bitset_invert(BitSetRef bs)
|
|
|
|
{
|
|
|
|
int i;
|
2013-03-01 20:36:37 +04:00
|
|
|
for (i = 0; i < BITSET_SIZE; i++) { bs[i] = ~(bs[i]); }
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bitset_invert_to(BitSetRef from, BitSetRef to)
|
|
|
|
{
|
|
|
|
int i;
|
2013-03-01 20:36:37 +04:00
|
|
|
for (i = 0; i < BITSET_SIZE; i++) { to[i] = ~(from[i]); }
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bitset_and(BitSetRef dest, BitSetRef bs)
|
|
|
|
{
|
|
|
|
int i;
|
2013-03-01 20:36:37 +04:00
|
|
|
for (i = 0; i < BITSET_SIZE; i++) { dest[i] &= bs[i]; }
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bitset_or(BitSetRef dest, BitSetRef bs)
|
|
|
|
{
|
|
|
|
int i;
|
2013-03-01 20:36:37 +04:00
|
|
|
for (i = 0; i < BITSET_SIZE; i++) { dest[i] |= bs[i]; }
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bitset_copy(BitSetRef dest, BitSetRef bs)
|
|
|
|
{
|
|
|
|
int i;
|
2013-03-01 20:36:37 +04:00
|
|
|
for (i = 0; i < BITSET_SIZE; i++) { dest[i] = bs[i]; }
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
#if defined(USE_NAMED_GROUP) && !defined(USE_ST_LIBRARY)
|
2004-03-05 18:31:51 +03:00
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_strncmp(const UChar* s1, const UChar* s2, int n)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
while (n-- > 0) {
|
|
|
|
x = *s2++ - *s1++;
|
|
|
|
if (x) return x;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
extern void
|
|
|
|
onig_strcpy(UChar* dest, const UChar* src, const UChar* end)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2009-06-30 06:08:54 +04:00
|
|
|
ptrdiff_t len = end - src;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (len > 0) {
|
|
|
|
xmemcpy(dest, src, len);
|
|
|
|
dest[len] = (UChar )0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_NAMED_GROUP
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
static UChar*
|
|
|
|
strdup_with_null(OnigEncoding enc, UChar* s, UChar* end)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2009-06-30 06:08:54 +04:00
|
|
|
ptrdiff_t slen;
|
|
|
|
int term_len, i;
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
UChar *r;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
slen = end - s;
|
|
|
|
term_len = ONIGENC_MBC_MINLEN(enc);
|
|
|
|
|
|
|
|
r = (UChar* )xmalloc(slen + term_len);
|
|
|
|
CHECK_NULL_RETURN(r);
|
|
|
|
xmemcpy(r, s, slen);
|
|
|
|
|
|
|
|
for (i = 0; i < term_len; i++)
|
|
|
|
r[slen + i] = (UChar )0;
|
|
|
|
|
|
|
|
return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
#endif
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
/* scan pattern methods */
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#define PEND_VALUE 0
|
|
|
|
|
2011-12-05 14:12:02 +04:00
|
|
|
#ifdef __GNUC__
|
2012-06-14 00:46:11 +04:00
|
|
|
/* get rid of Wunused-but-set-variable and Wuninitialized */
|
2016-12-10 20:47:04 +03:00
|
|
|
# define PFETCH_READY UChar* pfetch_prev = NULL; (void)pfetch_prev
|
2011-12-05 14:08:07 +04:00
|
|
|
#else
|
2016-12-10 20:47:04 +03:00
|
|
|
# define PFETCH_READY UChar* pfetch_prev
|
2011-12-05 14:08:07 +04:00
|
|
|
#endif
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#define PEND (p < end ? 0 : 1)
|
|
|
|
#define PUNFETCH p = pfetch_prev
|
|
|
|
#define PINC do { \
|
|
|
|
pfetch_prev = p; \
|
2008-05-19 12:25:03 +04:00
|
|
|
p += enclen(enc, p, end); \
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
} while (0)
|
|
|
|
#define PFETCH(c) do { \
|
2008-05-19 12:25:03 +04:00
|
|
|
c = ((enc->max_enc_len == 1) ? *p : ONIGENC_MBC_TO_CODE(enc, p, end)); \
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
pfetch_prev = p; \
|
2008-05-19 12:25:03 +04:00
|
|
|
p += enclen(enc, p, end); \
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
} while (0)
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2014-07-16 07:27:25 +04:00
|
|
|
#define PINC_S do { \
|
|
|
|
p += enclen(enc, p, end); \
|
|
|
|
} while (0)
|
|
|
|
#define PFETCH_S(c) do { \
|
|
|
|
c = ((enc->max_enc_len == 1) ? *p : ONIGENC_MBC_TO_CODE(enc, p, end)); \
|
|
|
|
p += enclen(enc, p, end); \
|
|
|
|
} while (0)
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#define PPEEK (p < end ? ONIGENC_MBC_TO_CODE(enc, p, end) : PEND_VALUE)
|
|
|
|
#define PPEEK_IS(c) (PPEEK == (OnigCodePoint )c)
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static UChar*
|
2007-05-23 05:32:08 +04:00
|
|
|
strcat_capa(UChar* dest, UChar* dest_end, const UChar* src, const UChar* src_end,
|
2011-01-31 06:44:57 +03:00
|
|
|
size_t capa)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
UChar* r;
|
|
|
|
|
|
|
|
if (dest)
|
|
|
|
r = (UChar* )xrealloc(dest, capa + 1);
|
|
|
|
else
|
|
|
|
r = (UChar* )xmalloc(capa + 1);
|
|
|
|
|
|
|
|
CHECK_NULL_RETURN(r);
|
2007-05-23 05:32:08 +04:00
|
|
|
onig_strcpy(r + (dest_end - dest), src, src_end);
|
2004-03-05 18:31:51 +03:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dest on static area */
|
|
|
|
static UChar*
|
|
|
|
strcat_capa_from_static(UChar* dest, UChar* dest_end,
|
2011-01-31 06:44:57 +03:00
|
|
|
const UChar* src, const UChar* src_end, size_t capa)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
UChar* r;
|
|
|
|
|
|
|
|
r = (UChar* )xmalloc(capa + 1);
|
|
|
|
CHECK_NULL_RETURN(r);
|
2007-05-23 05:32:08 +04:00
|
|
|
onig_strcpy(r, dest, dest_end);
|
|
|
|
onig_strcpy(r + (dest_end - dest), src, src_end);
|
2004-03-05 18:31:51 +03:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
#ifdef USE_ST_LIBRARY
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# ifdef RUBY
|
|
|
|
# include "ruby/st.h"
|
|
|
|
# else
|
|
|
|
# include "st.h"
|
|
|
|
# endif
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
typedef struct {
|
2009-09-22 11:26:22 +04:00
|
|
|
const UChar* s;
|
|
|
|
const UChar* end;
|
2008-01-03 18:55:04 +03:00
|
|
|
} st_str_end_key;
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
static int
|
2009-09-22 11:26:22 +04:00
|
|
|
str_end_cmp(st_data_t xp, st_data_t yp)
|
2007-07-23 13:39:30 +04:00
|
|
|
{
|
2009-09-22 11:26:22 +04:00
|
|
|
const st_str_end_key *x, *y;
|
|
|
|
const UChar *p, *q;
|
2007-07-23 13:39:30 +04:00
|
|
|
int c;
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
|
2009-09-22 11:26:22 +04:00
|
|
|
x = (const st_str_end_key *)xp;
|
|
|
|
y = (const st_str_end_key *)yp;
|
2007-07-23 13:39:30 +04:00
|
|
|
if ((x->end - x->s) != (y->end - y->s))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
p = x->s;
|
|
|
|
q = y->s;
|
|
|
|
while (p < x->end) {
|
|
|
|
c = (int )*p - (int )*q;
|
|
|
|
if (c != 0) return c;
|
|
|
|
|
|
|
|
p++; q++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-08 17:10:04 +04:00
|
|
|
static st_index_t
|
2009-09-22 11:26:22 +04:00
|
|
|
str_end_hash(st_data_t xp)
|
2007-07-23 13:39:30 +04:00
|
|
|
{
|
2009-09-22 11:26:22 +04:00
|
|
|
const st_str_end_key *x = (const st_str_end_key *)xp;
|
|
|
|
const UChar *p;
|
|
|
|
st_index_t val = 0;
|
2007-07-23 13:39:30 +04:00
|
|
|
|
|
|
|
p = x->s;
|
|
|
|
while (p < x->end) {
|
|
|
|
val = val * 997 + (int )*p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val + (val >> 5);
|
|
|
|
}
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
extern hash_table_type*
|
2009-09-22 11:26:22 +04:00
|
|
|
onig_st_init_strend_table_with_size(st_index_t size)
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
{
|
2008-07-01 12:21:44 +04:00
|
|
|
static const struct st_hash_type hashType = {
|
2007-07-23 13:39:30 +04:00
|
|
|
str_end_cmp,
|
|
|
|
str_end_hash,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (hash_table_type* )
|
|
|
|
onig_st_init_table_with_size(&hashType, size);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
extern int
|
|
|
|
onig_st_lookup_strend(hash_table_type* table, const UChar* str_key,
|
|
|
|
const UChar* end_key, hash_data_type *value)
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
{
|
2008-01-03 18:55:04 +03:00
|
|
|
st_str_end_key key;
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
key.s = (UChar* )str_key;
|
|
|
|
key.end = (UChar* )end_key;
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
return onig_st_lookup(table, (st_data_t )(&key), value);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
extern int
|
|
|
|
onig_st_insert_strend(hash_table_type* table, const UChar* str_key,
|
|
|
|
const UChar* end_key, hash_data_type value)
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
{
|
2008-01-03 18:55:04 +03:00
|
|
|
st_str_end_key* key;
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
int result;
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
key = (st_str_end_key* )xmalloc(sizeof(st_str_end_key));
|
2007-07-23 13:39:30 +04:00
|
|
|
key->s = (UChar* )str_key;
|
|
|
|
key->end = (UChar* )end_key;
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
result = onig_st_insert(table, (st_data_t )key, value);
|
|
|
|
if (result) {
|
|
|
|
xfree(key);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#endif /* USE_ST_LIBRARY */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# define INIT_NAME_BACKREFS_ALLOC_NUM 8
|
2008-01-03 18:55:04 +03:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
UChar* name;
|
2009-06-30 06:08:54 +04:00
|
|
|
size_t name_len; /* byte length */
|
2008-01-03 18:55:04 +03:00
|
|
|
int back_num; /* number of backrefs */
|
|
|
|
int back_alloc;
|
|
|
|
int back_ref1;
|
|
|
|
int* back_refs;
|
|
|
|
} NameEntry;
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# ifdef USE_ST_LIBRARY
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
typedef st_table NameTable;
|
|
|
|
typedef st_data_t HashDataType; /* 1.6 st.h doesn't define st_data_t type */
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# ifdef ONIG_DEBUG
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
|
|
|
i_print_name_entry(UChar* key, NameEntry* e, void* arg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FILE* fp = (FILE* )arg;
|
|
|
|
|
|
|
|
fprintf(fp, "%s: ", e->name);
|
|
|
|
if (e->back_num == 0)
|
|
|
|
fputs("-", fp);
|
|
|
|
else if (e->back_num == 1)
|
|
|
|
fprintf(fp, "%d", e->back_ref1);
|
|
|
|
else {
|
|
|
|
for (i = 0; i < e->back_num; i++) {
|
|
|
|
if (i > 0) fprintf(fp, ", ");
|
|
|
|
fprintf(fp, "%d", e->back_refs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputs("\n", fp);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onig_print_names(FILE* fp, regex_t* reg)
|
|
|
|
{
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(t)) {
|
|
|
|
fprintf(fp, "name table\n");
|
2019-08-26 10:06:40 +03:00
|
|
|
onig_st_foreach(t, (st_foreach_callback_func *)i_print_name_entry, (HashDataType )fp);
|
2004-03-05 18:31:51 +03:00
|
|
|
fputs("\n", fp);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
# endif /* ONIG_DEBUG */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static int
|
2008-01-03 18:55:04 +03:00
|
|
|
i_free_name_entry(UChar* key, NameEntry* e, void* arg ARG_UNUSED)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
xfree(e->name);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NOT_NULL(e->back_refs)) xfree(e->back_refs);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
xfree(key);
|
|
|
|
xfree(e);
|
2004-03-05 18:31:51 +03:00
|
|
|
return ST_DELETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
names_clear(regex_t* reg)
|
|
|
|
{
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(t)) {
|
2019-08-26 10:06:40 +03:00
|
|
|
onig_st_foreach(t, (st_foreach_callback_func *)i_free_name_entry, 0);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onig_names_free(regex_t* reg)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
NameTable* t;
|
|
|
|
|
|
|
|
r = names_clear(reg);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
t = (NameTable* )reg->name_table;
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
if (IS_NOT_NULL(t)) onig_st_free_table(t);
|
2004-03-05 18:31:51 +03:00
|
|
|
reg->name_table = (void* )NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NameEntry*
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
name_find(regex_t* reg, const UChar* name, const UChar* name_end)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
NameEntry* e;
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
e = (NameEntry* )NULL;
|
|
|
|
if (IS_NOT_NULL(t)) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
onig_st_lookup_strend(t, name, name_end, (HashDataType* )((void* )(&e)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
int (*func)(const UChar*, const UChar*,int,int*,regex_t*,void*);
|
2004-03-05 18:31:51 +03:00
|
|
|
regex_t* reg;
|
|
|
|
void* arg;
|
|
|
|
int ret;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigEncoding enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
} INamesArg;
|
|
|
|
|
|
|
|
static int
|
2008-01-03 18:55:04 +03:00
|
|
|
i_names(UChar* key ARG_UNUSED, NameEntry* e, INamesArg* arg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int r = (*(arg->func))(e->name,
|
2016-12-10 20:47:04 +03:00
|
|
|
e->name + e->name_len,
|
|
|
|
e->back_num,
|
2004-03-05 18:31:51 +03:00
|
|
|
(e->back_num > 1 ? e->back_refs : &(e->back_ref1)),
|
|
|
|
arg->reg, arg->arg);
|
|
|
|
if (r != 0) {
|
|
|
|
arg->ret = r;
|
|
|
|
return ST_STOP;
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onig_foreach_name(regex_t* reg,
|
2007-05-23 05:32:08 +04:00
|
|
|
int (*func)(const UChar*, const UChar*,int,int*,regex_t*,void*), void* arg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
INamesArg narg;
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
narg.ret = 0;
|
|
|
|
if (IS_NOT_NULL(t)) {
|
|
|
|
narg.func = func;
|
|
|
|
narg.reg = reg;
|
|
|
|
narg.arg = arg;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
narg.enc = reg->enc; /* should be pattern encoding. */
|
2019-08-26 10:06:40 +03:00
|
|
|
onig_st_foreach(t, (st_foreach_callback_func *)i_names, (HashDataType )&narg);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
return narg.ret;
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
static int
|
2008-01-03 18:55:04 +03:00
|
|
|
i_renumber_name(UChar* key ARG_UNUSED, NameEntry* e, GroupNumRemap* map)
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (e->back_num > 1) {
|
|
|
|
for (i = 0; i < e->back_num; i++) {
|
|
|
|
e->back_refs[i] = map[e->back_refs[i]].new_val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (e->back_num == 1) {
|
|
|
|
e->back_ref1 = map[e->back_ref1].new_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onig_renumber_name_table(regex_t* reg, GroupNumRemap* map)
|
|
|
|
{
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(t)) {
|
2019-08-26 10:06:40 +03:00
|
|
|
onig_st_foreach(t, (st_foreach_callback_func *)i_renumber_name, (HashDataType )map);
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
extern int
|
2016-12-10 20:47:04 +03:00
|
|
|
onig_number_of_names(const regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(t))
|
2013-03-01 20:36:37 +04:00
|
|
|
return (int )t->num_entries;
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# else /* USE_ST_LIBRARY */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# define INIT_NAMES_ALLOC_NUM 8
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
NameEntry* e;
|
|
|
|
int num;
|
|
|
|
int alloc;
|
|
|
|
} NameTable;
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# ifdef ONIG_DEBUG
|
2004-03-05 18:31:51 +03:00
|
|
|
extern int
|
|
|
|
onig_print_names(FILE* fp, regex_t* reg)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
NameEntry* e;
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(t) && t->num > 0) {
|
|
|
|
fprintf(fp, "name table\n");
|
|
|
|
for (i = 0; i < t->num; i++) {
|
|
|
|
e = &(t->e[i]);
|
|
|
|
fprintf(fp, "%s: ", e->name);
|
|
|
|
if (e->back_num == 0) {
|
|
|
|
fputs("-", fp);
|
|
|
|
}
|
|
|
|
else if (e->back_num == 1) {
|
|
|
|
fprintf(fp, "%d", e->back_ref1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (j = 0; j < e->back_num; j++) {
|
|
|
|
if (j > 0) fprintf(fp, ", ");
|
|
|
|
fprintf(fp, "%d", e->back_refs[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputs("\n", fp);
|
|
|
|
}
|
|
|
|
fputs("\n", fp);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
# endif
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
names_clear(regex_t* reg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
NameEntry* e;
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(t)) {
|
|
|
|
for (i = 0; i < t->num; i++) {
|
|
|
|
e = &(t->e[i]);
|
|
|
|
if (IS_NOT_NULL(e->name)) {
|
|
|
|
xfree(e->name);
|
|
|
|
e->name = NULL;
|
|
|
|
e->name_len = 0;
|
|
|
|
e->back_num = 0;
|
|
|
|
e->back_alloc = 0;
|
|
|
|
if (IS_NOT_NULL(e->back_refs)) xfree(e->back_refs);
|
|
|
|
e->back_refs = (int* )NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (IS_NOT_NULL(t->e)) {
|
|
|
|
xfree(t->e);
|
|
|
|
t->e = NULL;
|
|
|
|
}
|
|
|
|
t->num = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onig_names_free(regex_t* reg)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
NameTable* t;
|
|
|
|
|
|
|
|
r = names_clear(reg);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
t = (NameTable* )reg->name_table;
|
|
|
|
if (IS_NOT_NULL(t)) xfree(t);
|
|
|
|
reg->name_table = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NameEntry*
|
2012-02-17 11:42:23 +04:00
|
|
|
name_find(regex_t* reg, const UChar* name, const UChar* name_end)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
NameEntry* e;
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(t)) {
|
|
|
|
len = name_end - name;
|
|
|
|
for (i = 0; i < t->num; i++) {
|
|
|
|
e = &(t->e[i]);
|
|
|
|
if (len == e->name_len && onig_strncmp(name, e->name, len) == 0)
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (NameEntry* )NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onig_foreach_name(regex_t* reg,
|
2007-05-23 05:32:08 +04:00
|
|
|
int (*func)(const UChar*, const UChar*,int,int*,regex_t*,void*), void* arg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
NameEntry* e;
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(t)) {
|
|
|
|
for (i = 0; i < t->num; i++) {
|
|
|
|
e = &(t->e[i]);
|
|
|
|
r = (*func)(e->name, e->name + e->name_len, e->back_num,
|
|
|
|
(e->back_num > 1 ? e->back_refs : &(e->back_ref1)),
|
|
|
|
reg, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
2016-12-10 20:47:04 +03:00
|
|
|
onig_number_of_names(const regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(t))
|
|
|
|
return t->num;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# endif /* else USE_ST_LIBRARY */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
name_add(regex_t* reg, UChar* name, UChar* name_end, int backref, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int alloc;
|
|
|
|
NameEntry* e;
|
|
|
|
NameTable* t = (NameTable* )reg->name_table;
|
|
|
|
|
|
|
|
if (name_end - name <= 0)
|
|
|
|
return ONIGERR_EMPTY_GROUP_NAME;
|
|
|
|
|
|
|
|
e = name_find(reg, name, name_end);
|
|
|
|
if (IS_NULL(e)) {
|
2016-12-10 20:47:04 +03:00
|
|
|
# ifdef USE_ST_LIBRARY
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NULL(t)) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
t = onig_st_init_strend_table_with_size(5);
|
|
|
|
reg->name_table = (void* )t;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
e = (NameEntry* )xmalloc(sizeof(NameEntry));
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(e);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
e->name = strdup_with_null(reg->enc, name, name_end);
|
2008-07-30 16:30:28 +04:00
|
|
|
if (IS_NULL(e->name)) {
|
|
|
|
xfree(e);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
onig_st_insert_strend(t, e->name, (e->name + (name_end - name)),
|
|
|
|
(HashDataType )e);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
e->name_len = name_end - name;
|
|
|
|
e->back_num = 0;
|
|
|
|
e->back_alloc = 0;
|
|
|
|
e->back_refs = (int* )NULL;
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# else
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (IS_NULL(t)) {
|
|
|
|
alloc = INIT_NAMES_ALLOC_NUM;
|
|
|
|
t = (NameTable* )xmalloc(sizeof(NameTable));
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(t);
|
2004-03-05 18:31:51 +03:00
|
|
|
t->e = NULL;
|
|
|
|
t->alloc = 0;
|
|
|
|
t->num = 0;
|
|
|
|
|
|
|
|
t->e = (NameEntry* )xmalloc(sizeof(NameEntry) * alloc);
|
|
|
|
if (IS_NULL(t->e)) {
|
|
|
|
xfree(t);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
|
|
|
t->alloc = alloc;
|
|
|
|
reg->name_table = t;
|
|
|
|
goto clear;
|
|
|
|
}
|
|
|
|
else if (t->num == t->alloc) {
|
|
|
|
int i;
|
2012-02-17 11:42:23 +04:00
|
|
|
NameEntry* p;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
alloc = t->alloc * 2;
|
2012-02-17 11:42:23 +04:00
|
|
|
p = (NameEntry* )xrealloc(t->e, sizeof(NameEntry) * alloc);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(p);
|
|
|
|
t->e = p;
|
2004-03-05 18:31:51 +03:00
|
|
|
t->alloc = alloc;
|
|
|
|
|
|
|
|
clear:
|
|
|
|
for (i = t->num; i < t->alloc; i++) {
|
|
|
|
t->e[i].name = NULL;
|
|
|
|
t->e[i].name_len = 0;
|
|
|
|
t->e[i].back_num = 0;
|
|
|
|
t->e[i].back_alloc = 0;
|
|
|
|
t->e[i].back_refs = (int* )NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e = &(t->e[t->num]);
|
|
|
|
t->num++;
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
e->name = strdup_with_null(reg->enc, name, name_end);
|
2010-03-02 00:54:59 +03:00
|
|
|
if (IS_NULL(e->name)) return ONIGERR_MEMORY;
|
2004-03-05 18:31:51 +03:00
|
|
|
e->name_len = name_end - name;
|
2016-12-10 20:47:04 +03:00
|
|
|
# endif
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (e->back_num >= 1 &&
|
|
|
|
! IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME)) {
|
|
|
|
onig_scan_env_set_error_string(env, ONIGERR_MULTIPLEX_DEFINED_NAME,
|
|
|
|
name, name_end);
|
|
|
|
return ONIGERR_MULTIPLEX_DEFINED_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
e->back_num++;
|
|
|
|
if (e->back_num == 1) {
|
|
|
|
e->back_ref1 = backref;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (e->back_num == 2) {
|
|
|
|
alloc = INIT_NAME_BACKREFS_ALLOC_NUM;
|
|
|
|
e->back_refs = (int* )xmalloc(sizeof(int) * alloc);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(e->back_refs);
|
2004-03-05 18:31:51 +03:00
|
|
|
e->back_alloc = alloc;
|
|
|
|
e->back_refs[0] = e->back_ref1;
|
|
|
|
e->back_refs[1] = backref;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (e->back_num > e->back_alloc) {
|
2012-02-17 11:42:23 +04:00
|
|
|
int* p;
|
2004-03-05 18:31:51 +03:00
|
|
|
alloc = e->back_alloc * 2;
|
2012-02-17 11:42:23 +04:00
|
|
|
p = (int* )xrealloc(e->back_refs, sizeof(int) * alloc);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(p);
|
|
|
|
e->back_refs = p;
|
2004-03-05 18:31:51 +03:00
|
|
|
e->back_alloc = alloc;
|
|
|
|
}
|
|
|
|
e->back_refs[e->back_num - 1] = backref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_name_to_group_numbers(regex_t* reg, const UChar* name,
|
|
|
|
const UChar* name_end, int** nums)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-05-23 05:32:08 +04:00
|
|
|
NameEntry* e = name_find(reg, name, name_end);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (IS_NULL(e)) return ONIGERR_UNDEFINED_NAME_REFERENCE;
|
|
|
|
|
|
|
|
switch (e->back_num) {
|
|
|
|
case 0:
|
2008-04-22 17:49:43 +04:00
|
|
|
*nums = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
*nums = &(e->back_ref1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*nums = e->back_refs;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return e->back_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_name_to_backref_number(regex_t* reg, const UChar* name,
|
2016-12-10 20:47:04 +03:00
|
|
|
const UChar* name_end, const OnigRegion *region)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, n, *nums;
|
|
|
|
|
|
|
|
n = onig_name_to_group_numbers(reg, name, name_end, &nums);
|
|
|
|
if (n < 0)
|
|
|
|
return n;
|
|
|
|
else if (n == 0)
|
|
|
|
return ONIGERR_PARSER_BUG;
|
|
|
|
else if (n == 1)
|
|
|
|
return nums[0];
|
|
|
|
else {
|
|
|
|
if (IS_NOT_NULL(region)) {
|
|
|
|
for (i = n - 1; i >= 0; i--) {
|
|
|
|
if (region->beg[nums[i]] != ONIG_REGION_NOTPOS)
|
|
|
|
return nums[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nums[n - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* USE_NAMED_GROUP */
|
|
|
|
|
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_name_to_group_numbers(regex_t* reg, const UChar* name,
|
|
|
|
const UChar* name_end, int** nums)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
return ONIG_NO_SUPPORT_CONFIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_name_to_backref_number(regex_t* reg, const UChar* name,
|
2016-12-10 20:47:04 +03:00
|
|
|
const UChar* name_end, const OnigRegion* region)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
return ONIG_NO_SUPPORT_CONFIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onig_foreach_name(regex_t* reg,
|
2007-05-23 05:32:08 +04:00
|
|
|
int (*func)(const UChar*, const UChar*,int,int*,regex_t*,void*), void* arg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
return ONIG_NO_SUPPORT_CONFIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
2016-12-10 20:47:04 +03:00
|
|
|
onig_number_of_names(const regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* else USE_NAMED_GROUP */
|
|
|
|
|
2006-03-23 15:08:08 +03:00
|
|
|
extern int
|
2016-12-10 20:47:04 +03:00
|
|
|
onig_noname_group_capture_is_active(const regex_t* reg)
|
2006-03-23 15:08:08 +03:00
|
|
|
{
|
|
|
|
if (ONIG_IS_OPTION_ON(reg->options, ONIG_OPTION_DONT_CAPTURE_GROUP))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
if (onig_number_of_names(reg) > 0 &&
|
|
|
|
IS_SYNTAX_BV(reg->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) &&
|
|
|
|
!ONIG_IS_OPTION_ON(reg->options, ONIG_OPTION_CAPTURE_GROUP)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
#define INIT_SCANENV_MEMNODES_ALLOC_SIZE 16
|
|
|
|
|
|
|
|
static void
|
|
|
|
scan_env_clear(ScanEnv* env)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
BIT_STATUS_CLEAR(env->capture_history);
|
|
|
|
BIT_STATUS_CLEAR(env->bt_mem_start);
|
|
|
|
BIT_STATUS_CLEAR(env->bt_mem_end);
|
|
|
|
BIT_STATUS_CLEAR(env->backrefed_mem);
|
2007-05-23 05:32:08 +04:00
|
|
|
env->error = (UChar* )NULL;
|
|
|
|
env->error_end = (UChar* )NULL;
|
|
|
|
env->num_call = 0;
|
|
|
|
env->num_mem = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_NAMED_GROUP
|
2007-05-23 05:32:08 +04:00
|
|
|
env->num_named = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
|
|
|
env->mem_alloc = 0;
|
|
|
|
env->mem_nodes_dynamic = (Node** )NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < SCANENV_MEMNODES_SIZE; i++)
|
|
|
|
env->mem_nodes_static[i] = NULL_NODE;
|
2006-08-27 16:58:22 +04:00
|
|
|
|
|
|
|
#ifdef USE_COMBINATION_EXPLOSION_CHECK
|
|
|
|
env->num_comb_exp_check = 0;
|
|
|
|
env->comb_exp_max_regnum = 0;
|
|
|
|
env->curr_max_regnum = 0;
|
|
|
|
env->has_recursion = 0;
|
|
|
|
#endif
|
2016-12-10 20:47:04 +03:00
|
|
|
env->parse_depth = 0;
|
2010-01-28 03:50:17 +03:00
|
|
|
env->warnings_flag = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
scan_env_add_mem_entry(ScanEnv* env)
|
|
|
|
{
|
|
|
|
int i, need, alloc;
|
|
|
|
Node** p;
|
|
|
|
|
|
|
|
need = env->num_mem + 1;
|
2014-07-16 07:27:25 +04:00
|
|
|
if (need > ONIG_MAX_CAPTURE_GROUP_NUM)
|
|
|
|
return ONIGERR_TOO_MANY_CAPTURE_GROUPS;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (need >= SCANENV_MEMNODES_SIZE) {
|
|
|
|
if (env->mem_alloc <= need) {
|
|
|
|
if (IS_NULL(env->mem_nodes_dynamic)) {
|
|
|
|
alloc = INIT_SCANENV_MEMNODES_ALLOC_SIZE;
|
|
|
|
p = (Node** )xmalloc(sizeof(Node*) * alloc);
|
2017-02-11 18:08:33 +03:00
|
|
|
CHECK_NULL_RETURN_MEMERR(p);
|
2004-03-05 18:31:51 +03:00
|
|
|
xmemcpy(p, env->mem_nodes_static,
|
|
|
|
sizeof(Node*) * SCANENV_MEMNODES_SIZE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
alloc = env->mem_alloc * 2;
|
|
|
|
p = (Node** )xrealloc(env->mem_nodes_dynamic, sizeof(Node*) * alloc);
|
2017-02-11 18:08:33 +03:00
|
|
|
CHECK_NULL_RETURN_MEMERR(p);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = env->num_mem + 1; i < alloc; i++)
|
|
|
|
p[i] = NULL_NODE;
|
|
|
|
|
|
|
|
env->mem_nodes_dynamic = p;
|
|
|
|
env->mem_alloc = alloc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
env->num_mem++;
|
|
|
|
return env->num_mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
scan_env_set_mem_node(ScanEnv* env, int num, Node* node)
|
|
|
|
{
|
|
|
|
if (env->num_mem >= num)
|
|
|
|
SCANENV_MEM_NODES(env)[num] = node;
|
|
|
|
else
|
|
|
|
return ONIGERR_PARSER_BUG;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern void
|
|
|
|
onig_node_free(Node* node)
|
|
|
|
{
|
2004-11-29 18:16:20 +03:00
|
|
|
start:
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NULL(node)) return ;
|
|
|
|
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
|
|
|
if (NSTR(node)->capa != 0 &&
|
|
|
|
IS_NOT_NULL(NSTR(node)->s) && NSTR(node)->s != NSTR(node)->buf) {
|
|
|
|
xfree(NSTR(node)->s);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
|
|
|
onig_node_free(NCAR(node));
|
2004-11-29 18:16:20 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
Node* next_node = NCDR(node);
|
2004-11-29 18:16:20 +03:00
|
|
|
|
2015-12-09 10:30:44 +03:00
|
|
|
xfree(node);
|
2004-11-29 18:16:20 +03:00
|
|
|
node = next_node;
|
|
|
|
goto start;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
CClassNode* cc = NCCLASS(node);
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
|
|
|
if (cc->mbuf)
|
2016-12-10 20:47:04 +03:00
|
|
|
bbuf_free(cc->mbuf);
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
if (NQTFR(node)->target)
|
|
|
|
onig_node_free(NQTFR(node)->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
|
|
|
if (NENCLOSE(node)->target)
|
|
|
|
onig_node_free(NENCLOSE(node)->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
|
|
|
if (IS_NOT_NULL(NBREF(node)->back_dynamic))
|
|
|
|
xfree(NBREF(node)->back_dynamic);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
|
|
|
if (NANCHOR(node)->target)
|
|
|
|
onig_node_free(NANCHOR(node)->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-09 10:30:44 +03:00
|
|
|
xfree(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
2007-03-19 06:58:57 +03:00
|
|
|
node_new(void)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* node;
|
|
|
|
|
2014-07-16 07:27:25 +04:00
|
|
|
node = (Node* )xmalloc(sizeof(Node));
|
|
|
|
/* xmemset(node, 0, sizeof(Node)); */
|
|
|
|
return node;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
initialize_cclass(CClassNode* cc)
|
|
|
|
{
|
|
|
|
BITSET_CLEAR(cc->bs);
|
2007-07-23 13:39:30 +04:00
|
|
|
/* cc->base.flags = 0; */
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
cc->flags = 0;
|
|
|
|
cc->mbuf = NULL;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
2007-03-19 06:58:57 +03:00
|
|
|
node_new_cclass(void)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_NTYPE(node, NT_CCLASS);
|
|
|
|
initialize_cclass(NCCLASS(node));
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
2012-02-17 11:42:23 +04:00
|
|
|
node_new_ctype(int type, int not, int ascii_range)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
|
|
|
|
SET_NTYPE(node, NT_CTYPE);
|
|
|
|
NCTYPE(node)->ctype = type;
|
|
|
|
NCTYPE(node)->not = not;
|
2012-02-17 11:42:23 +04:00
|
|
|
NCTYPE(node)->ascii_range = ascii_range;
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
2007-03-19 06:58:57 +03:00
|
|
|
node_new_anychar(void)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
|
|
|
|
SET_NTYPE(node, NT_CANY);
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
|
|
|
node_new_list(Node* left, Node* right)
|
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
|
|
|
|
SET_NTYPE(node, NT_LIST);
|
|
|
|
NCAR(node) = left;
|
|
|
|
NCDR(node) = right;
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
extern Node*
|
|
|
|
onig_node_new_list(Node* left, Node* right)
|
|
|
|
{
|
|
|
|
return node_new_list(left, right);
|
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
extern Node*
|
|
|
|
onig_node_list_add(Node* list, Node* x)
|
|
|
|
{
|
|
|
|
Node *n;
|
|
|
|
|
|
|
|
n = onig_node_new_list(x, NULL);
|
|
|
|
if (IS_NULL(n)) return NULL_NODE;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(list)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
while (IS_NOT_NULL(NCDR(list)))
|
|
|
|
list = NCDR(list);
|
2007-05-23 05:32:08 +04:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
NCDR(list) = n;
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern Node*
|
|
|
|
onig_node_new_alt(Node* left, Node* right)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
|
|
|
|
SET_NTYPE(node, NT_ALT);
|
|
|
|
NCAR(node) = left;
|
|
|
|
NCDR(node) = right;
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern Node*
|
|
|
|
onig_node_new_anchor(int type)
|
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
|
|
|
|
SET_NTYPE(node, NT_ANCHOR);
|
|
|
|
NANCHOR(node)->type = type;
|
|
|
|
NANCHOR(node)->target = NULL;
|
|
|
|
NANCHOR(node)->char_len = -1;
|
2012-02-17 11:42:23 +04:00
|
|
|
NANCHOR(node)->ascii_range = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
2006-08-05 17:54:40 +04:00
|
|
|
node_new_backref(int back_num, int* backrefs, int by_name,
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
int exist_level, int nest_level,
|
|
|
|
#endif
|
|
|
|
ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Node* node = node_new();
|
|
|
|
|
|
|
|
CHECK_NULL_RETURN(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
|
|
|
|
SET_NTYPE(node, NT_BREF);
|
|
|
|
NBREF(node)->state = 0;
|
|
|
|
NBREF(node)->back_num = back_num;
|
|
|
|
NBREF(node)->back_dynamic = (int* )NULL;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (by_name != 0)
|
2007-07-23 13:39:30 +04:00
|
|
|
NBREF(node)->state |= NST_NAME_REF;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
if (exist_level != 0) {
|
2007-07-23 13:39:30 +04:00
|
|
|
NBREF(node)->state |= NST_NEST_LEVEL;
|
|
|
|
NBREF(node)->nest_level = nest_level;
|
2006-08-05 17:54:40 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
for (i = 0; i < back_num; i++) {
|
|
|
|
if (backrefs[i] <= env->num_mem &&
|
|
|
|
IS_NULL(SCANENV_MEM_NODES(env)[backrefs[i]])) {
|
2007-07-23 13:39:30 +04:00
|
|
|
NBREF(node)->state |= NST_RECURSION; /* /...(\1).../ */
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (back_num <= NODE_BACKREFS_SIZE) {
|
|
|
|
for (i = 0; i < back_num; i++)
|
2007-07-23 13:39:30 +04:00
|
|
|
NBREF(node)->back_static[i] = backrefs[i];
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
int* p = (int* )xmalloc(sizeof(int) * back_num);
|
|
|
|
if (IS_NULL(p)) {
|
|
|
|
onig_node_free(node);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
NBREF(node)->back_dynamic = p;
|
2004-03-05 18:31:51 +03:00
|
|
|
for (i = 0; i < back_num; i++)
|
|
|
|
p[i] = backrefs[i];
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
static Node*
|
2008-01-03 18:55:04 +03:00
|
|
|
node_new_call(UChar* name, UChar* name_end, int gnum)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_NTYPE(node, NT_CALL);
|
2008-01-03 18:55:04 +03:00
|
|
|
NCALL(node)->state = 0;
|
|
|
|
NCALL(node)->target = NULL_NODE;
|
|
|
|
NCALL(node)->name = name;
|
|
|
|
NCALL(node)->name_end = name_end;
|
|
|
|
NCALL(node)->group_num = gnum; /* call by number if gnum != 0 */
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static Node*
|
2007-05-23 05:32:08 +04:00
|
|
|
node_new_quantifier(int lower, int upper, int by_number)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
|
|
|
|
SET_NTYPE(node, NT_QTFR);
|
|
|
|
NQTFR(node)->state = 0;
|
|
|
|
NQTFR(node)->target = NULL;
|
|
|
|
NQTFR(node)->lower = lower;
|
|
|
|
NQTFR(node)->upper = upper;
|
|
|
|
NQTFR(node)->greedy = 1;
|
|
|
|
NQTFR(node)->target_empty_info = NQ_TARGET_ISNOT_EMPTY;
|
|
|
|
NQTFR(node)->head_exact = NULL_NODE;
|
|
|
|
NQTFR(node)->next_head_exact = NULL_NODE;
|
2018-01-18 14:44:10 +03:00
|
|
|
NQTFR(node)->is_referred = 0;
|
2006-08-27 16:58:22 +04:00
|
|
|
if (by_number != 0)
|
2007-07-23 13:39:30 +04:00
|
|
|
NQTFR(node)->state |= NST_BY_NUMBER;
|
2006-08-27 16:58:22 +04:00
|
|
|
|
|
|
|
#ifdef USE_COMBINATION_EXPLOSION_CHECK
|
2007-07-23 13:39:30 +04:00
|
|
|
NQTFR(node)->comb_exp_check_num = 0;
|
2006-08-27 16:58:22 +04:00
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
2007-07-23 13:39:30 +04:00
|
|
|
node_new_enclose(int type)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
|
|
|
|
SET_NTYPE(node, NT_ENCLOSE);
|
|
|
|
NENCLOSE(node)->type = type;
|
|
|
|
NENCLOSE(node)->state = 0;
|
|
|
|
NENCLOSE(node)->regnum = 0;
|
|
|
|
NENCLOSE(node)->option = 0;
|
|
|
|
NENCLOSE(node)->target = NULL;
|
|
|
|
NENCLOSE(node)->call_addr = -1;
|
|
|
|
NENCLOSE(node)->opt_count = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern Node*
|
2007-07-23 13:39:30 +04:00
|
|
|
onig_node_new_enclose(int type)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
return node_new_enclose(type);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
2007-07-23 13:39:30 +04:00
|
|
|
node_new_enclose_memory(OnigOptionType option, int is_named)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
Node* node = node_new_enclose(ENCLOSE_MEMORY);
|
2004-03-05 18:31:51 +03:00
|
|
|
CHECK_NULL_RETURN(node);
|
|
|
|
if (is_named != 0)
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_ENCLOSE_STATUS(node, NST_NAMED_GROUP);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
NENCLOSE(node)->option = option;
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
|
|
|
node_new_option(OnigOptionType option)
|
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
Node* node = node_new_enclose(ENCLOSE_OPTION);
|
2004-03-05 18:31:51 +03:00
|
|
|
CHECK_NULL_RETURN(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
NENCLOSE(node)->option = option;
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_node_str_cat(Node* node, const UChar* s, const UChar* end)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2009-06-30 06:08:54 +04:00
|
|
|
ptrdiff_t addlen = end - s;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (addlen > 0) {
|
2009-06-30 06:08:54 +04:00
|
|
|
ptrdiff_t len = NSTR(node)->end - NSTR(node)->s;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NSTR(node)->capa > 0 || (len + addlen > NODE_STR_BUF_SIZE - 1)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* p;
|
2009-09-22 11:26:22 +04:00
|
|
|
ptrdiff_t capa = len + addlen + NODE_STR_MARGIN;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (capa <= NSTR(node)->capa) {
|
|
|
|
onig_strcpy(NSTR(node)->s + len, s, end);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NSTR(node)->s == NSTR(node)->buf)
|
|
|
|
p = strcat_capa_from_static(NSTR(node)->s, NSTR(node)->end,
|
2004-03-05 18:31:51 +03:00
|
|
|
s, end, capa);
|
|
|
|
else
|
2007-07-23 13:39:30 +04:00
|
|
|
p = strcat_capa(NSTR(node)->s, NSTR(node)->end, s, end, capa);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(p);
|
|
|
|
NSTR(node)->s = p;
|
2012-02-17 11:42:23 +04:00
|
|
|
NSTR(node)->capa = (int )capa;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-07-23 13:39:30 +04:00
|
|
|
onig_strcpy(NSTR(node)->s + len, s, end);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
NSTR(node)->end = NSTR(node)->s + len + addlen;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
extern int
|
|
|
|
onig_node_str_set(Node* node, const UChar* s, const UChar* end)
|
|
|
|
{
|
|
|
|
onig_node_str_clear(node);
|
|
|
|
return onig_node_str_cat(node, s, end);
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
|
|
|
node_str_cat_char(Node* node, UChar c)
|
|
|
|
{
|
|
|
|
UChar s[1];
|
|
|
|
|
|
|
|
s[0] = c;
|
|
|
|
return onig_node_str_cat(node, s, s + 1);
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
static int
|
|
|
|
node_str_cat_codepoint(Node* node, OnigEncoding enc, OnigCodePoint c)
|
|
|
|
{
|
|
|
|
UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
|
|
|
|
int num = ONIGENC_CODE_TO_MBC(enc, c, buf);
|
|
|
|
if (num < 0) return num;
|
|
|
|
return onig_node_str_cat(node, buf, buf + num);
|
|
|
|
}
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
#if 0
|
2004-03-05 18:31:51 +03:00
|
|
|
extern void
|
|
|
|
onig_node_conv_to_str_node(Node* node, int flag)
|
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_NTYPE(node, NT_STR);
|
|
|
|
NSTR(node)->flag = flag;
|
|
|
|
NSTR(node)->capa = 0;
|
|
|
|
NSTR(node)->s = NSTR(node)->buf;
|
|
|
|
NSTR(node)->end = NSTR(node)->buf;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
extern void
|
|
|
|
onig_node_str_clear(Node* node)
|
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NSTR(node)->capa != 0 &&
|
|
|
|
IS_NOT_NULL(NSTR(node)->s) && NSTR(node)->s != NSTR(node)->buf) {
|
|
|
|
xfree(NSTR(node)->s);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
NSTR(node)->capa = 0;
|
|
|
|
NSTR(node)->flag = 0;
|
|
|
|
NSTR(node)->s = NSTR(node)->buf;
|
|
|
|
NSTR(node)->end = NSTR(node)->buf;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static Node*
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
node_new_str(const UChar* s, const UChar* end)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* node = node_new();
|
|
|
|
CHECK_NULL_RETURN(node);
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_NTYPE(node, NT_STR);
|
|
|
|
NSTR(node)->capa = 0;
|
|
|
|
NSTR(node)->flag = 0;
|
|
|
|
NSTR(node)->s = NSTR(node)->buf;
|
|
|
|
NSTR(node)->end = NSTR(node)->buf;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (onig_node_str_cat(node, s, end)) {
|
|
|
|
onig_node_free(node);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
extern Node*
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_node_new_str(const UChar* s, const UChar* end)
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
{
|
|
|
|
return node_new_str(s, end);
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static Node*
|
|
|
|
node_new_str_raw(UChar* s, UChar* end)
|
|
|
|
{
|
|
|
|
Node* node = node_new_str(s, end);
|
2012-02-17 11:42:23 +04:00
|
|
|
if (IS_NOT_NULL(node))
|
|
|
|
NSTRING_SET_RAW(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
2007-03-19 06:58:57 +03:00
|
|
|
node_new_empty(void)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
return node_new_str(NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
|
|
|
node_new_str_raw_char(UChar c)
|
|
|
|
{
|
|
|
|
UChar p[1];
|
|
|
|
|
|
|
|
p[0] = c;
|
|
|
|
return node_new_str_raw(p, p + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
|
|
|
str_node_split_last_char(StrNode* sn, OnigEncoding enc)
|
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
const UChar *p;
|
2004-03-05 18:31:51 +03:00
|
|
|
Node* n = NULL_NODE;
|
|
|
|
|
|
|
|
if (sn->end > sn->s) {
|
2008-09-13 22:22:04 +04:00
|
|
|
p = onigenc_get_prev_char_head(enc, sn->s, sn->end, sn->end);
|
2013-04-13 15:30:35 +04:00
|
|
|
if (p && p > sn->s) { /* can be split. */
|
2004-03-05 18:31:51 +03:00
|
|
|
n = node_new_str(p, sn->end);
|
2012-02-17 11:42:23 +04:00
|
|
|
if (IS_NOT_NULL(n) && (sn->flag & NSTR_RAW) != 0)
|
2004-03-05 18:31:51 +03:00
|
|
|
NSTRING_SET_RAW(n);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
sn->end = (UChar* )p;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
str_node_can_be_split(StrNode* sn, OnigEncoding enc)
|
|
|
|
{
|
|
|
|
if (sn->end > sn->s) {
|
2008-01-03 18:55:04 +03:00
|
|
|
return ((enclen(enc, sn->s, sn->end) < sn->end - sn->s) ? 1 : 0);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
#ifdef USE_PAD_TO_SHORT_BYTE_CHAR
|
|
|
|
static int
|
|
|
|
node_str_head_pad(StrNode* sn, int num, UChar val)
|
|
|
|
{
|
|
|
|
UChar buf[NODE_STR_BUF_SIZE];
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
len = sn->end - sn->s;
|
|
|
|
onig_strcpy(buf, sn->s, sn->end);
|
|
|
|
onig_strcpy(&(sn->s[num]), buf, buf + len);
|
|
|
|
sn->end += num;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
sn->s[i] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_scan_unsigned_number(UChar** src, const UChar* end, OnigEncoding enc)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
unsigned int num, val;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint c;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* p = *src;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH_READY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
num = 0;
|
|
|
|
while (!PEND) {
|
|
|
|
PFETCH(c);
|
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c)) {
|
|
|
|
val = (unsigned int )DIGITVAL(c);
|
|
|
|
if ((INT_MAX_LIMIT - val) / 10UL < num)
|
|
|
|
return -1; /* overflow */
|
|
|
|
|
|
|
|
num = num * 10 + val;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PUNFETCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*src = p;
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-02-17 11:42:23 +04:00
|
|
|
scan_unsigned_hexadecimal_number(UChar** src, UChar* end, int minlen,
|
|
|
|
int maxlen, OnigEncoding enc)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint c;
|
2004-03-05 18:31:51 +03:00
|
|
|
unsigned int num, val;
|
2012-02-17 11:42:23 +04:00
|
|
|
int restlen;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* p = *src;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH_READY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
restlen = maxlen - minlen;
|
2004-03-05 18:31:51 +03:00
|
|
|
num = 0;
|
|
|
|
while (!PEND && maxlen-- != 0) {
|
|
|
|
PFETCH(c);
|
|
|
|
if (ONIGENC_IS_CODE_XDIGIT(enc, c)) {
|
|
|
|
val = (unsigned int )XDIGITVAL(enc,c);
|
|
|
|
if ((INT_MAX_LIMIT - val) / 16UL < num)
|
|
|
|
return -1; /* overflow */
|
|
|
|
|
|
|
|
num = (num << 4) + XDIGITVAL(enc,c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PUNFETCH;
|
2016-12-10 20:47:04 +03:00
|
|
|
maxlen++;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
if (maxlen > restlen)
|
|
|
|
return -2; /* not enough digits */
|
2004-03-05 18:31:51 +03:00
|
|
|
*src = p;
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
scan_unsigned_octal_number(UChar** src, UChar* end, int maxlen,
|
|
|
|
OnigEncoding enc)
|
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint c;
|
2004-03-05 18:31:51 +03:00
|
|
|
unsigned int num, val;
|
|
|
|
UChar* p = *src;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH_READY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
num = 0;
|
|
|
|
while (!PEND && maxlen-- != 0) {
|
|
|
|
PFETCH(c);
|
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c) && c < '8') {
|
|
|
|
val = ODIGITVAL(c);
|
|
|
|
if ((INT_MAX_LIMIT - val) / 8UL < num)
|
|
|
|
return -1; /* overflow */
|
|
|
|
|
|
|
|
num = (num << 3) + val;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PUNFETCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*src = p;
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define BBUF_WRITE_CODE_POINT(bbuf,pos,code) \
|
|
|
|
BBUF_WRITE(bbuf, pos, &(code), SIZE_CODE_POINT)
|
|
|
|
|
|
|
|
/* data format:
|
|
|
|
[n][from-1][to-1][from-2][to-2] ... [from-n][to-n]
|
|
|
|
(all data size is OnigCodePoint)
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
new_code_range(BBuf** pbuf)
|
|
|
|
{
|
|
|
|
#define INIT_MULTI_BYTE_RANGE_SIZE (SIZE_CODE_POINT * 5)
|
|
|
|
int r;
|
|
|
|
OnigCodePoint n;
|
|
|
|
BBuf* bbuf;
|
|
|
|
|
|
|
|
bbuf = *pbuf = (BBuf* )xmalloc(sizeof(BBuf));
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*pbuf);
|
2004-03-05 18:31:51 +03:00
|
|
|
r = BBUF_INIT(*pbuf, INIT_MULTI_BYTE_RANGE_SIZE);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
BBUF_WRITE_CODE_POINT(bbuf, 0, n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-17 05:46:34 +04:00
|
|
|
add_code_range_to_buf0(BBuf** pbuf, ScanEnv* env, OnigCodePoint from, OnigCodePoint to,
|
|
|
|
int checkdup)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r, inc_n, pos;
|
2012-02-19 05:51:05 +04:00
|
|
|
OnigCodePoint low, high, bound, x;
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigCodePoint n, *data;
|
|
|
|
BBuf* bbuf;
|
|
|
|
|
|
|
|
if (from > to) {
|
|
|
|
n = from; from = to; to = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_NULL(*pbuf)) {
|
|
|
|
r = new_code_range(pbuf);
|
|
|
|
if (r) return r;
|
|
|
|
bbuf = *pbuf;
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bbuf = *pbuf;
|
|
|
|
GET_CODE_POINT(n, bbuf->p);
|
|
|
|
}
|
|
|
|
data = (OnigCodePoint* )(bbuf->p);
|
|
|
|
data++;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
bound = (from == 0) ? 0 : n;
|
|
|
|
for (low = 0; low < bound; ) {
|
2004-03-05 18:31:51 +03:00
|
|
|
x = (low + bound) >> 1;
|
2012-02-17 11:42:23 +04:00
|
|
|
if (from - 1 > data[x*2 + 1])
|
2004-03-05 18:31:51 +03:00
|
|
|
low = x + 1;
|
|
|
|
else
|
|
|
|
bound = x;
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
high = (to == ONIG_LAST_CODE_POINT) ? n : low;
|
|
|
|
for (bound = n; high < bound; ) {
|
2004-03-05 18:31:51 +03:00
|
|
|
x = (high + bound) >> 1;
|
2012-02-17 11:42:23 +04:00
|
|
|
if (to + 1 >= data[x*2])
|
2004-03-05 18:31:51 +03:00
|
|
|
high = x + 1;
|
|
|
|
else
|
|
|
|
bound = x;
|
|
|
|
}
|
2012-02-26 18:32:54 +04:00
|
|
|
/* data[(low-1)*2+1] << from <= data[low*2]
|
|
|
|
* data[(high-1)*2+1] <= to << data[high*2]
|
|
|
|
*/
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
inc_n = low + 1 - high;
|
|
|
|
if (n + inc_n > ONIG_MAX_MULTI_BYTE_RANGES_NUM)
|
|
|
|
return ONIGERR_TOO_MANY_MULTI_BYTE_RANGES;
|
|
|
|
|
|
|
|
if (inc_n != 1) {
|
2012-02-26 18:32:54 +04:00
|
|
|
if (checkdup && from <= data[low*2+1]
|
2012-02-29 20:29:06 +04:00
|
|
|
&& (data[low*2] <= from || data[low*2+1] <= to))
|
2018-10-15 15:31:22 +03:00
|
|
|
CC_DUP_WARN(env, from, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (from > data[low*2])
|
|
|
|
from = data[low*2];
|
|
|
|
if (to < data[(high - 1)*2 + 1])
|
|
|
|
to = data[(high - 1)*2 + 1];
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
if (inc_n != 0) {
|
2004-03-05 18:31:51 +03:00
|
|
|
int from_pos = SIZE_CODE_POINT * (1 + high * 2);
|
|
|
|
int to_pos = SIZE_CODE_POINT * (1 + (low + 1) * 2);
|
|
|
|
|
|
|
|
if (inc_n > 0) {
|
2012-02-29 20:29:06 +04:00
|
|
|
if (high < n) {
|
2012-02-17 11:42:23 +04:00
|
|
|
int size = (n - high) * 2 * SIZE_CODE_POINT;
|
|
|
|
BBUF_MOVE_RIGHT(bbuf, from_pos, to_pos, size);
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BBUF_MOVE_LEFT_REDUCE(bbuf, from_pos, to_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = SIZE_CODE_POINT * (1 + low * 2);
|
|
|
|
BBUF_ENSURE_SIZE(bbuf, pos + SIZE_CODE_POINT * 2);
|
|
|
|
BBUF_WRITE_CODE_POINT(bbuf, pos, from);
|
|
|
|
BBUF_WRITE_CODE_POINT(bbuf, pos + SIZE_CODE_POINT, to);
|
|
|
|
n += inc_n;
|
|
|
|
BBUF_WRITE_CODE_POINT(bbuf, 0, n);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-17 05:46:34 +04:00
|
|
|
add_code_range_to_buf(BBuf** pbuf, ScanEnv* env, OnigCodePoint from, OnigCodePoint to)
|
|
|
|
{
|
|
|
|
return add_code_range_to_buf0(pbuf, env, from, to, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_code_range0(BBuf** pbuf, ScanEnv* env, OnigCodePoint from, OnigCodePoint to, int checkdup)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
if (from > to) {
|
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS;
|
|
|
|
}
|
|
|
|
|
2009-08-17 05:46:34 +04:00
|
|
|
return add_code_range_to_buf0(pbuf, env, from, to, checkdup);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_code_range(BBuf** pbuf, ScanEnv* env, OnigCodePoint from, OnigCodePoint to)
|
|
|
|
{
|
2016-12-10 20:47:04 +03:00
|
|
|
return add_code_range0(pbuf, env, from, to, 1);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-04 08:14:38 +04:00
|
|
|
not_code_range_buf(OnigEncoding enc, BBuf* bbuf, BBuf** pbuf, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r, i, n;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint pre, from, *data, to = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
*pbuf = (BBuf* )NULL;
|
|
|
|
if (IS_NULL(bbuf)) {
|
|
|
|
set_all:
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
return SET_ALL_MULTI_BYTE_RANGE(enc, pbuf);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
data = (OnigCodePoint* )(bbuf->p);
|
|
|
|
GET_CODE_POINT(n, data);
|
|
|
|
data++;
|
|
|
|
if (n <= 0) goto set_all;
|
|
|
|
|
|
|
|
r = 0;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
pre = MBCODE_START_POS(enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
from = data[i*2];
|
|
|
|
to = data[i*2+1];
|
|
|
|
if (pre <= from - 1) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = add_code_range_to_buf(pbuf, env, pre, from - 1);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
if (to == ONIG_LAST_CODE_POINT) break;
|
2004-03-05 18:31:51 +03:00
|
|
|
pre = to + 1;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
if (to < ONIG_LAST_CODE_POINT) {
|
|
|
|
r = add_code_range_to_buf(pbuf, env, to + 1, ONIG_LAST_CODE_POINT);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2) do {\
|
|
|
|
BBuf *tbuf; \
|
|
|
|
int tnot; \
|
|
|
|
tnot = not1; not1 = not2; not2 = tnot; \
|
|
|
|
tbuf = bbuf1; bbuf1 = bbuf2; bbuf2 = tbuf; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
or_code_range_buf(OnigEncoding enc, BBuf* bbuf1, int not1,
|
2009-08-04 08:14:38 +04:00
|
|
|
BBuf* bbuf2, int not2, BBuf** pbuf, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
OnigCodePoint i, n1, *data1;
|
|
|
|
OnigCodePoint from, to;
|
|
|
|
|
|
|
|
*pbuf = (BBuf* )NULL;
|
|
|
|
if (IS_NULL(bbuf1) && IS_NULL(bbuf2)) {
|
|
|
|
if (not1 != 0 || not2 != 0)
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
return SET_ALL_MULTI_BYTE_RANGE(enc, pbuf);
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = 0;
|
|
|
|
if (IS_NULL(bbuf2))
|
|
|
|
SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2);
|
|
|
|
|
|
|
|
if (IS_NULL(bbuf1)) {
|
|
|
|
if (not1 != 0) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
return SET_ALL_MULTI_BYTE_RANGE(enc, pbuf);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (not2 == 0) {
|
|
|
|
return bbuf_clone(pbuf, bbuf2);
|
|
|
|
}
|
|
|
|
else {
|
2009-08-04 08:14:38 +04:00
|
|
|
return not_code_range_buf(enc, bbuf2, pbuf, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not1 != 0)
|
|
|
|
SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2);
|
|
|
|
|
|
|
|
data1 = (OnigCodePoint* )(bbuf1->p);
|
|
|
|
GET_CODE_POINT(n1, data1);
|
|
|
|
data1++;
|
|
|
|
|
|
|
|
if (not2 == 0 && not1 == 0) { /* 1 OR 2 */
|
|
|
|
r = bbuf_clone(pbuf, bbuf2);
|
|
|
|
}
|
|
|
|
else if (not1 == 0) { /* 1 OR (not 2) */
|
2009-08-04 08:14:38 +04:00
|
|
|
r = not_code_range_buf(enc, bbuf2, pbuf, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
for (i = 0; i < n1; i++) {
|
|
|
|
from = data1[i*2];
|
|
|
|
to = data1[i*2+1];
|
2009-08-04 08:14:38 +04:00
|
|
|
r = add_code_range_to_buf(pbuf, env, from, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-04 08:14:38 +04:00
|
|
|
and_code_range1(BBuf** pbuf, ScanEnv* env, OnigCodePoint from1, OnigCodePoint to1,
|
2016-12-10 20:47:04 +03:00
|
|
|
OnigCodePoint* data, int n)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
OnigCodePoint from2, to2;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
from2 = data[i*2];
|
|
|
|
to2 = data[i*2+1];
|
|
|
|
if (from2 < from1) {
|
|
|
|
if (to2 < from1) continue;
|
|
|
|
else {
|
|
|
|
from1 = to2 + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (from2 <= to1) {
|
|
|
|
if (to2 < to1) {
|
|
|
|
if (from1 <= from2 - 1) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = add_code_range_to_buf(pbuf, env, from1, from2-1);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
from1 = to2 + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
to1 = from2 - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
from1 = from2;
|
|
|
|
}
|
|
|
|
if (from1 > to1) break;
|
|
|
|
}
|
|
|
|
if (from1 <= to1) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = add_code_range_to_buf(pbuf, env, from1, to1);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-04 08:14:38 +04:00
|
|
|
and_code_range_buf(BBuf* bbuf1, int not1, BBuf* bbuf2, int not2, BBuf** pbuf, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
OnigCodePoint i, j, n1, n2, *data1, *data2;
|
|
|
|
OnigCodePoint from, to, from1, to1, from2, to2;
|
|
|
|
|
|
|
|
*pbuf = (BBuf* )NULL;
|
|
|
|
if (IS_NULL(bbuf1)) {
|
|
|
|
if (not1 != 0 && IS_NOT_NULL(bbuf2)) /* not1 != 0 -> not2 == 0 */
|
|
|
|
return bbuf_clone(pbuf, bbuf2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (IS_NULL(bbuf2)) {
|
|
|
|
if (not2 != 0)
|
|
|
|
return bbuf_clone(pbuf, bbuf1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not1 != 0)
|
|
|
|
SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2);
|
|
|
|
|
|
|
|
data1 = (OnigCodePoint* )(bbuf1->p);
|
|
|
|
data2 = (OnigCodePoint* )(bbuf2->p);
|
|
|
|
GET_CODE_POINT(n1, data1);
|
|
|
|
GET_CODE_POINT(n2, data2);
|
|
|
|
data1++;
|
|
|
|
data2++;
|
|
|
|
|
|
|
|
if (not2 == 0 && not1 == 0) { /* 1 AND 2 */
|
|
|
|
for (i = 0; i < n1; i++) {
|
|
|
|
from1 = data1[i*2];
|
|
|
|
to1 = data1[i*2+1];
|
|
|
|
for (j = 0; j < n2; j++) {
|
|
|
|
from2 = data2[j*2];
|
|
|
|
to2 = data2[j*2+1];
|
|
|
|
if (from2 > to1) break;
|
|
|
|
if (to2 < from1) continue;
|
|
|
|
from = MAX(from1, from2);
|
|
|
|
to = MIN(to1, to2);
|
2009-08-04 08:14:38 +04:00
|
|
|
r = add_code_range_to_buf(pbuf, env, from, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (not1 == 0) { /* 1 AND (not 2) */
|
|
|
|
for (i = 0; i < n1; i++) {
|
|
|
|
from1 = data1[i*2];
|
|
|
|
to1 = data1[i*2+1];
|
2009-08-04 08:14:38 +04:00
|
|
|
r = and_code_range1(pbuf, env, from1, to1, data2, n2);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-04 08:14:38 +04:00
|
|
|
and_cclass(CClassNode* dest, CClassNode* cc, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2009-08-04 08:14:38 +04:00
|
|
|
OnigEncoding enc = env->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
int r, not1, not2;
|
2010-11-15 19:06:35 +03:00
|
|
|
BBuf *buf1, *buf2, *pbuf = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
BitSetRef bsr1, bsr2;
|
|
|
|
BitSet bs1, bs2;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
not1 = IS_NCCLASS_NOT(dest);
|
2004-03-05 18:31:51 +03:00
|
|
|
bsr1 = dest->bs;
|
|
|
|
buf1 = dest->mbuf;
|
2007-07-23 13:39:30 +04:00
|
|
|
not2 = IS_NCCLASS_NOT(cc);
|
2004-03-05 18:31:51 +03:00
|
|
|
bsr2 = cc->bs;
|
|
|
|
buf2 = cc->mbuf;
|
|
|
|
|
|
|
|
if (not1 != 0) {
|
|
|
|
bitset_invert_to(bsr1, bs1);
|
|
|
|
bsr1 = bs1;
|
|
|
|
}
|
|
|
|
if (not2 != 0) {
|
|
|
|
bitset_invert_to(bsr2, bs2);
|
|
|
|
bsr2 = bs2;
|
|
|
|
}
|
|
|
|
bitset_and(bsr1, bsr2);
|
|
|
|
if (bsr1 != dest->bs) {
|
|
|
|
bitset_copy(dest->bs, bsr1);
|
|
|
|
bsr1 = dest->bs;
|
|
|
|
}
|
|
|
|
if (not1 != 0) {
|
|
|
|
bitset_invert(dest->bs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! ONIGENC_IS_SINGLEBYTE(enc)) {
|
|
|
|
if (not1 != 0 && not2 != 0) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = or_code_range_buf(enc, buf1, 0, buf2, 0, &pbuf, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = and_code_range_buf(buf1, not1, buf2, not2, &pbuf, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0 && not1 != 0) {
|
2010-11-15 19:06:35 +03:00
|
|
|
BBuf *tbuf = 0;
|
2009-08-04 08:14:38 +04:00
|
|
|
r = not_code_range_buf(enc, pbuf, &tbuf, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
bbuf_free(pbuf);
|
|
|
|
pbuf = tbuf;
|
|
|
|
}
|
|
|
|
}
|
2010-11-15 19:06:35 +03:00
|
|
|
if (r != 0) {
|
2012-02-17 11:42:23 +04:00
|
|
|
bbuf_free(pbuf);
|
|
|
|
return r;
|
2010-11-15 19:06:35 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
dest->mbuf = pbuf;
|
|
|
|
bbuf_free(buf1);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-04 08:14:38 +04:00
|
|
|
or_cclass(CClassNode* dest, CClassNode* cc, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2009-08-04 08:14:38 +04:00
|
|
|
OnigEncoding enc = env->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
int r, not1, not2;
|
2010-11-15 19:06:35 +03:00
|
|
|
BBuf *buf1, *buf2, *pbuf = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
BitSetRef bsr1, bsr2;
|
|
|
|
BitSet bs1, bs2;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
not1 = IS_NCCLASS_NOT(dest);
|
2004-03-05 18:31:51 +03:00
|
|
|
bsr1 = dest->bs;
|
|
|
|
buf1 = dest->mbuf;
|
2007-07-23 13:39:30 +04:00
|
|
|
not2 = IS_NCCLASS_NOT(cc);
|
2004-03-05 18:31:51 +03:00
|
|
|
bsr2 = cc->bs;
|
|
|
|
buf2 = cc->mbuf;
|
|
|
|
|
|
|
|
if (not1 != 0) {
|
|
|
|
bitset_invert_to(bsr1, bs1);
|
|
|
|
bsr1 = bs1;
|
|
|
|
}
|
|
|
|
if (not2 != 0) {
|
|
|
|
bitset_invert_to(bsr2, bs2);
|
|
|
|
bsr2 = bs2;
|
|
|
|
}
|
|
|
|
bitset_or(bsr1, bsr2);
|
|
|
|
if (bsr1 != dest->bs) {
|
|
|
|
bitset_copy(dest->bs, bsr1);
|
|
|
|
bsr1 = dest->bs;
|
|
|
|
}
|
|
|
|
if (not1 != 0) {
|
|
|
|
bitset_invert(dest->bs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! ONIGENC_IS_SINGLEBYTE(enc)) {
|
|
|
|
if (not1 != 0 && not2 != 0) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = and_code_range_buf(buf1, 0, buf2, 0, &pbuf, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = or_code_range_buf(enc, buf1, not1, buf2, not2, &pbuf, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0 && not1 != 0) {
|
2010-11-15 19:06:35 +03:00
|
|
|
BBuf *tbuf = 0;
|
2009-08-04 08:14:38 +04:00
|
|
|
r = not_code_range_buf(enc, pbuf, &tbuf, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
bbuf_free(pbuf);
|
|
|
|
pbuf = tbuf;
|
|
|
|
}
|
|
|
|
}
|
2010-11-15 19:06:35 +03:00
|
|
|
if (r != 0) {
|
2012-02-17 11:42:23 +04:00
|
|
|
bbuf_free(pbuf);
|
|
|
|
return r;
|
2010-11-15 19:06:35 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
dest->mbuf = pbuf;
|
|
|
|
bbuf_free(buf1);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-10 11:00:44 +04:00
|
|
|
static void UNKNOWN_ESC_WARN(ScanEnv *env, int c);
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
static OnigCodePoint
|
|
|
|
conv_backslash_value(OnigCodePoint c, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
if (IS_SYNTAX_OP(env->syntax, ONIG_SYN_OP_ESC_CONTROL_CHARS)) {
|
|
|
|
switch (c) {
|
2007-05-23 05:32:08 +04:00
|
|
|
case 'n': return '\n';
|
|
|
|
case 't': return '\t';
|
|
|
|
case 'r': return '\r';
|
|
|
|
case 'f': return '\f';
|
|
|
|
case 'a': return '\007';
|
|
|
|
case 'b': return '\010';
|
|
|
|
case 'e': return '\033';
|
2004-03-05 18:31:51 +03:00
|
|
|
case 'v':
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_ESC_V_VTAB))
|
|
|
|
return '\v';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-09-10 11:00:44 +04:00
|
|
|
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
|
|
|
|
UNKNOWN_ESC_WARN(env, c);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
#ifdef USE_NO_INVALID_QUANTIFIER
|
2016-12-10 20:47:04 +03:00
|
|
|
# define is_invalid_quantifier_target(node) 0
|
2012-02-17 11:42:23 +04:00
|
|
|
#else
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
2007-05-23 05:32:08 +04:00
|
|
|
is_invalid_quantifier_target(Node* node)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
|
|
|
/* allow enclosed elements */
|
|
|
|
/* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (! is_invalid_quantifier_target(NCAR(node))) return 0;
|
|
|
|
} while (IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (is_invalid_quantifier_target(NCAR(node))) return 1;
|
|
|
|
} while (IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-29 13:55:51 +03:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
/* ?:0, *:1, +:2, ??:3, *?:4, +?:5 */
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
popular_quantifier_num(QtfrNode* q)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-05-23 05:32:08 +04:00
|
|
|
if (q->greedy) {
|
|
|
|
if (q->lower == 0) {
|
|
|
|
if (q->upper == 1) return 0;
|
|
|
|
else if (IS_REPEAT_INFINITE(q->upper)) return 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
else if (q->lower == 1) {
|
|
|
|
if (IS_REPEAT_INFINITE(q->upper)) return 2;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-05-23 05:32:08 +04:00
|
|
|
if (q->lower == 0) {
|
|
|
|
if (q->upper == 1) return 3;
|
|
|
|
else if (IS_REPEAT_INFINITE(q->upper)) return 4;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
else if (q->lower == 1) {
|
|
|
|
if (IS_REPEAT_INFINITE(q->upper)) return 5;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-11-04 17:57:11 +03:00
|
|
|
|
2004-04-05 14:40:54 +04:00
|
|
|
enum ReduceType {
|
|
|
|
RQ_ASIS = 0, /* as is */
|
|
|
|
RQ_DEL = 1, /* delete parent */
|
|
|
|
RQ_A, /* to '*' */
|
|
|
|
RQ_AQ, /* to '*?' */
|
|
|
|
RQ_QQ, /* to '??' */
|
|
|
|
RQ_P_QQ, /* to '+)??' */
|
2006-08-27 16:58:22 +04:00
|
|
|
RQ_PQ_Q /* to '+?)?' */
|
2004-04-05 14:40:54 +04:00
|
|
|
};
|
|
|
|
|
2008-07-01 12:21:44 +04:00
|
|
|
static enum ReduceType const ReduceTypeTable[6][6] = {
|
2016-12-10 20:47:04 +03:00
|
|
|
/* '?', '*', '+', '??', '*?', '+?' p / c */
|
2004-04-05 14:40:54 +04:00
|
|
|
{RQ_DEL, RQ_A, RQ_A, RQ_QQ, RQ_AQ, RQ_ASIS}, /* '?' */
|
|
|
|
{RQ_DEL, RQ_DEL, RQ_DEL, RQ_P_QQ, RQ_P_QQ, RQ_DEL}, /* '*' */
|
|
|
|
{RQ_A, RQ_A, RQ_DEL, RQ_ASIS, RQ_P_QQ, RQ_DEL}, /* '+' */
|
|
|
|
{RQ_DEL, RQ_AQ, RQ_AQ, RQ_DEL, RQ_AQ, RQ_AQ}, /* '??' */
|
|
|
|
{RQ_DEL, RQ_DEL, RQ_DEL, RQ_DEL, RQ_DEL, RQ_DEL}, /* '*?' */
|
|
|
|
{RQ_ASIS, RQ_PQ_Q, RQ_DEL, RQ_AQ, RQ_AQ, RQ_DEL} /* '+?' */
|
|
|
|
};
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
extern void
|
2007-05-23 05:32:08 +04:00
|
|
|
onig_reduce_nested_quantifier(Node* pnode, Node* cnode)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int pnum, cnum;
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode *p, *c;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
p = NQTFR(pnode);
|
|
|
|
c = NQTFR(cnode);
|
2007-05-23 05:32:08 +04:00
|
|
|
pnum = popular_quantifier_num(p);
|
|
|
|
cnum = popular_quantifier_num(c);
|
2007-07-23 13:39:30 +04:00
|
|
|
if (pnum < 0 || cnum < 0) return ;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2012-12-29 16:22:04 +04:00
|
|
|
switch (ReduceTypeTable[cnum][pnum]) {
|
2004-04-05 14:40:54 +04:00
|
|
|
case RQ_DEL:
|
2007-07-23 13:39:30 +04:00
|
|
|
*pnode = *cnode;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2004-04-05 14:40:54 +04:00
|
|
|
case RQ_A:
|
2004-03-05 18:31:51 +03:00
|
|
|
p->target = c->target;
|
|
|
|
p->lower = 0; p->upper = REPEAT_INFINITE; p->greedy = 1;
|
|
|
|
break;
|
2004-04-05 14:40:54 +04:00
|
|
|
case RQ_AQ:
|
2004-03-05 18:31:51 +03:00
|
|
|
p->target = c->target;
|
|
|
|
p->lower = 0; p->upper = REPEAT_INFINITE; p->greedy = 0;
|
|
|
|
break;
|
2004-04-05 14:40:54 +04:00
|
|
|
case RQ_QQ:
|
2004-03-05 18:31:51 +03:00
|
|
|
p->target = c->target;
|
|
|
|
p->lower = 0; p->upper = 1; p->greedy = 0;
|
|
|
|
break;
|
2004-04-05 14:40:54 +04:00
|
|
|
case RQ_P_QQ:
|
2004-03-05 18:31:51 +03:00
|
|
|
p->target = cnode;
|
|
|
|
p->lower = 0; p->upper = 1; p->greedy = 0;
|
|
|
|
c->lower = 1; c->upper = REPEAT_INFINITE; c->greedy = 1;
|
|
|
|
return ;
|
|
|
|
break;
|
2004-04-05 14:40:54 +04:00
|
|
|
case RQ_PQ_Q:
|
2004-03-05 18:31:51 +03:00
|
|
|
p->target = cnode;
|
|
|
|
p->lower = 0; p->upper = 1; p->greedy = 1;
|
|
|
|
c->lower = 1; c->upper = REPEAT_INFINITE; c->greedy = 0;
|
|
|
|
return ;
|
|
|
|
break;
|
2004-04-05 14:40:54 +04:00
|
|
|
case RQ_ASIS:
|
2004-03-05 18:31:51 +03:00
|
|
|
p->target = cnode;
|
|
|
|
return ;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->target = NULL_NODE;
|
|
|
|
onig_node_free(cnode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum TokenSyms {
|
|
|
|
TK_EOT = 0, /* end of token */
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
TK_RAW_BYTE = 1,
|
|
|
|
TK_CHAR,
|
|
|
|
TK_STRING,
|
2004-03-05 18:31:51 +03:00
|
|
|
TK_CODE_POINT,
|
|
|
|
TK_ANYCHAR,
|
|
|
|
TK_CHAR_TYPE,
|
|
|
|
TK_BACKREF,
|
|
|
|
TK_CALL,
|
|
|
|
TK_ANCHOR,
|
|
|
|
TK_OP_REPEAT,
|
|
|
|
TK_INTERVAL,
|
|
|
|
TK_ANYCHAR_ANYTIME, /* SQL '%' == .* */
|
|
|
|
TK_ALT,
|
|
|
|
TK_SUBEXP_OPEN,
|
|
|
|
TK_SUBEXP_CLOSE,
|
|
|
|
TK_CC_OPEN,
|
|
|
|
TK_QUOTE_OPEN,
|
|
|
|
TK_CHAR_PROPERTY, /* \p{...}, \P{...} */
|
2012-02-17 11:42:23 +04:00
|
|
|
TK_LINEBREAK,
|
|
|
|
TK_EXTENDED_GRAPHEME_CLUSTER,
|
|
|
|
TK_KEEP,
|
2004-03-05 18:31:51 +03:00
|
|
|
/* in cc */
|
|
|
|
TK_CC_CLOSE,
|
|
|
|
TK_CC_RANGE,
|
|
|
|
TK_POSIX_BRACKET_OPEN,
|
|
|
|
TK_CC_AND, /* && */
|
|
|
|
TK_CC_CC_OPEN /* [ */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
enum TokenSyms type;
|
|
|
|
int escaped;
|
|
|
|
int base; /* is number: 8, 16 (used in [....]) */
|
|
|
|
UChar* backp;
|
|
|
|
union {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
UChar* s;
|
2004-03-05 18:31:51 +03:00
|
|
|
int c;
|
|
|
|
OnigCodePoint code;
|
2012-02-17 11:42:23 +04:00
|
|
|
struct {
|
|
|
|
int subtype;
|
|
|
|
int ascii_range;
|
|
|
|
} anchor;
|
2004-03-05 18:31:51 +03:00
|
|
|
struct {
|
|
|
|
int lower;
|
|
|
|
int upper;
|
|
|
|
int greedy;
|
|
|
|
int possessive;
|
|
|
|
} repeat;
|
|
|
|
struct {
|
|
|
|
int num;
|
|
|
|
int ref1;
|
|
|
|
int* refs;
|
|
|
|
int by_name;
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
int exist_level;
|
|
|
|
int level; /* \k<name+n> */
|
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
} backref;
|
|
|
|
struct {
|
|
|
|
UChar* name;
|
|
|
|
UChar* name_end;
|
2008-01-03 18:55:04 +03:00
|
|
|
int gnum;
|
2012-02-17 11:42:23 +04:00
|
|
|
int rel;
|
2004-03-05 18:31:51 +03:00
|
|
|
} call;
|
|
|
|
struct {
|
2007-05-23 05:32:08 +04:00
|
|
|
int ctype;
|
2004-03-05 18:31:51 +03:00
|
|
|
int not;
|
|
|
|
} prop;
|
|
|
|
} u;
|
|
|
|
} OnigToken;
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2007-05-23 05:32:08 +04:00
|
|
|
fetch_range_quantifier(UChar** src, UChar* end, OnigToken* tok, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int low, up, syn_allow, non_low = 0;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int r = 0;
|
|
|
|
OnigCodePoint c;
|
|
|
|
OnigEncoding enc = env->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* p = *src;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH_READY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
syn_allow = IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_INVALID_INTERVAL);
|
|
|
|
|
|
|
|
if (PEND) {
|
|
|
|
if (syn_allow)
|
|
|
|
return 1; /* "....{" : OK! */
|
|
|
|
else
|
|
|
|
return ONIGERR_END_PATTERN_AT_LEFT_BRACE; /* "....{" syntax error */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! syn_allow) {
|
|
|
|
c = PPEEK;
|
|
|
|
if (c == ')' || c == '(' || c == '|') {
|
|
|
|
return ONIGERR_END_PATTERN_AT_LEFT_BRACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
low = onig_scan_unsigned_number(&p, end, env->enc);
|
|
|
|
if (low < 0) return ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE;
|
|
|
|
if (low > ONIG_MAX_REPEAT_NUM)
|
|
|
|
return ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE;
|
|
|
|
|
|
|
|
if (p == *src) { /* can't read low */
|
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV)) {
|
|
|
|
/* allow {,n} as {0,n} */
|
|
|
|
low = 0;
|
|
|
|
non_low = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PEND) goto invalid;
|
|
|
|
PFETCH(c);
|
|
|
|
if (c == ',') {
|
|
|
|
UChar* prev = p;
|
|
|
|
up = onig_scan_unsigned_number(&p, end, env->enc);
|
|
|
|
if (up < 0) return ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE;
|
|
|
|
if (up > ONIG_MAX_REPEAT_NUM)
|
|
|
|
return ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE;
|
|
|
|
|
|
|
|
if (p == prev) {
|
|
|
|
if (non_low != 0)
|
|
|
|
goto invalid;
|
|
|
|
up = REPEAT_INFINITE; /* {n,} : {n,infinite} */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (non_low != 0)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
PUNFETCH;
|
|
|
|
up = low; /* {n} : exact n times */
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
r = 2; /* fixed */
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (PEND) goto invalid;
|
|
|
|
PFETCH(c);
|
|
|
|
if (IS_SYNTAX_OP(env->syntax, ONIG_SYN_OP_ESC_BRACE_INTERVAL)) {
|
2007-05-23 05:32:08 +04:00
|
|
|
if (c != MC_ESC(env->syntax)) goto invalid;
|
2016-12-10 20:47:04 +03:00
|
|
|
if (PEND) goto invalid;
|
2004-03-05 18:31:51 +03:00
|
|
|
PFETCH(c);
|
|
|
|
}
|
|
|
|
if (c != '}') goto invalid;
|
|
|
|
|
|
|
|
if (!IS_REPEAT_INFINITE(up) && low > up) {
|
|
|
|
return ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tok->type = TK_INTERVAL;
|
|
|
|
tok->u.repeat.lower = low;
|
|
|
|
tok->u.repeat.upper = up;
|
|
|
|
*src = p;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
return r; /* 0: normal {n,m}, 2: fixed {n} */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
invalid:
|
|
|
|
if (syn_allow)
|
|
|
|
return 1; /* OK */
|
|
|
|
else
|
|
|
|
return ONIGERR_INVALID_REPEAT_RANGE_PATTERN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* \M-, \C-, \c, or \... */
|
|
|
|
static int
|
2016-12-10 20:47:04 +03:00
|
|
|
fetch_escaped_value(UChar** src, UChar* end, ScanEnv* env, OnigCodePoint* val)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int v;
|
|
|
|
OnigCodePoint c;
|
|
|
|
OnigEncoding enc = env->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* p = *src;
|
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
if (PEND) return ONIGERR_END_PATTERN_AT_ESCAPE;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (c) {
|
|
|
|
case 'M':
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META)) {
|
|
|
|
if (PEND) return ONIGERR_END_PATTERN_AT_META;
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (c != '-') return ONIGERR_META_CODE_SYNTAX;
|
|
|
|
if (PEND) return ONIGERR_END_PATTERN_AT_META;
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (c == MC_ESC(env->syntax)) {
|
2016-12-10 20:47:04 +03:00
|
|
|
v = fetch_escaped_value(&p, end, env, &c);
|
|
|
|
if (v < 0) return v;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
c = ((c & 0xff) | 0x80);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto backslash;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL)) {
|
|
|
|
if (PEND) return ONIGERR_END_PATTERN_AT_CONTROL;
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (c != '-') return ONIGERR_CONTROL_CODE_SYNTAX;
|
|
|
|
goto control;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto backslash;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
if (IS_SYNTAX_OP(env->syntax, ONIG_SYN_OP_ESC_C_CONTROL)) {
|
|
|
|
control:
|
|
|
|
if (PEND) return ONIGERR_END_PATTERN_AT_CONTROL;
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2006-02-04 15:31:19 +03:00
|
|
|
if (c == '?') {
|
2016-12-10 20:47:04 +03:00
|
|
|
c = 0177;
|
2006-02-04 15:31:19 +03:00
|
|
|
}
|
|
|
|
else {
|
2016-12-10 20:47:04 +03:00
|
|
|
if (c == MC_ESC(env->syntax)) {
|
|
|
|
v = fetch_escaped_value(&p, end, env, &c);
|
|
|
|
if (v < 0) return v;
|
|
|
|
}
|
|
|
|
c &= 0x9f;
|
2006-02-04 15:31:19 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
backslash:
|
|
|
|
c = conv_backslash_value(c, env);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*src = p;
|
2016-12-10 20:47:04 +03:00
|
|
|
*val = c;
|
|
|
|
return 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env);
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
static OnigCodePoint
|
|
|
|
get_name_end_code_point(OnigCodePoint start)
|
|
|
|
{
|
|
|
|
switch (start) {
|
|
|
|
case '<': return (OnigCodePoint )'>'; break;
|
|
|
|
case '\'': return (OnigCodePoint )'\''; break;
|
2012-02-17 11:42:23 +04:00
|
|
|
case '(': return (OnigCodePoint )')'; break;
|
|
|
|
case '{': return (OnigCodePoint )'}'; break;
|
2007-05-23 05:32:08 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (OnigCodePoint )0;
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_NAMED_GROUP
|
2016-12-10 20:47:04 +03:00
|
|
|
# ifdef RUBY
|
|
|
|
# define ONIGENC_IS_CODE_NAME(enc, c) TRUE
|
|
|
|
# else
|
|
|
|
# define ONIGENC_IS_CODE_NAME(enc, c) ONIGENC_IS_CODE_WORD(enc, c)
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
/*
|
|
|
|
\k<name+n>, \k<name-n>
|
2008-01-03 18:55:04 +03:00
|
|
|
\k<num+n>, \k<num-n>
|
|
|
|
\k<-num+n>, \k<-num-n>
|
2006-08-05 17:54:40 +04:00
|
|
|
*/
|
|
|
|
static int
|
2007-05-23 05:32:08 +04:00
|
|
|
fetch_name_with_level(OnigCodePoint start_code, UChar** src, UChar* end,
|
2008-01-03 18:55:04 +03:00
|
|
|
UChar** rname_end, ScanEnv* env,
|
|
|
|
int* rback_num, int* rlevel)
|
2006-08-05 17:54:40 +04:00
|
|
|
{
|
2008-01-03 18:55:04 +03:00
|
|
|
int r, sign, is_num, exist_level;
|
2007-05-23 05:32:08 +04:00
|
|
|
OnigCodePoint end_code;
|
2006-08-05 17:54:40 +04:00
|
|
|
OnigCodePoint c = 0;
|
|
|
|
OnigEncoding enc = env->enc;
|
|
|
|
UChar *name_end;
|
2008-01-03 18:55:04 +03:00
|
|
|
UChar *pnum_head;
|
2006-08-05 17:54:40 +04:00
|
|
|
UChar *p = *src;
|
|
|
|
PFETCH_READY;
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
*rback_num = 0;
|
|
|
|
is_num = exist_level = 0;
|
|
|
|
sign = 1;
|
|
|
|
pnum_head = *src;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
end_code = get_name_end_code_point(start_code);
|
|
|
|
|
2006-08-05 17:54:40 +04:00
|
|
|
name_end = end;
|
|
|
|
r = 0;
|
|
|
|
if (PEND) {
|
|
|
|
return ONIGERR_EMPTY_GROUP_NAME;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PFETCH(c);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (c == end_code)
|
2006-08-05 17:54:40 +04:00
|
|
|
return ONIGERR_EMPTY_GROUP_NAME;
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c)) {
|
|
|
|
is_num = 1;
|
|
|
|
}
|
|
|
|
else if (c == '-') {
|
|
|
|
is_num = 2;
|
|
|
|
sign = -1;
|
|
|
|
pnum_head = p;
|
|
|
|
}
|
2016-01-21 19:09:09 +03:00
|
|
|
else if (!ONIGENC_IS_CODE_NAME(enc, c)) {
|
2006-08-05 17:54:40 +04:00
|
|
|
r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!PEND) {
|
|
|
|
name_end = p;
|
|
|
|
PFETCH(c);
|
2008-01-03 18:55:04 +03:00
|
|
|
if (c == end_code || c == ')' || c == '+' || c == '-') {
|
2013-03-01 20:36:37 +04:00
|
|
|
if (is_num == 2) r = ONIGERR_INVALID_GROUP_NAME;
|
2008-01-03 18:55:04 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-08-05 17:54:40 +04:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (is_num != 0) {
|
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c)) {
|
2016-12-10 20:47:04 +03:00
|
|
|
is_num = 1;
|
2008-01-03 18:55:04 +03:00
|
|
|
}
|
|
|
|
else {
|
2016-12-10 20:47:04 +03:00
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
is_num = 0;
|
2008-01-03 18:55:04 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-21 19:09:09 +03:00
|
|
|
else if (!ONIGENC_IS_CODE_NAME(enc, c)) {
|
2006-08-05 17:54:40 +04:00
|
|
|
r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (r == 0 && c != end_code) {
|
2006-08-05 17:54:40 +04:00
|
|
|
if (c == '+' || c == '-') {
|
2008-01-03 18:55:04 +03:00
|
|
|
int level;
|
2006-08-05 17:54:40 +04:00
|
|
|
int flag = (c == '-' ? -1 : 1);
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
if (PEND) {
|
|
|
|
r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
|
|
|
|
goto end;
|
|
|
|
}
|
2006-08-05 17:54:40 +04:00
|
|
|
PFETCH(c);
|
|
|
|
if (! ONIGENC_IS_CODE_DIGIT(enc, c)) goto err;
|
|
|
|
PUNFETCH;
|
2008-01-03 18:55:04 +03:00
|
|
|
level = onig_scan_unsigned_number(&p, end, enc);
|
|
|
|
if (level < 0) return ONIGERR_TOO_BIG_NUMBER;
|
|
|
|
*rlevel = (level * flag);
|
2006-08-05 17:54:40 +04:00
|
|
|
exist_level = 1;
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!PEND) {
|
|
|
|
PFETCH(c);
|
|
|
|
if (c == end_code)
|
|
|
|
goto end;
|
|
|
|
}
|
2006-08-05 17:54:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
name_end = end;
|
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
end:
|
2006-08-05 17:54:40 +04:00
|
|
|
if (r == 0) {
|
2008-01-03 18:55:04 +03:00
|
|
|
if (is_num != 0) {
|
|
|
|
*rback_num = onig_scan_unsigned_number(&pnum_head, name_end, enc);
|
|
|
|
if (*rback_num < 0) return ONIGERR_TOO_BIG_NUMBER;
|
|
|
|
else if (*rback_num == 0) goto err;
|
|
|
|
|
|
|
|
*rback_num *= sign;
|
|
|
|
}
|
|
|
|
|
2006-08-05 17:54:40 +04:00
|
|
|
*rname_end = name_end;
|
|
|
|
*src = p;
|
|
|
|
return (exist_level ? 1 : 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
onig_scan_env_set_error_string(env, r, *src, name_end);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
# endif /* USE_BACKREF_WITH_LEVEL */
|
2006-08-05 17:54:40 +04:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
/*
|
2012-02-17 11:42:23 +04:00
|
|
|
ref: 0 -> define name (don't allow number name)
|
2004-03-05 18:31:51 +03:00
|
|
|
1 -> reference name (allow number name)
|
|
|
|
*/
|
|
|
|
static int
|
2007-05-23 05:32:08 +04:00
|
|
|
fetch_name(OnigCodePoint start_code, UChar** src, UChar* end,
|
2008-01-03 18:55:04 +03:00
|
|
|
UChar** rname_end, ScanEnv* env, int* rback_num, int ref)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2008-01-03 18:55:04 +03:00
|
|
|
int r, is_num, sign;
|
2007-05-23 05:32:08 +04:00
|
|
|
OnigCodePoint end_code;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint c = 0;
|
|
|
|
OnigEncoding enc = env->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar *name_end;
|
2008-01-03 18:55:04 +03:00
|
|
|
UChar *pnum_head;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar *p = *src;
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
*rback_num = 0;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
end_code = get_name_end_code_point(start_code);
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
name_end = end;
|
2008-01-03 18:55:04 +03:00
|
|
|
pnum_head = *src;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = 0;
|
|
|
|
is_num = 0;
|
2008-01-03 18:55:04 +03:00
|
|
|
sign = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (PEND) {
|
|
|
|
return ONIGERR_EMPTY_GROUP_NAME;
|
|
|
|
}
|
|
|
|
else {
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (c == end_code)
|
2004-03-05 18:31:51 +03:00
|
|
|
return ONIGERR_EMPTY_GROUP_NAME;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (ref == 1)
|
2016-12-10 20:47:04 +03:00
|
|
|
is_num = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
else {
|
2016-12-10 20:47:04 +03:00
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
is_num = 0;
|
2008-01-03 18:55:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '-') {
|
|
|
|
if (ref == 1) {
|
2016-12-10 20:47:04 +03:00
|
|
|
is_num = 2;
|
|
|
|
sign = -1;
|
|
|
|
pnum_head = p;
|
2008-01-03 18:55:04 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
2009-02-22 17:23:33 +03:00
|
|
|
is_num = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-21 19:09:09 +03:00
|
|
|
else if (!ONIGENC_IS_CODE_NAME(enc, c)) {
|
2004-04-05 14:40:54 +04:00
|
|
|
r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (r == 0) {
|
|
|
|
while (!PEND) {
|
|
|
|
name_end = p;
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2008-01-03 18:55:04 +03:00
|
|
|
if (c == end_code || c == ')') {
|
2016-12-10 20:47:04 +03:00
|
|
|
if (is_num == 2) {
|
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
goto teardown;
|
|
|
|
}
|
|
|
|
break;
|
2008-01-03 18:55:04 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (is_num != 0) {
|
2016-12-10 20:47:04 +03:00
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c)) {
|
|
|
|
is_num = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!ONIGENC_IS_CODE_WORD(enc, c))
|
|
|
|
r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
|
|
|
|
else
|
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
goto teardown;
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
}
|
|
|
|
else {
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!ONIGENC_IS_CODE_NAME(enc, c)) {
|
|
|
|
r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
|
|
|
|
goto teardown;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
|
|
|
|
if (c != end_code) {
|
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
name_end = end;
|
2016-01-21 19:09:09 +03:00
|
|
|
goto err;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (is_num != 0) {
|
|
|
|
*rback_num = onig_scan_unsigned_number(&pnum_head, name_end, enc);
|
|
|
|
if (*rback_num < 0) return ONIGERR_TOO_BIG_NUMBER;
|
|
|
|
else if (*rback_num == 0) {
|
2016-12-10 20:47:04 +03:00
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
goto err;
|
2008-01-03 18:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
*rback_num *= sign;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
*rname_end = name_end;
|
|
|
|
*src = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
2016-12-10 20:47:04 +03:00
|
|
|
teardown:
|
2008-01-03 18:55:04 +03:00
|
|
|
while (!PEND) {
|
|
|
|
name_end = p;
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2008-01-03 18:55:04 +03:00
|
|
|
if (c == end_code || c == ')')
|
2016-12-10 20:47:04 +03:00
|
|
|
break;
|
2008-01-03 18:55:04 +03:00
|
|
|
}
|
|
|
|
if (PEND)
|
|
|
|
name_end = end;
|
|
|
|
|
|
|
|
err:
|
2004-03-05 18:31:51 +03:00
|
|
|
onig_scan_env_set_error_string(env, r, *src, name_end);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int
|
2007-05-23 05:32:08 +04:00
|
|
|
fetch_name(OnigCodePoint start_code, UChar** src, UChar* end,
|
2008-01-03 18:55:04 +03:00
|
|
|
UChar** rname_end, ScanEnv* env, int* rback_num, int ref)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2008-01-03 18:55:04 +03:00
|
|
|
int r, is_num, sign;
|
2007-05-23 05:32:08 +04:00
|
|
|
OnigCodePoint end_code;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint c = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar *name_end;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigEncoding enc = env->enc;
|
2008-01-03 18:55:04 +03:00
|
|
|
UChar *pnum_head;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar *p = *src;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH_READY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
*rback_num = 0;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
end_code = get_name_end_code_point(start_code);
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
*rname_end = name_end = end;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = 0;
|
2008-01-03 18:55:04 +03:00
|
|
|
pnum_head = *src;
|
|
|
|
is_num = 0;
|
|
|
|
sign = 1;
|
|
|
|
|
|
|
|
if (PEND) {
|
|
|
|
return ONIGERR_EMPTY_GROUP_NAME;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PFETCH(c);
|
|
|
|
if (c == end_code)
|
|
|
|
return ONIGERR_EMPTY_GROUP_NAME;
|
|
|
|
|
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c)) {
|
|
|
|
is_num = 1;
|
|
|
|
}
|
|
|
|
else if (c == '-') {
|
|
|
|
is_num = 2;
|
|
|
|
sign = -1;
|
|
|
|
pnum_head = p;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
while (!PEND) {
|
|
|
|
name_end = p;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH(c);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (c == end_code || c == ')') break;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (! ONIGENC_IS_CODE_DIGIT(enc, c))
|
2004-03-05 18:31:51 +03:00
|
|
|
r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
if (r == 0 && c != end_code) {
|
2004-03-05 18:31:51 +03:00
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
name_end = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r == 0) {
|
2008-01-03 18:55:04 +03:00
|
|
|
*rback_num = onig_scan_unsigned_number(&pnum_head, name_end, enc);
|
|
|
|
if (*rback_num < 0) return ONIGERR_TOO_BIG_NUMBER;
|
|
|
|
else if (*rback_num == 0) {
|
|
|
|
r = ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
*rback_num *= sign;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
*rname_end = name_end;
|
|
|
|
*src = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
err:
|
|
|
|
onig_scan_env_set_error_string(env, r, *src, name_end);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
#endif /* USE_NAMED_GROUP */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2009-10-11 04:48:35 +04:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static void
|
2009-10-10 22:12:26 +04:00
|
|
|
onig_syntax_warn(ScanEnv *env, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
UChar buf[WARN_BUFSIZE];
|
|
|
|
va_start(args, fmt);
|
2009-10-11 04:48:35 +04:00
|
|
|
onig_vsnprintf_with_pattern(buf, WARN_BUFSIZE, env->enc,
|
2009-10-10 22:12:26 +04:00
|
|
|
env->pattern, env->pattern_end,
|
|
|
|
(const UChar *)fmt, args);
|
|
|
|
va_end(args);
|
2016-12-10 20:47:04 +03:00
|
|
|
#ifdef RUBY
|
2009-10-10 22:12:26 +04:00
|
|
|
if (env->sourcefile == NULL)
|
2010-05-31 14:26:01 +04:00
|
|
|
rb_warn("%s", (char *)buf);
|
2009-10-10 22:12:26 +04:00
|
|
|
else
|
2010-05-31 14:26:01 +04:00
|
|
|
rb_compile_warn(env->sourcefile, env->sourceline, "%s", (char *)buf);
|
2016-12-10 20:47:04 +03:00
|
|
|
#else
|
|
|
|
(*onig_warn)((char* )buf);
|
|
|
|
#endif
|
2009-10-10 22:12:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CC_ESC_WARN(ScanEnv *env, UChar *c)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
if (onig_warn == onig_null_warn) return ;
|
|
|
|
|
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_WARN_CC_OP_NOT_ESCAPED) &&
|
|
|
|
IS_SYNTAX_BV(env->syntax, ONIG_SYN_BACKSLASH_ESCAPE_IN_CC)) {
|
2009-10-10 22:12:26 +04:00
|
|
|
onig_syntax_warn(env, "character class has '%s' without escape", c);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-07-23 13:39:30 +04:00
|
|
|
CLOSE_BRACKET_WITHOUT_ESC_WARN(ScanEnv* env, UChar* c)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
if (onig_warn == onig_null_warn) return ;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_WARN_CC_OP_NOT_ESCAPED)) {
|
|
|
|
onig_syntax_warn(env, "regular expression has '%s' without escape", c);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
#ifndef RTEST
|
|
|
|
# define RTEST(v) 1
|
|
|
|
#endif
|
|
|
|
|
2009-08-04 08:14:38 +04:00
|
|
|
static void
|
2018-10-15 15:31:22 +03:00
|
|
|
CC_DUP_WARN(ScanEnv *env, OnigCodePoint from ARG_UNUSED, OnigCodePoint to ARG_UNUSED)
|
2009-08-04 08:14:38 +04:00
|
|
|
{
|
|
|
|
if (onig_warn == onig_null_warn || !RTEST(ruby_verbose)) return ;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_WARN_CC_DUP) &&
|
|
|
|
!(env->warnings_flag & ONIG_SYN_WARN_CC_DUP)) {
|
2018-10-15 15:31:22 +03:00
|
|
|
#ifdef WARN_ALL_CC_DUP
|
|
|
|
onig_syntax_warn(env, "character class has duplicated range: %04x-%04x", from, to);
|
|
|
|
#else
|
2012-02-17 11:42:23 +04:00
|
|
|
env->warnings_flag |= ONIG_SYN_WARN_CC_DUP;
|
2009-10-10 22:12:26 +04:00
|
|
|
onig_syntax_warn(env, "character class has duplicated range");
|
2018-10-15 15:31:22 +03:00
|
|
|
#endif
|
2009-08-04 08:14:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-10 11:00:44 +04:00
|
|
|
static void
|
|
|
|
UNKNOWN_ESC_WARN(ScanEnv *env, int c)
|
|
|
|
{
|
|
|
|
if (onig_warn == onig_null_warn || !RTEST(ruby_verbose)) return ;
|
2009-10-10 22:12:26 +04:00
|
|
|
onig_syntax_warn(env, "Unknown escape \\%c is ignored", c);
|
2009-09-10 11:00:44 +04:00
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static UChar*
|
|
|
|
find_str_position(OnigCodePoint s[], int n, UChar* from, UChar* to,
|
|
|
|
UChar **next, OnigEncoding enc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
OnigCodePoint x;
|
|
|
|
UChar *q;
|
|
|
|
UChar *p = from;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
while (p < to) {
|
|
|
|
x = ONIGENC_MBC_TO_CODE(enc, p, to);
|
2008-01-03 18:55:04 +03:00
|
|
|
q = p + enclen(enc, p, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (x == s[0]) {
|
|
|
|
for (i = 1; i < n && q < to; i++) {
|
|
|
|
x = ONIGENC_MBC_TO_CODE(enc, q, to);
|
|
|
|
if (x != s[i]) break;
|
2008-01-03 18:55:04 +03:00
|
|
|
q += enclen(enc, q, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
if (i >= n) {
|
|
|
|
if (IS_NOT_NULL(next))
|
|
|
|
*next = q;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
return NULL_UCHARP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
str_exist_check_with_esc(OnigCodePoint s[], int n, UChar* from, UChar* to,
|
2008-07-01 12:21:44 +04:00
|
|
|
OnigCodePoint bad, OnigEncoding enc, const OnigSyntaxType* syn)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, in_esc;
|
|
|
|
OnigCodePoint x;
|
|
|
|
UChar *q;
|
|
|
|
UChar *p = from;
|
|
|
|
|
|
|
|
in_esc = 0;
|
|
|
|
while (p < to) {
|
|
|
|
if (in_esc) {
|
|
|
|
in_esc = 0;
|
2008-01-03 18:55:04 +03:00
|
|
|
p += enclen(enc, p, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
x = ONIGENC_MBC_TO_CODE(enc, p, to);
|
2008-01-03 18:55:04 +03:00
|
|
|
q = p + enclen(enc, p, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (x == s[0]) {
|
|
|
|
for (i = 1; i < n && q < to; i++) {
|
|
|
|
x = ONIGENC_MBC_TO_CODE(enc, q, to);
|
|
|
|
if (x != s[i]) break;
|
2008-01-03 18:55:04 +03:00
|
|
|
q += enclen(enc, q, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
if (i >= n) return 1;
|
2008-01-03 18:55:04 +03:00
|
|
|
p += enclen(enc, p, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
x = ONIGENC_MBC_TO_CODE(enc, p, to);
|
|
|
|
if (x == bad) return 0;
|
2007-05-23 05:32:08 +04:00
|
|
|
else if (x == MC_ESC(syn)) in_esc = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fetch_token_in_cc(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env)
|
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int num;
|
|
|
|
OnigCodePoint c, c2;
|
2008-07-01 12:21:44 +04:00
|
|
|
const OnigSyntaxType* syn = env->syntax;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigEncoding enc = env->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* prev;
|
|
|
|
UChar* p = *src;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH_READY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (PEND) {
|
|
|
|
tok->type = TK_EOT;
|
|
|
|
return tok->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
PFETCH(c);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
tok->type = TK_CHAR;
|
2004-03-05 18:31:51 +03:00
|
|
|
tok->base = 0;
|
|
|
|
tok->u.c = c;
|
2005-11-20 16:42:57 +03:00
|
|
|
tok->escaped = 0;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (c == ']') {
|
|
|
|
tok->type = TK_CC_CLOSE;
|
|
|
|
}
|
|
|
|
else if (c == '-') {
|
|
|
|
tok->type = TK_CC_RANGE;
|
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
else if (c == MC_ESC(syn)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (! IS_SYNTAX_BV(syn, ONIG_SYN_BACKSLASH_ESCAPE_IN_CC))
|
|
|
|
goto end;
|
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
if (PEND) return ONIGERR_END_PATTERN_AT_ESCAPE;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
PFETCH(c);
|
|
|
|
tok->escaped = 1;
|
|
|
|
tok->u.c = c;
|
|
|
|
switch (c) {
|
|
|
|
case 'w':
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_WORD;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_WORD;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_DIGIT;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_DIGIT;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_SPACE;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_SPACE;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
case 'h':
|
|
|
|
if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT;
|
|
|
|
tok->u.prop.not = 0;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT;
|
|
|
|
tok->u.prop.not = 1;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
2016-12-10 20:47:04 +03:00
|
|
|
if (PEND) break;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
c2 = PPEEK;
|
|
|
|
if (c2 == '{' &&
|
2004-03-16 18:25:28 +03:00
|
|
|
IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PINC;
|
|
|
|
tok->type = TK_CHAR_PROPERTY;
|
|
|
|
tok->u.prop.not = (c == 'P' ? 1 : 0);
|
2004-03-16 18:25:28 +03:00
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!PEND && IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) {
|
2004-03-16 18:25:28 +03:00
|
|
|
PFETCH(c2);
|
|
|
|
if (c2 == '^') {
|
|
|
|
tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PUNFETCH;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2009-10-11 05:06:30 +04:00
|
|
|
else {
|
2012-02-17 11:42:23 +04:00
|
|
|
onig_syntax_warn(env, "invalid Unicode Property \\%c", c);
|
2009-10-11 05:06:30 +04:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
|
|
|
if (PEND) break;
|
|
|
|
|
|
|
|
prev = p;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (PPEEK_IS('{') && IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_BRACE_HEX8)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PINC;
|
2012-02-17 11:42:23 +04:00
|
|
|
num = scan_unsigned_hexadecimal_number(&p, end, 0, 8, enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (num < 0) return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (!PEND) {
|
2016-12-10 20:47:04 +03:00
|
|
|
c2 = PPEEK;
|
|
|
|
if (ONIGENC_IS_CODE_XDIGIT(enc, c2))
|
|
|
|
return ONIGERR_TOO_LONG_WIDE_CHAR_VALUE;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (p > prev + enclen(enc, prev, end) && !PEND && (PPEEK_IS('}'))) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PINC;
|
|
|
|
tok->type = TK_CODE_POINT;
|
|
|
|
tok->base = 16;
|
|
|
|
tok->u.code = (OnigCodePoint )num;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* can't read nothing or invalid format */
|
|
|
|
p = prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_HEX2)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
num = scan_unsigned_hexadecimal_number(&p, end, 0, 2, enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
|
|
|
|
if (p == prev) { /* can't read nothing. */
|
|
|
|
num = 0; /* but, it's not error */
|
|
|
|
}
|
|
|
|
tok->type = TK_RAW_BYTE;
|
|
|
|
tok->base = 16;
|
|
|
|
tok->u.c = num;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
if (PEND) break;
|
|
|
|
|
|
|
|
prev = p;
|
|
|
|
if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_U_HEX4)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
num = scan_unsigned_hexadecimal_number(&p, end, 4, 4, enc);
|
|
|
|
if (num < -1) return ONIGERR_TOO_SHORT_DIGITS;
|
|
|
|
else if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (p == prev) { /* can't read nothing. */
|
|
|
|
num = 0; /* but, it's not error */
|
|
|
|
}
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
tok->type = TK_CODE_POINT;
|
|
|
|
tok->base = 16;
|
|
|
|
tok->u.code = (OnigCodePoint )num;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
case 'o':
|
|
|
|
if (PEND) break;
|
|
|
|
|
|
|
|
prev = p;
|
|
|
|
if (PPEEK_IS('{') && IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_O_BRACE_OCTAL)) {
|
|
|
|
PINC;
|
|
|
|
num = scan_unsigned_octal_number(&p, end, 11, enc);
|
|
|
|
if (num < 0) return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
|
|
|
|
if (!PEND) {
|
|
|
|
c2 = PPEEK;
|
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c2) && c2 < '8')
|
|
|
|
return ONIGERR_TOO_LONG_WIDE_CHAR_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p > prev + enclen(enc, prev, end) && !PEND && (PPEEK_IS('}'))) {
|
|
|
|
PINC;
|
|
|
|
tok->type = TK_CODE_POINT;
|
|
|
|
tok->base = 8;
|
|
|
|
tok->u.code = (OnigCodePoint )num;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* can't read nothing or invalid format */
|
|
|
|
p = prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
case '0':
|
|
|
|
case '1': case '2': case '3': case '4': case '5': case '6': case '7':
|
|
|
|
if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_OCTAL3)) {
|
|
|
|
PUNFETCH;
|
|
|
|
prev = p;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
num = scan_unsigned_octal_number(&p, end, 3, enc);
|
2016-05-25 12:45:22 +03:00
|
|
|
if (num < 0 || 0xff < num) return ONIGERR_TOO_BIG_NUMBER;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (p == prev) { /* can't read nothing. */
|
|
|
|
num = 0; /* but, it's not error */
|
|
|
|
}
|
|
|
|
tok->type = TK_RAW_BYTE;
|
|
|
|
tok->base = 8;
|
|
|
|
tok->u.c = num;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
PUNFETCH;
|
2016-12-10 20:47:04 +03:00
|
|
|
num = fetch_escaped_value(&p, end, env, &c2);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (num < 0) return num;
|
2017-02-11 18:08:33 +03:00
|
|
|
if ((OnigCodePoint )tok->u.c != c2) {
|
2016-12-10 20:47:04 +03:00
|
|
|
tok->u.code = (OnigCodePoint )c2;
|
2004-11-28 06:16:16 +03:00
|
|
|
tok->type = TK_CODE_POINT;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '[') {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_POSIX_BRACKET) && (PPEEK_IS(':'))) {
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigCodePoint send[] = { (OnigCodePoint )':', (OnigCodePoint )']' };
|
2013-04-13 15:30:35 +04:00
|
|
|
tok->backp = p; /* point at '[' is read */
|
2004-03-05 18:31:51 +03:00
|
|
|
PINC;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (str_exist_check_with_esc(send, 2, p, end,
|
2007-05-23 05:32:08 +04:00
|
|
|
(OnigCodePoint )']', enc, syn)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
tok->type = TK_POSIX_BRACKET_OPEN;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PUNFETCH;
|
|
|
|
goto cc_in_cc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cc_in_cc:
|
|
|
|
if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_CCLASS_SET_OP)) {
|
|
|
|
tok->type = TK_CC_CC_OPEN;
|
|
|
|
}
|
|
|
|
else {
|
2006-02-04 15:31:19 +03:00
|
|
|
CC_ESC_WARN(env, (UChar* )"[");
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '&') {
|
|
|
|
if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_CCLASS_SET_OP) &&
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
!PEND && (PPEEK_IS('&'))) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PINC;
|
|
|
|
tok->type = TK_CC_AND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
*src = p;
|
|
|
|
return tok->type;
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
static int
|
|
|
|
fetch_named_backref_token(OnigCodePoint c, OnigToken* tok, UChar** src,
|
|
|
|
UChar* end, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r, num;
|
|
|
|
const OnigSyntaxType* syn = env->syntax;
|
|
|
|
UChar* prev;
|
|
|
|
UChar* p = *src;
|
|
|
|
UChar* name_end;
|
|
|
|
int* backs;
|
|
|
|
int back_num;
|
|
|
|
|
|
|
|
prev = p;
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# ifdef USE_BACKREF_WITH_LEVEL
|
2012-02-17 11:42:23 +04:00
|
|
|
name_end = NULL_UCHARP; /* no need. escape gcc warning. */
|
|
|
|
r = fetch_name_with_level(c, &p, end, &name_end,
|
|
|
|
env, &back_num, &tok->u.backref.level);
|
|
|
|
if (r == 1) tok->u.backref.exist_level = 1;
|
|
|
|
else tok->u.backref.exist_level = 0;
|
2016-12-10 20:47:04 +03:00
|
|
|
# else
|
2012-02-17 11:42:23 +04:00
|
|
|
r = fetch_name(&p, end, &name_end, env, &back_num, 1);
|
2016-12-10 20:47:04 +03:00
|
|
|
# endif
|
2012-02-17 11:42:23 +04:00
|
|
|
if (r < 0) return r;
|
|
|
|
|
|
|
|
if (back_num != 0) {
|
|
|
|
if (back_num < 0) {
|
|
|
|
back_num = BACKREF_REL_TO_ABS(back_num, env);
|
|
|
|
if (back_num <= 0)
|
|
|
|
return ONIGERR_INVALID_BACKREF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_SYNTAX_BV(syn, ONIG_SYN_STRICT_CHECK_BACKREF)) {
|
|
|
|
if (back_num > env->num_mem ||
|
|
|
|
IS_NULL(SCANENV_MEM_NODES(env)[back_num]))
|
|
|
|
return ONIGERR_INVALID_BACKREF;
|
|
|
|
}
|
|
|
|
tok->type = TK_BACKREF;
|
|
|
|
tok->u.backref.by_name = 0;
|
|
|
|
tok->u.backref.num = 1;
|
|
|
|
tok->u.backref.ref1 = back_num;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
num = onig_name_to_group_numbers(env->reg, prev, name_end, &backs);
|
|
|
|
if (num <= 0) {
|
|
|
|
onig_scan_env_set_error_string(env,
|
|
|
|
ONIGERR_UNDEFINED_NAME_REFERENCE, prev, name_end);
|
|
|
|
return ONIGERR_UNDEFINED_NAME_REFERENCE;
|
|
|
|
}
|
|
|
|
if (IS_SYNTAX_BV(syn, ONIG_SYN_STRICT_CHECK_BACKREF)) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
if (backs[i] > env->num_mem ||
|
|
|
|
IS_NULL(SCANENV_MEM_NODES(env)[backs[i]]))
|
|
|
|
return ONIGERR_INVALID_BACKREF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tok->type = TK_BACKREF;
|
|
|
|
tok->u.backref.by_name = 1;
|
2016-12-10 20:47:04 +03:00
|
|
|
if (num == 1 || IS_SYNTAX_BV(syn, ONIG_SYN_USE_LEFT_MOST_NAMED_GROUP)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.backref.num = 1;
|
|
|
|
tok->u.backref.ref1 = backs[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tok->u.backref.num = num;
|
|
|
|
tok->u.backref.refs = backs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*src = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
|
|
|
fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env)
|
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int r, num;
|
|
|
|
OnigCodePoint c;
|
|
|
|
OnigEncoding enc = env->enc;
|
2008-07-01 12:21:44 +04:00
|
|
|
const OnigSyntaxType* syn = env->syntax;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* prev;
|
|
|
|
UChar* p = *src;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH_READY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
start:
|
|
|
|
if (PEND) {
|
|
|
|
tok->type = TK_EOT;
|
|
|
|
return tok->type;
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
tok->type = TK_STRING;
|
|
|
|
tok->base = 0;
|
|
|
|
tok->backp = p;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
PFETCH(c);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (IS_MC_ESC_CODE(c, syn)) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
if (PEND) return ONIGERR_END_PATTERN_AT_ESCAPE;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
tok->backp = p;
|
2004-03-05 18:31:51 +03:00
|
|
|
PFETCH(c);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
tok->u.c = c;
|
|
|
|
tok->escaped = 1;
|
|
|
|
switch (c) {
|
|
|
|
case '*':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF)) break;
|
|
|
|
tok->type = TK_OP_REPEAT;
|
|
|
|
tok->u.repeat.lower = 0;
|
|
|
|
tok->u.repeat.upper = REPEAT_INFINITE;
|
|
|
|
goto greedy_check;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_PLUS_ONE_INF)) break;
|
|
|
|
tok->type = TK_OP_REPEAT;
|
|
|
|
tok->u.repeat.lower = 1;
|
|
|
|
tok->u.repeat.upper = REPEAT_INFINITE;
|
|
|
|
goto greedy_check;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_QMARK_ZERO_ONE)) break;
|
|
|
|
tok->type = TK_OP_REPEAT;
|
|
|
|
tok->u.repeat.lower = 0;
|
|
|
|
tok->u.repeat.upper = 1;
|
|
|
|
greedy_check:
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (!PEND && PPEEK_IS('?') &&
|
2004-03-05 18:31:51 +03:00
|
|
|
IS_SYNTAX_OP(syn, ONIG_SYN_OP_QMARK_NON_GREEDY)) {
|
|
|
|
PFETCH(c);
|
|
|
|
tok->u.repeat.greedy = 0;
|
|
|
|
tok->u.repeat.possessive = 0;
|
|
|
|
}
|
|
|
|
else {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
possessive_check:
|
|
|
|
if (!PEND && PPEEK_IS('+') &&
|
|
|
|
((IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT) &&
|
|
|
|
tok->type != TK_INTERVAL) ||
|
|
|
|
(IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL) &&
|
|
|
|
tok->type == TK_INTERVAL))) {
|
|
|
|
PFETCH(c);
|
|
|
|
tok->u.repeat.greedy = 1;
|
|
|
|
tok->u.repeat.possessive = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tok->u.repeat.greedy = 1;
|
|
|
|
tok->u.repeat.possessive = 0;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '{':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_BRACE_INTERVAL)) break;
|
2007-05-23 05:32:08 +04:00
|
|
|
r = fetch_range_quantifier(&p, end, tok, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) return r; /* error */
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (r == 0) goto greedy_check;
|
|
|
|
else if (r == 2) { /* {n} */
|
|
|
|
if (IS_SYNTAX_BV(syn, ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY))
|
|
|
|
goto possessive_check;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
goto greedy_check;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
/* r == 1 : normal char */
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '|':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_VBAR_ALT)) break;
|
|
|
|
tok->type = TK_ALT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '(':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LPAREN_SUBEXP)) break;
|
|
|
|
tok->type = TK_SUBEXP_OPEN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ')':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LPAREN_SUBEXP)) break;
|
|
|
|
tok->type = TK_SUBEXP_CLOSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_W_WORD)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_WORD;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'W':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_W_WORD)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_WORD;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_B_WORD_BOUND)) break;
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = ANCHOR_WORD_BOUND;
|
|
|
|
tok->u.anchor.ascii_range = IS_ASCII_RANGE(env->option)
|
|
|
|
&& ! IS_WORD_BOUND_ALL_RANGE(env->option);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'B':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_B_WORD_BOUND)) break;
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = ANCHOR_NOT_WORD_BOUND;
|
|
|
|
tok->u.anchor.ascii_range = IS_ASCII_RANGE(env->option)
|
|
|
|
&& ! IS_WORD_BOUND_ALL_RANGE(env->option);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_WORD_BEGIN_END
|
|
|
|
case '<':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END)) break;
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = ANCHOR_WORD_BEGIN;
|
|
|
|
tok->u.anchor.ascii_range = IS_ASCII_RANGE(env->option);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '>':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END)) break;
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = ANCHOR_WORD_END;
|
|
|
|
tok->u.anchor.ascii_range = IS_ASCII_RANGE(env->option);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_S_WHITE_SPACE)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_SPACE;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_S_WHITE_SPACE)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_SPACE;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_D_DIGIT)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_DIGIT;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_D_DIGIT)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_DIGIT;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.not = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
case 'h':
|
|
|
|
if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT;
|
|
|
|
tok->u.prop.not = 0;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'H':
|
|
|
|
if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
|
|
|
|
tok->type = TK_CHAR_TYPE;
|
2007-05-23 05:32:08 +04:00
|
|
|
tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT;
|
|
|
|
tok->u.prop.not = 1;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
case 'A':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break;
|
|
|
|
begin_buf:
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = ANCHOR_BEGIN_BUF;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Z':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break;
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = ANCHOR_SEMI_END_BUF;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'z':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break;
|
|
|
|
end_buf:
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = ANCHOR_END_BUF;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'G':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR)) break;
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = ANCHOR_BEGIN_POSITION;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '`':
|
|
|
|
if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR)) break;
|
|
|
|
goto begin_buf;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\'':
|
|
|
|
if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR)) break;
|
|
|
|
goto end_buf;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
|
|
|
if (PEND) break;
|
|
|
|
|
|
|
|
prev = p;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (PPEEK_IS('{') && IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_BRACE_HEX8)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PINC;
|
2012-02-17 11:42:23 +04:00
|
|
|
num = scan_unsigned_hexadecimal_number(&p, end, 0, 8, enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (num < 0) return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (!PEND) {
|
2016-12-10 20:47:04 +03:00
|
|
|
if (ONIGENC_IS_CODE_XDIGIT(enc, PPEEK))
|
|
|
|
return ONIGERR_TOO_LONG_WIDE_CHAR_VALUE;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if ((p > prev + enclen(enc, prev, end)) && !PEND && PPEEK_IS('}')) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PINC;
|
|
|
|
tok->type = TK_CODE_POINT;
|
|
|
|
tok->u.code = (OnigCodePoint )num;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* can't read nothing or invalid format */
|
|
|
|
p = prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_HEX2)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
num = scan_unsigned_hexadecimal_number(&p, end, 0, 2, enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
|
|
|
|
if (p == prev) { /* can't read nothing. */
|
|
|
|
num = 0; /* but, it's not error */
|
|
|
|
}
|
|
|
|
tok->type = TK_RAW_BYTE;
|
|
|
|
tok->base = 16;
|
|
|
|
tok->u.c = num;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
if (PEND) break;
|
|
|
|
|
|
|
|
prev = p;
|
|
|
|
if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_U_HEX4)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
num = scan_unsigned_hexadecimal_number(&p, end, 4, 4, enc);
|
|
|
|
if (num < -1) return ONIGERR_TOO_SHORT_DIGITS;
|
|
|
|
else if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (p == prev) { /* can't read nothing. */
|
|
|
|
num = 0; /* but, it's not error */
|
|
|
|
}
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
tok->type = TK_CODE_POINT;
|
|
|
|
tok->base = 16;
|
|
|
|
tok->u.code = (OnigCodePoint )num;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
case 'o':
|
|
|
|
if (PEND) break;
|
|
|
|
|
|
|
|
prev = p;
|
|
|
|
if (PPEEK_IS('{') && IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_O_BRACE_OCTAL)) {
|
|
|
|
PINC;
|
|
|
|
num = scan_unsigned_octal_number(&p, end, 11, enc);
|
|
|
|
if (num < 0) return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
|
|
|
|
if (!PEND) {
|
|
|
|
OnigCodePoint c = PPEEK;
|
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c) && c < '8')
|
|
|
|
return ONIGERR_TOO_LONG_WIDE_CHAR_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p > prev + enclen(enc, prev, end)) && !PEND && PPEEK_IS('}')) {
|
|
|
|
PINC;
|
|
|
|
tok->type = TK_CODE_POINT;
|
|
|
|
tok->u.code = (OnigCodePoint )num;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* can't read nothing or invalid format */
|
|
|
|
p = prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
|
|
|
PUNFETCH;
|
|
|
|
prev = p;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
num = onig_scan_unsigned_number(&p, end, enc);
|
|
|
|
if (num < 0 || num > ONIG_MAX_BACKREF_NUM) {
|
2016-12-10 20:47:04 +03:00
|
|
|
goto skip_backref;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2009-02-22 17:23:33 +03:00
|
|
|
if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_DECIMAL_BACKREF) &&
|
2004-03-05 18:31:51 +03:00
|
|
|
(num <= env->num_mem || num <= 9)) { /* This spec. from GNU regex */
|
|
|
|
if (IS_SYNTAX_BV(syn, ONIG_SYN_STRICT_CHECK_BACKREF)) {
|
|
|
|
if (num > env->num_mem || IS_NULL(SCANENV_MEM_NODES(env)[num]))
|
|
|
|
return ONIGERR_INVALID_BACKREF;
|
|
|
|
}
|
|
|
|
|
|
|
|
tok->type = TK_BACKREF;
|
|
|
|
tok->u.backref.num = 1;
|
|
|
|
tok->u.backref.ref1 = num;
|
|
|
|
tok->u.backref.by_name = 0;
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
tok->u.backref.exist_level = 0;
|
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
|
|
|
skip_backref:
|
|
|
|
if (c == '8' || c == '9') {
|
2004-03-05 18:31:51 +03:00
|
|
|
/* normal char */
|
|
|
|
p = prev; PINC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = prev;
|
|
|
|
/* fall through */
|
|
|
|
case '0':
|
|
|
|
if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_OCTAL3)) {
|
|
|
|
prev = p;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
num = scan_unsigned_octal_number(&p, end, (c == '0' ? 2:3), enc);
|
2017-12-01 16:50:13 +03:00
|
|
|
if (num < 0 || 0xff < num) return ONIGERR_TOO_BIG_NUMBER;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (p == prev) { /* can't read nothing. */
|
|
|
|
num = 0; /* but, it's not error */
|
|
|
|
}
|
|
|
|
tok->type = TK_RAW_BYTE;
|
|
|
|
tok->base = 8;
|
|
|
|
tok->u.c = num;
|
|
|
|
}
|
|
|
|
else if (c != '0') {
|
|
|
|
PINC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
case 'k':
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!PEND && IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_K_NAMED_BACKREF)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PFETCH(c);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (c == '<' || c == '\'') {
|
2012-02-17 11:42:23 +04:00
|
|
|
r = fetch_named_backref_token(c, tok, &p, end, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) return r;
|
|
|
|
}
|
2009-10-12 00:52:51 +04:00
|
|
|
else {
|
2012-02-17 11:42:23 +04:00
|
|
|
PUNFETCH;
|
|
|
|
onig_syntax_warn(env, "invalid back reference");
|
2009-10-12 00:52:51 +04:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
#if defined(USE_SUBEXP_CALL) || defined(USE_NAMED_GROUP)
|
2004-03-05 18:31:51 +03:00
|
|
|
case 'g':
|
2016-12-10 20:47:04 +03:00
|
|
|
# ifdef USE_NAMED_GROUP
|
|
|
|
if (!PEND && IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_G_BRACE_BACKREF)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
PFETCH(c);
|
|
|
|
if (c == '{') {
|
|
|
|
r = fetch_named_backref_token(c, tok, &p, end, env);
|
|
|
|
if (r < 0) return r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PUNFETCH;
|
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
# endif
|
|
|
|
# ifdef USE_SUBEXP_CALL
|
|
|
|
if (!PEND && IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_G_SUBEXP_CALL)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PFETCH(c);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (c == '<' || c == '\'') {
|
2012-02-17 11:42:23 +04:00
|
|
|
int gnum = -1, rel = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* name_end;
|
2012-02-17 11:42:23 +04:00
|
|
|
OnigCodePoint cnext;
|
|
|
|
|
|
|
|
cnext = PPEEK;
|
|
|
|
if (cnext == '0') {
|
|
|
|
PINC;
|
2012-02-22 06:03:56 +04:00
|
|
|
if (PPEEK_IS(get_name_end_code_point(c))) { /* \g<0>, \g'0' */
|
2012-02-17 11:42:23 +04:00
|
|
|
PINC;
|
|
|
|
name_end = p;
|
|
|
|
gnum = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cnext == '+') {
|
|
|
|
PINC;
|
|
|
|
rel = 1;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
prev = p;
|
2012-02-17 11:42:23 +04:00
|
|
|
if (gnum < 0) {
|
|
|
|
r = fetch_name((OnigCodePoint )c, &p, end, &name_end, env, &gnum, 1);
|
|
|
|
if (r < 0) return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
tok->type = TK_CALL;
|
|
|
|
tok->u.call.name = prev;
|
|
|
|
tok->u.call.name_end = name_end;
|
2008-01-03 18:55:04 +03:00
|
|
|
tok->u.call.gnum = gnum;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.call.rel = rel;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2009-10-12 00:52:51 +04:00
|
|
|
else {
|
2012-02-17 11:42:23 +04:00
|
|
|
onig_syntax_warn(env, "invalid subexp call");
|
|
|
|
PUNFETCH;
|
2009-10-12 00:52:51 +04:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
# endif
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case 'Q':
|
|
|
|
if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE)) {
|
|
|
|
tok->type = TK_QUOTE_OPEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (PPEEK_IS('{') &&
|
2004-03-16 18:25:28 +03:00
|
|
|
IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PINC;
|
|
|
|
tok->type = TK_CHAR_PROPERTY;
|
|
|
|
tok->u.prop.not = (c == 'P' ? 1 : 0);
|
2004-03-16 18:25:28 +03:00
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!PEND && IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH(c);
|
|
|
|
if (c == '^') {
|
2004-03-16 18:25:28 +03:00
|
|
|
tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PUNFETCH;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2009-10-11 05:06:30 +04:00
|
|
|
else {
|
2012-02-17 11:42:23 +04:00
|
|
|
onig_syntax_warn(env, "invalid Unicode Property \\%c", c);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'R':
|
|
|
|
if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_CAPITAL_R_LINEBREAK)) {
|
|
|
|
tok->type = TK_LINEBREAK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_CAPITAL_X_EXTENDED_GRAPHEME_CLUSTER)) {
|
|
|
|
tok->type = TK_EXTENDED_GRAPHEME_CLUSTER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'K':
|
|
|
|
if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_CAPITAL_K_KEEP)) {
|
|
|
|
tok->type = TK_KEEP;
|
2009-10-11 05:06:30 +04:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-12-10 20:47:04 +03:00
|
|
|
{
|
|
|
|
OnigCodePoint c2;
|
|
|
|
|
|
|
|
PUNFETCH;
|
|
|
|
num = fetch_escaped_value(&p, end, env, &c2);
|
|
|
|
if (num < 0) return num;
|
|
|
|
/* set_raw: */
|
2017-02-11 18:08:33 +03:00
|
|
|
if ((OnigCodePoint )tok->u.c != c2) {
|
2016-12-10 20:47:04 +03:00
|
|
|
tok->type = TK_CODE_POINT;
|
|
|
|
tok->u.code = (OnigCodePoint )c2;
|
|
|
|
}
|
|
|
|
else { /* string */
|
|
|
|
p = tok->backp + enclen(enc, tok->backp, end);
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tok->u.c = c;
|
|
|
|
tok->escaped = 0;
|
|
|
|
|
|
|
|
#ifdef USE_VARIABLE_META_CHARS
|
|
|
|
if ((c != ONIG_INEFFECTIVE_META_CHAR) &&
|
|
|
|
IS_SYNTAX_OP(syn, ONIG_SYN_OP_VARIABLE_META_CHARACTERS)) {
|
2007-05-23 05:32:08 +04:00
|
|
|
if (c == MC_ANYCHAR(syn))
|
2004-03-05 18:31:51 +03:00
|
|
|
goto any_char;
|
2007-05-23 05:32:08 +04:00
|
|
|
else if (c == MC_ANYTIME(syn))
|
2004-03-05 18:31:51 +03:00
|
|
|
goto anytime;
|
2007-05-23 05:32:08 +04:00
|
|
|
else if (c == MC_ZERO_OR_ONE_TIME(syn))
|
2004-03-05 18:31:51 +03:00
|
|
|
goto zero_or_one_time;
|
2007-05-23 05:32:08 +04:00
|
|
|
else if (c == MC_ONE_OR_MORE_TIME(syn))
|
2004-03-05 18:31:51 +03:00
|
|
|
goto one_or_more_time;
|
2007-05-23 05:32:08 +04:00
|
|
|
else if (c == MC_ANYCHAR_ANYTIME(syn)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
tok->type = TK_ANYCHAR_ANYTIME;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '.':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_DOT_ANYCHAR)) break;
|
2005-06-28 19:06:03 +04:00
|
|
|
#ifdef USE_VARIABLE_META_CHARS
|
2004-03-05 18:31:51 +03:00
|
|
|
any_char:
|
2005-06-28 19:06:03 +04:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
tok->type = TK_ANYCHAR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '*':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ASTERISK_ZERO_INF)) break;
|
2005-06-28 19:06:03 +04:00
|
|
|
#ifdef USE_VARIABLE_META_CHARS
|
2004-03-05 18:31:51 +03:00
|
|
|
anytime:
|
2005-06-28 19:06:03 +04:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
tok->type = TK_OP_REPEAT;
|
|
|
|
tok->u.repeat.lower = 0;
|
|
|
|
tok->u.repeat.upper = REPEAT_INFINITE;
|
|
|
|
goto greedy_check;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_PLUS_ONE_INF)) break;
|
2005-06-28 19:06:03 +04:00
|
|
|
#ifdef USE_VARIABLE_META_CHARS
|
2004-03-05 18:31:51 +03:00
|
|
|
one_or_more_time:
|
2005-06-28 19:06:03 +04:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
tok->type = TK_OP_REPEAT;
|
|
|
|
tok->u.repeat.lower = 1;
|
|
|
|
tok->u.repeat.upper = REPEAT_INFINITE;
|
|
|
|
goto greedy_check;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_QMARK_ZERO_ONE)) break;
|
2005-06-28 19:06:03 +04:00
|
|
|
#ifdef USE_VARIABLE_META_CHARS
|
2004-03-05 18:31:51 +03:00
|
|
|
zero_or_one_time:
|
2005-06-28 19:06:03 +04:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
tok->type = TK_OP_REPEAT;
|
|
|
|
tok->u.repeat.lower = 0;
|
|
|
|
tok->u.repeat.upper = 1;
|
|
|
|
goto greedy_check;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '{':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_BRACE_INTERVAL)) break;
|
2007-05-23 05:32:08 +04:00
|
|
|
r = fetch_range_quantifier(&p, end, tok, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) return r; /* error */
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (r == 0) goto greedy_check;
|
|
|
|
else if (r == 2) { /* {n} */
|
|
|
|
if (IS_SYNTAX_BV(syn, ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY))
|
|
|
|
goto possessive_check;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
goto greedy_check;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
/* r == 1 : normal char */
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '|':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_VBAR_ALT)) break;
|
|
|
|
tok->type = TK_ALT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '(':
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (PPEEK_IS('?') &&
|
2016-12-10 20:47:04 +03:00
|
|
|
IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_QMARK_GROUP_EFFECT)) {
|
|
|
|
PINC;
|
|
|
|
if (PPEEK_IS('#')) {
|
|
|
|
PFETCH(c);
|
|
|
|
while (1) {
|
|
|
|
if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
|
|
|
|
PFETCH(c);
|
|
|
|
if (c == MC_ESC(syn)) {
|
|
|
|
if (!PEND) PFETCH(c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (c == ')') break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto start;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
#ifdef USE_PERL_SUBEXP_CALL
|
|
|
|
/* (?&name), (?n), (?R), (?0), (?+n), (?-n) */
|
|
|
|
c = PPEEK;
|
|
|
|
if ((c == '&' || c == 'R' || ONIGENC_IS_CODE_DIGIT(enc, c)) &&
|
|
|
|
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_SUBEXP_CALL)) {
|
|
|
|
/* (?&name), (?n), (?R), (?0) */
|
|
|
|
int gnum;
|
|
|
|
UChar *name;
|
|
|
|
UChar *name_end;
|
|
|
|
|
|
|
|
if (c == 'R' || c == '0') {
|
|
|
|
PINC; /* skip 'R' / '0' */
|
|
|
|
if (!PPEEK_IS(')')) return ONIGERR_INVALID_GROUP_NAME;
|
|
|
|
PINC; /* skip ')' */
|
|
|
|
name_end = name = p;
|
|
|
|
gnum = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int numref = 1;
|
|
|
|
if (c == '&') { /* (?&name) */
|
|
|
|
PINC;
|
|
|
|
numref = 0; /* don't allow number name */
|
|
|
|
}
|
|
|
|
name = p;
|
|
|
|
r = fetch_name((OnigCodePoint )'(', &p, end, &name_end, env, &gnum, numref);
|
|
|
|
if (r < 0) return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
tok->type = TK_CALL;
|
|
|
|
tok->u.call.name = name;
|
|
|
|
tok->u.call.name_end = name_end;
|
|
|
|
tok->u.call.gnum = gnum;
|
|
|
|
tok->u.call.rel = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if ((c == '-' || c == '+') &&
|
|
|
|
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_SUBEXP_CALL)) {
|
|
|
|
/* (?+n), (?-n) */
|
|
|
|
int gnum;
|
|
|
|
UChar *name;
|
|
|
|
UChar *name_end;
|
|
|
|
OnigCodePoint cnext;
|
|
|
|
PFETCH_READY;
|
|
|
|
|
|
|
|
PINC; /* skip '-' / '+' */
|
|
|
|
cnext = PPEEK;
|
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, cnext)) {
|
|
|
|
if (c == '-') PUNFETCH;
|
|
|
|
name = p;
|
|
|
|
r = fetch_name((OnigCodePoint )'(', &p, end, &name_end, env, &gnum, 1);
|
|
|
|
if (r < 0) return r;
|
|
|
|
|
|
|
|
tok->type = TK_CALL;
|
|
|
|
tok->u.call.name = name;
|
|
|
|
tok->u.call.name_end = name_end;
|
|
|
|
tok->u.call.gnum = gnum;
|
|
|
|
tok->u.call.rel = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* USE_PERL_SUBEXP_CALL */
|
|
|
|
#ifdef USE_CAPITAL_P_NAMED_GROUP
|
|
|
|
if (PPEEK_IS('P') &&
|
|
|
|
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_CAPITAL_P_NAMED_GROUP)) {
|
|
|
|
int gnum;
|
|
|
|
UChar *name;
|
|
|
|
UChar *name_end;
|
|
|
|
PFETCH_READY;
|
|
|
|
|
|
|
|
PINC; /* skip 'P' */
|
2016-12-10 20:47:04 +03:00
|
|
|
if (PEND) return ONIGERR_UNDEFINED_GROUP_OPTION;
|
2012-02-17 11:42:23 +04:00
|
|
|
PFETCH(c);
|
|
|
|
if (c == '=') { /* (?P=name): backref */
|
|
|
|
r = fetch_named_backref_token((OnigCodePoint )'(', tok, &p, end, env);
|
|
|
|
if (r < 0) return r;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (c == '>') { /* (?P>name): subexp call */
|
|
|
|
name = p;
|
|
|
|
r = fetch_name((OnigCodePoint )'(', &p, end, &name_end, env, &gnum, 0);
|
|
|
|
if (r < 0) return r;
|
|
|
|
|
|
|
|
tok->type = TK_CALL;
|
|
|
|
tok->u.call.name = name;
|
|
|
|
tok->u.call.name_end = name_end;
|
|
|
|
tok->u.call.gnum = gnum;
|
|
|
|
tok->u.call.rel = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* USE_CAPITAL_P_NAMED_GROUP */
|
2016-12-10 20:47:04 +03:00
|
|
|
PUNFETCH;
|
2004-04-05 14:40:54 +04:00
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LPAREN_SUBEXP)) break;
|
|
|
|
tok->type = TK_SUBEXP_OPEN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ')':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LPAREN_SUBEXP)) break;
|
|
|
|
tok->type = TK_SUBEXP_CLOSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '^':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break;
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = (IS_SINGLELINE(env->option)
|
|
|
|
? ANCHOR_BEGIN_BUF : ANCHOR_BEGIN_LINE);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '$':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break;
|
|
|
|
tok->type = TK_ANCHOR;
|
2012-02-17 11:42:23 +04:00
|
|
|
tok->u.anchor.subtype = (IS_SINGLELINE(env->option)
|
|
|
|
? ANCHOR_SEMI_END_BUF : ANCHOR_END_LINE);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_BRACKET_CC)) break;
|
|
|
|
tok->type = TK_CC_OPEN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ']':
|
|
|
|
if (*src > env->pattern) /* /].../ is allowed. */
|
2007-07-23 13:39:30 +04:00
|
|
|
CLOSE_BRACKET_WITHOUT_ESC_WARN(env, (UChar* )"]");
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '#':
|
|
|
|
if (IS_EXTEND(env->option)) {
|
|
|
|
while (!PEND) {
|
|
|
|
PFETCH(c);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (ONIGENC_IS_CODE_NEWLINE(enc, c))
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ' ': case '\t': case '\n': case '\r': case '\f':
|
|
|
|
if (IS_EXTEND(env->option))
|
|
|
|
goto start;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
/* string */
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-28 19:06:03 +04:00
|
|
|
#ifdef USE_VARIABLE_META_CHARS
|
2004-03-05 18:31:51 +03:00
|
|
|
out:
|
2005-06-28 19:06:03 +04:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
*src = p;
|
|
|
|
return tok->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-01-03 18:55:04 +03:00
|
|
|
add_ctype_to_cc_by_range(CClassNode* cc, int ctype ARG_UNUSED, int not,
|
2009-08-04 08:14:38 +04:00
|
|
|
ScanEnv* env,
|
2007-05-23 05:32:08 +04:00
|
|
|
OnigCodePoint sb_out, const OnigCodePoint mbr[])
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int i, r;
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigCodePoint j;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
int n = ONIGENC_CODE_RANGE_NUM(mbr);
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (not == 0) {
|
2007-05-23 05:32:08 +04:00
|
|
|
for (i = 0; i < n; i++) {
|
2016-12-10 20:47:04 +03:00
|
|
|
for (j = ONIGENC_CODE_RANGE_FROM(mbr, i);
|
|
|
|
j <= ONIGENC_CODE_RANGE_TO(mbr, i); j++) {
|
2007-05-23 05:32:08 +04:00
|
|
|
if (j >= sb_out) {
|
2009-08-15 20:27:13 +04:00
|
|
|
if (j > ONIGENC_CODE_RANGE_FROM(mbr, i)) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = add_code_range_to_buf(&(cc->mbuf), env, j,
|
2007-05-23 05:32:08 +04:00
|
|
|
ONIGENC_CODE_RANGE_TO(mbr, i));
|
|
|
|
if (r != 0) return r;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto sb_end;
|
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, j);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
sb_end:
|
|
|
|
for ( ; i < n; i++) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = add_code_range_to_buf(&(cc->mbuf), env,
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
ONIGENC_CODE_RANGE_FROM(mbr, i),
|
|
|
|
ONIGENC_CODE_RANGE_TO(mbr, i));
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
OnigCodePoint prev = 0;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
for (j = prev;
|
|
|
|
j < ONIGENC_CODE_RANGE_FROM(mbr, i); j++) {
|
|
|
|
if (j >= sb_out) {
|
|
|
|
goto sb_end2;
|
|
|
|
}
|
2009-08-04 08:14:38 +04:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, j);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
prev = ONIGENC_CODE_RANGE_TO(mbr, i) + 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
for (j = prev; j < sb_out; j++) {
|
2009-08-04 08:14:38 +04:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, j);
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sb_end2:
|
|
|
|
prev = sb_out;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
for (i = 0; i < n; i++) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
if (prev < ONIGENC_CODE_RANGE_FROM(mbr, i)) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = add_code_range_to_buf(&(cc->mbuf), env, prev,
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
ONIGENC_CODE_RANGE_FROM(mbr, i) - 1);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
prev = ONIGENC_CODE_RANGE_TO(mbr, i) + 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
if (prev < 0x7fffffff) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = add_code_range_to_buf(&(cc->mbuf), env, prev, 0x7fffffff);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
return 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-15 20:18:41 +04:00
|
|
|
add_ctype_to_cc(CClassNode* cc, int ctype, int not, int ascii_range, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2014-09-15 20:18:41 +04:00
|
|
|
int maxcode;
|
2004-03-05 18:31:51 +03:00
|
|
|
int c, r;
|
2007-05-23 05:32:08 +04:00
|
|
|
const OnigCodePoint *ranges;
|
|
|
|
OnigCodePoint sb_out;
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigEncoding enc = env->enc;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
r = ONIGENC_GET_CTYPE_CODE_RANGE(enc, ctype, &sb_out, &ranges);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (r == 0) {
|
2013-03-01 20:36:37 +04:00
|
|
|
if (ascii_range) {
|
|
|
|
CClassNode ccwork;
|
|
|
|
initialize_cclass(&ccwork);
|
|
|
|
r = add_ctype_to_cc_by_range(&ccwork, ctype, not, env, sb_out,
|
|
|
|
ranges);
|
|
|
|
if (r == 0) {
|
|
|
|
if (not) {
|
|
|
|
r = add_code_range_to_buf0(&(ccwork.mbuf), env, 0x80, ONIG_LAST_CODE_POINT, FALSE);
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-01 20:36:37 +04:00
|
|
|
CClassNode ccascii;
|
|
|
|
initialize_cclass(&ccascii);
|
|
|
|
if (ONIGENC_MBC_MINLEN(env->enc) > 1) {
|
2016-12-10 20:47:04 +03:00
|
|
|
r = add_code_range(&(ccascii.mbuf), env, 0x00, 0x7F);
|
2013-03-01 20:36:37 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
bitset_set_range(env, ccascii.bs, 0x00, 0x7F);
|
2016-12-10 20:47:04 +03:00
|
|
|
r = 0;
|
|
|
|
}
|
|
|
|
if (r == 0) {
|
|
|
|
r = and_cclass(&ccwork, &ccascii, env);
|
2013-03-01 20:36:37 +04:00
|
|
|
}
|
|
|
|
if (IS_NOT_NULL(ccascii.mbuf)) bbuf_free(ccascii.mbuf);
|
|
|
|
}
|
|
|
|
if (r == 0) {
|
|
|
|
r = or_cclass(cc, &ccwork, env);
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
2013-03-01 20:36:37 +04:00
|
|
|
if (IS_NOT_NULL(ccwork.mbuf)) bbuf_free(ccwork.mbuf);
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-01 20:36:37 +04:00
|
|
|
else {
|
|
|
|
r = add_ctype_to_cc_by_range(cc, ctype, not, env, sb_out, ranges);
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
return r;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
else if (r != ONIG_NO_SUPPORT_CONFIG) {
|
2004-03-05 18:31:51 +03:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
maxcode = ascii_range ? 0x80 : SINGLE_BYTE_SIZE;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = 0;
|
|
|
|
switch (ctype) {
|
|
|
|
case ONIGENC_CTYPE_ALPHA:
|
|
|
|
case ONIGENC_CTYPE_BLANK:
|
|
|
|
case ONIGENC_CTYPE_CNTRL:
|
|
|
|
case ONIGENC_CTYPE_DIGIT:
|
|
|
|
case ONIGENC_CTYPE_LOWER:
|
|
|
|
case ONIGENC_CTYPE_PUNCT:
|
|
|
|
case ONIGENC_CTYPE_SPACE:
|
|
|
|
case ONIGENC_CTYPE_UPPER:
|
|
|
|
case ONIGENC_CTYPE_XDIGIT:
|
|
|
|
case ONIGENC_CTYPE_ASCII:
|
|
|
|
case ONIGENC_CTYPE_ALNUM:
|
|
|
|
if (not != 0) {
|
|
|
|
for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
|
|
|
|
if (! ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
|
2009-08-04 08:14:38 +04:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, c);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
|
|
|
|
if (ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
|
2009-08-04 08:14:38 +04:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, c);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ONIGENC_CTYPE_GRAPH:
|
|
|
|
case ONIGENC_CTYPE_PRINT:
|
|
|
|
if (not != 0) {
|
|
|
|
for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
|
2012-02-17 11:42:23 +04:00
|
|
|
if (! ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype)
|
|
|
|
|| c >= maxcode)
|
2009-08-04 08:14:38 +04:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, c);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
if (ascii_range)
|
2016-12-10 20:47:04 +03:00
|
|
|
ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
2012-02-17 11:42:23 +04:00
|
|
|
for (c = 0; c < maxcode; c++) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
|
2009-08-04 08:14:38 +04:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, c);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
if (! ascii_range)
|
2016-12-10 20:47:04 +03:00
|
|
|
ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ONIGENC_CTYPE_WORD:
|
|
|
|
if (not == 0) {
|
2012-02-17 11:42:23 +04:00
|
|
|
for (c = 0; c < maxcode; c++) {
|
|
|
|
if (ONIGENC_IS_CODE_WORD(enc, c)) BITSET_SET_BIT_CHKDUP(cc->bs, c);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
if (! ascii_range)
|
2016-12-10 20:47:04 +03:00
|
|
|
ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
|
2016-12-10 20:47:04 +03:00
|
|
|
if ((ONIGENC_CODE_TO_MBCLEN(enc, c) > 0) /* check invalid code point */
|
2012-02-17 11:42:23 +04:00
|
|
|
&& (! ONIGENC_IS_CODE_WORD(enc, c) || c >= maxcode))
|
2009-08-04 08:14:38 +04:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, c);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
if (ascii_range)
|
2016-12-10 20:47:04 +03:00
|
|
|
ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ONIGERR_PARSER_BUG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-15 20:18:41 +04:00
|
|
|
parse_posix_bracket(CClassNode* cc, CClassNode* asc_cc,
|
|
|
|
UChar** src, UChar* end, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
#define POSIX_BRACKET_CHECK_LIMIT_LENGTH 20
|
2007-05-23 05:32:08 +04:00
|
|
|
#define POSIX_BRACKET_NAME_MIN_LEN 4
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-07-01 12:21:44 +04:00
|
|
|
static const PosixBracketEntryType PBS[] = {
|
2014-09-15 20:18:41 +04:00
|
|
|
POSIX_BRACKET_ENTRY_INIT("alnum", ONIGENC_CTYPE_ALNUM),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("alpha", ONIGENC_CTYPE_ALPHA),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("blank", ONIGENC_CTYPE_BLANK),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("cntrl", ONIGENC_CTYPE_CNTRL),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("digit", ONIGENC_CTYPE_DIGIT),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("graph", ONIGENC_CTYPE_GRAPH),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("lower", ONIGENC_CTYPE_LOWER),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("print", ONIGENC_CTYPE_PRINT),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("punct", ONIGENC_CTYPE_PUNCT),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("space", ONIGENC_CTYPE_SPACE),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("upper", ONIGENC_CTYPE_UPPER),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("xdigit", ONIGENC_CTYPE_XDIGIT),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("ascii", ONIGENC_CTYPE_ASCII),
|
|
|
|
POSIX_BRACKET_ENTRY_INIT("word", ONIGENC_CTYPE_WORD),
|
2004-03-05 18:31:51 +03:00
|
|
|
};
|
|
|
|
|
2008-07-01 12:21:44 +04:00
|
|
|
const PosixBracketEntryType *pb;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int not, i, r;
|
2014-09-15 20:18:41 +04:00
|
|
|
int ascii_range;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint c;
|
|
|
|
OnigEncoding enc = env->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar *p = *src;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (PPEEK_IS('^')) {
|
2014-07-16 07:27:25 +04:00
|
|
|
PINC_S;
|
2004-03-05 18:31:51 +03:00
|
|
|
not = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
not = 0;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
if (onigenc_strlen(enc, p, end) < POSIX_BRACKET_NAME_MIN_LEN + 3)
|
2004-03-05 18:31:51 +03:00
|
|
|
goto not_posix_bracket;
|
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
ascii_range = IS_ASCII_RANGE(env->option) &&
|
|
|
|
! IS_POSIX_BRACKET_ALL_RANGE(env->option);
|
|
|
|
for (pb = PBS; pb < PBS + numberof(PBS); pb++) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (onigenc_with_ascii_strncmp(enc, p, end, pb->name, pb->len) == 0) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
p = (UChar* )onigenc_step(enc, p, end, pb->len);
|
2006-02-04 15:31:19 +03:00
|
|
|
if (onigenc_with_ascii_strncmp(enc, p, end, (UChar* )":]", 2) != 0)
|
2016-12-10 20:47:04 +03:00
|
|
|
return ONIGERR_INVALID_POSIX_BRACKET_TYPE;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
r = add_ctype_to_cc(cc, pb->ctype, not, ascii_range, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
|
|
|
if (pb->ctype != ONIGENC_CTYPE_WORD &&
|
|
|
|
pb->ctype != ONIGENC_CTYPE_ASCII &&
|
|
|
|
!ascii_range)
|
|
|
|
r = add_ctype_to_cc(asc_cc, pb->ctype, not, ascii_range, env);
|
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
|
2014-07-16 07:27:25 +04:00
|
|
|
PINC_S; PINC_S;
|
2004-03-05 18:31:51 +03:00
|
|
|
*src = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
not_posix_bracket:
|
|
|
|
c = 0;
|
|
|
|
i = 0;
|
|
|
|
while (!PEND && ((c = PPEEK) != ':') && c != ']') {
|
2014-07-16 07:27:25 +04:00
|
|
|
PINC_S;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (++i > POSIX_BRACKET_CHECK_LIMIT_LENGTH) break;
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (c == ':' && ! PEND) {
|
2014-07-16 07:27:25 +04:00
|
|
|
PINC_S;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (! PEND) {
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (c == ']')
|
2016-12-10 20:47:04 +03:00
|
|
|
return ONIGERR_INVALID_POSIX_BRACKET_TYPE;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
return 1; /* 1: is not POSIX bracket, but no error. */
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fetch_char_property_to_ctype(UChar** src, UChar* end, ScanEnv* env)
|
|
|
|
{
|
2007-05-23 05:32:08 +04:00
|
|
|
int r;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint c;
|
|
|
|
OnigEncoding enc = env->enc;
|
2004-03-16 18:25:28 +03:00
|
|
|
UChar *prev, *start, *p = *src;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
r = 0;
|
2004-03-16 18:25:28 +03:00
|
|
|
start = prev = p;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
while (!PEND) {
|
|
|
|
prev = p;
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(c);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (c == '}') {
|
2007-05-23 05:32:08 +04:00
|
|
|
r = ONIGENC_PROPERTY_NAME_TO_CTYPE(enc, start, prev);
|
|
|
|
if (r < 0) break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
*src = p;
|
2007-05-23 05:32:08 +04:00
|
|
|
return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
else if (c == '(' || c == ')' || c == '{' || c == '|') {
|
|
|
|
r = ONIGERR_INVALID_CHAR_PROPERTY_NAME;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
onig_scan_env_set_error_string(env, r, *src, prev);
|
|
|
|
return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
static int cclass_case_fold(Node** np, CClassNode* cc, CClassNode* asc_cc, ScanEnv* env);
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
|
|
|
parse_char_property(Node** np, OnigToken* tok, UChar** src, UChar* end,
|
|
|
|
ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r, ctype;
|
|
|
|
CClassNode* cc;
|
|
|
|
|
|
|
|
ctype = fetch_char_property_to_ctype(src, end, env);
|
|
|
|
if (ctype < 0) return ctype;
|
|
|
|
|
|
|
|
*np = node_new_cclass();
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
cc = NCCLASS(*np);
|
2014-09-15 20:18:41 +04:00
|
|
|
r = add_ctype_to_cc(cc, ctype, 0, 0, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
2007-07-23 13:39:30 +04:00
|
|
|
if (tok->u.prop.not != 0) NCCLASS_SET_NOT(cc);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_IGNORECASE(env->option)) {
|
|
|
|
if (ctype != ONIGENC_CTYPE_ASCII)
|
|
|
|
r = cclass_case_fold(np, cc, cc, env);
|
|
|
|
}
|
|
|
|
return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum CCSTATE {
|
|
|
|
CCS_VALUE,
|
|
|
|
CCS_RANGE,
|
|
|
|
CCS_COMPLETE,
|
|
|
|
CCS_START
|
|
|
|
};
|
|
|
|
|
|
|
|
enum CCVALTYPE {
|
|
|
|
CCV_SB,
|
|
|
|
CCV_CODE_POINT,
|
|
|
|
CCV_CLASS
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2014-09-15 20:18:41 +04:00
|
|
|
next_state_class(CClassNode* cc, CClassNode* asc_cc,
|
2016-12-10 20:47:04 +03:00
|
|
|
OnigCodePoint* vs, enum CCVALTYPE* type,
|
2004-03-05 18:31:51 +03:00
|
|
|
enum CCSTATE* state, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (*state == CCS_RANGE)
|
|
|
|
return ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE;
|
|
|
|
|
|
|
|
if (*state == CCS_VALUE && *type != CCV_CLASS) {
|
2014-09-15 20:18:41 +04:00
|
|
|
if (*type == CCV_SB) {
|
2009-08-04 08:14:38 +04:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, (int )(*vs));
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc))
|
|
|
|
BITSET_SET_BIT(asc_cc->bs, (int )(*vs));
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
else if (*type == CCV_CODE_POINT) {
|
|
|
|
r = add_code_range(&(cc->mbuf), env, *vs, *vs);
|
|
|
|
if (r < 0) return r;
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
|
|
|
r = add_code_range0(&(asc_cc->mbuf), env, *vs, *vs, 0);
|
|
|
|
if (r < 0) return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*state = CCS_VALUE;
|
|
|
|
*type = CCV_CLASS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-15 20:18:41 +04:00
|
|
|
next_state_val(CClassNode* cc, CClassNode* asc_cc,
|
2017-12-01 16:50:13 +03:00
|
|
|
OnigCodePoint *from, OnigCodePoint to,
|
|
|
|
int* from_israw, int to_israw,
|
2004-03-05 18:31:51 +03:00
|
|
|
enum CCVALTYPE intype, enum CCVALTYPE* type,
|
|
|
|
enum CCSTATE* state, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
switch (*state) {
|
|
|
|
case CCS_VALUE:
|
2014-09-15 20:18:41 +04:00
|
|
|
if (*type == CCV_SB) {
|
2017-12-01 16:50:13 +03:00
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, (int )(*from));
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc))
|
2017-12-01 16:50:13 +03:00
|
|
|
BITSET_SET_BIT(asc_cc->bs, (int )(*from));
|
2014-09-15 20:18:41 +04:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
else if (*type == CCV_CODE_POINT) {
|
2017-12-01 16:50:13 +03:00
|
|
|
r = add_code_range(&(cc->mbuf), env, *from, *from);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) return r;
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
2017-12-01 16:50:13 +03:00
|
|
|
r = add_code_range0(&(asc_cc->mbuf), env, *from, *from, 0);
|
2014-09-15 20:18:41 +04:00
|
|
|
if (r < 0) return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CCS_RANGE:
|
|
|
|
if (intype == *type) {
|
|
|
|
if (intype == CCV_SB) {
|
2017-12-01 16:50:13 +03:00
|
|
|
if (*from > 0xff || to > 0xff)
|
2016-12-10 20:47:04 +03:00
|
|
|
return ONIGERR_INVALID_CODE_POINT_VALUE;
|
2004-11-28 06:09:13 +03:00
|
|
|
|
2017-12-01 16:50:13 +03:00
|
|
|
if (*from > to) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC))
|
|
|
|
goto ccs_range_end;
|
|
|
|
else
|
|
|
|
return ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS;
|
|
|
|
}
|
2017-12-01 16:50:13 +03:00
|
|
|
bitset_set_range(env, cc->bs, (int )*from, (int )to);
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc))
|
2017-12-01 16:50:13 +03:00
|
|
|
bitset_set_range(env, asc_cc->bs, (int )*from, (int )to);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
2017-12-01 16:50:13 +03:00
|
|
|
r = add_code_range(&(cc->mbuf), env, *from, to);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) return r;
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
2017-12-01 16:50:13 +03:00
|
|
|
r = add_code_range0(&(asc_cc->mbuf), env, *from, to, 0);
|
2014-09-15 20:18:41 +04:00
|
|
|
if (r < 0) return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2017-12-01 16:50:13 +03:00
|
|
|
if (*from > to) {
|
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC))
|
|
|
|
goto ccs_range_end;
|
|
|
|
else
|
|
|
|
return ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS;
|
|
|
|
}
|
|
|
|
bitset_set_range(env, cc->bs, (int )*from, (int )(to < 0xff ? to : 0xff));
|
|
|
|
r = add_code_range(&(cc->mbuf), env, (OnigCodePoint )*from, to);
|
|
|
|
if (r < 0) return r;
|
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
|
|
|
bitset_set_range(env, asc_cc->bs, (int )*from, (int )(to < 0xff ? to : 0xff));
|
|
|
|
r = add_code_range0(&(asc_cc->mbuf), env, (OnigCodePoint )*from, to, 0);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (r < 0) return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
ccs_range_end:
|
|
|
|
*state = CCS_COMPLETE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CCS_COMPLETE:
|
|
|
|
case CCS_START:
|
|
|
|
*state = CCS_VALUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-01 16:50:13 +03:00
|
|
|
*from_israw = to_israw;
|
|
|
|
*from = to;
|
|
|
|
*type = intype;
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
code_exist_check(OnigCodePoint c, UChar* from, UChar* end, int ignore_escaped,
|
2007-05-23 05:32:08 +04:00
|
|
|
ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int in_esc;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint code;
|
2007-05-23 05:32:08 +04:00
|
|
|
OnigEncoding enc = env->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* p = from;
|
|
|
|
|
|
|
|
in_esc = 0;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
while (! PEND) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (ignore_escaped && in_esc) {
|
|
|
|
in_esc = 0;
|
|
|
|
}
|
|
|
|
else {
|
2014-07-16 07:27:25 +04:00
|
|
|
PFETCH_S(code);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (code == c) return 1;
|
2007-05-23 05:32:08 +04:00
|
|
|
if (code == MC_ESC(env->syntax)) in_esc = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-15 20:18:41 +04:00
|
|
|
parse_char_class(Node** np, Node** asc_np, OnigToken* tok, UChar** src, UChar* end,
|
2004-03-05 18:31:51 +03:00
|
|
|
ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r, neg, len, fetched, and_start;
|
|
|
|
OnigCodePoint v, vs;
|
|
|
|
UChar *p;
|
|
|
|
Node* node;
|
2014-09-15 20:18:41 +04:00
|
|
|
Node* asc_node;
|
2004-03-05 18:31:51 +03:00
|
|
|
CClassNode *cc, *prev_cc;
|
2014-09-15 20:18:41 +04:00
|
|
|
CClassNode *asc_cc, *asc_prev_cc;
|
|
|
|
CClassNode work_cc, asc_work_cc;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
enum CCSTATE state;
|
|
|
|
enum CCVALTYPE val_type, in_type;
|
|
|
|
int val_israw, in_israw;
|
|
|
|
|
2017-02-20 12:46:12 +03:00
|
|
|
*np = *asc_np = NULL_NODE;
|
2016-12-10 20:47:04 +03:00
|
|
|
env->parse_depth++;
|
|
|
|
if (env->parse_depth > ParseDepthLimit)
|
|
|
|
return ONIGERR_PARSE_DEPTH_LIMIT_OVER;
|
2014-09-15 20:18:41 +04:00
|
|
|
prev_cc = asc_prev_cc = (CClassNode* )NULL;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = fetch_token_in_cc(tok, src, end, env);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (r == TK_CHAR && tok->u.c == '^' && tok->escaped == 0) {
|
2004-03-05 18:31:51 +03:00
|
|
|
neg = 1;
|
|
|
|
r = fetch_token_in_cc(tok, src, end, env);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
neg = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r < 0) return r;
|
|
|
|
if (r == TK_CC_CLOSE) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (! code_exist_check((OnigCodePoint )']',
|
2007-05-23 05:32:08 +04:00
|
|
|
*src, env->pattern_end, 1, env))
|
2004-03-05 18:31:51 +03:00
|
|
|
return ONIGERR_EMPTY_CHAR_CLASS;
|
|
|
|
|
2006-02-04 15:31:19 +03:00
|
|
|
CC_ESC_WARN(env, (UChar* )"]");
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
r = tok->type = TK_CHAR; /* allow []...] */
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
*np = node = node_new_cclass();
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(node);
|
|
|
|
cc = NCCLASS(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_IGNORECASE(env->option)) {
|
|
|
|
*asc_np = asc_node = node_new_cclass();
|
|
|
|
CHECK_NULL_RETURN_MEMERR(asc_node);
|
|
|
|
asc_cc = NCCLASS(asc_node);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
asc_node = NULL_NODE;
|
|
|
|
asc_cc = NULL;
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
and_start = 0;
|
|
|
|
state = CCS_START;
|
|
|
|
p = *src;
|
|
|
|
while (r != TK_CC_CLOSE) {
|
|
|
|
fetched = 0;
|
|
|
|
switch (r) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
case TK_CHAR:
|
2008-10-21 03:56:40 +04:00
|
|
|
if ((tok->u.code >= SINGLE_BYTE_SIZE) ||
|
|
|
|
(len = ONIGENC_CODE_TO_MBCLEN(env->enc, tok->u.c)) > 1) {
|
2004-03-05 18:31:51 +03:00
|
|
|
in_type = CCV_CODE_POINT;
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
else if (len < 0) {
|
|
|
|
r = len;
|
|
|
|
goto err;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
else {
|
|
|
|
sb_char:
|
|
|
|
in_type = CCV_SB;
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
v = (OnigCodePoint )tok->u.c;
|
2004-03-05 18:31:51 +03:00
|
|
|
in_israw = 0;
|
|
|
|
goto val_entry2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_RAW_BYTE:
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
/* tok->base != 0 : octal or hexadec. */
|
|
|
|
if (! ONIGENC_IS_SINGLEBYTE(env->enc) && tok->base != 0) {
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
|
|
|
|
UChar* bufe = buf + ONIGENC_CODE_TO_MBC_MAXLEN;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
UChar* psave = p;
|
2004-03-05 18:31:51 +03:00
|
|
|
int i, base = tok->base;
|
|
|
|
|
2013-03-01 20:36:37 +04:00
|
|
|
buf[0] = (UChar )tok->u.c;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
for (i = 1; i < ONIGENC_MBC_MAXLEN(env->enc); i++) {
|
|
|
|
r = fetch_token_in_cc(tok, &p, end, env);
|
|
|
|
if (r < 0) goto err;
|
|
|
|
if (r != TK_RAW_BYTE || tok->base != base) {
|
|
|
|
fetched = 1;
|
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2013-03-01 20:36:37 +04:00
|
|
|
buf[i] = (UChar )tok->u.c;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
|
|
|
if (i < ONIGENC_MBC_MINLEN(env->enc)) {
|
|
|
|
r = ONIGERR_TOO_SHORT_MULTI_BYTE_STRING;
|
|
|
|
goto err;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
len = enclen(env->enc, buf, buf + i);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (i < len) {
|
|
|
|
r = ONIGERR_TOO_SHORT_MULTI_BYTE_STRING;
|
|
|
|
goto err;
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
else if (i > len) { /* fetch back */
|
|
|
|
p = psave;
|
|
|
|
for (i = 1; i < len; i++) {
|
2016-12-10 20:47:04 +03:00
|
|
|
(void)fetch_token_in_cc(tok, &p, end, env);
|
2019-12-20 03:19:39 +03:00
|
|
|
/* no need to check the return value (already checked above) */
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
fetched = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 1) {
|
|
|
|
v = (OnigCodePoint )buf[0];
|
|
|
|
goto raw_single;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
v = ONIGENC_MBC_TO_CODE(env->enc, buf, bufe);
|
|
|
|
in_type = CCV_CODE_POINT;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
v = (OnigCodePoint )tok->u.c;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
raw_single:
|
2004-03-05 18:31:51 +03:00
|
|
|
in_type = CCV_SB;
|
|
|
|
}
|
|
|
|
in_israw = 1;
|
|
|
|
goto val_entry2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CODE_POINT:
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
v = tok->u.code;
|
2004-03-05 18:31:51 +03:00
|
|
|
in_israw = 1;
|
|
|
|
val_entry:
|
|
|
|
len = ONIGENC_CODE_TO_MBCLEN(env->enc, v);
|
|
|
|
if (len < 0) {
|
|
|
|
r = len;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
in_type = (len == 1 ? CCV_SB : CCV_CODE_POINT);
|
|
|
|
val_entry2:
|
2014-09-15 20:18:41 +04:00
|
|
|
r = next_state_val(cc, asc_cc, &vs, v, &val_israw, in_israw, in_type, &val_type,
|
2004-03-05 18:31:51 +03:00
|
|
|
&state, env);
|
|
|
|
if (r != 0) goto err;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_POSIX_BRACKET_OPEN:
|
2014-09-15 20:18:41 +04:00
|
|
|
r = parse_posix_bracket(cc, asc_cc, &p, end, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) goto err;
|
|
|
|
if (r == 1) { /* is not POSIX bracket */
|
2006-02-04 15:31:19 +03:00
|
|
|
CC_ESC_WARN(env, (UChar* )"[");
|
2004-03-05 18:31:51 +03:00
|
|
|
p = tok->backp;
|
|
|
|
v = (OnigCodePoint )tok->u.c;
|
|
|
|
in_israw = 0;
|
|
|
|
goto val_entry;
|
|
|
|
}
|
|
|
|
goto next_class;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CHAR_TYPE:
|
2014-09-15 20:18:41 +04:00
|
|
|
r = add_ctype_to_cc(cc, tok->u.prop.ctype, tok->u.prop.not,
|
|
|
|
IS_ASCII_RANGE(env->option), env);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (r != 0) return r;
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
|
|
|
if (tok->u.prop.ctype != ONIGENC_CTYPE_WORD)
|
|
|
|
r = add_ctype_to_cc(asc_cc, tok->u.prop.ctype, tok->u.prop.not,
|
|
|
|
IS_ASCII_RANGE(env->option), env);
|
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
next_class:
|
2014-09-15 20:18:41 +04:00
|
|
|
r = next_state_class(cc, asc_cc, &vs, &val_type, &state, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) goto err;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CHAR_PROPERTY:
|
|
|
|
{
|
|
|
|
int ctype;
|
|
|
|
|
|
|
|
ctype = fetch_char_property_to_ctype(&p, end, env);
|
|
|
|
if (ctype < 0) return ctype;
|
2014-09-15 20:18:41 +04:00
|
|
|
r = add_ctype_to_cc(cc, ctype, tok->u.prop.not, 0, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
|
|
|
if (ctype != ONIGENC_CTYPE_ASCII)
|
|
|
|
r = add_ctype_to_cc(asc_cc, ctype, tok->u.prop.not, 0, env);
|
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
goto next_class;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CC_RANGE:
|
|
|
|
if (state == CCS_VALUE) {
|
|
|
|
r = fetch_token_in_cc(tok, &p, end, env);
|
|
|
|
if (r < 0) goto err;
|
|
|
|
fetched = 1;
|
|
|
|
if (r == TK_CC_CLOSE) { /* allow [x-] */
|
|
|
|
range_end_val:
|
|
|
|
v = (OnigCodePoint )'-';
|
|
|
|
in_israw = 0;
|
|
|
|
goto val_entry;
|
|
|
|
}
|
|
|
|
else if (r == TK_CC_AND) {
|
2006-02-04 15:31:19 +03:00
|
|
|
CC_ESC_WARN(env, (UChar* )"-");
|
2004-03-05 18:31:51 +03:00
|
|
|
goto range_end_val;
|
|
|
|
}
|
2017-12-01 16:50:13 +03:00
|
|
|
|
|
|
|
if (val_type == CCV_CLASS) {
|
|
|
|
r = ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
state = CCS_RANGE;
|
|
|
|
}
|
|
|
|
else if (state == CCS_START) {
|
|
|
|
/* [-xa] is allowed */
|
|
|
|
v = (OnigCodePoint )tok->u.c;
|
|
|
|
in_israw = 0;
|
|
|
|
|
|
|
|
r = fetch_token_in_cc(tok, &p, end, env);
|
|
|
|
if (r < 0) goto err;
|
|
|
|
fetched = 1;
|
|
|
|
/* [--x] or [a&&-x] is warned. */
|
|
|
|
if (r == TK_CC_RANGE || and_start != 0)
|
2006-02-04 15:31:19 +03:00
|
|
|
CC_ESC_WARN(env, (UChar* )"-");
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
goto val_entry;
|
|
|
|
}
|
|
|
|
else if (state == CCS_RANGE) {
|
2006-02-04 15:31:19 +03:00
|
|
|
CC_ESC_WARN(env, (UChar* )"-");
|
2004-03-05 18:31:51 +03:00
|
|
|
goto sb_char; /* [!--x] is allowed */
|
|
|
|
}
|
|
|
|
else { /* CCS_COMPLETE */
|
|
|
|
r = fetch_token_in_cc(tok, &p, end, env);
|
|
|
|
if (r < 0) goto err;
|
|
|
|
fetched = 1;
|
|
|
|
if (r == TK_CC_CLOSE) goto range_end_val; /* allow [a-b-] */
|
|
|
|
else if (r == TK_CC_AND) {
|
2006-02-04 15:31:19 +03:00
|
|
|
CC_ESC_WARN(env, (UChar* )"-");
|
2004-03-05 18:31:51 +03:00
|
|
|
goto range_end_val;
|
|
|
|
}
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC)) {
|
2006-02-04 15:31:19 +03:00
|
|
|
CC_ESC_WARN(env, (UChar* )"-");
|
2013-03-01 20:36:37 +04:00
|
|
|
goto range_end_val; /* [0-9-a] is allowed as [0-9\-a] */
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
r = ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CC_CC_OPEN: /* [ */
|
|
|
|
{
|
2014-09-15 20:18:41 +04:00
|
|
|
Node *anode, *aasc_node;
|
2004-03-05 18:31:51 +03:00
|
|
|
CClassNode* acc;
|
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
r = parse_char_class(&anode, &aasc_node, tok, &p, end, env);
|
2009-08-16 05:45:18 +04:00
|
|
|
if (r == 0) {
|
|
|
|
acc = NCCLASS(anode);
|
|
|
|
r = or_cclass(cc, acc, env);
|
|
|
|
}
|
2014-09-15 20:18:41 +04:00
|
|
|
if (r == 0 && IS_NOT_NULL(aasc_node)) {
|
|
|
|
acc = NCCLASS(aasc_node);
|
|
|
|
r = or_cclass(asc_cc, acc, env);
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
onig_node_free(anode);
|
2014-09-15 20:18:41 +04:00
|
|
|
onig_node_free(aasc_node);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) goto err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CC_AND: /* && */
|
|
|
|
{
|
|
|
|
if (state == CCS_VALUE) {
|
2014-09-15 20:18:41 +04:00
|
|
|
r = next_state_val(cc, asc_cc, &vs, 0, &val_israw, 0, val_type,
|
2004-03-05 18:31:51 +03:00
|
|
|
&val_type, &state, env);
|
|
|
|
if (r != 0) goto err;
|
|
|
|
}
|
|
|
|
/* initialize local variables */
|
|
|
|
and_start = 1;
|
|
|
|
state = CCS_START;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(prev_cc)) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = and_cclass(prev_cc, cc, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) goto err;
|
|
|
|
bbuf_free(cc->mbuf);
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
|
|
|
r = and_cclass(asc_prev_cc, asc_cc, env);
|
|
|
|
if (r != 0) goto err;
|
|
|
|
bbuf_free(asc_cc->mbuf);
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
prev_cc = cc;
|
|
|
|
cc = &work_cc;
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
|
|
|
asc_prev_cc = asc_cc;
|
|
|
|
asc_cc = &asc_work_cc;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
initialize_cclass(cc);
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc))
|
|
|
|
initialize_cclass(asc_cc);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_EOT:
|
|
|
|
r = ONIGERR_PREMATURE_END_OF_CHAR_CLASS;
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r = ONIGERR_PARSER_BUG;
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fetched)
|
|
|
|
r = tok->type;
|
|
|
|
else {
|
|
|
|
r = fetch_token_in_cc(tok, &p, end, env);
|
|
|
|
if (r < 0) goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == CCS_VALUE) {
|
2014-09-15 20:18:41 +04:00
|
|
|
r = next_state_val(cc, asc_cc, &vs, 0, &val_israw, 0, val_type,
|
2004-03-05 18:31:51 +03:00
|
|
|
&val_type, &state, env);
|
|
|
|
if (r != 0) goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(prev_cc)) {
|
2009-08-04 08:14:38 +04:00
|
|
|
r = and_cclass(prev_cc, cc, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) goto err;
|
|
|
|
bbuf_free(cc->mbuf);
|
|
|
|
cc = prev_cc;
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc)) {
|
|
|
|
r = and_cclass(asc_prev_cc, asc_cc, env);
|
|
|
|
if (r != 0) goto err;
|
|
|
|
bbuf_free(asc_cc->mbuf);
|
|
|
|
asc_cc = asc_prev_cc;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
if (neg != 0) {
|
2007-07-23 13:39:30 +04:00
|
|
|
NCCLASS_SET_NOT(cc);
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc))
|
|
|
|
NCCLASS_SET_NOT(asc_cc);
|
|
|
|
}
|
|
|
|
else {
|
2007-07-23 13:39:30 +04:00
|
|
|
NCCLASS_CLEAR_NOT(cc);
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc))
|
|
|
|
NCCLASS_CLEAR_NOT(asc_cc);
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_NCCLASS_NOT(cc) &&
|
2004-03-05 18:31:51 +03:00
|
|
|
IS_SYNTAX_BV(env->syntax, ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC)) {
|
|
|
|
int is_empty;
|
|
|
|
|
|
|
|
is_empty = (IS_NULL(cc->mbuf) ? 1 : 0);
|
|
|
|
if (is_empty != 0)
|
|
|
|
BITSET_IS_EMPTY(cc->bs, is_empty);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
|
|
|
if (is_empty == 0) {
|
|
|
|
#define NEWLINE_CODE 0x0a
|
|
|
|
|
|
|
|
if (ONIGENC_IS_CODE_NEWLINE(env->enc, NEWLINE_CODE)) {
|
2016-12-10 20:47:04 +03:00
|
|
|
if (ONIGENC_CODE_TO_MBCLEN(env->enc, NEWLINE_CODE) == 1)
|
|
|
|
BITSET_SET_BIT_CHKDUP(cc->bs, NEWLINE_CODE);
|
|
|
|
else {
|
|
|
|
r = add_code_range(&(cc->mbuf), env, NEWLINE_CODE, NEWLINE_CODE);
|
|
|
|
if (r < 0) goto err;
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
*src = p;
|
2016-12-10 20:47:04 +03:00
|
|
|
env->parse_depth--;
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2007-07-23 13:39:30 +04:00
|
|
|
if (cc != NCCLASS(*np))
|
2004-03-05 18:31:51 +03:00
|
|
|
bbuf_free(cc->mbuf);
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NOT_NULL(asc_cc) && (asc_cc != NCCLASS(*asc_np)))
|
|
|
|
bbuf_free(asc_cc->mbuf);
|
2004-03-05 18:31:51 +03:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_subexp(Node** top, OnigToken* tok, int term,
|
|
|
|
UChar** src, UChar* end, ScanEnv* env);
|
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
parse_enclose(Node** np, OnigToken* tok, int term, UChar** src, UChar* end,
|
|
|
|
ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2012-02-17 11:42:23 +04:00
|
|
|
int r = 0, num;
|
|
|
|
Node *target, *work1 = NULL, *work2 = NULL;
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigOptionType option;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigCodePoint c;
|
2008-01-03 18:55:04 +03:00
|
|
|
OnigEncoding enc = env->enc;
|
|
|
|
|
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
int list_capture;
|
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* p = *src;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
PFETCH_READY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
*np = NULL;
|
|
|
|
if (PEND) return ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS;
|
|
|
|
|
|
|
|
option = env->option;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (PPEEK_IS('?') &&
|
2004-03-05 18:31:51 +03:00
|
|
|
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_GROUP_EFFECT)) {
|
|
|
|
PINC;
|
|
|
|
if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
|
|
|
|
|
|
|
|
PFETCH(c);
|
|
|
|
switch (c) {
|
|
|
|
case ':': /* (?:...) grouping only */
|
|
|
|
group:
|
|
|
|
r = fetch_token(tok, &p, end, env);
|
|
|
|
if (r < 0) return r;
|
|
|
|
r = parse_subexp(np, tok, term, &p, end, env);
|
|
|
|
if (r < 0) return r;
|
|
|
|
*src = p;
|
|
|
|
return 1; /* group */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '=':
|
|
|
|
*np = onig_node_new_anchor(ANCHOR_PREC_READ);
|
|
|
|
break;
|
2012-02-17 11:42:23 +04:00
|
|
|
case '!': /* preceding read */
|
2004-03-05 18:31:51 +03:00
|
|
|
*np = onig_node_new_anchor(ANCHOR_PREC_READ_NOT);
|
|
|
|
break;
|
2012-02-17 11:42:23 +04:00
|
|
|
case '>': /* (?>...) stop backtrack */
|
2007-07-23 13:39:30 +04:00
|
|
|
*np = node_new_enclose(ENCLOSE_STOP_BACKTRACK);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2017-02-11 18:08:33 +03:00
|
|
|
case '~': /* (?~...) absent operator */
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_TILDE_ABSENT)) {
|
|
|
|
*np = node_new_enclose(ENCLOSE_ABSENT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
}
|
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_NAMED_GROUP
|
2007-05-23 05:32:08 +04:00
|
|
|
case '\'':
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP)) {
|
|
|
|
goto named_group1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
2012-02-17 11:42:23 +04:00
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
# ifdef USE_CAPITAL_P_NAMED_GROUP
|
2012-02-17 11:42:23 +04:00
|
|
|
case 'P': /* (?P<name>...) */
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!PEND &&
|
|
|
|
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_CAPITAL_P_NAMED_GROUP)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
PFETCH(c);
|
|
|
|
if (c == '<') goto named_group1;
|
|
|
|
}
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
2016-12-10 20:47:04 +03:00
|
|
|
# endif
|
2008-01-03 18:55:04 +03:00
|
|
|
#endif
|
2007-05-23 05:32:08 +04:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
case '<': /* look behind (?<=...), (?<!...) */
|
2016-12-10 20:47:04 +03:00
|
|
|
if (PEND) return ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS;
|
2004-03-05 18:31:51 +03:00
|
|
|
PFETCH(c);
|
|
|
|
if (c == '=')
|
|
|
|
*np = onig_node_new_anchor(ANCHOR_LOOK_BEHIND);
|
|
|
|
else if (c == '!')
|
|
|
|
*np = onig_node_new_anchor(ANCHOR_LOOK_BEHIND_NOT);
|
|
|
|
#ifdef USE_NAMED_GROUP
|
2012-02-17 11:42:23 +04:00
|
|
|
else { /* (?<name>...) */
|
2007-05-23 05:32:08 +04:00
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP)) {
|
|
|
|
UChar *name;
|
|
|
|
UChar *name_end;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
PUNFETCH;
|
|
|
|
c = '<';
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
named_group1:
|
|
|
|
list_capture = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2017-02-11 18:08:33 +03:00
|
|
|
# ifdef USE_CAPTURE_HISTORY
|
2007-05-23 05:32:08 +04:00
|
|
|
named_group2:
|
2017-02-11 18:08:33 +03:00
|
|
|
# endif
|
2007-05-23 05:32:08 +04:00
|
|
|
name = p;
|
2008-01-03 18:55:04 +03:00
|
|
|
r = fetch_name((OnigCodePoint )c, &p, end, &name_end, env, &num, 0);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (r < 0) return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
num = scan_env_add_mem_entry(env);
|
|
|
|
if (num < 0) return num;
|
2008-01-03 18:55:04 +03:00
|
|
|
if (list_capture != 0 && num >= (int )BIT_STATUS_BITS_NUM)
|
2007-05-23 05:32:08 +04:00
|
|
|
return ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY;
|
|
|
|
|
|
|
|
r = name_add(env->reg, name, name_end, num, env);
|
|
|
|
if (r != 0) return r;
|
2007-07-23 13:39:30 +04:00
|
|
|
*np = node_new_enclose_memory(env->option, 1);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
NENCLOSE(*np)->regnum = num;
|
2007-05-23 05:32:08 +04:00
|
|
|
if (list_capture != 0)
|
|
|
|
BIT_STATUS_ON_AT_SIMPLE(env->capture_history, num);
|
|
|
|
env->num_named++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
#else
|
|
|
|
else {
|
2004-03-05 18:31:51 +03:00
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2017-02-11 18:08:33 +03:00
|
|
|
#ifdef USE_CAPTURE_HISTORY
|
2004-03-05 18:31:51 +03:00
|
|
|
case '@':
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY)) {
|
2017-02-11 18:08:33 +03:00
|
|
|
# ifdef USE_NAMED_GROUP
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!PEND &&
|
|
|
|
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
PFETCH(c);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (c == '<' || c == '\'') {
|
2004-03-05 18:31:51 +03:00
|
|
|
list_capture = 1;
|
2007-05-23 05:32:08 +04:00
|
|
|
goto named_group2; /* (?@<name>...) */
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
PUNFETCH;
|
|
|
|
}
|
2017-02-11 18:08:33 +03:00
|
|
|
# endif
|
2007-07-23 13:39:30 +04:00
|
|
|
*np = node_new_enclose_memory(env->option, 0);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
num = scan_env_add_mem_entry(env);
|
2014-07-16 07:27:25 +04:00
|
|
|
if (num < 0) return num;
|
|
|
|
if (num >= (int )BIT_STATUS_BITS_NUM)
|
2004-03-05 18:31:51 +03:00
|
|
|
return ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY;
|
2014-07-16 07:27:25 +04:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
NENCLOSE(*np)->regnum = num;
|
2004-03-05 18:31:51 +03:00
|
|
|
BIT_STATUS_ON_AT_SIMPLE(env->capture_history, num);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
}
|
|
|
|
break;
|
2017-02-11 18:08:33 +03:00
|
|
|
#endif /* USE_CAPTURE_HISTORY */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
case '(': /* conditional expression: (?(cond)yes), (?(cond)yes|no) */
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!PEND &&
|
|
|
|
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_LPAREN_CONDITION)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
UChar *name = NULL;
|
|
|
|
UChar *name_end;
|
|
|
|
PFETCH(c);
|
|
|
|
if (ONIGENC_IS_CODE_DIGIT(enc, c)) { /* (n) */
|
|
|
|
PUNFETCH;
|
|
|
|
r = fetch_name((OnigCodePoint )'(', &p, end, &name_end, env, &num, 1);
|
|
|
|
if (r < 0) return r;
|
2014-07-16 07:27:25 +04:00
|
|
|
#if 0
|
|
|
|
/* Relative number is not currently supported. (same as Perl) */
|
2012-02-17 11:42:23 +04:00
|
|
|
if (num < 0) {
|
|
|
|
num = BACKREF_REL_TO_ABS(num, env);
|
|
|
|
if (num <= 0)
|
|
|
|
return ONIGERR_INVALID_BACKREF;
|
|
|
|
}
|
2014-07-16 07:27:25 +04:00
|
|
|
#endif
|
2012-02-17 11:42:23 +04:00
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_STRICT_CHECK_BACKREF)) {
|
|
|
|
if (num > env->num_mem ||
|
2016-12-10 20:47:04 +03:00
|
|
|
IS_NULL(SCANENV_MEM_NODES(env)[num]))
|
2012-02-17 11:42:23 +04:00
|
|
|
return ONIGERR_INVALID_BACKREF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
else if (c == '<' || c == '\'') { /* (<name>), ('name') */
|
|
|
|
name = p;
|
2016-12-10 20:47:04 +03:00
|
|
|
r = fetch_named_backref_token(c, tok, &p, end, env);
|
2012-02-17 11:42:23 +04:00
|
|
|
if (r < 0) return r;
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!PPEEK_IS(')')) return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
PINC;
|
2012-02-17 11:42:23 +04:00
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_USE_LEFT_MOST_NAMED_GROUP)) {
|
|
|
|
num = tok->u.backref.ref1;
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
else {
|
|
|
|
/* FIXME:
|
|
|
|
* Use left most named group for now. This is the same as Perl.
|
|
|
|
* However this should use the same strategy as normal back-
|
|
|
|
* references on Ruby syntax; search right to left. */
|
|
|
|
int len = tok->u.backref.num;
|
|
|
|
num = len > 1 ? tok->u.backref.refs[0] : tok->u.backref.ref1;
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-21 14:53:06 +04:00
|
|
|
else
|
|
|
|
return ONIGERR_INVALID_CONDITION_PATTERN;
|
2012-02-17 11:42:23 +04:00
|
|
|
*np = node_new_enclose(ENCLOSE_CONDITION);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
NENCLOSE(*np)->regnum = num;
|
|
|
|
if (IS_NOT_NULL(name)) NENCLOSE(*np)->state |= NST_NAME_REF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
case '|': /* branch reset: (?|...) */
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_VBAR_BRANCH_RESET)) {
|
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case '^': /* loads default options */
|
2016-12-10 20:47:04 +03:00
|
|
|
if (!PEND && IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_PERL)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
/* d-imsx */
|
|
|
|
ONOFF(option, ONIG_OPTION_ASCII_RANGE, 1);
|
|
|
|
ONOFF(option, ONIG_OPTION_IGNORECASE, 1);
|
|
|
|
ONOFF(option, ONIG_OPTION_SINGLELINE, 0);
|
|
|
|
ONOFF(option, ONIG_OPTION_MULTILINE, 1);
|
|
|
|
ONOFF(option, ONIG_OPTION_EXTEND, 1);
|
|
|
|
PFETCH(c);
|
|
|
|
}
|
|
|
|
#if 0
|
2016-12-10 20:47:04 +03:00
|
|
|
else if (!PEND && IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_RUBY)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
/* d-imx */
|
|
|
|
ONOFF(option, ONIG_OPTION_ASCII_RANGE, 0);
|
|
|
|
ONOFF(option, ONIG_OPTION_POSIX_BRACKET_ALL_RANGE, 0);
|
|
|
|
ONOFF(option, ONIG_OPTION_WORD_BOUND_ALL_RANGE, 0);
|
|
|
|
ONOFF(option, ONIG_OPTION_IGNORECASE, 1);
|
|
|
|
ONOFF(option, ONIG_OPTION_MULTILINE, 1);
|
|
|
|
ONOFF(option, ONIG_OPTION_EXTEND, 1);
|
|
|
|
PFETCH(c);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_POSIXLINE_OPTION
|
|
|
|
case 'p':
|
|
|
|
#endif
|
|
|
|
case '-': case 'i': case 'm': case 's': case 'x':
|
2012-02-17 11:42:23 +04:00
|
|
|
case 'a': case 'd': case 'l': case 'u':
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int neg = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
switch (c) {
|
|
|
|
case ':':
|
|
|
|
case ')':
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '-': neg = 1; break;
|
|
|
|
case 'x': ONOFF(option, ONIG_OPTION_EXTEND, neg); break;
|
|
|
|
case 'i': ONOFF(option, ONIG_OPTION_IGNORECASE, neg); break;
|
|
|
|
case 's':
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_PERL)) {
|
|
|
|
ONOFF(option, ONIG_OPTION_MULTILINE, neg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_PERL)) {
|
|
|
|
ONOFF(option, ONIG_OPTION_SINGLELINE, (neg == 0 ? 1 : 0));
|
|
|
|
}
|
|
|
|
else if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_RUBY)) {
|
|
|
|
ONOFF(option, ONIG_OPTION_MULTILINE, neg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
|
|
|
#ifdef USE_POSIXLINE_OPTION
|
|
|
|
case 'p':
|
|
|
|
ONOFF(option, ONIG_OPTION_MULTILINE|ONIG_OPTION_SINGLELINE, neg);
|
|
|
|
break;
|
|
|
|
#endif
|
2012-02-17 11:42:23 +04:00
|
|
|
|
|
|
|
case 'a': /* limits \d, \s, \w and POSIX brackets to ASCII range */
|
|
|
|
if ((IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_PERL) ||
|
2016-12-10 20:47:04 +03:00
|
|
|
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_RUBY)) &&
|
|
|
|
(neg == 0)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
ONOFF(option, ONIG_OPTION_ASCII_RANGE, 0);
|
|
|
|
ONOFF(option, ONIG_OPTION_POSIX_BRACKET_ALL_RANGE, 1);
|
|
|
|
ONOFF(option, ONIG_OPTION_WORD_BOUND_ALL_RANGE, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
if ((IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_PERL) ||
|
2016-12-10 20:47:04 +03:00
|
|
|
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_RUBY)) &&
|
|
|
|
(neg == 0)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
ONOFF(option, ONIG_OPTION_ASCII_RANGE, 1);
|
|
|
|
ONOFF(option, ONIG_OPTION_POSIX_BRACKET_ALL_RANGE, 1);
|
|
|
|
ONOFF(option, ONIG_OPTION_WORD_BOUND_ALL_RANGE, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_PERL) &&
|
2016-12-10 20:47:04 +03:00
|
|
|
(neg == 0)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
ONOFF(option, ONIG_OPTION_ASCII_RANGE, 1);
|
|
|
|
}
|
|
|
|
else if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_RUBY) &&
|
2016-12-10 20:47:04 +03:00
|
|
|
(neg == 0)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
ONOFF(option, ONIG_OPTION_ASCII_RANGE, 0);
|
|
|
|
ONOFF(option, ONIG_OPTION_POSIX_BRACKET_ALL_RANGE, 0);
|
|
|
|
ONOFF(option, ONIG_OPTION_WORD_BOUND_ALL_RANGE, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_PERL) && (neg == 0)) {
|
|
|
|
ONOFF(option, ONIG_OPTION_ASCII_RANGE, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == ')') {
|
|
|
|
*np = node_new_option(option);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
*src = p;
|
|
|
|
return 2; /* option only */
|
|
|
|
}
|
|
|
|
else if (c == ':') {
|
|
|
|
OnigOptionType prev = env->option;
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
env->option = option;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = fetch_token(tok, &p, end, env);
|
2016-12-10 20:47:04 +03:00
|
|
|
if (r < 0) {
|
|
|
|
env->option = prev;
|
|
|
|
return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
r = parse_subexp(&target, tok, term, &p, end, env);
|
|
|
|
env->option = prev;
|
|
|
|
if (r < 0) return r;
|
|
|
|
*np = node_new_option(option);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
NENCLOSE(*np)->target = target;
|
2004-03-05 18:31:51 +03:00
|
|
|
*src = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
|
|
|
|
PFETCH(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_OPTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_DONT_CAPTURE_GROUP))
|
|
|
|
goto group;
|
2006-03-23 15:08:08 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
*np = node_new_enclose_memory(env->option, 0);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
num = scan_env_add_mem_entry(env);
|
|
|
|
if (num < 0) return num;
|
2007-07-23 13:39:30 +04:00
|
|
|
NENCLOSE(*np)->regnum = num;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
r = fetch_token(tok, &p, end, env);
|
|
|
|
if (r < 0) return r;
|
|
|
|
r = parse_subexp(&target, tok, term, &p, end, env);
|
2009-08-16 06:15:13 +04:00
|
|
|
if (r < 0) {
|
|
|
|
onig_node_free(target);
|
|
|
|
return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(*np) == NT_ANCHOR)
|
|
|
|
NANCHOR(*np)->target = target;
|
2004-03-05 18:31:51 +03:00
|
|
|
else {
|
2007-07-23 13:39:30 +04:00
|
|
|
NENCLOSE(*np)->target = target;
|
|
|
|
if (NENCLOSE(*np)->type == ENCLOSE_MEMORY) {
|
2004-03-05 18:31:51 +03:00
|
|
|
/* Don't move this to previous of parse_subexp() */
|
2007-07-23 13:39:30 +04:00
|
|
|
r = scan_env_set_mem_node(env, NENCLOSE(*np)->regnum, *np);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
else if (NENCLOSE(*np)->type == ENCLOSE_CONDITION) {
|
|
|
|
if (NTYPE(target) != NT_ALT) {
|
|
|
|
/* convert (?(cond)yes) to (?(cond)yes|empty) */
|
|
|
|
work1 = node_new_empty();
|
|
|
|
if (IS_NULL(work1)) goto err;
|
|
|
|
work2 = onig_node_new_alt(work1, NULL_NODE);
|
|
|
|
if (IS_NULL(work2)) goto err;
|
|
|
|
work1 = onig_node_new_alt(target, work2);
|
|
|
|
if (IS_NULL(work1)) goto err;
|
|
|
|
NENCLOSE(*np)->target = work1;
|
|
|
|
}
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
*src = p;
|
|
|
|
return 0;
|
2012-02-17 11:42:23 +04:00
|
|
|
|
|
|
|
err:
|
|
|
|
onig_node_free(work1);
|
|
|
|
onig_node_free(work2);
|
|
|
|
onig_node_free(*np);
|
|
|
|
*np = NULL;
|
|
|
|
return ONIGERR_MEMORY;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
2008-07-01 12:21:44 +04:00
|
|
|
static const char* const PopularQStr[] = {
|
2004-04-05 14:40:54 +04:00
|
|
|
"?", "*", "+", "??", "*?", "+?"
|
|
|
|
};
|
|
|
|
|
2008-07-01 12:21:44 +04:00
|
|
|
static const char* const ReduceQStr[] = {
|
2004-04-05 14:40:54 +04:00
|
|
|
"", "", "*", "*?", "??", "+ and ??", "+? and ?"
|
|
|
|
};
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
2007-05-23 05:32:08 +04:00
|
|
|
set_quantifier(Node* qnode, Node* target, int group, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qn;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
qn = NQTFR(qnode);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (qn->lower == 1 && qn->upper == 1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (NTYPE(target)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
if (! group) {
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* sn = NSTR(target);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (str_node_can_be_split(sn, env->enc)) {
|
|
|
|
Node* n = str_node_split_last_char(sn, env->enc);
|
|
|
|
if (IS_NOT_NULL(n)) {
|
|
|
|
qn->target = n;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{ /* check redundant double repeat. */
|
|
|
|
/* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qnt = NQTFR(target);
|
2007-05-23 05:32:08 +04:00
|
|
|
int nestq_num = popular_quantifier_num(qn);
|
|
|
|
int targetq_num = popular_quantifier_num(qnt);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
#ifdef USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
|
2016-12-10 20:47:04 +03:00
|
|
|
if (nestq_num >= 0 && targetq_num >= 0 &&
|
2004-03-05 18:31:51 +03:00
|
|
|
IS_SYNTAX_BV(env->syntax, ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT)) {
|
2016-12-10 20:47:04 +03:00
|
|
|
switch (ReduceTypeTable[targetq_num][nestq_num]) {
|
|
|
|
case RQ_ASIS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RQ_DEL:
|
|
|
|
if (onig_warn != onig_null_warn) {
|
|
|
|
onig_syntax_warn(env, "regular expression has redundant nested repeat operator '%s'",
|
|
|
|
PopularQStr[targetq_num]);
|
|
|
|
}
|
|
|
|
goto warn_exit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (onig_warn != onig_null_warn) {
|
|
|
|
onig_syntax_warn(env, "nested repeat operator '%s' and '%s' was replaced with '%s' in regular expression",
|
|
|
|
PopularQStr[targetq_num], PopularQStr[nestq_num],
|
|
|
|
ReduceQStr[ReduceTypeTable[targetq_num][nestq_num]]);
|
|
|
|
}
|
|
|
|
goto warn_exit;
|
|
|
|
break;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
warn_exit:
|
|
|
|
#endif
|
2006-08-27 16:58:22 +04:00
|
|
|
if (targetq_num >= 0) {
|
|
|
|
if (nestq_num >= 0) {
|
2007-05-23 05:32:08 +04:00
|
|
|
onig_reduce_nested_quantifier(qnode, target);
|
2006-08-27 16:58:22 +04:00
|
|
|
goto q_exit;
|
|
|
|
}
|
|
|
|
else if (targetq_num == 1 || targetq_num == 2) { /* * or + */
|
|
|
|
/* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
|
|
|
|
if (! IS_REPEAT_INFINITE(qn->upper) && qn->upper > 1 && qn->greedy) {
|
|
|
|
qn->upper = (qn->lower == 0 ? 1 : qn->lower);
|
|
|
|
}
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
qn->target = target;
|
|
|
|
q_exit:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifndef CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS
|
|
|
|
static int
|
|
|
|
clear_not_flag_cclass(CClassNode* cc, OnigEncoding enc)
|
|
|
|
{
|
|
|
|
BBuf *tbuf;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (IS_NCCLASS_NOT(cc)) {
|
|
|
|
bitset_invert(cc->bs);
|
|
|
|
|
|
|
|
if (! ONIGENC_IS_SINGLEBYTE(enc)) {
|
|
|
|
r = not_code_range_buf(enc, cc->mbuf, &tbuf);
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
bbuf_free(cc->mbuf);
|
|
|
|
cc->mbuf = tbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
NCCLASS_CLEAR_NOT(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS */
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
typedef struct {
|
|
|
|
ScanEnv* env;
|
|
|
|
CClassNode* cc;
|
2014-09-15 20:18:41 +04:00
|
|
|
CClassNode* asc_cc;
|
2007-05-23 05:32:08 +04:00
|
|
|
Node* alt_root;
|
|
|
|
Node** ptail;
|
2007-07-23 13:39:30 +04:00
|
|
|
} IApplyCaseFoldArg;
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
i_apply_case_fold(OnigCodePoint from, OnigCodePoint to[],
|
|
|
|
int to_len, void* arg)
|
2007-05-23 05:32:08 +04:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
IApplyCaseFoldArg* iarg;
|
2007-05-23 05:32:08 +04:00
|
|
|
ScanEnv* env;
|
|
|
|
CClassNode* cc;
|
2014-09-15 20:18:41 +04:00
|
|
|
CClassNode* asc_cc;
|
2007-05-23 05:32:08 +04:00
|
|
|
BitSetRef bs;
|
2016-12-10 20:47:04 +03:00
|
|
|
int add_flag, r;
|
2007-05-23 05:32:08 +04:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
iarg = (IApplyCaseFoldArg* )arg;
|
2007-05-23 05:32:08 +04:00
|
|
|
env = iarg->env;
|
|
|
|
cc = iarg->cc;
|
2014-09-15 20:18:41 +04:00
|
|
|
asc_cc = iarg->asc_cc;
|
2007-05-23 05:32:08 +04:00
|
|
|
bs = cc->bs;
|
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
if (IS_NULL(asc_cc)) {
|
|
|
|
add_flag = 0;
|
|
|
|
}
|
|
|
|
else if (ONIGENC_IS_ASCII_CODE(from) == ONIGENC_IS_ASCII_CODE(*to)) {
|
|
|
|
add_flag = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
add_flag = onig_is_code_in_cc(env->enc, from, asc_cc);
|
|
|
|
if (IS_NCCLASS_NOT(asc_cc))
|
|
|
|
add_flag = !add_flag;
|
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
if (to_len == 1) {
|
2008-01-03 18:55:04 +03:00
|
|
|
int is_in = onig_is_code_in_cc(env->enc, from, cc);
|
|
|
|
#ifdef CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS
|
|
|
|
if ((is_in != 0 && !IS_NCCLASS_NOT(cc)) ||
|
|
|
|
(is_in == 0 && IS_NCCLASS_NOT(cc))) {
|
2014-09-15 20:18:41 +04:00
|
|
|
if (add_flag) {
|
|
|
|
if (ONIGENC_MBC_MINLEN(env->enc) > 1 || *to >= SINGLE_BYTE_SIZE) {
|
2016-12-10 20:47:04 +03:00
|
|
|
r = add_code_range0(&(cc->mbuf), env, *to, *to, 0);
|
|
|
|
if (r < 0) return r;
|
2014-09-15 20:18:41 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BITSET_SET_BIT(bs, *to);
|
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
#else
|
|
|
|
if (is_in != 0) {
|
2014-09-15 20:18:41 +04:00
|
|
|
if (add_flag) {
|
|
|
|
if (ONIGENC_MBC_MINLEN(env->enc) > 1 || *to >= SINGLE_BYTE_SIZE) {
|
|
|
|
if (IS_NCCLASS_NOT(cc)) clear_not_flag_cclass(cc, env->enc);
|
2016-12-10 20:47:04 +03:00
|
|
|
r = add_code_range0(&(cc->mbuf), env, *to, *to, 0);
|
|
|
|
if (r < 0) return r;
|
2014-09-15 20:18:41 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (IS_NCCLASS_NOT(cc)) {
|
|
|
|
BITSET_CLEAR_BIT(bs, *to);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BITSET_SET_BIT(bs, *to);
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS */
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
int r, i, len;
|
|
|
|
UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
|
|
|
|
Node *snode = NULL_NODE;
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (onig_is_code_in_cc(env->enc, from, cc)
|
|
|
|
#ifdef CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS
|
|
|
|
&& !IS_NCCLASS_NOT(cc)
|
|
|
|
#endif
|
|
|
|
) {
|
2007-05-23 05:32:08 +04:00
|
|
|
for (i = 0; i < to_len; i++) {
|
|
|
|
len = ONIGENC_CODE_TO_MBC(env->enc, to[i], buf);
|
|
|
|
if (i == 0) {
|
|
|
|
snode = onig_node_new_str(buf, buf + len);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(snode);
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
/* char-class expanded multi-char only
|
|
|
|
compare with string folded at match time. */
|
|
|
|
NSTRING_SET_AMBIG(snode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = onig_node_str_cat(snode, buf, buf + len);
|
|
|
|
if (r < 0) {
|
|
|
|
onig_node_free(snode);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*(iarg->ptail) = onig_node_new_alt(snode, NULL_NODE);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*(iarg->ptail));
|
|
|
|
iarg->ptail = &(NCDR((*(iarg->ptail))));
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
static int
|
|
|
|
cclass_case_fold(Node** np, CClassNode* cc, CClassNode* asc_cc, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
IApplyCaseFoldArg iarg;
|
|
|
|
|
|
|
|
iarg.env = env;
|
|
|
|
iarg.cc = cc;
|
|
|
|
iarg.asc_cc = asc_cc;
|
|
|
|
iarg.alt_root = NULL_NODE;
|
|
|
|
iarg.ptail = &(iarg.alt_root);
|
|
|
|
|
|
|
|
r = ONIGENC_APPLY_ALL_CASE_FOLD(env->enc, env->case_fold_flag,
|
|
|
|
i_apply_case_fold, &iarg);
|
|
|
|
if (r != 0) {
|
|
|
|
onig_node_free(iarg.alt_root);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
if (IS_NOT_NULL(iarg.alt_root)) {
|
|
|
|
Node* work = onig_node_new_alt(*np, iarg.alt_root);
|
|
|
|
if (IS_NULL(work)) {
|
|
|
|
onig_node_free(iarg.alt_root);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
|
|
|
*np = work;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
static int
|
|
|
|
node_linebreak(Node** np, ScanEnv* env)
|
|
|
|
{
|
|
|
|
/* same as (?>\x0D\x0A|[\x0A-\x0D\x{85}\x{2028}\x{2029}]) */
|
|
|
|
Node* left = NULL;
|
|
|
|
Node* right = NULL;
|
|
|
|
Node* target1 = NULL;
|
|
|
|
Node* target2 = NULL;
|
|
|
|
CClassNode* cc;
|
2016-12-10 20:47:04 +03:00
|
|
|
int num1, num2, r;
|
2012-02-17 11:42:23 +04:00
|
|
|
UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN * 2];
|
|
|
|
|
|
|
|
/* \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;
|
|
|
|
left = node_new_str_raw(buf, buf + num1 + num2);
|
|
|
|
if (IS_NULL(left)) goto err;
|
|
|
|
|
|
|
|
/* [\x0A-\x0D] or [\x0A-\x0D\x{85}\x{2028}\x{2029}] */
|
|
|
|
right = node_new_cclass();
|
|
|
|
if (IS_NULL(right)) goto err;
|
|
|
|
cc = NCCLASS(right);
|
|
|
|
if (ONIGENC_MBC_MINLEN(env->enc) > 1) {
|
2016-12-10 20:47:04 +03:00
|
|
|
r = add_code_range(&(cc->mbuf), env, 0x0A, 0x0D);
|
|
|
|
if (r != 0) goto err;
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
bitset_set_range(env, cc->bs, 0x0A, 0x0D);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: move this block to enc/unicode.c */
|
|
|
|
if (ONIGENC_IS_UNICODE(env->enc)) {
|
|
|
|
/* UTF-8, UTF-16BE/LE, UTF-32BE/LE */
|
2016-12-10 20:47:04 +03:00
|
|
|
r = add_code_range(&(cc->mbuf), env, 0x85, 0x85);
|
|
|
|
if (r != 0) goto err;
|
|
|
|
r = add_code_range(&(cc->mbuf), env, 0x2028, 0x2029);
|
|
|
|
if (r != 0) goto err;
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ...|... */
|
|
|
|
target1 = onig_node_new_alt(right, NULL_NODE);
|
|
|
|
if (IS_NULL(target1)) goto err;
|
|
|
|
right = NULL;
|
|
|
|
target2 = onig_node_new_alt(left, target1);
|
|
|
|
if (IS_NULL(target2)) goto err;
|
|
|
|
left = NULL;
|
|
|
|
target1 = NULL;
|
|
|
|
|
|
|
|
/* (?>...) */
|
|
|
|
*np = node_new_enclose(ENCLOSE_STOP_BACKTRACK);
|
|
|
|
if (IS_NULL(*np)) goto err;
|
|
|
|
NENCLOSE(*np)->target = target2;
|
|
|
|
return ONIG_NORMAL;
|
|
|
|
|
|
|
|
err:
|
|
|
|
onig_node_free(left);
|
|
|
|
onig_node_free(right);
|
|
|
|
onig_node_free(target1);
|
|
|
|
onig_node_free(target2);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
|
|
|
|
2016-11-30 20:29:19 +03:00
|
|
|
static int
|
|
|
|
propname2ctype(ScanEnv* env, const char* propname)
|
|
|
|
{
|
2016-12-10 20:47:04 +03:00
|
|
|
UChar* name = (UChar* )propname;
|
2018-10-16 11:13:58 +03:00
|
|
|
UChar* name_end = name + strlen(propname);
|
2016-11-30 20:29:19 +03:00
|
|
|
int ctype = env->enc->property_name_to_ctype(ONIG_ENCODING_ASCII,
|
2018-10-16 11:13:58 +03:00
|
|
|
name, name_end);
|
|
|
|
if (ctype < 0) {
|
|
|
|
onig_scan_env_set_error_string(env, ctype, name, name_end);
|
|
|
|
}
|
2016-11-30 20:29:19 +03:00
|
|
|
return ctype;
|
|
|
|
}
|
|
|
|
|
2018-10-16 11:13:58 +03:00
|
|
|
static int
|
|
|
|
add_property_to_cc(CClassNode* cc, const char* propname, int not, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int ctype = propname2ctype(env, propname);
|
|
|
|
if (ctype < 0) return ctype;
|
|
|
|
return add_ctype_to_cc(cc, ctype, not, 0, env);
|
|
|
|
}
|
|
|
|
|
2018-11-27 12:44:35 +03:00
|
|
|
/*
|
|
|
|
* helper methods for node_extended_grapheme_cluster (/\X/)
|
|
|
|
*/
|
2018-11-25 14:02:41 +03:00
|
|
|
static int
|
|
|
|
create_property_node(Node **np, ScanEnv* env, const char* propname)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
CClassNode* cc;
|
|
|
|
|
|
|
|
*np = node_new_cclass();
|
|
|
|
if (IS_NULL(*np)) return ONIGERR_MEMORY;
|
|
|
|
cc = NCCLASS(*np);
|
|
|
|
r = add_property_to_cc(cc, propname, 0, env);
|
|
|
|
if (r != 0)
|
|
|
|
onig_node_free(*np);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-11-27 12:44:35 +03:00
|
|
|
static int
|
|
|
|
quantify_node(Node **np, int lower, int upper)
|
|
|
|
{
|
|
|
|
Node* tmp = node_new_quantifier(lower, upper, 0);
|
|
|
|
if (IS_NULL(tmp)) return ONIGERR_MEMORY;
|
|
|
|
NQTFR(tmp)->target = *np;
|
|
|
|
*np = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-27 13:15:45 +03:00
|
|
|
static int
|
2018-11-28 03:28:52 +03:00
|
|
|
quantify_property_node(Node **np, ScanEnv* env, const char* propname, char repetitions)
|
2018-11-27 13:15:45 +03:00
|
|
|
{
|
|
|
|
int r;
|
2018-11-28 03:28:52 +03:00
|
|
|
int lower = 0;
|
|
|
|
int upper = REPEAT_INFINITE;
|
|
|
|
|
2018-11-27 13:15:45 +03:00
|
|
|
r = create_property_node(np, env, propname);
|
2018-11-27 13:15:46 +03:00
|
|
|
if (r != 0) return r;
|
2018-11-28 03:28:52 +03:00
|
|
|
switch (repetitions) {
|
2018-12-02 04:06:28 +03:00
|
|
|
case '?': upper = 1; break;
|
|
|
|
case '+': lower = 1; break;
|
|
|
|
case '*': break;
|
|
|
|
case '2': lower = upper = 2; break;
|
|
|
|
default : return ONIGERR_PARSER_BUG;
|
2018-11-28 03:28:52 +03:00
|
|
|
}
|
2018-11-27 13:15:45 +03:00
|
|
|
return quantify_node(np, lower, upper);
|
|
|
|
}
|
|
|
|
|
2018-12-06 07:46:57 +03:00
|
|
|
#define LIST 0
|
|
|
|
#define ALT 1
|
2018-11-27 14:04:02 +03:00
|
|
|
|
2018-12-01 10:31:34 +03:00
|
|
|
/* IMPORTANT: Make sure node_array ends with NULL_NODE */
|
|
|
|
static int
|
2018-12-06 07:46:57 +03:00
|
|
|
create_node_from_array(int kind, Node **np, Node **node_array)
|
2018-12-01 10:31:34 +03:00
|
|
|
{
|
|
|
|
Node* tmp = NULL_NODE;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (node_array[i] != NULL_NODE) i++;
|
|
|
|
while (--i >= 0) {
|
2018-12-06 07:46:57 +03:00
|
|
|
*np = kind==LIST ? node_new_list(node_array[i], tmp)
|
|
|
|
: onig_node_new_alt(node_array[i], tmp);
|
2018-12-01 10:31:34 +03:00
|
|
|
if (IS_NULL(*np)) {
|
|
|
|
while (i >= 0) {
|
|
|
|
onig_node_free(node_array[i]);
|
|
|
|
node_array[i--] = NULL_NODE;
|
|
|
|
}
|
|
|
|
onig_node_free(tmp);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
2018-12-03 00:41:50 +03:00
|
|
|
else
|
|
|
|
node_array[i] = NULL_NODE;
|
2018-12-01 10:31:34 +03:00
|
|
|
tmp = *np;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-28 03:53:35 +03:00
|
|
|
#define R_ERR(call) r=(call);if(r!=0)goto err
|
2018-12-06 12:16:43 +03:00
|
|
|
|
|
|
|
/* Memory layout for common node array:
|
|
|
|
* The main purpose is to be able to easily free all leftover nodes
|
|
|
|
* after an error. As a side effect, we share some memory.
|
|
|
|
*
|
|
|
|
* The layout is as shown below (each line corresponds to one call of
|
|
|
|
* create_node_from_array()). Because create_node_from_array sets all
|
|
|
|
* nodes of the source to NULL_NODE, we can overlap the target array
|
|
|
|
* as long as we do not override the actual target location.
|
|
|
|
*
|
|
|
|
* Target Array name Index
|
|
|
|
*
|
2018-12-07 10:04:00 +03:00
|
|
|
* node_array 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
|
|
|
* top_alts alts[5] 0 1 2 3 4*
|
|
|
|
* alts+1 list[4] 0 1 2 3*
|
|
|
|
* list+1 core_alts[7] 0 1 2 3 4 5 6*
|
|
|
|
* core_alts+0 H_list[4] 0 1 2 3*
|
|
|
|
* H_list+1 H_alt2[4] 0 1 2 3*
|
|
|
|
* h_alt2+1 H_list2[3] 0 1 2*
|
|
|
|
* core_alts+4 XP_list[4] 0 1 2 3*
|
|
|
|
* XP_list+1 Ex_list[4] 0 1 2 3*
|
2018-12-06 12:16:43 +03:00
|
|
|
*/
|
2018-12-07 10:04:00 +03:00
|
|
|
#define NODE_COMMON_SIZE 16
|
2018-11-28 03:53:35 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
static int
|
|
|
|
node_extended_grapheme_cluster(Node** np, ScanEnv* env)
|
|
|
|
{
|
2016-12-10 20:47:04 +03:00
|
|
|
Node* tmp = NULL;
|
2012-02-17 11:42:23 +04:00
|
|
|
Node* np1 = NULL;
|
2018-12-05 11:10:24 +03:00
|
|
|
Node* top_alt = NULL;
|
2012-02-17 11:42:23 +04:00
|
|
|
int r = 0;
|
2016-12-10 20:47:04 +03:00
|
|
|
int num1;
|
2018-12-03 00:41:50 +03:00
|
|
|
int i;
|
2018-12-07 10:04:00 +03:00
|
|
|
int any_target_position;
|
2016-12-10 20:47:04 +03:00
|
|
|
UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN * 2];
|
|
|
|
OnigOptionType option;
|
2018-12-07 10:04:00 +03:00
|
|
|
/* node_common is function-global so that we can free all nodes
|
2018-12-03 00:41:50 +03:00
|
|
|
* in case of error. Unused slots are set to NULL_NODE at all times. */
|
2018-12-06 12:16:43 +03:00
|
|
|
Node *node_common[NODE_COMMON_SIZE];
|
2018-12-07 10:04:00 +03:00
|
|
|
Node **alts = node_common+0; /* size: 5 */
|
|
|
|
|
|
|
|
for (i=0; i<NODE_COMMON_SIZE; i++)
|
|
|
|
node_common[i] = NULL_NODE;
|
|
|
|
|
|
|
|
/* CRLF, common for both Unicode and non-Unicode */
|
|
|
|
/* \x0D\x0A */
|
|
|
|
r = ONIGENC_CODE_TO_MBC(env->enc, 0x0D, buf);
|
|
|
|
if (r < 0) goto err;
|
|
|
|
num1 = r;
|
|
|
|
r = ONIGENC_CODE_TO_MBC(env->enc, 0x0A, buf + num1);
|
|
|
|
if (r < 0) goto err;
|
|
|
|
alts[0] = node_new_str_raw(buf, buf + num1 + r);
|
|
|
|
if (IS_NULL(alts[0])) goto err;
|
2012-02-17 11:42:23 +04:00
|
|
|
|
|
|
|
#ifdef USE_UNICODE_PROPERTIES
|
2018-12-05 12:00:40 +03:00
|
|
|
if (ONIGENC_IS_UNICODE(env->enc)) { /* UTF-8, UTF-16BE/LE, UTF-32BE/LE */
|
2016-11-30 20:29:19 +03:00
|
|
|
CClassNode* cc;
|
2012-02-17 11:42:23 +04:00
|
|
|
|
2018-11-27 07:13:21 +03:00
|
|
|
if (propname2ctype(env, "Grapheme_Cluster_Break=Extend") < 0) goto err;
|
2018-12-05 11:10:24 +03:00
|
|
|
/* Unicode 11.0.0
|
2018-12-07 10:04:00 +03:00
|
|
|
* CRLF (already done)
|
2018-12-05 11:10:24 +03:00
|
|
|
* | [Control CR LF]
|
|
|
|
* | precore* core postcore*
|
|
|
|
* | . (to catch invalid stuff, because this seems to be spec for String#grapheme_clusters) */
|
2018-12-07 10:04:00 +03:00
|
|
|
|
|
|
|
/* [Control CR LF] (CR and LF are not in the spec, but this is a conformed fix) */
|
|
|
|
alts[1] = node_new_cclass();
|
|
|
|
if (IS_NULL(alts[1])) goto err;
|
|
|
|
cc = NCCLASS(alts[1]);
|
|
|
|
R_ERR(add_property_to_cc(cc, "Grapheme_Cluster_Break=Control", 0, env));
|
|
|
|
if (ONIGENC_MBC_MINLEN(env->enc) > 1) { /* UTF-16/UTF-32 */
|
|
|
|
R_ERR(add_code_range(&(cc->mbuf), env, 0x000A, 0x000A)); /* CR */
|
|
|
|
R_ERR(add_code_range(&(cc->mbuf), env, 0x000D, 0x000D)); /* LF */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BITSET_SET_BIT(cc->bs, 0x0a);
|
|
|
|
BITSET_SET_BIT(cc->bs, 0x0d);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* precore* core postcore* */
|
2018-11-28 04:58:35 +03:00
|
|
|
{
|
2018-12-07 10:04:00 +03:00
|
|
|
Node **list = alts + 3; /* size: 4 */
|
2016-11-30 20:29:19 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* precore*; precore := Prepend */
|
|
|
|
R_ERR(quantify_property_node(list+0, env, "Grapheme_Cluster_Break=Prepend", '*'));
|
2016-11-30 20:29:19 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* core := hangul-syllable
|
|
|
|
* | ri-sequence
|
|
|
|
* | xpicto-sequence
|
|
|
|
* | [^Control CR LF] */
|
2018-12-01 10:31:34 +03:00
|
|
|
{
|
2018-12-07 10:04:00 +03:00
|
|
|
Node **core_alts = list + 2; /* size: 7 */
|
2016-11-30 20:29:19 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* hangul-syllable :=
|
|
|
|
* L* (V+ | LV V* | LVT) T*
|
|
|
|
* | L+
|
|
|
|
* | T+ */
|
|
|
|
/* hangul-syllable is an alternative (would be called H_alt)
|
|
|
|
* inside an alternative, but we flatten it into core_alts */
|
2016-11-30 20:29:19 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* L* (V+ | LV V* | LVT) T* */
|
2018-12-05 11:10:24 +03:00
|
|
|
{
|
2018-12-07 10:04:00 +03:00
|
|
|
Node **H_list = core_alts + 1; /* size: 4 */
|
|
|
|
R_ERR(quantify_property_node(H_list+0, env, "Grapheme_Cluster_Break=L", '*'));
|
2018-12-05 11:10:24 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* V+ | LV V* | LVT */
|
2018-12-05 11:10:24 +03:00
|
|
|
{
|
2018-12-07 10:04:00 +03:00
|
|
|
Node **H_alt2 = H_list + 2; /* size: 4 */
|
|
|
|
R_ERR(quantify_property_node(H_alt2+0, env, "Grapheme_Cluster_Break=V", '+'));
|
2018-12-05 11:10:24 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* LV V* */
|
2018-12-05 11:10:24 +03:00
|
|
|
{
|
2018-12-07 10:04:00 +03:00
|
|
|
Node **H_list2 = H_alt2 + 2; /* size: 3 */
|
2018-12-05 11:10:24 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(create_property_node(H_list2+0, env, "Grapheme_Cluster_Break=LV"));
|
|
|
|
R_ERR(quantify_property_node(H_list2+1, env, "Grapheme_Cluster_Break=V", '*'));
|
|
|
|
R_ERR(create_node_from_array(LIST, H_alt2+1, H_list2));
|
2018-12-05 11:10:24 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(create_property_node(H_alt2+2, env, "Grapheme_Cluster_Break=LVT"));
|
|
|
|
R_ERR(create_node_from_array(ALT, H_list+1, H_alt2));
|
2018-12-05 11:10:24 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(quantify_property_node(H_list+2, env, "Grapheme_Cluster_Break=T", '*'));
|
|
|
|
R_ERR(create_node_from_array(LIST, core_alts+0, H_list));
|
|
|
|
}
|
2018-12-05 11:10:24 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(quantify_property_node(core_alts+1, env, "Grapheme_Cluster_Break=L", '+'));
|
|
|
|
R_ERR(quantify_property_node(core_alts+2, env, "Grapheme_Cluster_Break=T", '+'));
|
|
|
|
/* end of hangul-syllable */
|
2018-12-05 11:10:24 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* ri-sequence := RI RI */
|
|
|
|
R_ERR(quantify_property_node(core_alts+3, env, "Regional_Indicator", '2'));
|
2018-12-05 11:10:24 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* xpicto-sequence := \p{Extended_Pictographic} (Extend* ZWJ \p{Extended_Pictographic})* */
|
|
|
|
{
|
|
|
|
Node **XP_list = core_alts + 5; /* size: 3 */
|
|
|
|
R_ERR(create_property_node(XP_list+0, env, "Extended_Pictographic"));
|
2018-12-05 11:10:24 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* (Extend* ZWJ \p{Extended_Pictographic})* */
|
|
|
|
{
|
|
|
|
Node **Ex_list = XP_list + 2; /* size: 4 */
|
2018-12-07 10:20:26 +03:00
|
|
|
/* assert(Ex_list+4 == node_common+NODE_COMMON_SIZE); */
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(quantify_property_node(Ex_list+0, env, "Grapheme_Cluster_Break=Extend", '*'));
|
|
|
|
|
|
|
|
/* ZWJ (ZERO WIDTH JOINER) */
|
|
|
|
r = ONIGENC_CODE_TO_MBC(env->enc, 0x200D, buf);
|
|
|
|
if (r < 0) goto err;
|
|
|
|
Ex_list[1] = node_new_str_raw(buf, buf + r);
|
|
|
|
if (IS_NULL(Ex_list[1])) goto err;
|
|
|
|
|
|
|
|
R_ERR(create_property_node(Ex_list+2, env, "Extended_Pictographic"));
|
|
|
|
R_ERR(create_node_from_array(LIST, XP_list+1, Ex_list));
|
2018-12-05 11:10:24 +03:00
|
|
|
}
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(quantify_node(XP_list+1, 0, REPEAT_INFINITE)); /* TODO: Check about node freeing */
|
2018-12-05 11:10:24 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(create_node_from_array(LIST, core_alts+4, XP_list));
|
2018-12-05 11:10:24 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* [^Control CR LF] */
|
|
|
|
core_alts[5] = node_new_cclass();
|
|
|
|
if (IS_NULL(core_alts[5])) goto err;
|
|
|
|
cc = NCCLASS(core_alts[5]);
|
|
|
|
if (ONIGENC_MBC_MINLEN(env->enc) > 1) { /* UTF-16/UTF-32 */
|
|
|
|
BBuf *inverted_buf = NULL;
|
|
|
|
|
2019-06-29 04:10:17 +03:00
|
|
|
/* TODO: fix false warning */
|
|
|
|
const int dup_not_warned = env->warnings_flag | ~ONIG_SYN_WARN_CC_DUP;
|
|
|
|
env->warnings_flag |= ONIG_SYN_WARN_CC_DUP;
|
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* Start with a positive buffer and invert at the end.
|
|
|
|
* Otherwise, adding single-character ranges work the wrong way. */
|
|
|
|
R_ERR(add_property_to_cc(cc, "Grapheme_Cluster_Break=Control", 0, env));
|
|
|
|
R_ERR(add_code_range(&(cc->mbuf), env, 0x000A, 0x000A)); /* CR */
|
|
|
|
R_ERR(add_code_range(&(cc->mbuf), env, 0x000D, 0x000D)); /* LF */
|
|
|
|
R_ERR(not_code_range_buf(env->enc, cc->mbuf, &inverted_buf, env));
|
|
|
|
cc->mbuf = inverted_buf; /* TODO: check what to do with buffer before inversion */
|
2019-06-29 04:10:17 +03:00
|
|
|
|
|
|
|
env->warnings_flag &= dup_not_warned; /* TODO: fix false warning */
|
2018-12-07 10:04:00 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
R_ERR(add_property_to_cc(cc, "Grapheme_Cluster_Break=Control", 1, env));
|
|
|
|
BITSET_CLEAR_BIT(cc->bs, 0x0a);
|
|
|
|
BITSET_CLEAR_BIT(cc->bs, 0x0d);
|
|
|
|
}
|
2018-12-05 11:10:24 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(create_node_from_array(ALT, list+1, core_alts));
|
2018-12-01 10:31:34 +03:00
|
|
|
}
|
2016-11-30 20:29:19 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* postcore*; postcore = [Extend ZWJ SpacingMark] */
|
|
|
|
R_ERR(create_property_node(list+2, env, "Grapheme_Cluster_Break=Extend"));
|
|
|
|
cc = NCCLASS(list[2]);
|
|
|
|
R_ERR(add_property_to_cc(cc, "Grapheme_Cluster_Break=SpacingMark", 0, env));
|
|
|
|
R_ERR(add_code_range(&(cc->mbuf), env, 0x200D, 0x200D));
|
|
|
|
R_ERR(quantify_node(list+2, 0, REPEAT_INFINITE));
|
2016-11-30 20:29:19 +03:00
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(create_node_from_array(LIST, alts+2, list));
|
2018-12-05 12:00:40 +03:00
|
|
|
}
|
2018-12-07 10:04:00 +03:00
|
|
|
|
|
|
|
any_target_position = 3;
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
else
|
2012-02-17 11:42:23 +04:00
|
|
|
#endif /* USE_UNICODE_PROPERTIES */
|
2016-12-10 20:47:04 +03:00
|
|
|
{
|
2018-12-07 10:04:00 +03:00
|
|
|
any_target_position = 1;
|
2016-12-10 20:47:04 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
/* PerlSyntax: (?s:.), RubySyntax: (?m:.), common for both Unicode and non-Unicode */
|
|
|
|
/* Not in Unicode spec (UAX #29), but added to catch invalid stuff,
|
|
|
|
* because this is Ruby spec for String#grapheme_clusters. */
|
|
|
|
np1 = node_new_anychar();
|
2016-12-10 20:47:04 +03:00
|
|
|
if (IS_NULL(np1)) goto err;
|
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
option = env->option;
|
|
|
|
ONOFF(option, ONIG_OPTION_MULTILINE, 0);
|
|
|
|
tmp = node_new_option(option);
|
2016-12-10 20:47:04 +03:00
|
|
|
if (IS_NULL(tmp)) goto err;
|
2018-12-07 10:04:00 +03:00
|
|
|
NENCLOSE(tmp)->target = np1;
|
|
|
|
alts[any_target_position] = tmp;
|
2016-12-10 20:47:04 +03:00
|
|
|
np1 = NULL;
|
|
|
|
|
2018-12-07 10:04:00 +03:00
|
|
|
R_ERR(create_node_from_array(ALT, &top_alt, alts));
|
|
|
|
|
|
|
|
/* (?>): For efficiency, because there is no text piece
|
|
|
|
* that is not in a grapheme cluster, and there is only one way
|
|
|
|
* to split a string into grapheme clusters. */
|
2016-12-10 20:47:04 +03:00
|
|
|
tmp = node_new_enclose(ENCLOSE_STOP_BACKTRACK);
|
|
|
|
if (IS_NULL(tmp)) goto err;
|
2018-12-05 11:10:24 +03:00
|
|
|
NENCLOSE(tmp)->target = top_alt;
|
2016-12-10 20:47:04 +03:00
|
|
|
np1 = tmp;
|
|
|
|
|
|
|
|
#ifdef USE_UNICODE_PROPERTIES
|
|
|
|
if (ONIGENC_IS_UNICODE(env->enc)) {
|
|
|
|
/* Don't ignore case. */
|
|
|
|
option = env->option;
|
|
|
|
ONOFF(option, ONIG_OPTION_IGNORECASE, 1);
|
2012-02-17 11:42:23 +04:00
|
|
|
*np = node_new_option(option);
|
|
|
|
if (IS_NULL(*np)) goto err;
|
|
|
|
NENCLOSE(*np)->target = np1;
|
|
|
|
}
|
2016-12-10 20:47:04 +03:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
*np = np1;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
return ONIG_NORMAL;
|
|
|
|
|
|
|
|
err:
|
|
|
|
onig_node_free(np1);
|
2018-12-06 12:16:43 +03:00
|
|
|
for (i=0; i<NODE_COMMON_SIZE; i++)
|
|
|
|
onig_node_free(node_common[i]);
|
2012-02-17 11:42:23 +04:00
|
|
|
return (r == 0) ? ONIGERR_MEMORY : r;
|
|
|
|
}
|
2018-11-28 03:53:35 +03:00
|
|
|
#undef R_ERR
|
2012-02-17 11:42:23 +04:00
|
|
|
|
|
|
|
static int
|
2012-03-15 05:39:00 +04:00
|
|
|
countbits(unsigned int bits)
|
|
|
|
{
|
2012-02-17 11:42:23 +04:00
|
|
|
bits = (bits & 0x55555555) + ((bits >> 1) & 0x55555555);
|
|
|
|
bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333);
|
|
|
|
bits = (bits & 0x0f0f0f0f) + ((bits >> 4) & 0x0f0f0f0f);
|
|
|
|
bits = (bits & 0x00ff00ff) + ((bits >> 8) & 0x00ff00ff);
|
|
|
|
return (bits & 0x0000ffff) + ((bits >>16) & 0x0000ffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_onechar_cclass(CClassNode* cc, OnigCodePoint* code)
|
|
|
|
{
|
2013-03-01 20:36:37 +04:00
|
|
|
const OnigCodePoint not_found = ONIG_LAST_CODE_POINT;
|
2012-07-18 12:41:01 +04:00
|
|
|
OnigCodePoint c = not_found;
|
2012-06-14 00:46:11 +04:00
|
|
|
int i;
|
2012-02-17 11:42:23 +04:00
|
|
|
BBuf *bbuf = cc->mbuf;
|
|
|
|
|
|
|
|
if (IS_NCCLASS_NOT(cc)) return 0;
|
|
|
|
|
|
|
|
/* check bbuf */
|
|
|
|
if (IS_NOT_NULL(bbuf)) {
|
|
|
|
OnigCodePoint n, *data;
|
|
|
|
GET_CODE_POINT(n, bbuf->p);
|
|
|
|
data = (OnigCodePoint* )(bbuf->p) + 1;
|
|
|
|
if ((n == 1) && (data[0] == data[1])) {
|
|
|
|
/* only one char found in the bbuf, save the code point. */
|
|
|
|
c = data[0];
|
2012-07-18 12:41:01 +04:00
|
|
|
if (((c < SINGLE_BYTE_SIZE) && BITSET_AT(cc->bs, c))) {
|
2016-12-10 20:47:04 +03:00
|
|
|
/* skip if c is included in the bitset */
|
2012-07-18 12:41:01 +04:00
|
|
|
c = not_found;
|
2012-06-14 00:46:11 +04:00
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0; /* the bbuf contains multiple chars */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check bitset */
|
2013-03-01 20:36:37 +04:00
|
|
|
for (i = 0; i < BITSET_SIZE; i++) {
|
2012-06-14 00:46:11 +04:00
|
|
|
Bits b1 = cc->bs[i];
|
2012-02-17 11:42:23 +04:00
|
|
|
if (b1 != 0) {
|
2012-07-18 12:41:01 +04:00
|
|
|
if (((b1 & (b1 - 1)) == 0) && (c == not_found)) {
|
2016-12-10 20:47:04 +03:00
|
|
|
c = BITS_IN_ROOM * i + countbits(b1 - 1);
|
2012-02-17 11:42:23 +04:00
|
|
|
} else {
|
2016-12-10 20:47:04 +03:00
|
|
|
return 0; /* the character class contains multiple chars */
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 00:46:11 +04:00
|
|
|
|
2012-07-18 12:41:01 +04:00
|
|
|
if (c != not_found) {
|
2012-06-14 00:46:11 +04:00
|
|
|
*code = c;
|
|
|
|
return 1;
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
2012-06-14 00:46:11 +04:00
|
|
|
|
|
|
|
/* the character class contains no char. */
|
|
|
|
return 0;
|
2012-02-17 11:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
|
|
|
parse_exp(Node** np, OnigToken* tok, int term,
|
|
|
|
UChar** src, UChar* end, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r, len, group = 0;
|
|
|
|
Node* qn;
|
|
|
|
Node** targetp;
|
|
|
|
|
|
|
|
*np = NULL;
|
2008-01-03 18:55:04 +03:00
|
|
|
if (tok->type == (enum TokenSyms )term)
|
2004-03-05 18:31:51 +03:00
|
|
|
goto end_of_token;
|
|
|
|
|
|
|
|
switch (tok->type) {
|
|
|
|
case TK_ALT:
|
|
|
|
case TK_EOT:
|
2012-02-29 20:29:06 +04:00
|
|
|
end_of_token:
|
2009-08-16 05:45:18 +04:00
|
|
|
*np = node_new_empty();
|
|
|
|
return tok->type;
|
2012-02-17 11:42:23 +04:00
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
case TK_SUBEXP_OPEN:
|
2007-07-23 13:39:30 +04:00
|
|
|
r = parse_enclose(np, tok, TK_SUBEXP_CLOSE, src, end, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) return r;
|
|
|
|
if (r == 1) group = 1;
|
|
|
|
else if (r == 2) { /* option only */
|
|
|
|
Node* target;
|
|
|
|
OnigOptionType prev = env->option;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
env->option = NENCLOSE(*np)->option;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = fetch_token(tok, src, end, env);
|
2016-12-10 20:47:04 +03:00
|
|
|
if (r < 0) {
|
|
|
|
env->option = prev;
|
|
|
|
return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
r = parse_subexp(&target, tok, term, src, end, env);
|
|
|
|
env->option = prev;
|
2009-08-16 06:15:13 +04:00
|
|
|
if (r < 0) {
|
|
|
|
onig_node_free(target);
|
|
|
|
return r;
|
|
|
|
}
|
2009-02-22 17:23:33 +03:00
|
|
|
NENCLOSE(*np)->target = target;
|
2004-03-05 18:31:51 +03:00
|
|
|
return tok->type;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_SUBEXP_CLOSE:
|
|
|
|
if (! IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP))
|
|
|
|
return ONIGERR_UNMATCHED_CLOSE_PARENTHESIS;
|
|
|
|
|
|
|
|
if (tok->escaped) goto tk_raw_byte;
|
|
|
|
else goto tk_byte;
|
|
|
|
break;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
case TK_LINEBREAK:
|
|
|
|
r = node_linebreak(np, env);
|
|
|
|
if (r < 0) return r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_EXTENDED_GRAPHEME_CLUSTER:
|
|
|
|
r = node_extended_grapheme_cluster(np, env);
|
|
|
|
if (r < 0) return r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_KEEP:
|
|
|
|
*np = onig_node_new_anchor(ANCHOR_KEEP);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
break;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
case TK_STRING:
|
2004-03-05 18:31:51 +03:00
|
|
|
tk_byte:
|
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
*np = node_new_str(tok->backp, *src);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
string_loop:
|
2004-03-05 18:31:51 +03:00
|
|
|
while (1) {
|
|
|
|
r = fetch_token(tok, src, end, env);
|
2009-08-16 06:20:00 +04:00
|
|
|
if (r < 0) return r;
|
2012-02-17 11:42:23 +04:00
|
|
|
if (r == TK_STRING) {
|
|
|
|
r = onig_node_str_cat(*np, tok->backp, *src);
|
|
|
|
}
|
|
|
|
#ifndef NUMBERED_CHAR_IS_NOT_CASE_AMBIG
|
|
|
|
else if (r == TK_CODE_POINT) {
|
|
|
|
r = node_str_cat_codepoint(*np, env->enc, tok->u.code);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
2009-08-16 06:20:00 +04:00
|
|
|
if (r < 0) return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
string_end:
|
2004-03-05 18:31:51 +03:00
|
|
|
targetp = np;
|
|
|
|
goto repeat;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_RAW_BYTE:
|
|
|
|
tk_raw_byte:
|
|
|
|
{
|
|
|
|
*np = node_new_str_raw_char((UChar )tok->u.c);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
len = 1;
|
|
|
|
while (1) {
|
2007-05-23 05:32:08 +04:00
|
|
|
if (len >= ONIGENC_MBC_MINLEN(env->enc)) {
|
2008-01-03 18:55:04 +03:00
|
|
|
if (len == enclen(env->enc, NSTR(*np)->s, NSTR(*np)->end)) {
|
2007-05-23 05:32:08 +04:00
|
|
|
r = fetch_token(tok, src, end, env);
|
|
|
|
NSTRING_CLEAR_RAW(*np);
|
|
|
|
goto string_end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
r = fetch_token(tok, src, end, env);
|
2009-08-16 06:20:00 +04:00
|
|
|
if (r < 0) return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != TK_RAW_BYTE) {
|
2007-05-23 05:32:08 +04:00
|
|
|
/* Don't use this, it is wrong for little endian encodings. */
|
|
|
|
#ifdef USE_PAD_TO_SHORT_BYTE_CHAR
|
|
|
|
int rem;
|
|
|
|
if (len < ONIGENC_MBC_MINLEN(env->enc)) {
|
|
|
|
rem = ONIGENC_MBC_MINLEN(env->enc) - len;
|
2007-07-23 13:39:30 +04:00
|
|
|
(void )node_str_head_pad(NSTR(*np), rem, (UChar )0);
|
2008-01-03 18:55:04 +03:00
|
|
|
if (len + rem == enclen(env->enc, NSTR(*np)->s)) {
|
2007-05-23 05:32:08 +04:00
|
|
|
NSTRING_CLEAR_RAW(*np);
|
|
|
|
goto string_end;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
#endif
|
2007-05-23 05:32:08 +04:00
|
|
|
return ONIGERR_TOO_SHORT_MULTI_BYTE_STRING;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
r = node_str_cat_char(*np, (UChar )tok->u.c);
|
2009-08-16 06:20:00 +04:00
|
|
|
if (r < 0) return r;
|
2007-05-23 05:32:08 +04:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CODE_POINT:
|
|
|
|
{
|
2012-02-17 11:42:23 +04:00
|
|
|
*np = node_new_empty();
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
r = node_str_cat_codepoint(*np, env->enc, tok->u.code);
|
|
|
|
if (r != 0) return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef NUMBERED_CHAR_IS_NOT_CASE_AMBIG
|
2012-02-17 11:42:23 +04:00
|
|
|
NSTRING_SET_RAW(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
#else
|
2012-02-17 11:42:23 +04:00
|
|
|
goto string_loop;
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_QUOTE_OPEN:
|
|
|
|
{
|
2004-03-08 07:40:39 +03:00
|
|
|
OnigCodePoint end_op[2];
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar *qstart, *qend, *nextp;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
end_op[0] = (OnigCodePoint )MC_ESC(env->syntax);
|
2004-03-08 07:40:39 +03:00
|
|
|
end_op[1] = (OnigCodePoint )'E';
|
2004-03-05 18:31:51 +03:00
|
|
|
qstart = *src;
|
|
|
|
qend = find_str_position(end_op, 2, qstart, end, &nextp, env->enc);
|
|
|
|
if (IS_NULL(qend)) {
|
|
|
|
nextp = qend = end;
|
|
|
|
}
|
|
|
|
*np = node_new_str(qstart, qend);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
*src = nextp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CHAR_TYPE:
|
|
|
|
{
|
2007-05-23 05:32:08 +04:00
|
|
|
switch (tok->u.prop.ctype) {
|
|
|
|
case ONIGENC_CTYPE_WORD:
|
2012-02-17 11:42:23 +04:00
|
|
|
*np = node_new_ctype(tok->u.prop.ctype, tok->u.prop.not,
|
|
|
|
IS_ASCII_RANGE(env->option));
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
case ONIGENC_CTYPE_SPACE:
|
|
|
|
case ONIGENC_CTYPE_DIGIT:
|
|
|
|
case ONIGENC_CTYPE_XDIGIT:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
CClassNode* cc;
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
*np = node_new_cclass();
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
cc = NCCLASS(*np);
|
|
|
|
r = add_ctype_to_cc(cc, tok->u.prop.ctype, 0,
|
|
|
|
IS_ASCII_RANGE(env->option), env);
|
|
|
|
if (r != 0) return r;
|
|
|
|
if (tok->u.prop.not != 0) NCCLASS_SET_NOT(cc);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ONIGERR_PARSER_BUG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CHAR_PROPERTY:
|
|
|
|
r = parse_char_property(np, tok, src, end, env);
|
|
|
|
if (r != 0) return r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CC_OPEN:
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
{
|
2014-09-15 20:18:41 +04:00
|
|
|
Node *asc_node;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
CClassNode* cc;
|
2012-02-17 11:42:23 +04:00
|
|
|
OnigCodePoint code;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2014-09-15 20:18:41 +04:00
|
|
|
r = parse_char_class(np, &asc_node, tok, src, end, env);
|
|
|
|
if (r != 0) {
|
|
|
|
onig_node_free(asc_node);
|
|
|
|
return r;
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
cc = NCCLASS(*np);
|
2012-02-17 11:42:23 +04:00
|
|
|
if (is_onechar_cclass(cc, &code)) {
|
2012-03-21 14:53:06 +04:00
|
|
|
onig_node_free(*np);
|
2014-09-15 20:18:41 +04:00
|
|
|
onig_node_free(asc_node);
|
2012-02-17 11:42:23 +04:00
|
|
|
*np = node_new_empty();
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
r = node_str_cat_codepoint(*np, env->enc, code);
|
|
|
|
if (r != 0) return r;
|
|
|
|
goto string_loop;
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (IS_IGNORECASE(env->option)) {
|
2014-09-15 20:18:41 +04:00
|
|
|
r = cclass_case_fold(np, cc, NCCLASS(asc_node), env);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (r != 0) {
|
2014-09-15 20:18:41 +04:00
|
|
|
onig_node_free(asc_node);
|
2009-08-16 06:20:00 +04:00
|
|
|
return r;
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2014-09-15 20:18:41 +04:00
|
|
|
onig_node_free(asc_node);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_ANYCHAR:
|
|
|
|
*np = node_new_anychar();
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_ANYCHAR_ANYTIME:
|
|
|
|
*np = node_new_anychar();
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2007-05-23 05:32:08 +04:00
|
|
|
qn = node_new_quantifier(0, REPEAT_INFINITE, 0);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(qn);
|
|
|
|
NQTFR(qn)->target = *np;
|
2004-03-05 18:31:51 +03:00
|
|
|
*np = qn;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_BACKREF:
|
|
|
|
len = tok->u.backref.num;
|
|
|
|
*np = node_new_backref(len,
|
2006-08-05 17:54:40 +04:00
|
|
|
(len > 1 ? tok->u.backref.refs : &(tok->u.backref.ref1)),
|
|
|
|
tok->u.backref.by_name,
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
tok->u.backref.exist_level,
|
|
|
|
tok->u.backref.level,
|
|
|
|
#endif
|
|
|
|
env);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
case TK_CALL:
|
2008-01-03 18:55:04 +03:00
|
|
|
{
|
|
|
|
int gnum = tok->u.call.gnum;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
if (gnum < 0 || tok->u.call.rel != 0) {
|
|
|
|
if (gnum > 0) gnum--;
|
2008-01-03 18:55:04 +03:00
|
|
|
gnum = BACKREF_REL_TO_ABS(gnum, env);
|
|
|
|
if (gnum <= 0)
|
|
|
|
return ONIGERR_INVALID_BACKREF;
|
|
|
|
}
|
|
|
|
*np = node_new_call(tok->u.call.name, tok->u.call.name_end, gnum);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
env->num_call++;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case TK_ANCHOR:
|
2012-02-17 11:42:23 +04:00
|
|
|
*np = onig_node_new_anchor(tok->u.anchor.subtype);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(*np);
|
|
|
|
NANCHOR(*np)->ascii_range = tok->u.anchor.ascii_range;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_OP_REPEAT:
|
|
|
|
case TK_INTERVAL:
|
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS)) {
|
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS))
|
|
|
|
return ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED;
|
|
|
|
else
|
|
|
|
*np = node_new_empty();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto tk_byte;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ONIGERR_PARSER_BUG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
targetp = np;
|
|
|
|
|
|
|
|
re_entry:
|
|
|
|
r = fetch_token(tok, src, end, env);
|
2009-08-16 06:20:00 +04:00
|
|
|
if (r < 0) return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
repeat:
|
|
|
|
if (r == TK_OP_REPEAT || r == TK_INTERVAL) {
|
2007-05-23 05:32:08 +04:00
|
|
|
if (is_invalid_quantifier_target(*targetp))
|
2004-03-05 18:31:51 +03:00
|
|
|
return ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
qn = node_new_quantifier(tok->u.repeat.lower, tok->u.repeat.upper,
|
2007-07-23 13:39:30 +04:00
|
|
|
(r == TK_INTERVAL ? 1 : 0));
|
|
|
|
CHECK_NULL_RETURN_MEMERR(qn);
|
|
|
|
NQTFR(qn)->greedy = tok->u.repeat.greedy;
|
2007-05-23 05:32:08 +04:00
|
|
|
r = set_quantifier(qn, *targetp, group, env);
|
2010-03-02 00:54:59 +03:00
|
|
|
if (r < 0) {
|
|
|
|
onig_node_free(qn);
|
|
|
|
return r;
|
|
|
|
}
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (tok->u.repeat.possessive != 0) {
|
|
|
|
Node* en;
|
2007-07-23 13:39:30 +04:00
|
|
|
en = node_new_enclose(ENCLOSE_STOP_BACKTRACK);
|
2008-09-12 15:02:21 +04:00
|
|
|
if (IS_NULL(en)) {
|
|
|
|
onig_node_free(qn);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
NENCLOSE(en)->target = qn;
|
2004-03-05 18:31:51 +03:00
|
|
|
qn = en;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
*targetp = qn;
|
|
|
|
}
|
2008-07-30 16:08:28 +04:00
|
|
|
else if (r == 1) {
|
2012-02-17 11:42:23 +04:00
|
|
|
onig_node_free(qn);
|
2008-07-30 16:08:28 +04:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
else if (r == 2) { /* split case: /abc+/ */
|
|
|
|
Node *tmp;
|
|
|
|
|
|
|
|
*targetp = node_new_list(*targetp, NULL);
|
2010-03-02 00:54:59 +03:00
|
|
|
if (IS_NULL(*targetp)) {
|
|
|
|
onig_node_free(qn);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
tmp = NCDR(*targetp) = node_new_list(qn, NULL);
|
2010-03-02 00:54:59 +03:00
|
|
|
if (IS_NULL(tmp)) {
|
|
|
|
onig_node_free(qn);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
targetp = &(NCAR(tmp));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
goto re_entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_branch(Node** top, OnigToken* tok, int term,
|
|
|
|
UChar** src, UChar* end, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
Node *node, **headp;
|
|
|
|
|
|
|
|
*top = NULL;
|
|
|
|
r = parse_exp(&node, tok, term, src, end, env);
|
2009-08-16 06:15:13 +04:00
|
|
|
if (r < 0) {
|
|
|
|
onig_node_free(node);
|
|
|
|
return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (r == TK_EOT || r == term || r == TK_ALT) {
|
|
|
|
*top = node;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*top = node_new_list(node, NULL);
|
2007-07-23 13:39:30 +04:00
|
|
|
headp = &(NCDR(*top));
|
2004-03-05 18:31:51 +03:00
|
|
|
while (r != TK_EOT && r != term && r != TK_ALT) {
|
|
|
|
r = parse_exp(&node, tok, term, src, end, env);
|
2009-08-16 05:45:18 +04:00
|
|
|
if (r < 0) {
|
2009-08-16 06:15:13 +04:00
|
|
|
onig_node_free(node);
|
2009-08-16 05:45:18 +04:00
|
|
|
return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(node) == NT_LIST) {
|
2004-03-05 18:31:51 +03:00
|
|
|
*headp = node;
|
2007-07-23 13:39:30 +04:00
|
|
|
while (IS_NOT_NULL(NCDR(node))) node = NCDR(node);
|
|
|
|
headp = &(NCDR(node));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*headp = node_new_list(node, NULL);
|
2007-07-23 13:39:30 +04:00
|
|
|
headp = &(NCDR(*headp));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* term_tok: TK_EOT or TK_SUBEXP_CLOSE */
|
|
|
|
static int
|
|
|
|
parse_subexp(Node** top, OnigToken* tok, int term,
|
|
|
|
UChar** src, UChar* end, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
Node *node, **headp;
|
|
|
|
|
|
|
|
*top = NULL;
|
2016-12-10 20:47:04 +03:00
|
|
|
env->parse_depth++;
|
|
|
|
if (env->parse_depth > ParseDepthLimit)
|
|
|
|
return ONIGERR_PARSE_DEPTH_LIMIT_OVER;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = parse_branch(&node, tok, term, src, end, env);
|
2009-08-16 06:20:00 +04:00
|
|
|
if (r < 0) {
|
|
|
|
onig_node_free(node);
|
|
|
|
return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (r == term) {
|
|
|
|
*top = node;
|
|
|
|
}
|
|
|
|
else if (r == TK_ALT) {
|
2007-05-23 05:32:08 +04:00
|
|
|
*top = onig_node_new_alt(node, NULL);
|
2007-07-23 13:39:30 +04:00
|
|
|
headp = &(NCDR(*top));
|
2004-03-05 18:31:51 +03:00
|
|
|
while (r == TK_ALT) {
|
|
|
|
r = fetch_token(tok, src, end, env);
|
2009-08-16 06:20:00 +04:00
|
|
|
if (r < 0) return r;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = parse_branch(&node, tok, term, src, end, env);
|
2009-08-16 05:45:18 +04:00
|
|
|
if (r < 0) {
|
2009-08-16 06:15:13 +04:00
|
|
|
onig_node_free(node);
|
2009-08-16 05:45:18 +04:00
|
|
|
return r;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
*headp = onig_node_new_alt(node, NULL);
|
2007-07-23 13:39:30 +04:00
|
|
|
headp = &(NCDR(*headp));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
2009-08-16 06:20:00 +04:00
|
|
|
if (tok->type != (enum TokenSyms )term)
|
2004-03-05 18:31:51 +03:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else {
|
2009-08-16 06:15:13 +04:00
|
|
|
onig_node_free(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
err:
|
|
|
|
if (term == TK_SUBEXP_CLOSE)
|
|
|
|
return ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS;
|
|
|
|
else
|
|
|
|
return ONIGERR_PARSER_BUG;
|
|
|
|
}
|
|
|
|
|
2016-12-10 20:47:04 +03:00
|
|
|
env->parse_depth--;
|
2004-03-05 18:31:51 +03:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_regexp(Node** top, UChar** src, UChar* end, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
OnigToken tok;
|
|
|
|
|
|
|
|
r = fetch_token(&tok, src, end, env);
|
|
|
|
if (r < 0) return r;
|
|
|
|
r = parse_subexp(top, &tok, TK_EOT, src, end, env);
|
|
|
|
if (r < 0) return r;
|
2012-02-17 11:42:23 +04:00
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
if (env->num_call > 0) {
|
|
|
|
/* Capture the pattern itself. It is used for (?R), (?0) and \g<0>. */
|
|
|
|
const int num = 0;
|
|
|
|
Node* np;
|
|
|
|
np = node_new_enclose_memory(env->option, 0);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(np);
|
|
|
|
NENCLOSE(np)->regnum = num;
|
|
|
|
NENCLOSE(np)->target = *top;
|
|
|
|
r = scan_env_set_mem_node(env, num, np);
|
2016-05-08 20:52:38 +03:00
|
|
|
if (r != 0) {
|
|
|
|
onig_node_free(np);
|
|
|
|
return r;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
*top = np;
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
2007-07-23 13:39:30 +04:00
|
|
|
onig_parse_make_tree(Node** root, const UChar* pattern, const UChar* end,
|
|
|
|
regex_t* reg, ScanEnv* env)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
UChar* p;
|
|
|
|
|
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
names_clear(reg);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
scan_env_clear(env);
|
2007-05-23 05:32:08 +04:00
|
|
|
env->option = reg->options;
|
|
|
|
env->case_fold_flag = reg->case_fold_flag;
|
|
|
|
env->enc = reg->enc;
|
|
|
|
env->syntax = reg->syntax;
|
|
|
|
env->pattern = (UChar* )pattern;
|
|
|
|
env->pattern_end = (UChar* )end;
|
|
|
|
env->reg = reg;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
*root = NULL;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
p = (UChar* )pattern;
|
|
|
|
r = parse_regexp(root, &p, (UChar* )end, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
reg->num_mem = env->num_mem;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void
|
2008-01-03 18:55:04 +03:00
|
|
|
onig_scan_env_set_error_string(ScanEnv* env, int ecode ARG_UNUSED,
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar* arg, UChar* arg_end)
|
|
|
|
{
|
|
|
|
env->error = arg;
|
|
|
|
env->error_end = arg_end;
|
|
|
|
}
|