2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
re.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Mon Aug 9 18:24:49 JST 1993
|
|
|
|
|
2003-01-16 02:34:03 -05:00
|
|
|
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#include "ruby.h"
|
|
|
|
#include "re.h"
|
2005-05-05 19:08:47 -04:00
|
|
|
#include "regint.h"
|
2001-05-16 05:05:54 -04:00
|
|
|
#include <ctype.h>
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-02-26 03:05:06 -05:00
|
|
|
#define MBCTYPE_ASCII 0
|
|
|
|
#define MBCTYPE_EUC 1
|
|
|
|
#define MBCTYPE_SJIS 2
|
|
|
|
#define MBCTYPE_UTF8 3
|
|
|
|
|
2000-08-28 05:53:42 -04:00
|
|
|
static VALUE rb_eRegexpError;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#define BEG(no) regs->beg[no]
|
|
|
|
#define END(no) regs->end[no]
|
|
|
|
|
|
|
|
#if 'a' == 97 /* it's ascii */
|
1999-08-13 01:45:20 -04:00
|
|
|
static const char casetable[] = {
|
1998-01-16 07:13:05 -05:00
|
|
|
'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
|
|
|
|
'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
|
|
|
|
'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
|
|
|
|
'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
|
|
|
|
/* ' ' '!' '"' '#' '$' '%' '&' ''' */
|
|
|
|
'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
|
|
|
|
/* '(' ')' '*' '+' ',' '-' '.' '/' */
|
|
|
|
'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
|
|
|
|
/* '0' '1' '2' '3' '4' '5' '6' '7' */
|
|
|
|
'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
|
|
|
|
/* '8' '9' ':' ';' '<' '=' '>' '?' */
|
|
|
|
'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
|
|
|
|
/* '@' 'A' 'B' 'C' 'D' 'E' 'F' 'G' */
|
|
|
|
'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
|
|
/* 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' */
|
|
|
|
'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
|
|
/* 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' */
|
|
|
|
'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
|
|
/* 'X' 'Y' 'Z' '[' '\' ']' '^' '_' */
|
|
|
|
'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
|
|
|
|
/* '`' 'a' 'b' 'c' 'd' 'e' 'f' 'g' */
|
|
|
|
'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
|
|
/* 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' */
|
|
|
|
'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
|
|
/* 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' */
|
|
|
|
'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
|
|
/* 'x' 'y' 'z' '{' '|' '}' '~' */
|
|
|
|
'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
|
|
|
|
'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
|
|
|
|
'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
|
|
|
|
'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
|
|
|
|
'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
|
|
|
|
'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
|
|
|
|
'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
|
|
|
|
'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
|
|
|
|
'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
|
|
|
|
'\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
|
|
|
|
'\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
|
|
|
|
'\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
|
|
|
|
'\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
|
|
|
|
'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
|
|
|
|
'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
|
|
|
|
'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
|
|
|
|
'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
|
|
|
|
};
|
|
|
|
#else
|
2002-08-21 11:47:54 -04:00
|
|
|
# error >>> "You lose. You will need a translation table for your character set." <<<
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_memcicmp(char *p1, char *p2, long len)
|
2000-06-14 01:30:29 -04:00
|
|
|
{
|
|
|
|
int tmp;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-06-14 01:30:29 -04:00
|
|
|
while (len--) {
|
|
|
|
if (tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++])
|
|
|
|
return tmp;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-06-14 01:30:29 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-24 05:07:33 -04:00
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_memcmp(char *p1, char *p2, long len)
|
2001-07-24 05:07:33 -04:00
|
|
|
{
|
|
|
|
if (!ruby_ignorecase) {
|
|
|
|
return memcmp(p1, p2, len);
|
|
|
|
}
|
|
|
|
return rb_memcicmp(p1, p2, len);
|
|
|
|
}
|
|
|
|
|
2003-02-07 01:35:26 -05:00
|
|
|
long
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_memsearch(char *x0, long m, char *y0, long n)
|
2003-02-03 00:34:16 -05:00
|
|
|
{
|
2003-08-16 10:58:34 -04:00
|
|
|
unsigned char *x = (unsigned char *)x0, *y = (unsigned char *)y0;
|
2003-02-03 00:34:16 -05:00
|
|
|
unsigned char *s, *e;
|
2003-02-03 02:34:06 -05:00
|
|
|
long i;
|
|
|
|
int d;
|
2003-02-03 00:34:16 -05:00
|
|
|
unsigned long hx, hy;
|
|
|
|
|
2004-02-13 11:03:15 -05:00
|
|
|
#define KR_REHASH(a, b, h) (((h) << 1) - ((long)(a)<<d) + (b))
|
2003-02-03 00:34:16 -05:00
|
|
|
|
2003-09-01 11:44:39 -04:00
|
|
|
if (m > n) return -1;
|
|
|
|
s = y; e = s + n - m;
|
2003-02-03 00:34:16 -05:00
|
|
|
|
|
|
|
/* Preprocessing */
|
|
|
|
/* computes d = 2^(m-1) with
|
|
|
|
the left-shift operator */
|
2003-02-03 02:34:06 -05:00
|
|
|
d = sizeof(hx) * CHAR_BIT - 1;
|
|
|
|
if (d > m) d = m;
|
2003-02-03 00:34:16 -05:00
|
|
|
|
|
|
|
if (ruby_ignorecase) {
|
2003-09-01 11:44:39 -04:00
|
|
|
if (n == m) {
|
|
|
|
return rb_memcicmp(x, s, m) == 0 ? 0 : -1;
|
|
|
|
}
|
2003-02-03 00:34:16 -05:00
|
|
|
/* Prepare hash value */
|
2003-02-03 02:34:06 -05:00
|
|
|
for (hy = hx = i = 0; i < d; ++i) {
|
|
|
|
hx = KR_REHASH(0, casetable[x[i]], hx);
|
|
|
|
hy = KR_REHASH(0, casetable[s[i]], hy);
|
2003-02-03 00:34:16 -05:00
|
|
|
}
|
|
|
|
/* Searching */
|
2003-09-01 11:44:39 -04:00
|
|
|
while (hx != hy || rb_memcicmp(x, s, m)) {
|
|
|
|
if (s >= e) return -1;
|
2003-02-03 02:34:06 -05:00
|
|
|
hy = KR_REHASH(casetable[*s], casetable[*(s+d)], hy);
|
2003-02-03 00:34:16 -05:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-09-01 11:44:39 -04:00
|
|
|
if (n == m) {
|
|
|
|
return memcmp(x, s, m) == 0 ? 0 : -1;
|
|
|
|
}
|
2003-02-03 00:34:16 -05:00
|
|
|
/* Prepare hash value */
|
2003-02-03 02:34:06 -05:00
|
|
|
for (hy = hx = i = 0; i < d; ++i) {
|
|
|
|
hx = KR_REHASH(0, x[i], hx);
|
|
|
|
hy = KR_REHASH(0, s[i], hy);
|
2003-02-03 00:34:16 -05:00
|
|
|
}
|
|
|
|
/* Searching */
|
2003-09-01 11:44:39 -04:00
|
|
|
while (hx != hy || memcmp(x, s, m)) {
|
|
|
|
if (s >= e) return -1;
|
2003-02-03 02:34:06 -05:00
|
|
|
hy = KR_REHASH(*s, *(s+d), hy);
|
2003-02-03 00:34:16 -05:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
2003-09-01 11:44:39 -04:00
|
|
|
return s-y;
|
2003-02-03 00:34:16 -05:00
|
|
|
}
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#define REG_CASESTATE FL_USER0
|
1998-01-16 07:13:05 -05:00
|
|
|
#define KCODE_NONE 0
|
2000-05-22 03:09:55 -04:00
|
|
|
#define KCODE_EUC FL_USER1
|
|
|
|
#define KCODE_SJIS FL_USER2
|
|
|
|
#define KCODE_UTF8 FL_USER3
|
|
|
|
#define KCODE_FIXED FL_USER4
|
1999-01-19 23:59:39 -05:00
|
|
|
#define KCODE_MASK (KCODE_EUC|KCODE_SJIS|KCODE_UTF8)
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static int reg_kcode = DEFAULT_KCODE;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
kcode_euc(struct RRegexp *re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
FL_UNSET(re, KCODE_MASK);
|
|
|
|
FL_SET(re, KCODE_EUC);
|
|
|
|
FL_SET(re, KCODE_FIXED);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
kcode_sjis(struct RRegexp *re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
FL_UNSET(re, KCODE_MASK);
|
|
|
|
FL_SET(re, KCODE_SJIS);
|
|
|
|
FL_SET(re, KCODE_FIXED);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
kcode_utf8(struct RRegexp *re)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
FL_UNSET(re, KCODE_MASK);
|
|
|
|
FL_SET(re, KCODE_UTF8);
|
|
|
|
FL_SET(re, KCODE_FIXED);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
kcode_none(struct RRegexp *re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
FL_UNSET(re, KCODE_MASK);
|
|
|
|
FL_SET(re, KCODE_FIXED);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static int curr_kcode;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
kcode_set_option(VALUE re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
if (!FL_TEST(re, KCODE_FIXED)) return;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
curr_kcode = RBASIC(re)->flags & KCODE_MASK;
|
1999-01-19 23:59:39 -05:00
|
|
|
if (reg_kcode == curr_kcode) return;
|
|
|
|
switch (curr_kcode) {
|
1998-01-16 07:13:05 -05:00
|
|
|
case KCODE_NONE:
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_ASCII);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case KCODE_EUC:
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_EUC_JP);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case KCODE_SJIS:
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_SJIS);
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
case KCODE_UTF8:
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_UTF8);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
}
|
2004-03-05 17:37:35 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
kcode_reset_option(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (reg_kcode == curr_kcode) return;
|
1998-01-16 07:13:05 -05:00
|
|
|
switch (reg_kcode) {
|
|
|
|
case KCODE_NONE:
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_ASCII);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case KCODE_EUC:
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_EUC_JP);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case KCODE_SJIS:
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_SJIS);
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
case KCODE_UTF8:
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_UTF8);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-04 03:39:57 -05:00
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_mbclen2(unsigned int c, VALUE re)
|
1999-11-04 03:39:57 -05:00
|
|
|
{
|
|
|
|
int len;
|
* 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 09:43:08 -05:00
|
|
|
unsigned char uc = (unsigned char)c;
|
1999-11-04 03:39:57 -05:00
|
|
|
|
|
|
|
if (!FL_TEST(re, KCODE_FIXED))
|
* 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 09:43:08 -05:00
|
|
|
return mbclen(uc);
|
1999-11-04 03:39:57 -05:00
|
|
|
kcode_set_option(re);
|
* 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 09:43:08 -05:00
|
|
|
len = mbclen(uc);
|
1999-11-04 03:39:57 -05:00
|
|
|
kcode_reset_option();
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_check(VALUE re)
|
2000-05-22 03:09:55 -04:00
|
|
|
{
|
|
|
|
if (!RREGEXP(re)->ptr || !RREGEXP(re)->str) {
|
|
|
|
rb_raise(rb_eTypeError, "uninitialized Regexp");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_expr_str(VALUE str, const char *s, long len)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
const char *p, *pend;
|
2000-05-30 00:24:17 -04:00
|
|
|
int need_escape = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
p = s; pend = p + len;
|
|
|
|
while (p<pend) {
|
2000-05-30 00:24:17 -04:00
|
|
|
if (*p == '/' || (!ISPRINT(*p) && !ismbchar(*p))) {
|
|
|
|
need_escape = 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
}
|
2002-04-24 00:54:16 -04:00
|
|
|
p += mbclen(*p);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-05-30 00:24:17 -04:00
|
|
|
if (!need_escape) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(str, s, len);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
2004-03-05 17:37:35 -05:00
|
|
|
p = s;
|
1998-01-16 07:13:05 -05:00
|
|
|
while (p<pend) {
|
2002-06-28 10:42:46 -04:00
|
|
|
if (*p == '\\') {
|
2002-09-02 10:04:19 -04:00
|
|
|
int n = mbclen(p[1]) + 1;
|
|
|
|
rb_str_buf_cat(str, p, n);
|
|
|
|
p += n;
|
2002-06-28 10:42:46 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (*p == '/') {
|
1998-01-16 07:13:05 -05:00
|
|
|
char c = '\\';
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(str, &c, 1);
|
|
|
|
rb_str_buf_cat(str, p, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-05-30 00:24:17 -04:00
|
|
|
else if (ismbchar(*p)) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(str, p, mbclen(*p));
|
2000-05-30 00:24:17 -04:00
|
|
|
p += mbclen(*p);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (ISPRINT(*p)) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(str, p, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2002-04-24 00:54:16 -04:00
|
|
|
else if (!ISSPACE(*p)) {
|
2000-05-30 00:24:17 -04:00
|
|
|
char b[8];
|
2002-04-24 00:54:16 -04:00
|
|
|
|
|
|
|
sprintf(b, "\\%03o", *p & 0377);
|
|
|
|
rb_str_buf_cat(str, b, 4);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_str_buf_cat(str, p, 1);
|
2000-05-30 00:24:17 -04:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_desc(const char *s, long len, VALUE re)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2001-05-30 05:12:34 -04:00
|
|
|
VALUE str = rb_str_buf_new2("/");
|
2000-05-22 03:09:55 -04:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_reg_expr_str(str, s, len);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, "/");
|
1998-01-16 07:13:05 -05:00
|
|
|
if (re) {
|
2000-05-24 03:36:46 -04:00
|
|
|
rb_reg_check(re);
|
2005-02-17 09:43:38 -05:00
|
|
|
if (RREGEXP(re)->ptr->options & ONIG_OPTION_MULTILINE)
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, "m");
|
2005-02-17 09:43:38 -05:00
|
|
|
if (RREGEXP(re)->ptr->options & ONIG_OPTION_IGNORECASE)
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, "i");
|
2005-02-17 09:43:38 -05:00
|
|
|
if (RREGEXP(re)->ptr->options & ONIG_OPTION_EXTEND)
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, "x");
|
2004-03-05 17:37:35 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FL_TEST(re, KCODE_FIXED)) {
|
1998-01-16 07:19:22 -05:00
|
|
|
switch ((RBASIC(re)->flags & KCODE_MASK)) {
|
|
|
|
case KCODE_NONE:
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, "n");
|
1998-01-16 07:19:22 -05:00
|
|
|
break;
|
|
|
|
case KCODE_EUC:
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, "e");
|
1998-01-16 07:19:22 -05:00
|
|
|
break;
|
|
|
|
case KCODE_SJIS:
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, "s");
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
case KCODE_UTF8:
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, "u");
|
1998-01-16 07:19:22 -05:00
|
|
|
break;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
2000-02-23 00:23:12 -05:00
|
|
|
OBJ_INFECT(str, re);
|
1998-01-16 07:13:05 -05:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.source => str
|
|
|
|
*
|
|
|
|
* Returns the original string of the pattern.
|
|
|
|
*
|
|
|
|
* /ab+c/ix.source #=> "ab+c"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_source(VALUE re)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
VALUE str;
|
|
|
|
|
|
|
|
rb_reg_check(re);
|
|
|
|
str = rb_str_new(RREGEXP(re)->str,RREGEXP(re)->len);
|
1999-12-01 04:24:48 -05:00
|
|
|
if (OBJ_TAINTED(re)) OBJ_TAINT(str);
|
|
|
|
return str;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-12-30 11:38:32 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.inspect => string
|
|
|
|
*
|
|
|
|
* Produce a nicely formatted string-version of _rxp_. Perhaps surprisingly,
|
|
|
|
* <code>#inspect</code> actually produces the more natural version of
|
|
|
|
* the string than <code>#to_s</code>.
|
|
|
|
*
|
|
|
|
* /ab+c/ix.to_s #=> /ab+c/ix
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_inspect(VALUE re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_desc(RREGEXP(re)->str, RREGEXP(re)->len, re);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.to_s => str
|
|
|
|
*
|
* array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-14 00:06:52 -04:00
|
|
|
* Returns a string containing the regular expression and its options (using the
|
2003-12-26 10:58:28 -05:00
|
|
|
* <code>(?xxx:yyy)</code> notation. This string can be fed back in to
|
|
|
|
* <code>Regexp::new</code> to a regular expression with the same semantics as
|
|
|
|
* the original. (However, <code>Regexp#==</code> may not return true when
|
|
|
|
* comparing the two, as the source of the regular expression itself may
|
|
|
|
* differ, as the example shows). <code>Regexp#inspect</code> produces a
|
|
|
|
* generally more readable version of <i>rxp</i>.
|
|
|
|
*
|
|
|
|
* r1 = /ab+c/ix #=> /ab+c/ix
|
|
|
|
* s1 = r1.to_s #=> "(?ix-m:ab+c)"
|
|
|
|
* r2 = Regexp.new(s1) #=> /(?ix-m:ab+c)/
|
|
|
|
* r1 == r2 #=> false
|
|
|
|
* r1.source #=> "ab+c"
|
|
|
|
* r2.source #=> "(?ix-m:ab+c)"
|
|
|
|
*/
|
|
|
|
|
2002-04-18 04:04:57 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_to_s(VALUE re)
|
2002-04-18 04:04:57 -04:00
|
|
|
{
|
2002-04-19 00:14:07 -04:00
|
|
|
int options;
|
2005-02-17 09:43:38 -05:00
|
|
|
const int embeddable = ONIG_OPTION_MULTILINE|ONIG_OPTION_IGNORECASE|ONIG_OPTION_EXTEND;
|
2002-04-19 00:14:07 -04:00
|
|
|
long len;
|
|
|
|
const char* ptr;
|
2002-04-18 04:04:57 -04:00
|
|
|
VALUE str = rb_str_buf_new2("(?");
|
|
|
|
|
|
|
|
rb_reg_check(re);
|
|
|
|
|
2002-04-19 00:14:07 -04:00
|
|
|
options = RREGEXP(re)->ptr->options;
|
|
|
|
ptr = RREGEXP(re)->str;
|
|
|
|
len = RREGEXP(re)->len;
|
2002-04-24 00:54:16 -04:00
|
|
|
again:
|
|
|
|
if (len >= 4 && ptr[0] == '(' && ptr[1] == '?') {
|
2002-04-19 01:59:45 -04:00
|
|
|
int err = 1;
|
2002-04-19 00:14:07 -04:00
|
|
|
ptr += 2;
|
2002-04-24 00:54:16 -04:00
|
|
|
if ((len -= 2) > 0) {
|
2002-04-19 00:14:07 -04:00
|
|
|
do {
|
|
|
|
if (*ptr == 'm') {
|
2005-02-17 09:43:38 -05:00
|
|
|
options |= ONIG_OPTION_MULTILINE;
|
2002-04-19 00:14:07 -04:00
|
|
|
}
|
|
|
|
else if (*ptr == 'i') {
|
2005-02-17 09:43:38 -05:00
|
|
|
options |= ONIG_OPTION_IGNORECASE;
|
2002-04-19 00:14:07 -04:00
|
|
|
}
|
|
|
|
else if (*ptr == 'x') {
|
2005-02-17 09:43:38 -05:00
|
|
|
options |= ONIG_OPTION_EXTEND;
|
2002-04-19 00:14:07 -04:00
|
|
|
}
|
|
|
|
else break;
|
|
|
|
++ptr;
|
|
|
|
} while (--len > 0);
|
|
|
|
}
|
|
|
|
if (len > 1 && *ptr == '-') {
|
|
|
|
++ptr;
|
|
|
|
--len;
|
|
|
|
do {
|
|
|
|
if (*ptr == 'm') {
|
2005-02-17 09:43:38 -05:00
|
|
|
options &= ~ONIG_OPTION_MULTILINE;
|
2002-04-19 00:14:07 -04:00
|
|
|
}
|
|
|
|
else if (*ptr == 'i') {
|
2005-02-17 09:43:38 -05:00
|
|
|
options &= ~ONIG_OPTION_IGNORECASE;
|
2002-04-19 00:14:07 -04:00
|
|
|
}
|
|
|
|
else if (*ptr == 'x') {
|
2005-02-17 09:43:38 -05:00
|
|
|
options &= ~ONIG_OPTION_EXTEND;
|
2002-04-19 00:14:07 -04:00
|
|
|
}
|
|
|
|
else break;
|
|
|
|
++ptr;
|
|
|
|
} while (--len > 0);
|
|
|
|
}
|
2002-04-24 00:54:16 -04:00
|
|
|
if (*ptr == ')') {
|
|
|
|
--len;
|
|
|
|
++ptr;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if (*ptr == ':' && ptr[len-1] == ')') {
|
2004-03-05 10:40:36 -05:00
|
|
|
int r;
|
2002-04-24 00:54:16 -04:00
|
|
|
Regexp *rp;
|
2002-04-19 00:14:07 -04:00
|
|
|
kcode_set_option(re);
|
2005-02-17 09:43:38 -05:00
|
|
|
r = onig_alloc_init(&rp, ONIG_OPTION_DEFAULT,
|
|
|
|
ONIGENC_AMBIGUOUS_MATCH_DEFAULT,
|
|
|
|
onigenc_get_default_encoding(),
|
|
|
|
OnigDefaultSyntax);
|
2004-03-05 10:40:36 -05:00
|
|
|
if (r == 0) {
|
2005-02-17 09:43:38 -05:00
|
|
|
++ptr;
|
|
|
|
len -= 2;
|
|
|
|
err = (onig_compile(rp, ptr, ptr + len, NULL) != 0);
|
2004-03-05 10:40:36 -05:00
|
|
|
}
|
2002-04-19 00:14:07 -04:00
|
|
|
kcode_reset_option();
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_free(rp);
|
2002-04-19 00:14:07 -04:00
|
|
|
}
|
2002-04-19 01:59:45 -04:00
|
|
|
if (err) {
|
2002-04-19 00:14:07 -04:00
|
|
|
options = RREGEXP(re)->ptr->options;
|
|
|
|
ptr = RREGEXP(re)->str;
|
|
|
|
len = RREGEXP(re)->len;
|
|
|
|
}
|
|
|
|
}
|
2002-04-18 04:04:57 -04:00
|
|
|
|
2005-02-17 09:43:38 -05:00
|
|
|
if (options & ONIG_OPTION_MULTILINE) rb_str_buf_cat2(str, "m");
|
|
|
|
if (options & ONIG_OPTION_IGNORECASE) rb_str_buf_cat2(str, "i");
|
|
|
|
if (options & ONIG_OPTION_EXTEND) rb_str_buf_cat2(str, "x");
|
2002-04-19 00:14:07 -04:00
|
|
|
|
|
|
|
if ((options & embeddable) != embeddable) {
|
2002-04-18 04:04:57 -04:00
|
|
|
rb_str_buf_cat2(str, "-");
|
2005-02-17 09:43:38 -05:00
|
|
|
if (!(options & ONIG_OPTION_MULTILINE)) rb_str_buf_cat2(str, "m");
|
|
|
|
if (!(options & ONIG_OPTION_IGNORECASE)) rb_str_buf_cat2(str, "i");
|
|
|
|
if (!(options & ONIG_OPTION_EXTEND)) rb_str_buf_cat2(str, "x");
|
2002-04-18 04:04:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
rb_str_buf_cat2(str, ":");
|
2002-04-19 00:14:07 -04:00
|
|
|
rb_reg_expr_str(str, ptr, len);
|
2002-04-18 04:04:57 -04:00
|
|
|
rb_str_buf_cat2(str, ")");
|
|
|
|
|
|
|
|
OBJ_INFECT(str, re);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_raise(const char *s, long len, const char *err, VALUE re, int ce)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE desc = rb_reg_desc(s, len, re);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2004-09-24 01:53:43 -04:00
|
|
|
if (ce)
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_compile_error("%s: %s", err, RSTRING(desc)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
else
|
2000-08-28 05:53:42 -04:00
|
|
|
rb_raise(rb_eRegexpError, "%s: %s", err, RSTRING(desc)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.casefold? => true or false
|
|
|
|
*
|
|
|
|
* Returns the value of the case-insensitive flag.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_casefold_p(VALUE re)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
2005-02-17 09:43:38 -05:00
|
|
|
if (RREGEXP(re)->ptr->options & ONIG_OPTION_IGNORECASE) return Qtrue;
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.options => fixnum
|
|
|
|
*
|
|
|
|
* Returns the set of bits corresponding to the options used when creating this
|
|
|
|
* Regexp (see <code>Regexp::new</code> for details. Note that additional bits
|
|
|
|
* may be set in the returned options: these are used internally by the regular
|
|
|
|
* expression code. These extra bits are ignored if the options are passed to
|
|
|
|
* <code>Regexp::new</code>.
|
|
|
|
*
|
|
|
|
* Regexp::IGNORECASE #=> 1
|
|
|
|
* Regexp::EXTENDED #=> 2
|
|
|
|
* Regexp::MULTILINE #=> 4
|
|
|
|
*
|
|
|
|
* /cat/.options #=> 128
|
|
|
|
* /cat/ix.options #=> 131
|
|
|
|
* Regexp.new('cat', true).options #=> 129
|
|
|
|
* Regexp.new('cat', 0, 's').options #=> 384
|
|
|
|
*
|
|
|
|
* r = /cat/ix
|
|
|
|
* Regexp.new(r.source, r.options) #=> /cat/ix
|
|
|
|
*/
|
|
|
|
|
2001-02-08 04:19:27 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_options_m(VALUE re)
|
2001-02-08 04:19:27 -05:00
|
|
|
{
|
2003-07-25 00:38:42 -04:00
|
|
|
int options = rb_reg_options(re);
|
|
|
|
return INT2NUM(options);
|
2001-02-08 04:19:27 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.kcode => str
|
|
|
|
*
|
|
|
|
* Returns the character set code for the regexp.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_kcode_m(VALUE re)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2000-06-22 04:29:58 -04:00
|
|
|
char *kcode;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
|
|
|
if (FL_TEST(re, KCODE_FIXED)) {
|
|
|
|
switch (RBASIC(re)->flags & KCODE_MASK) {
|
|
|
|
case KCODE_NONE:
|
|
|
|
kcode = "none"; break;
|
|
|
|
case KCODE_EUC:
|
|
|
|
kcode = "euc"; break;
|
|
|
|
case KCODE_SJIS:
|
|
|
|
kcode = "sjis"; break;
|
1999-01-19 23:59:39 -05:00
|
|
|
case KCODE_UTF8:
|
|
|
|
kcode = "utf8"; break;
|
1998-01-16 07:19:22 -05:00
|
|
|
default:
|
2003-02-03 00:34:16 -05:00
|
|
|
rb_bug("unknown kcode - should not happen");
|
1998-01-16 07:19:22 -05:00
|
|
|
break;
|
|
|
|
}
|
2000-06-22 04:29:58 -04:00
|
|
|
return rb_str_new2(kcode);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
2000-06-22 04:29:58 -04:00
|
|
|
return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static Regexp*
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
make_regexp(const char *s, long len, int flags, int ce)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
Regexp *rp;
|
2004-03-05 10:40:36 -05:00
|
|
|
char err[ONIG_MAX_ERROR_MESSAGE_LEN];
|
|
|
|
int r;
|
2005-02-17 09:43:38 -05:00
|
|
|
OnigErrorInfo einfo;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
/* Handle escaped characters first. */
|
|
|
|
|
|
|
|
/* Build a copy of the string (in dest) with the
|
|
|
|
escaped characters translated, and generate the regex
|
|
|
|
from that.
|
|
|
|
*/
|
|
|
|
|
2005-02-17 09:43:38 -05:00
|
|
|
r = onig_alloc_init(&rp, flags,
|
|
|
|
ONIGENC_AMBIGUOUS_MATCH_DEFAULT,
|
|
|
|
onigenc_get_default_encoding(),
|
|
|
|
OnigDefaultSyntax);
|
2004-03-05 10:40:36 -05:00
|
|
|
if (r) {
|
2005-05-22 23:24:28 -04:00
|
|
|
onig_error_code_to_str((UChar*)err, r);
|
2004-09-24 01:53:43 -04:00
|
|
|
rb_reg_raise(s, len, err, 0, ce);
|
2004-03-05 10:40:36 -05:00
|
|
|
}
|
2004-03-05 17:37:35 -05:00
|
|
|
|
2005-05-22 23:24:28 -04:00
|
|
|
r = onig_compile(rp, (UChar*)s, (UChar*)(s + len), &einfo);
|
2002-08-21 11:47:54 -04:00
|
|
|
|
2004-03-05 10:40:36 -05:00
|
|
|
if (r != 0) {
|
2005-03-16 04:25:45 -05:00
|
|
|
onig_free(rp);
|
2005-05-22 23:24:28 -04:00
|
|
|
(void )onig_error_code_to_str((UChar*)err, r, &einfo);
|
2004-09-24 01:53:43 -04:00
|
|
|
rb_reg_raise(s, len, err, 0, ce);
|
2005-05-22 23:24:28 -04:00
|
|
|
return 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return rp;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: MatchData
|
|
|
|
*
|
|
|
|
* <code>MatchData</code> is the type of the special variable <code>$~</code>,
|
|
|
|
* and is the type of the object returned by <code>Regexp#match</code> and
|
|
|
|
* <code>Regexp#last_match</code>. It encapsulates all the results of a pattern
|
|
|
|
* match, results normally accessed through the special variables
|
|
|
|
* <code>$&</code>, <code>$'</code>, <code>$`</code>, <code>$1</code>,
|
|
|
|
* <code>$2</code>, and so on. <code>Matchdata</code> is also known as
|
|
|
|
* <code>MatchingData</code>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE rb_cMatch;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_alloc(VALUE klass)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
NEWOBJ(match, struct RMatch);
|
2002-08-30 04:22:09 -04:00
|
|
|
OBJSETUP(match, klass, T_MATCH);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
match->str = 0;
|
1999-01-19 23:59:39 -05:00
|
|
|
match->regs = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
match->regs = ALLOC(struct re_registers);
|
|
|
|
MEMZERO(match->regs, struct re_registers, 1);
|
|
|
|
|
|
|
|
return (VALUE)match;
|
|
|
|
}
|
|
|
|
|
2004-01-18 09:16:47 -05:00
|
|
|
/* :nodoc: */
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_init_copy(VALUE obj, VALUE orig)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2002-08-30 04:22:09 -04:00
|
|
|
if (obj == orig) return obj;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2002-08-30 04:22:09 -04:00
|
|
|
if (!rb_obj_is_instance_of(orig, rb_obj_class(obj))) {
|
|
|
|
rb_raise(rb_eTypeError, "wrong argument class");
|
|
|
|
}
|
|
|
|
RMATCH(obj)->str = RMATCH(orig)->str;
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_region_free(RMATCH(obj)->regs, 0);
|
2002-08-30 04:22:09 -04:00
|
|
|
RMATCH(obj)->regs->allocated = 0;
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_region_copy(RMATCH(obj)->regs, RMATCH(orig)->regs);
|
2002-08-27 04:31:08 -04:00
|
|
|
|
2002-08-30 04:22:09 -04:00
|
|
|
return obj;
|
2002-08-27 04:31:08 -04:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.length => integer
|
|
|
|
* mtch.size => integer
|
|
|
|
*
|
|
|
|
* Returns the number of elements in the match array.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.length #=> 5
|
|
|
|
* m.size #=> 5
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_size(VALUE match)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
return INT2FIX(RMATCH(match)->regs->num_regs);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.offset(n) => array
|
|
|
|
*
|
|
|
|
* Returns a two-element array containing the beginning and ending offsets of
|
|
|
|
* the <em>n</em>th match.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.offset(0) #=> [1, 7]
|
|
|
|
* m.offset(4) #=> [6, 7]
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_offset(VALUE match, VALUE n)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
int i = NUM2INT(n);
|
|
|
|
|
|
|
|
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
|
|
|
|
rb_raise(rb_eIndexError, "index %d out of matches", i);
|
|
|
|
|
|
|
|
if (RMATCH(match)->regs->beg[i] < 0)
|
|
|
|
return rb_assoc_new(Qnil, Qnil);
|
|
|
|
|
|
|
|
return rb_assoc_new(INT2FIX(RMATCH(match)->regs->beg[i]),
|
|
|
|
INT2FIX(RMATCH(match)->regs->end[i]));
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.begin(n) => integer
|
|
|
|
*
|
|
|
|
* Returns the offset of the start of the <em>n</em>th element of the match
|
|
|
|
* array in the string.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.begin(0) #=> 1
|
|
|
|
* m.begin(2) #=> 2
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_begin(VALUE match, VALUE n)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
int i = NUM2INT(n);
|
|
|
|
|
|
|
|
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
|
|
|
|
rb_raise(rb_eIndexError, "index %d out of matches", i);
|
|
|
|
|
|
|
|
if (RMATCH(match)->regs->beg[i] < 0)
|
|
|
|
return Qnil;
|
|
|
|
|
|
|
|
return INT2FIX(RMATCH(match)->regs->beg[i]);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.end(n) => integer
|
|
|
|
*
|
|
|
|
* Returns the offset of the character immediately following the end of the
|
|
|
|
* <em>n</em>th element of the match array in the string.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.end(0) #=> 7
|
|
|
|
* m.end(2) #=> 3
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_end(VALUE match, VALUE n)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
int i = NUM2INT(n);
|
|
|
|
|
|
|
|
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
|
|
|
|
rb_raise(rb_eIndexError, "index %d out of matches", i);
|
|
|
|
|
|
|
|
if (RMATCH(match)->regs->beg[i] < 0)
|
|
|
|
return Qnil;
|
|
|
|
|
|
|
|
return INT2FIX(RMATCH(match)->regs->end[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MATCH_BUSY FL_USER2
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_match_busy(VALUE match)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2000-02-08 03:54:01 -05:00
|
|
|
FL_SET(match, MATCH_BUSY);
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
int ruby_ignorecase;
|
|
|
|
static int may_need_recompile;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_prepare_re(VALUE re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int need_recompile = 0;
|
2000-06-13 05:42:40 -04:00
|
|
|
int state;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
2000-06-13 05:42:40 -04:00
|
|
|
state = FL_TEST(re, REG_CASESTATE);
|
|
|
|
/* ignorecase status */
|
|
|
|
if (ruby_ignorecase && !state) {
|
|
|
|
FL_SET(re, REG_CASESTATE);
|
2005-02-17 09:43:38 -05:00
|
|
|
RREGEXP(re)->ptr->options |= ONIG_OPTION_IGNORECASE;
|
2000-06-13 05:42:40 -04:00
|
|
|
need_recompile = 1;
|
|
|
|
}
|
|
|
|
if (!ruby_ignorecase && state) {
|
|
|
|
FL_UNSET(re, REG_CASESTATE);
|
2005-02-17 09:43:38 -05:00
|
|
|
RREGEXP(re)->ptr->options &= ~ONIG_OPTION_IGNORECASE;
|
2000-06-13 05:42:40 -04:00
|
|
|
need_recompile = 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
if (!FL_TEST(re, KCODE_FIXED) &&
|
|
|
|
(RBASIC(re)->flags & KCODE_MASK) != reg_kcode) {
|
1998-01-16 07:13:05 -05:00
|
|
|
need_recompile = 1;
|
2000-05-22 03:09:55 -04:00
|
|
|
RBASIC(re)->flags &= ~KCODE_MASK;
|
|
|
|
RBASIC(re)->flags |= reg_kcode;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (need_recompile) {
|
2004-03-05 10:40:36 -05:00
|
|
|
char err[ONIG_MAX_ERROR_MESSAGE_LEN];
|
|
|
|
int r;
|
2005-02-17 09:43:38 -05:00
|
|
|
OnigErrorInfo einfo;
|
|
|
|
regex_t *reg;
|
|
|
|
UChar *pattern;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
if (FL_TEST(re, KCODE_FIXED))
|
|
|
|
kcode_set_option(re);
|
|
|
|
rb_reg_check(re);
|
2005-02-17 09:43:38 -05:00
|
|
|
reg = RREGEXP(re)->ptr;
|
2005-05-22 23:24:28 -04:00
|
|
|
pattern = ((UChar*)RREGEXP(re)->str);
|
2005-02-17 09:43:38 -05:00
|
|
|
r = onig_recompile(reg, pattern, pattern + RREGEXP(re)->len,
|
|
|
|
reg->options, onigenc_get_default_encoding(),
|
|
|
|
OnigDefaultSyntax, &einfo);
|
|
|
|
|
2004-03-05 10:40:36 -05:00
|
|
|
if (r != 0) {
|
2005-05-22 23:24:28 -04:00
|
|
|
(void )onig_error_code_to_str((UChar*)err, r, &einfo);
|
2005-02-17 09:43:38 -05:00
|
|
|
rb_reg_raise(pattern, RREGEXP(re)->len, err, re, Qfalse);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-08-21 11:47:54 -04:00
|
|
|
long
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, long reverse)
|
1999-12-14 01:50:43 -05:00
|
|
|
{
|
2002-08-21 11:47:54 -04:00
|
|
|
long range;
|
2005-02-17 09:43:38 -05:00
|
|
|
OnigEncoding enc;
|
|
|
|
UChar *p, *string;
|
1999-12-14 01:50:43 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
|
|
|
if (may_need_recompile) rb_reg_prepare_re(re);
|
1999-12-14 01:50:43 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
if (FL_TEST(re, KCODE_FIXED))
|
|
|
|
kcode_set_option(re);
|
1999-12-14 01:50:43 -05:00
|
|
|
else if (reg_kcode != curr_kcode)
|
|
|
|
kcode_reset_option();
|
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
range = -pos;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
range = RSTRING(str)->len - pos;
|
|
|
|
}
|
2005-02-17 09:43:38 -05:00
|
|
|
|
|
|
|
enc = (RREGEXP(re)->ptr)->enc;
|
|
|
|
|
|
|
|
if (pos > 0 && ONIGENC_MBC_MAXLEN(enc) != 1 && pos < RSTRING(str)->len) {
|
2005-05-22 23:24:28 -04:00
|
|
|
string = (UChar*)RSTRING(str)->ptr;
|
2005-02-17 09:43:38 -05:00
|
|
|
|
|
|
|
if (range > 0) {
|
|
|
|
p = onigenc_get_right_adjust_char_head(enc, string, string + pos);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, string, string + pos);
|
|
|
|
}
|
|
|
|
return p - string;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
1999-12-14 01:50:43 -05:00
|
|
|
}
|
|
|
|
|
2002-08-21 11:47:54 -04:00
|
|
|
long
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_search(VALUE re, VALUE str, long pos, long reverse)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2002-08-21 11:47:54 -04:00
|
|
|
long result;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE match;
|
2000-02-08 03:54:01 -05:00
|
|
|
static struct re_registers regs;
|
2002-08-21 11:47:54 -04:00
|
|
|
long range;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2002-03-19 04:03:11 -05:00
|
|
|
if (pos > RSTRING(str)->len || pos < 0) {
|
|
|
|
rb_backref_set(Qnil);
|
|
|
|
return -1;
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
|
|
|
if (may_need_recompile) rb_reg_prepare_re(re);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
if (FL_TEST(re, KCODE_FIXED))
|
|
|
|
kcode_set_option(re);
|
1999-01-19 23:59:39 -05:00
|
|
|
else if (reg_kcode != curr_kcode)
|
|
|
|
kcode_reset_option();
|
1998-01-16 07:19:22 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (reverse) {
|
1999-08-13 01:45:20 -04:00
|
|
|
range = -pos;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
else {
|
1999-08-13 01:45:20 -04:00
|
|
|
range = RSTRING(str)->len - pos;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2005-02-17 09:43:38 -05:00
|
|
|
|
|
|
|
result = onig_search(RREGEXP(re)->ptr,
|
2005-05-22 23:24:28 -04:00
|
|
|
(UChar*)(RSTRING(str)->ptr),
|
|
|
|
((UChar*)(RSTRING(str)->ptr) + RSTRING(str)->len),
|
|
|
|
((UChar*)(RSTRING(str)->ptr) + pos),
|
|
|
|
((UChar*)(RSTRING(str)->ptr) + pos + range),
|
2005-02-17 09:43:38 -05:00
|
|
|
®s, ONIG_OPTION_NONE);
|
1999-11-04 03:39:57 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
if (FL_TEST(re, KCODE_FIXED))
|
1999-08-13 01:45:20 -04:00
|
|
|
kcode_reset_option();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (result < 0) {
|
2004-09-24 01:53:43 -04:00
|
|
|
if (result == ONIG_MISMATCH) {
|
|
|
|
rb_backref_set(Qnil);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char err[ONIG_MAX_ERROR_MESSAGE_LEN];
|
2005-05-22 23:24:28 -04:00
|
|
|
onig_error_code_to_str((UChar*)err, result);
|
2004-09-24 01:53:43 -04:00
|
|
|
rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len, err, 0, Qfalse);
|
|
|
|
}
|
2000-02-08 03:54:01 -05:00
|
|
|
}
|
|
|
|
|
2001-09-20 02:23:50 -04:00
|
|
|
match = rb_backref_get();
|
2000-02-08 03:54:01 -05:00
|
|
|
if (NIL_P(match) || FL_TEST(match, MATCH_BUSY)) {
|
2002-09-02 10:04:19 -04:00
|
|
|
match = match_alloc(rb_cMatch);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2002-01-04 09:15:33 -05:00
|
|
|
else {
|
2004-03-05 17:37:35 -05:00
|
|
|
if (rb_safe_level() >= 3)
|
2002-01-04 09:15:33 -05:00
|
|
|
OBJ_TAINT(match);
|
|
|
|
else
|
|
|
|
FL_UNSET(match, FL_TAINT);
|
|
|
|
}
|
|
|
|
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_region_copy(RMATCH(match)->regs, ®s);
|
2000-02-08 03:54:01 -05:00
|
|
|
RMATCH(match)->str = rb_str_new4(str);
|
|
|
|
rb_backref_set(match);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
OBJ_INFECT(match, re);
|
2000-01-04 23:41:21 -05:00
|
|
|
OBJ_INFECT(match, str);
|
1998-01-16 07:13:05 -05:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_nth_defined(int nth, VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (nth >= RMATCH(match)->regs->num_regs) {
|
2001-10-03 03:19:19 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
if (nth < 0) {
|
|
|
|
nth += RMATCH(match)->regs->num_regs;
|
|
|
|
if (nth <= 0) return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RMATCH(match)->BEG(nth) == -1) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_nth_match(int nth, VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-01-04 23:41:21 -05:00
|
|
|
VALUE str;
|
2002-08-28 04:05:23 -04:00
|
|
|
long start, end, len;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (nth >= RMATCH(match)->regs->num_regs) {
|
1998-01-16 07:13:05 -05:00
|
|
|
return Qnil;
|
|
|
|
}
|
2001-10-03 03:19:19 -04:00
|
|
|
if (nth < 0) {
|
|
|
|
nth += RMATCH(match)->regs->num_regs;
|
|
|
|
if (nth <= 0) return Qnil;
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
start = RMATCH(match)->BEG(nth);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (start == -1) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
end = RMATCH(match)->END(nth);
|
1998-01-16 07:13:05 -05:00
|
|
|
len = end - start;
|
2002-12-17 07:15:45 -05:00
|
|
|
str = rb_str_substr(RMATCH(match)->str, start, len);
|
|
|
|
OBJ_INFECT(str, match);
|
2000-01-04 23:41:21 -05:00
|
|
|
return str;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_last_match(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_nth_match(0, match);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.pre_match => str
|
|
|
|
*
|
|
|
|
* Returns the portion of the original string before the current match.
|
|
|
|
* Equivalent to the special variable <code>$`</code>.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.pre_match #=> "T"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match_pre(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-10-02 00:31:23 -04:00
|
|
|
VALUE str;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RMATCH(match)->BEG(0) == -1) return Qnil;
|
2002-12-19 10:21:01 -05:00
|
|
|
str = rb_str_substr(RMATCH(match)->str, 0, RMATCH(match)->BEG(0));
|
2001-10-02 00:31:23 -04:00
|
|
|
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
|
|
|
|
return str;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.post_match => str
|
|
|
|
*
|
|
|
|
* Returns the portion of the original string after the current match.
|
|
|
|
* Equivalent to the special variable <code>$'</code>.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
|
|
|
|
* m.post_match #=> ": The Movie"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match_post(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-10-02 00:31:23 -04:00
|
|
|
VALUE str;
|
2002-12-19 10:21:01 -05:00
|
|
|
long pos;
|
2001-10-02 00:31:23 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RMATCH(match)->BEG(0) == -1) return Qnil;
|
2002-12-19 10:21:01 -05:00
|
|
|
str = RMATCH(match)->str;
|
|
|
|
pos = RMATCH(match)->END(0);
|
|
|
|
str = rb_str_substr(str, pos, RSTRING(str)->len - pos);
|
2001-10-02 00:31:23 -04:00
|
|
|
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
|
|
|
|
return str;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match_last(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RMATCH(match)->BEG(0) == -1) return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
for (i=RMATCH(match)->regs->num_regs-1; RMATCH(match)->BEG(i) == -1 && i > 0; i--)
|
1998-01-16 07:13:05 -05:00
|
|
|
;
|
|
|
|
if (i == 0) return Qnil;
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_nth_match(i, match);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
last_match_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_last_match(rb_backref_get());
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
prematch_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_match_pre(rb_backref_get());
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
postmatch_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_match_post(rb_backref_get());
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
last_paren_match_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_match_last(rb_backref_get());
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_array(VALUE match, int start)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
struct re_registers *regs = RMATCH(match)->regs;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE ary = rb_ary_new2(regs->num_regs);
|
2002-12-19 10:21:01 -05:00
|
|
|
VALUE target = RMATCH(match)->str;
|
1998-01-16 07:13:05 -05:00
|
|
|
int i;
|
2001-12-21 04:23:28 -05:00
|
|
|
int taint = OBJ_TAINTED(match);
|
2004-03-05 17:37:35 -05:00
|
|
|
|
2003-07-03 07:02:53 -04:00
|
|
|
for (i=start; i<regs->num_regs; i++) {
|
2001-12-21 04:23:28 -05:00
|
|
|
if (regs->beg[i] == -1) {
|
|
|
|
rb_ary_push(ary, Qnil);
|
2002-05-01 05:41:50 -04:00
|
|
|
}
|
|
|
|
else {
|
2002-12-19 10:21:01 -05:00
|
|
|
VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]);
|
2001-12-21 04:23:28 -05:00
|
|
|
if (taint) OBJ_TAINT(str);
|
|
|
|
rb_ary_push(ary, str);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/* [MG]:FIXME: I put parens around the /.../.match() in the first line of the
|
|
|
|
second example to prevent the '*' followed by a '/' from ending the
|
|
|
|
comment. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.to_a => anArray
|
|
|
|
*
|
|
|
|
* Returns the array of matches.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.to_a #=> ["HX1138", "H", "X", "113", "8"]
|
|
|
|
*
|
* array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-14 00:06:52 -04:00
|
|
|
* Because <code>to_a</code> is called when expanding
|
2003-12-26 10:58:28 -05:00
|
|
|
* <code>*</code><em>variable</em>, there's a useful assignment
|
|
|
|
* shortcut for extracting matched fields. This is slightly slower than
|
|
|
|
* accessing the fields directly (as an intermediate array is
|
|
|
|
* generated).
|
|
|
|
*
|
|
|
|
* all,f1,f2,f3 = *(/(.)(.)(\d+)(\d)/.match("THX1138."))
|
|
|
|
* all #=> "HX1138"
|
|
|
|
* f1 #=> "H"
|
|
|
|
* f2 #=> "X"
|
|
|
|
* f3 #=> "113"
|
|
|
|
*/
|
|
|
|
|
2003-07-03 07:02:53 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_to_a(VALUE match)
|
2003-07-03 07:02:53 -04:00
|
|
|
{
|
|
|
|
return match_array(match, 0);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.captures => array
|
|
|
|
*
|
|
|
|
* Returns the array of captures; equivalent to <code>mtch.to_a[1..-1]</code>.
|
|
|
|
*
|
|
|
|
* f1,f2,f3,f4 = /(.)(.)(\d+)(\d)/.match("THX1138.").captures
|
|
|
|
* f1 #=> "H"
|
|
|
|
* f2 #=> "X"
|
|
|
|
* f3 #=> "113"
|
|
|
|
* f4 #=> "8"
|
|
|
|
*/
|
2003-07-03 07:02:53 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_captures(VALUE match)
|
2003-07-03 07:02:53 -04:00
|
|
|
{
|
|
|
|
return match_array(match, 1);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch[i] => obj
|
|
|
|
* mtch[start, length] => array
|
|
|
|
* mtch[range] => array
|
|
|
|
*
|
|
|
|
* Match Reference---<code>MatchData</code> acts as an array, and may be
|
|
|
|
* accessed using the normal array indexing techniques. <i>mtch</i>[0] is
|
|
|
|
* equivalent to the special variable <code>$&</code>, and returns the entire
|
|
|
|
* matched string. <i>mtch</i>[1], <i>mtch</i>[2], and so on return the values
|
|
|
|
* of the matched backreferences (portions of the pattern between parentheses).
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m[0] #=> "HX1138"
|
|
|
|
* m[1, 2] #=> ["H", "X"]
|
|
|
|
* m[1..3] #=> ["H", "X", "113"]
|
|
|
|
* m[-3, 2] #=> ["X", "113"]
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_aref(int argc, VALUE *argv, VALUE match)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
|
|
|
VALUE idx, rest;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &idx, &rest);
|
|
|
|
|
|
|
|
if (!NIL_P(rest) || !FIXNUM_P(idx) || FIX2INT(idx) < 0) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_ary_aref(argc, argv, match_to_a(match));
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
2000-09-01 05:18:11 -04:00
|
|
|
return rb_reg_nth_match(FIX2INT(idx), match);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-07-03 07:02:53 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_entry(VALUE match, long n)
|
2003-07-03 07:02:53 -04:00
|
|
|
{
|
|
|
|
return rb_reg_nth_match(n, match);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.select([index]*) => array
|
|
|
|
*
|
|
|
|
* Uses each <i>index</i> to access the matching values, returning an array of
|
|
|
|
* the corresponding matches.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
|
|
|
|
* m.to_a #=> ["HX1138", "H", "X", "113", "8"]
|
|
|
|
* m.select(0, 2, -2) #=> ["HX1138", "X", "113"]
|
|
|
|
*/
|
|
|
|
|
2001-12-10 22:48:08 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_values_at(int argc, VALUE *argv, VALUE match)
|
2001-12-10 22:48:08 -05:00
|
|
|
{
|
2004-04-06 22:51:05 -04:00
|
|
|
return rb_get_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry);
|
2001-12-10 22:48:08 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.select([index]*) => array
|
|
|
|
*
|
|
|
|
* Uses each <i>index</i> to access the matching values, returning an
|
|
|
|
* array of the corresponding matches.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
|
|
|
|
* m.to_a #=> ["HX1138", "H", "X", "113", "8"]
|
|
|
|
* m.select(0, 2, -2) #=> ["HX1138", "X", "113"]
|
|
|
|
*/
|
|
|
|
|
2003-05-04 12:03:24 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_select(int argc, VALUE *argv, VALUE match)
|
2003-05-04 12:03:24 -04:00
|
|
|
{
|
2003-05-06 02:51:31 -04:00
|
|
|
if (argc > 0) {
|
2004-03-29 02:54:38 -05:00
|
|
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
|
2003-05-06 02:51:31 -04:00
|
|
|
}
|
2003-05-04 12:03:24 -04:00
|
|
|
else {
|
|
|
|
struct re_registers *regs = RMATCH(match)->regs;
|
|
|
|
VALUE target = RMATCH(match)->str;
|
|
|
|
VALUE result = rb_ary_new();
|
|
|
|
int i;
|
|
|
|
int taint = OBJ_TAINTED(match);
|
|
|
|
|
|
|
|
for (i=0; i<regs->num_regs; i++) {
|
|
|
|
VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]);
|
|
|
|
if (taint) OBJ_TAINT(str);
|
2003-05-06 02:51:31 -04:00
|
|
|
if (RTEST(rb_yield(str))) {
|
2003-05-04 12:03:24 -04:00
|
|
|
rb_ary_push(result, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.to_s => str
|
|
|
|
*
|
|
|
|
* Returns the entire matched string.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.to_s #=> "HX1138"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_to_s(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE str = rb_reg_last_match(match);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-12-01 04:24:48 -05:00
|
|
|
if (NIL_P(str)) str = rb_str_new(0,0);
|
|
|
|
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
|
2000-01-04 23:41:21 -05:00
|
|
|
if (OBJ_TAINTED(RMATCH(match)->str)) OBJ_TAINT(str);
|
1998-01-16 07:13:05 -05:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.string => str
|
|
|
|
*
|
|
|
|
* Returns a frozen copy of the string passed in to <code>match</code>.
|
|
|
|
*
|
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.string #=> "THX1138."
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_string(VALUE match)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
1999-10-15 04:52:18 -04:00
|
|
|
return RMATCH(match)->str; /* str is frozen */
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_cRegexp;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_initialize(VALUE obj, const char *s, long len,
|
|
|
|
int options, /* CASEFOLD = 1 */
|
1999-01-19 23:59:39 -05:00
|
|
|
/* EXTENDED = 2 */
|
2000-05-17 02:33:50 -04:00
|
|
|
/* MULTILINE = 4 */
|
2000-05-23 11:36:43 -04:00
|
|
|
/* CODE_NONE = 16 */
|
|
|
|
/* CODE_EUC = 32 */
|
|
|
|
/* CODE_SJIS = 48 */
|
|
|
|
/* CODE_UTF8 = 64 */
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
int ce) /* call rb_compile_error() */
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
struct RRegexp *re = RREGEXP(obj);
|
|
|
|
|
2005-02-17 09:43:38 -05:00
|
|
|
if (re->ptr) onig_free(re->ptr);
|
2000-07-01 02:47:47 -04:00
|
|
|
if (re->str) free(re->str);
|
1999-01-19 23:59:39 -05:00
|
|
|
re->ptr = 0;
|
|
|
|
re->str = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-23 11:36:43 -04:00
|
|
|
switch (options & ~0xf) {
|
1998-01-16 07:13:05 -05:00
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
FL_SET(re, reg_kcode);
|
|
|
|
break;
|
2000-05-22 03:29:50 -04:00
|
|
|
case 16:
|
1998-01-16 07:13:05 -05:00
|
|
|
kcode_none(re);
|
|
|
|
break;
|
2000-05-22 03:29:50 -04:00
|
|
|
case 32:
|
1998-01-16 07:13:05 -05:00
|
|
|
kcode_euc(re);
|
|
|
|
break;
|
2000-05-22 03:29:50 -04:00
|
|
|
case 48:
|
1998-01-16 07:13:05 -05:00
|
|
|
kcode_sjis(re);
|
|
|
|
break;
|
2000-05-22 03:29:50 -04:00
|
|
|
case 64:
|
1999-01-19 23:59:39 -05:00
|
|
|
kcode_utf8(re);
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2000-05-22 03:29:50 -04:00
|
|
|
if (options & ~0xf) {
|
1999-01-19 23:59:39 -05:00
|
|
|
kcode_set_option((VALUE)re);
|
|
|
|
}
|
|
|
|
if (ruby_ignorecase) {
|
2005-02-17 09:43:38 -05:00
|
|
|
options |= ONIG_OPTION_IGNORECASE;
|
1999-01-19 23:59:39 -05:00
|
|
|
FL_SET(re, REG_CASESTATE);
|
|
|
|
}
|
2004-09-24 01:53:43 -04:00
|
|
|
re->ptr = make_regexp(s, len, options & 0xf, ce);
|
1998-01-16 07:13:05 -05:00
|
|
|
re->str = ALLOC_N(char, len+1);
|
|
|
|
memcpy(re->str, s, len);
|
|
|
|
re->str[len] = '\0';
|
|
|
|
re->len = len;
|
2000-05-22 03:29:50 -04:00
|
|
|
if (options & ~0xf) {
|
1999-01-19 23:59:39 -05:00
|
|
|
kcode_reset_option();
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2001-10-05 02:30:42 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_s_alloc(VALUE klass)
|
2001-10-05 02:30:42 -04:00
|
|
|
{
|
|
|
|
NEWOBJ(re, struct RRegexp);
|
|
|
|
OBJSETUP(re, klass, T_REGEXP);
|
|
|
|
|
|
|
|
re->ptr = 0;
|
|
|
|
re->len = 0;
|
|
|
|
re->str = 0;
|
|
|
|
|
|
|
|
return (VALUE)re;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_new(const char *s, long len, int options)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-10-05 02:30:42 -04:00
|
|
|
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
2000-05-22 03:09:55 -04:00
|
|
|
|
2004-09-24 01:53:43 -04:00
|
|
|
rb_reg_initialize(re, s, len, options, Qfalse);
|
|
|
|
return (VALUE)re;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_compile(const char *s, long len, int options)
|
2004-09-24 01:53:43 -04:00
|
|
|
{
|
|
|
|
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
|
|
|
|
|
|
|
rb_reg_initialize(re, s, len, options, Qtrue);
|
2000-05-22 03:09:55 -04:00
|
|
|
return (VALUE)re;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static int case_cache;
|
|
|
|
static int kcode_cache;
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE reg_cache;
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_regcomp(VALUE str)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
if (reg_cache && RREGEXP(reg_cache)->len == RSTRING(str)->len
|
1999-01-19 23:59:39 -05:00
|
|
|
&& case_cache == ruby_ignorecase
|
|
|
|
&& kcode_cache == reg_kcode
|
1998-01-16 07:19:22 -05:00
|
|
|
&& memcmp(RREGEXP(reg_cache)->str, RSTRING(str)->ptr, RSTRING(str)->len) == 0)
|
1998-01-16 07:13:05 -05:00
|
|
|
return reg_cache;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
case_cache = ruby_ignorecase;
|
|
|
|
kcode_cache = reg_kcode;
|
|
|
|
return reg_cache = rb_reg_new(RSTRING(str)->ptr, RSTRING(str)->len,
|
|
|
|
ruby_ignorecase);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_cur_kcode(VALUE re)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
|
|
|
if (FL_TEST(re, KCODE_FIXED)) {
|
|
|
|
return RBASIC(re)->flags & KCODE_MASK;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-30 11:38:32 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.hash => fixnum
|
|
|
|
*
|
|
|
|
* Produce a hash based on the text and options of this regular expression.
|
|
|
|
*/
|
|
|
|
|
2002-12-12 04:17:32 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_hash(VALUE re)
|
2002-12-12 04:17:32 -05:00
|
|
|
{
|
|
|
|
int hashval, len;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
rb_reg_check(re);
|
|
|
|
hashval = RREGEXP(re)->ptr->options;
|
|
|
|
len = RREGEXP(re)->len;
|
|
|
|
p = RREGEXP(re)->str;
|
|
|
|
while (len--) {
|
|
|
|
hashval = hashval * 33 + *p++;
|
|
|
|
}
|
|
|
|
hashval = hashval + (hashval>>5);
|
2004-03-05 17:37:35 -05:00
|
|
|
|
2002-12-12 04:17:32 -05:00
|
|
|
return INT2FIX(hashval);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp == other_rxp => true or false
|
|
|
|
* rxp.eql?(other_rxp) => true or false
|
|
|
|
*
|
|
|
|
* Equality---Two regexps are equal if their patterns are identical, they have
|
|
|
|
* the same character set code, and their <code>casefold?</code> values are the
|
|
|
|
* same.
|
|
|
|
*
|
|
|
|
* /abc/ == /abc/x #=> false
|
|
|
|
* /abc/ == /abc/i #=> false
|
|
|
|
* /abc/u == /abc/n #=> false
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_equal(VALUE re1, VALUE re2)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (re1 == re2) return Qtrue;
|
|
|
|
if (TYPE(re2) != T_REGEXP) return Qfalse;
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re1); rb_reg_check(re2);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RREGEXP(re1)->len != RREGEXP(re2)->len) return Qfalse;
|
2002-01-11 04:18:54 -05:00
|
|
|
if (memcmp(RREGEXP(re1)->str, RREGEXP(re2)->str, RREGEXP(re1)->len) == 0 &&
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_reg_cur_kcode(re1) == rb_reg_cur_kcode(re2) &&
|
2001-02-08 04:19:27 -05:00
|
|
|
RREGEXP(re1)->ptr->options == RREGEXP(re2)->ptr->options) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2004-07-17 02:28:10 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match_pos(VALUE re, VALUE str, long pos)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2004-07-17 04:02:20 -04:00
|
|
|
if (NIL_P(str)) {
|
|
|
|
rb_backref_set(Qnil);
|
|
|
|
return Qnil;
|
|
|
|
}
|
2001-05-02 00:22:21 -04:00
|
|
|
StringValue(str);
|
2004-07-17 02:28:10 -04:00
|
|
|
if (pos != 0) {
|
|
|
|
if (pos < 0) {
|
|
|
|
pos += RSTRING(str)->len;
|
|
|
|
if (pos < 0) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos = rb_reg_adjust_startpos(re, str, pos, 0);
|
|
|
|
}
|
|
|
|
pos = rb_reg_search(re, str, pos, 0);
|
|
|
|
if (pos < 0) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2004-07-17 02:28:10 -04:00
|
|
|
return LONG2FIX(pos);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2004-10-19 21:38:04 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp =~ str => integer or nil
|
|
|
|
*
|
|
|
|
* Match---Matches <i>rxp</i> against <i>str</i>.
|
|
|
|
*
|
|
|
|
* /at/ =~ "input data" #=> 7
|
|
|
|
*/
|
|
|
|
|
2004-07-17 02:28:10 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match(VALUE re, VALUE str)
|
2004-07-17 02:28:10 -04:00
|
|
|
{
|
|
|
|
return rb_reg_match_pos(re, str, 0);
|
|
|
|
}
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp === str => true or false
|
|
|
|
*
|
|
|
|
* Case Equality---Synonym for <code>Regexp#=~</code> used in case statements.
|
|
|
|
*
|
|
|
|
* a = "HELLO"
|
|
|
|
* case a
|
2004-12-06 10:31:26 -05:00
|
|
|
* when /^[a-z]*$/; print "Lower case\n"
|
|
|
|
* when /^[A-Z]*$/; print "Upper case\n"
|
2003-12-26 10:58:28 -05:00
|
|
|
* else; print "Mixed case\n"
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* Upper case
|
|
|
|
*/
|
|
|
|
|
2002-12-19 04:20:20 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_eqq(VALUE re, VALUE str)
|
2002-12-19 04:20:20 -05:00
|
|
|
{
|
|
|
|
long start;
|
|
|
|
|
|
|
|
if (TYPE(str) != T_STRING) {
|
|
|
|
str = rb_check_string_type(str);
|
|
|
|
if (NIL_P(str)) {
|
|
|
|
rb_backref_set(Qnil);
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StringValue(str);
|
|
|
|
start = rb_reg_search(re, str, 0, 0);
|
|
|
|
if (start < 0) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ~ rxp => integer or nil
|
|
|
|
*
|
|
|
|
* Match---Matches <i>rxp</i> against the contents of <code>$_</code>.
|
|
|
|
* Equivalent to <code><i>rxp</i> =~ $_</code>.
|
|
|
|
*
|
|
|
|
* $_ = "input data"
|
|
|
|
* ~ /at/ #=> 7
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match2(VALUE re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-08-28 04:05:23 -04:00
|
|
|
long start;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE line = rb_lastline_get();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-03-14 01:23:46 -05:00
|
|
|
if (TYPE(line) != T_STRING) {
|
|
|
|
rb_backref_set(Qnil);
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qnil;
|
2002-03-14 01:23:46 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
start = rb_reg_search(re, line, 0, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (start < 0) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2FIX(start);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-07-17 02:28:10 -04:00
|
|
|
* rxp.match(str) => matchdata or nil
|
|
|
|
* rxp.match(str,pos) => matchdata or nil
|
2003-12-26 10:58:28 -05:00
|
|
|
*
|
|
|
|
* Returns a <code>MatchData</code> object describing the match, or
|
|
|
|
* <code>nil</code> if there was no match. This is equivalent to retrieving the
|
|
|
|
* value of the special variable <code>$~</code> following a normal match.
|
2004-07-17 02:28:10 -04:00
|
|
|
* If the second parameter is present, it specifies the position in the string
|
|
|
|
* to begin the search.
|
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* /(.)(.)(.)/.match("abc")[2] #=> "b"
|
2004-07-17 02:28:10 -04:00
|
|
|
* /(.)(.)/.match("abc", 1)[2] #=> "c"
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match_m(int argc, VALUE *argv, VALUE re)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2004-07-17 02:28:10 -04:00
|
|
|
VALUE result, str, initpos;
|
|
|
|
long pos;
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2004-07-17 02:28:10 -04:00
|
|
|
if (rb_scan_args(argc, argv, "11", &str, &initpos) == 2) {
|
|
|
|
pos = NUM2LONG(initpos);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = rb_reg_match_pos(re, str, pos);
|
|
|
|
if (NIL_P(result)) {
|
|
|
|
rb_backref_set(Qnil);
|
|
|
|
return Qnil;
|
|
|
|
}
|
2000-07-14 03:18:58 -04:00
|
|
|
result = rb_backref_get();
|
|
|
|
rb_match_busy(result);
|
|
|
|
return result;
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
2003-12-30 11:38:32 -05:00
|
|
|
/*
|
|
|
|
* Document-method: compile
|
|
|
|
*
|
|
|
|
* Synonym for <code>Regexp.new</code>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Regexp.new(string [, options [, lang]]) => regexp
|
|
|
|
* Regexp.new(regexp) => regexp
|
2004-02-21 19:52:38 -05:00
|
|
|
* Regexp.compile(string [, options [, lang]]) => regexp
|
2003-12-26 10:58:28 -05:00
|
|
|
* Regexp.compile(regexp) => regexp
|
|
|
|
*
|
|
|
|
* Constructs a new regular expression from <i>pattern</i>, which can be either
|
|
|
|
* a <code>String</code> or a <code>Regexp</code> (in which case that regexp's
|
|
|
|
* options are propagated, and new options may not be specified (a change as of
|
|
|
|
* Ruby 1.8). If <i>options</i> is a <code>Fixnum</code>, it should be one or
|
|
|
|
* more of the constants <code>Regexp::EXTENDED</code>,
|
2005-03-09 04:29:52 -05:00
|
|
|
* <code>Regexp::IGNORECASE</code>, and <code>Regexp::MULTILINE</code>,
|
2003-12-26 10:58:28 -05:00
|
|
|
* <em>or</em>-ed together. Otherwise, if <i>options</i> is not
|
|
|
|
* <code>nil</code>, the regexp will be case insensitive. The <i>lang</i>
|
|
|
|
* parameter enables multibyte support for the regexp: `n', `N' = none, `e',
|
|
|
|
* `E' = EUC, `s', `S' = SJIS, `u', `U' = UTF-8.
|
2004-02-21 19:52:38 -05:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* r1 = Regexp.new('^a-z+:\\s+\w+') #=> /^a-z+:\s+\w+/
|
|
|
|
* r2 = Regexp.new('cat', true) #=> /cat/i
|
|
|
|
* r3 = Regexp.new('dog', Regexp::EXTENDED) #=> /dog/x
|
|
|
|
* r4 = Regexp.new(r2) #=> /cat/i
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-02-03 03:45:26 -05:00
|
|
|
const char *s;
|
|
|
|
long len;
|
2001-02-02 06:38:20 -05:00
|
|
|
int flags = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-02-03 03:45:26 -05:00
|
|
|
rb_check_frozen(self);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (argc == 0 || argc > 3) {
|
2004-03-29 02:54:38 -05:00
|
|
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-02-03 03:45:26 -05:00
|
|
|
if (TYPE(argv[0]) == T_REGEXP) {
|
|
|
|
if (argc > 1) {
|
|
|
|
rb_warn("flags%s ignored", (argc == 3) ? " and encoding": "");
|
|
|
|
}
|
|
|
|
rb_reg_check(argv[0]);
|
|
|
|
flags = RREGEXP(argv[0])->ptr->options & 0xf;
|
2003-02-06 05:06:47 -05:00
|
|
|
if (FL_TEST(argv[0], KCODE_FIXED)) {
|
|
|
|
switch (RBASIC(argv[0])->flags & KCODE_MASK) {
|
|
|
|
case KCODE_NONE:
|
|
|
|
flags |= 16;
|
|
|
|
break;
|
|
|
|
case KCODE_EUC:
|
|
|
|
flags |= 32;
|
|
|
|
break;
|
|
|
|
case KCODE_SJIS:
|
|
|
|
flags |= 48;
|
|
|
|
break;
|
|
|
|
case KCODE_UTF8:
|
|
|
|
flags |= 64;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-02-03 03:45:26 -05:00
|
|
|
s = RREGEXP(argv[0])->str;
|
|
|
|
len = RREGEXP(argv[0])->len;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
else {
|
2003-02-03 03:45:26 -05:00
|
|
|
if (argc >= 2) {
|
|
|
|
if (FIXNUM_P(argv[1])) flags = FIX2INT(argv[1]);
|
2005-02-17 09:43:38 -05:00
|
|
|
else if (RTEST(argv[1])) flags = ONIG_OPTION_IGNORECASE;
|
2003-02-03 03:45:26 -05:00
|
|
|
}
|
2003-07-25 00:38:42 -04:00
|
|
|
if (argc == 3 && !NIL_P(argv[2])) {
|
2003-02-03 03:45:26 -05:00
|
|
|
char *kcode = StringValuePtr(argv[2]);
|
|
|
|
|
2003-07-25 00:38:42 -04:00
|
|
|
flags &= ~0x70;
|
2003-02-03 03:45:26 -05:00
|
|
|
switch (kcode[0]) {
|
|
|
|
case 'n': case 'N':
|
|
|
|
flags |= 16;
|
|
|
|
break;
|
|
|
|
case 'e': case 'E':
|
|
|
|
flags |= 32;
|
|
|
|
break;
|
|
|
|
case 's': case 'S':
|
|
|
|
flags |= 48;
|
|
|
|
break;
|
|
|
|
case 'u': case 'U':
|
|
|
|
flags |= 64;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-10-01 11:56:05 -04:00
|
|
|
s = StringValuePtr(argv[0]);
|
|
|
|
len = RSTRING(argv[0])->len;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2004-11-16 21:27:38 -05:00
|
|
|
rb_reg_initialize(self, s, len, flags, Qfalse);
|
2001-01-15 02:01:00 -05:00
|
|
|
return self;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2002-07-26 02:12:39 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_quote(VALUE str)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
char *s, *send, *t;
|
2000-10-10 03:03:36 -04:00
|
|
|
VALUE tmp;
|
2002-05-01 05:41:50 -04:00
|
|
|
int c;
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
s = RSTRING(str)->ptr;
|
|
|
|
send = s + RSTRING(str)->len;
|
2002-07-26 02:12:39 -04:00
|
|
|
for (; s < send; s++) {
|
|
|
|
c = *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 09:43:08 -05:00
|
|
|
if (ismbchar(*s)) {
|
|
|
|
int n = mbclen(*s);
|
2002-07-26 02:12:39 -04:00
|
|
|
|
|
|
|
while (n-- && s < send)
|
|
|
|
s++;
|
|
|
|
s--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (c) {
|
|
|
|
case '[': case ']': case '{': case '}':
|
|
|
|
case '(': case ')': case '|': case '-':
|
|
|
|
case '*': case '.': case '\\':
|
|
|
|
case '?': case '+': case '^': case '$':
|
|
|
|
case ' ': case '#':
|
2003-05-16 19:28:31 -04:00
|
|
|
case '\t': case '\f': case '\n': case '\r':
|
2002-07-26 02:12:39 -04:00
|
|
|
goto meta_found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
|
|
|
|
meta_found:
|
2001-05-02 00:22:21 -04:00
|
|
|
tmp = rb_str_new(0, RSTRING(str)->len*2);
|
2000-10-10 03:03:36 -04:00
|
|
|
t = RSTRING(tmp)->ptr;
|
2002-07-29 02:14:10 -04:00
|
|
|
/* copy upto metacharacter */
|
|
|
|
memcpy(t, RSTRING(str)->ptr, s - RSTRING(str)->ptr);
|
|
|
|
t += s - RSTRING(str)->ptr;
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2000-07-01 02:47:47 -04:00
|
|
|
for (; s < send; s++) {
|
2002-05-01 05:41:50 -04:00
|
|
|
c = *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 09:43:08 -05:00
|
|
|
if (ismbchar(*s)) {
|
|
|
|
int n = mbclen(*s);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2000-07-01 02:47:47 -04:00
|
|
|
while (n-- && s < send)
|
1999-08-13 01:45:20 -04:00
|
|
|
*t++ = *s++;
|
|
|
|
s--;
|
|
|
|
continue;
|
|
|
|
}
|
2002-05-01 05:41:50 -04:00
|
|
|
switch (c) {
|
|
|
|
case '[': case ']': case '{': case '}':
|
|
|
|
case '(': case ')': case '|': case '-':
|
|
|
|
case '*': case '.': case '\\':
|
|
|
|
case '?': case '+': case '^': case '$':
|
2003-05-16 19:28:31 -04:00
|
|
|
case '#':
|
|
|
|
*t++ = '\\';
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
*t++ = '\\';
|
2003-05-19 00:48:57 -04:00
|
|
|
*t++ = ' ';
|
|
|
|
continue;
|
2003-05-16 19:28:31 -04:00
|
|
|
case '\t':
|
|
|
|
*t++ = '\\';
|
|
|
|
*t++ = 't';
|
2003-05-19 00:48:57 -04:00
|
|
|
continue;
|
2003-05-16 19:28:31 -04:00
|
|
|
case '\n':
|
|
|
|
*t++ = '\\';
|
|
|
|
*t++ = 'n';
|
2003-05-19 00:48:57 -04:00
|
|
|
continue;
|
2003-05-16 19:28:31 -04:00
|
|
|
case '\r':
|
|
|
|
*t++ = '\\';
|
|
|
|
*t++ = 'r';
|
2003-05-19 00:48:57 -04:00
|
|
|
continue;
|
2003-05-16 19:28:31 -04:00
|
|
|
case '\f':
|
2002-05-01 05:41:50 -04:00
|
|
|
*t++ = '\\';
|
2003-05-16 19:28:31 -04:00
|
|
|
*t++ = 'f';
|
2003-05-19 00:48:57 -04:00
|
|
|
continue;
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
2002-05-01 05:41:50 -04:00
|
|
|
*t++ = c;
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
2000-10-10 03:03:36 -04:00
|
|
|
rb_str_resize(tmp, t - RSTRING(tmp)->ptr);
|
2001-12-21 04:23:28 -05:00
|
|
|
OBJ_INFECT(tmp, str);
|
2000-10-10 03:03:36 -04:00
|
|
|
return tmp;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2005-03-16 04:25:45 -05:00
|
|
|
* Regexp.escape(str) => a_str
|
|
|
|
* Regexp.quote(str) => a_str
|
2003-12-26 10:58:28 -05:00
|
|
|
*
|
|
|
|
* Escapes any characters that would have special meaning in a regular
|
2005-03-16 04:25:45 -05:00
|
|
|
* expression. Returns a new escaped string, or self if no characters are
|
|
|
|
* escaped. For any string,
|
2003-12-26 10:58:28 -05:00
|
|
|
* <code>Regexp.escape(<i>str</i>)=~<i>str</i></code> will be true.
|
|
|
|
*
|
|
|
|
* Regexp.escape('\\*?{}.') #=> \\\\\*\?\{\}\.
|
|
|
|
*/
|
|
|
|
|
2002-07-26 02:12:39 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_s_quote(int argc, VALUE *argv)
|
2002-07-26 02:12:39 -04:00
|
|
|
{
|
|
|
|
VALUE str, kcode;
|
|
|
|
int kcode_saved = reg_kcode;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &str, &kcode);
|
|
|
|
if (!NIL_P(kcode)) {
|
|
|
|
rb_set_kcode(StringValuePtr(kcode));
|
|
|
|
curr_kcode = reg_kcode;
|
|
|
|
reg_kcode = kcode_saved;
|
|
|
|
}
|
|
|
|
StringValue(str);
|
|
|
|
str = rb_reg_quote(str);
|
|
|
|
kcode_reset_option();
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_kcode(void)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
switch (reg_kcode) {
|
|
|
|
case KCODE_EUC:
|
|
|
|
return MBCTYPE_EUC;
|
|
|
|
case KCODE_SJIS:
|
|
|
|
return MBCTYPE_SJIS;
|
1999-08-13 01:45:20 -04:00
|
|
|
case KCODE_UTF8:
|
|
|
|
return MBCTYPE_UTF8;
|
1999-01-19 23:59:39 -05:00
|
|
|
case KCODE_NONE:
|
|
|
|
return MBCTYPE_ASCII;
|
|
|
|
}
|
|
|
|
rb_bug("wrong reg_kcode value (0x%x)", reg_kcode);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_get_kcode(VALUE re)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
|
|
|
switch (RBASIC(re)->flags & KCODE_MASK) {
|
|
|
|
case KCODE_NONE:
|
2000-05-24 00:34:26 -04:00
|
|
|
return 16;
|
1999-01-19 23:59:39 -05:00
|
|
|
case KCODE_EUC:
|
2000-05-24 00:34:26 -04:00
|
|
|
return 32;
|
1998-01-16 07:19:22 -05:00
|
|
|
case KCODE_SJIS:
|
2000-05-24 00:34:26 -04:00
|
|
|
return 48;
|
1999-08-13 01:45:20 -04:00
|
|
|
case KCODE_UTF8:
|
2000-05-24 00:34:26 -04:00
|
|
|
return 64;
|
1998-01-16 07:19:22 -05:00
|
|
|
default:
|
2000-05-24 00:34:26 -04:00
|
|
|
return 0;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_options(VALUE re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-07-25 00:38:42 -04:00
|
|
|
int options;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
2003-07-25 00:38:42 -04:00
|
|
|
options = RREGEXP(re)->ptr->options &
|
2005-02-17 09:43:38 -05:00
|
|
|
(ONIG_OPTION_IGNORECASE|ONIG_OPTION_MULTILINE|ONIG_OPTION_EXTEND);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (FL_TEST(re, KCODE_FIXED)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
options |= rb_reg_get_kcode(re);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Regexp.union([pattern]*) => new_str
|
|
|
|
*
|
|
|
|
* Return a <code>Regexp</code> object that is the union of the given
|
|
|
|
* <em>pattern</em>s, i.e., will match any of its parts. The <em>pattern</em>s
|
|
|
|
* can be Regexp objects, in which case their options will be preserved, or
|
|
|
|
* Strings. If no arguments are given, returns <code>/(?!)/</code>.
|
|
|
|
*
|
|
|
|
* Regexp.union #=> /(?!)/
|
|
|
|
* Regexp.union("penzance") #=> /penzance/
|
|
|
|
* Regexp.union("skiing", "sledding") #=> /skiing|sledding/
|
|
|
|
* Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/
|
|
|
|
*/
|
2003-10-29 03:31:43 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_s_union(int argc, VALUE *argv)
|
2003-10-29 03:31:43 -05:00
|
|
|
{
|
|
|
|
if (argc == 0) {
|
|
|
|
VALUE args[1];
|
|
|
|
args[0] = rb_str_new2("(?!)");
|
|
|
|
return rb_class_new_instance(1, args, rb_cRegexp);
|
|
|
|
}
|
|
|
|
else if (argc == 1) {
|
|
|
|
VALUE v;
|
|
|
|
v = rb_check_convert_type(argv[0], T_REGEXP, "Regexp", "to_regexp");
|
|
|
|
if (!NIL_P(v))
|
|
|
|
return v;
|
|
|
|
else {
|
|
|
|
VALUE args[1];
|
|
|
|
args[0] = rb_reg_s_quote(argc, argv);
|
|
|
|
return rb_class_new_instance(1, args, rb_cRegexp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int i, kcode = -1;
|
|
|
|
VALUE kcode_re = Qnil;
|
|
|
|
VALUE source = rb_str_buf_new(0);
|
|
|
|
VALUE args[3];
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
volatile VALUE v;
|
|
|
|
if (0 < i)
|
|
|
|
rb_str_buf_cat2(source, "|");
|
|
|
|
v = rb_check_convert_type(argv[i], T_REGEXP, "Regexp", "to_regexp");
|
|
|
|
if (!NIL_P(v)) {
|
|
|
|
if (FL_TEST(v, KCODE_FIXED)) {
|
|
|
|
if (kcode == -1) {
|
|
|
|
kcode_re = v;
|
|
|
|
kcode = RBASIC(v)->flags & KCODE_MASK;
|
|
|
|
}
|
|
|
|
else if ((RBASIC(v)->flags & KCODE_MASK) != kcode) {
|
|
|
|
volatile VALUE str1, str2;
|
|
|
|
str1 = rb_inspect(kcode_re);
|
|
|
|
str2 = rb_inspect(v);
|
|
|
|
rb_raise(rb_eArgError, "mixed kcode: %s and %s",
|
|
|
|
RSTRING(str1)->ptr, RSTRING(str2)->ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v = rb_reg_to_s(v);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
args[0] = argv[i];
|
|
|
|
v = rb_reg_s_quote(1, args);
|
|
|
|
}
|
|
|
|
rb_str_buf_append(source, v);
|
|
|
|
}
|
|
|
|
args[0] = source;
|
|
|
|
args[1] = Qnil;
|
|
|
|
switch (kcode) {
|
|
|
|
case -1:
|
|
|
|
args[2] = Qnil;
|
|
|
|
break;
|
|
|
|
case KCODE_NONE:
|
|
|
|
args[2] = rb_str_new2("n");
|
|
|
|
break;
|
|
|
|
case KCODE_EUC:
|
|
|
|
args[2] = rb_str_new2("e");
|
|
|
|
break;
|
|
|
|
case KCODE_SJIS:
|
|
|
|
args[2] = rb_str_new2("s");
|
|
|
|
break;
|
|
|
|
case KCODE_UTF8:
|
|
|
|
args[2] = rb_str_new2("u");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rb_class_new_instance(3, args, rb_cRegexp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-18 09:16:47 -05:00
|
|
|
/* :nodoc: */
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_init_copy(VALUE copy, VALUE re)
|
2000-01-04 23:41:21 -05:00
|
|
|
{
|
2002-09-03 01:20:14 -04:00
|
|
|
if (copy == re) return copy;
|
|
|
|
rb_check_frozen(copy);
|
2002-08-27 04:31:08 -04:00
|
|
|
/* need better argument type check */
|
2002-09-03 01:20:14 -04:00
|
|
|
if (!rb_obj_is_instance_of(re, rb_obj_class(copy))) {
|
2002-08-27 04:31:08 -04:00
|
|
|
rb_raise(rb_eTypeError, "wrong argument type");
|
|
|
|
}
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
2002-09-03 01:20:14 -04:00
|
|
|
rb_reg_initialize(copy, RREGEXP(re)->str, RREGEXP(re)->len,
|
2004-10-19 06:25:23 -04:00
|
|
|
rb_reg_options(re), Qfalse);
|
2002-09-03 01:20:14 -04:00
|
|
|
return copy;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
VALUE val = 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 09:43:08 -05:00
|
|
|
char *p, *s, *e;
|
|
|
|
unsigned char uc;
|
1998-01-16 07:13:05 -05:00
|
|
|
int no;
|
|
|
|
|
* 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 09:43:08 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
p = s = RSTRING(str)->ptr;
|
|
|
|
e = s + RSTRING(str)->len;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (s < e) {
|
|
|
|
char *ss = 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 09:43:08 -05:00
|
|
|
uc = (unsigned char)*s++;
|
|
|
|
if (ismbchar(uc)) {
|
|
|
|
s += mbclen(uc) - 1;
|
1999-01-19 23:59:39 -05:00
|
|
|
continue;
|
|
|
|
}
|
* 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 09:43:08 -05:00
|
|
|
if (uc != '\\' || s == e) continue;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-05-30 05:12:34 -04:00
|
|
|
if (!val) {
|
|
|
|
val = rb_str_buf_new(ss-p);
|
|
|
|
rb_str_buf_cat(val, p, ss-p);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_str_buf_cat(val, p, ss-p);
|
|
|
|
}
|
1998-01-16 07:13:05 -05: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 09:43:08 -05:00
|
|
|
uc = (unsigned char)*s++;
|
1998-01-16 07:13:05 -05:00
|
|
|
p = 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 09:43:08 -05:00
|
|
|
switch (uc) {
|
1998-01-16 07:13:05 -05:00
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
* 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 09:43:08 -05:00
|
|
|
no = uc - '0';
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
no = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '`':
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(val, RSTRING(src)->ptr, BEG(0));
|
1998-01-16 07:13:05 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case '\'':
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(val, RSTRING(src)->ptr+END(0), RSTRING(src)->len-END(0));
|
1998-01-16 07:13:05 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
no = regs->num_regs-1;
|
|
|
|
while (BEG(no) == -1 && no > 0) no--;
|
|
|
|
if (no == 0) continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\\':
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(val, s-1, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
default:
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(val, s-2, 2);
|
1998-01-16 07:13:05 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (no >= 0) {
|
2000-02-08 03:54:01 -05:00
|
|
|
if (no >= regs->num_regs) continue;
|
1998-01-16 07:13:05 -05:00
|
|
|
if (BEG(no) == -1) continue;
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(val, RSTRING(src)->ptr+BEG(no), END(no)-BEG(no));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p < e) {
|
2001-05-30 05:12:34 -04:00
|
|
|
if (!val) {
|
|
|
|
val = rb_str_buf_new(e-p);
|
|
|
|
rb_str_buf_cat(val, p, e-p);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_str_buf_cat(val, p, e-p);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
if (!val) return str;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
const char*
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_get_kcode(void)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
switch (reg_kcode) {
|
|
|
|
case KCODE_SJIS:
|
|
|
|
return "SJIS";
|
|
|
|
case KCODE_EUC:
|
|
|
|
return "EUC";
|
|
|
|
case KCODE_UTF8:
|
|
|
|
return "UTF8";
|
|
|
|
default:
|
|
|
|
return "NONE";
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
kcode_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2(rb_get_kcode());
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_set_kcode(const char *code)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (code == 0) goto set_no_conversion;
|
|
|
|
|
|
|
|
switch (code[0]) {
|
|
|
|
case 'E':
|
|
|
|
case 'e':
|
|
|
|
reg_kcode = KCODE_EUC;
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_EUC_JP);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
case 's':
|
|
|
|
reg_kcode = KCODE_SJIS;
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_SJIS);
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
case 'u':
|
|
|
|
reg_kcode = KCODE_UTF8;
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_UTF8);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 'N':
|
|
|
|
case 'n':
|
1999-01-19 23:59:39 -05:00
|
|
|
case 'A':
|
|
|
|
case 'a':
|
1998-01-16 07:13:05 -05:00
|
|
|
set_no_conversion:
|
|
|
|
reg_kcode = KCODE_NONE;
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_ASCII);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
kcode_setter(VALUE val)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
may_need_recompile = 1;
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_set_kcode(StringValuePtr(val));
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
ignorecase_getter(void)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
return ruby_ignorecase?Qtrue:Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
ignorecase_setter(VALUE val, ID id)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2003-10-29 23:37:50 -05:00
|
|
|
rb_warn("modifying %s is deprecated", rb_id2name(id));
|
1999-01-19 23:59:39 -05:00
|
|
|
may_need_recompile = 1;
|
|
|
|
ruby_ignorecase = RTEST(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
VALUE match = rb_backref_get();
|
|
|
|
|
|
|
|
if (NIL_P(match)) return Qnil;
|
2000-02-08 03:54:01 -05:00
|
|
|
rb_match_busy(match);
|
|
|
|
return match;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_setter(VALUE val)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-04-01 02:39:09 -05:00
|
|
|
if (!NIL_P(val)) {
|
|
|
|
Check_Type(val, T_MATCH);
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_backref_set(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Regexp.last_match => matchdata
|
|
|
|
* Regexp.last_match(fixnum) => str
|
|
|
|
*
|
|
|
|
* The first form returns the <code>MatchData</code> object generated by the
|
|
|
|
* last successful pattern match. Equivalent to reading the global variable
|
|
|
|
* <code>$~</code>. The second form returns the nth field in this
|
|
|
|
* <code>MatchData</code> object.
|
|
|
|
*
|
|
|
|
* /c(.)t/ =~ 'cat' #=> 0
|
|
|
|
* Regexp.last_match #=> #<MatchData:0x401b3d30>
|
|
|
|
* Regexp.last_match(0) #=> "cat"
|
|
|
|
* Regexp.last_match(1) #=> "a"
|
|
|
|
* Regexp.last_match(2) #=> nil
|
|
|
|
*/
|
|
|
|
|
2001-01-15 02:01:00 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_s_last_match(int argc, VALUE *argv)
|
2001-01-15 02:01:00 -05:00
|
|
|
{
|
|
|
|
VALUE nth;
|
|
|
|
|
|
|
|
if (rb_scan_args(argc, argv, "01", &nth) == 1) {
|
|
|
|
return rb_reg_nth_match(NUM2INT(nth), rb_backref_get());
|
|
|
|
}
|
|
|
|
return match_getter();
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: Regexp
|
|
|
|
*
|
|
|
|
* A <code>Regexp</code> holds a regular expression, used to match a pattern
|
|
|
|
* against strings. Regexps are created using the <code>/.../</code> and
|
|
|
|
* <code>%r{...}</code> literals, and by the <code>Regexp::new</code>
|
|
|
|
* constructor.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
Init_Regexp(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-08-28 05:53:42 -04:00
|
|
|
rb_eRegexpError = rb_define_class("RegexpError", rb_eStandardError);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-05-22 23:24:28 -04:00
|
|
|
onigenc_set_default_caseconv_table((UChar*)casetable);
|
1999-08-13 01:45:20 -04:00
|
|
|
#if DEFAULT_KCODE == KCODE_EUC
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_EUC_JP);
|
1999-01-19 23:59:39 -05:00
|
|
|
#else
|
1999-08-13 01:45:20 -04:00
|
|
|
#if DEFAULT_KCODE == KCODE_SJIS
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_SJIS);
|
1999-01-19 23:59:39 -05:00
|
|
|
#else
|
1999-08-13 01:45:20 -04:00
|
|
|
#if DEFAULT_KCODE == KCODE_UTF8
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_UTF8);
|
1999-01-19 23:59:39 -05:00
|
|
|
#else
|
2005-02-17 09:43:38 -05:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_ASCII);
|
1999-01-19 23:59:39 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
rb_define_virtual_variable("$~", match_getter, match_setter);
|
|
|
|
rb_define_virtual_variable("$&", last_match_getter, 0);
|
|
|
|
rb_define_virtual_variable("$`", prematch_getter, 0);
|
|
|
|
rb_define_virtual_variable("$'", postmatch_getter, 0);
|
|
|
|
rb_define_virtual_variable("$+", last_paren_match_getter, 0);
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_virtual_variable("$=", ignorecase_getter, ignorecase_setter);
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_define_virtual_variable("$KCODE", kcode_getter, kcode_setter);
|
|
|
|
rb_define_virtual_variable("$-K", kcode_getter, kcode_setter);
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_cRegexp = rb_define_class("Regexp", rb_cObject);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_define_alloc_func(rb_cRegexp, rb_reg_s_alloc);
|
2001-10-03 03:19:19 -04:00
|
|
|
rb_define_singleton_method(rb_cRegexp, "compile", rb_class_new_instance, -1);
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_define_singleton_method(rb_cRegexp, "quote", rb_reg_s_quote, -1);
|
|
|
|
rb_define_singleton_method(rb_cRegexp, "escape", rb_reg_s_quote, -1);
|
2003-10-29 03:31:43 -05:00
|
|
|
rb_define_singleton_method(rb_cRegexp, "union", rb_reg_s_union, -1);
|
2001-01-15 02:01:00 -05:00
|
|
|
rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1);
|
2003-05-19 01:41:08 -04:00
|
|
|
rb_define_method(rb_cRegexp, "initialize_copy", rb_reg_init_copy, 1);
|
2002-12-12 04:17:32 -05:00
|
|
|
rb_define_method(rb_cRegexp, "hash", rb_reg_hash, 0);
|
|
|
|
rb_define_method(rb_cRegexp, "eql?", rb_reg_equal, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1);
|
|
|
|
rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1);
|
2002-12-19 04:20:20 -05:00
|
|
|
rb_define_method(rb_cRegexp, "===", rb_reg_eqq, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cRegexp, "~", rb_reg_match2, 0);
|
2004-07-17 02:28:10 -04:00
|
|
|
rb_define_method(rb_cRegexp, "match", rb_reg_match_m, -1);
|
2002-04-18 04:04:57 -04:00
|
|
|
rb_define_method(rb_cRegexp, "to_s", rb_reg_to_s, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cRegexp, "inspect", rb_reg_inspect, 0);
|
|
|
|
rb_define_method(rb_cRegexp, "source", rb_reg_source, 0);
|
|
|
|
rb_define_method(rb_cRegexp, "casefold?", rb_reg_casefold_p, 0);
|
2001-02-08 04:19:27 -05:00
|
|
|
rb_define_method(rb_cRegexp, "options", rb_reg_options_m, 0);
|
2000-01-04 23:41:21 -05:00
|
|
|
rb_define_method(rb_cRegexp, "kcode", rb_reg_kcode_m, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-02-17 09:43:38 -05:00
|
|
|
rb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(ONIG_OPTION_IGNORECASE));
|
|
|
|
rb_define_const(rb_cRegexp, "EXTENDED", INT2FIX(ONIG_OPTION_EXTEND));
|
|
|
|
rb_define_const(rb_cRegexp, "MULTILINE", INT2FIX(ONIG_OPTION_MULTILINE));
|
1999-08-13 01:45:20 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_global_variable(®_cache);
|
|
|
|
|
2000-02-23 00:23:12 -05:00
|
|
|
rb_cMatch = rb_define_class("MatchData", rb_cObject);
|
|
|
|
rb_define_global_const("MatchingData", rb_cMatch);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_define_alloc_func(rb_cMatch, match_alloc);
|
1999-10-15 04:52:18 -04:00
|
|
|
rb_undef_method(CLASS_OF(rb_cMatch), "new");
|
|
|
|
|
2003-05-19 01:41:08 -04:00
|
|
|
rb_define_method(rb_cMatch, "initialize_copy", match_init_copy, 1);
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_define_method(rb_cMatch, "size", match_size, 0);
|
|
|
|
rb_define_method(rb_cMatch, "length", match_size, 0);
|
|
|
|
rb_define_method(rb_cMatch, "offset", match_offset, 1);
|
|
|
|
rb_define_method(rb_cMatch, "begin", match_begin, 1);
|
|
|
|
rb_define_method(rb_cMatch, "end", match_end, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cMatch, "to_a", match_to_a, 0);
|
|
|
|
rb_define_method(rb_cMatch, "[]", match_aref, -1);
|
2003-07-17 05:53:16 -04:00
|
|
|
rb_define_method(rb_cMatch, "captures", match_captures, 0);
|
2001-12-10 22:48:08 -05:00
|
|
|
rb_define_method(rb_cMatch, "select", match_select, -1);
|
2003-05-04 12:03:24 -04:00
|
|
|
rb_define_method(rb_cMatch, "values_at", match_values_at, -1);
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);
|
|
|
|
rb_define_method(rb_cMatch, "post_match", rb_reg_match_post, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cMatch, "to_s", match_to_s, 0);
|
2004-01-07 21:21:28 -05:00
|
|
|
rb_define_method(rb_cMatch, "inspect", rb_any_to_s, 0); /* in object.c */
|
2001-09-05 02:54:57 -04:00
|
|
|
rb_define_method(rb_cMatch, "string", match_string, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|