summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authorYukihiro Matsumoto <matz@ruby-lang.org>1995-02-24 13:15:43 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-08-17 22:09:31 +0900
commit881c5a9c320c637ee0f6526b40cf70c1379ab656 (patch)
tree3c0327fc9bdef8f056563ceee400226ac572535b /re.c
parent2f106ab85c4f4e171374aee261f5a12bdd923c41 (diff)
version 0.68v0_68
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.67-0.68.diff.gz Fri Feb 24 13:15:43 1995 Yukihiro Matsumoto (matz@ix-02) * version 0.68 Thu Feb 23 11:19:19 1995 Yukihiro Matsumoto (matz@ix-02) * eval.c: resque節のselfの値が間違っていた. * eval.c(rb_clear_cache): キャッシュのクリアし忘れがあった. * eval.c: 定数のスコープをクラス内の静的スコープに変更した.これに よって,特異メソッドからは参照される定数は,レシーバのクラスでは なく,定義されたスコープのクラスの定数となる. Wed Feb 22 00:51:38 1995 Yukihiro Matsumoto (matz@dyna) * regex.c: ignorecaseを正規表現のコンパイル前に指定しないと正しく 動作しない.修正. * string.c(toupper,tolower): bug fix. * ENV,VERSION: readonly変数から定数へ.
Diffstat (limited to 're.c')
-rw-r--r--re.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/re.c b/re.c
index 2b2a06fe09..bc83ec71db 100644
--- a/re.c
+++ b/re.c
@@ -6,7 +6,7 @@
$Date: 1995/01/10 10:42:49 $
created at: Mon Aug 9 18:24:49 JST 1993
- Copyright (C) 1994 Yukihiro Matsumoto
+ Copyright (C) 1995 Yukihiro Matsumoto
************************************************/
@@ -84,7 +84,7 @@ str_cicmp(str1, str2)
return str1->len - str2->len;
}
-Regexp*
+static Regexp*
make_regexp(s, len)
char *s;
int len;
@@ -108,6 +108,7 @@ int len;
if ((err = re_compile_pattern(s, (size_t)len, &(rp->pat))) != NULL)
Fail("%s: /%s/", err, s);
+
return rp;
}
@@ -118,26 +119,27 @@ struct match {
};
struct match last_match;
+VALUE ignorecase;
int
-research(reg, str, start, ignorecase)
+research(reg, str, start)
struct RRegexp *reg;
struct RString *str;
int start;
- int ignorecase;
{
int result;
+ int casefold = ignorecase;
/* case-flag set for the object */
if (FL_TEST(reg, FL_USER1)) {
- ignorecase = 1;
+ casefold = TRUE;
}
- if (ignorecase)
+ if (casefold)
reg->ptr->pat.translate = casetable;
else
reg->ptr->pat.translate = NULL;
- if (start >= str->len) return -1;
+ if (start > str->len) return -1;
result = re_search(&(reg->ptr->pat), str->ptr, str->len,
start, str->len - start, &(reg->ptr->regs));
@@ -290,14 +292,13 @@ const char *s;
Fail(s);
}
-VALUE ignorecase;
VALUE C_Regexp;
static VALUE
-regexp_new_1(class, s, len)
+regexp_new_1(class, s, len, ci)
VALUE class;
char *s;
- int len;
+ int len, ci;
{
NEWOBJ(re, struct RRegexp);
OBJSETUP(re, class, T_REGEXP);
@@ -307,15 +308,17 @@ regexp_new_1(class, s, len)
memcpy(re->str, s, len);
re->str[len] = '\0';
re->len = len;
+
+ if (ci) FL_SET(re, FL_USER1);
return (VALUE)re;
}
VALUE
-regexp_new(s, len)
+regexp_new(s, len, ci)
char *s;
- int len;
+ int len, ci;
{
- return regexp_new_1(C_Regexp, s, len);
+ return regexp_new_1(C_Regexp, s, len, ci);
}
static VALUE str_cache, reg_cache;
@@ -329,7 +332,7 @@ re_regcomp(str)
return reg_cache;
str_cache = (VALUE)str;
- return reg_cache = regexp_new(str->ptr, str->len);
+ return reg_cache = regexp_new(str->ptr, str->len, ignorecase);
}
VALUE
@@ -340,7 +343,7 @@ Freg_match(re, str)
int start;
Check_Type(str, T_STRING);
- start = research(re, str, 0, ignorecase);
+ start = research(re, str, 0);
if (start == -1) {
return Qnil;
}
@@ -357,7 +360,7 @@ Freg_match2(re)
if (TYPE(rb_lastline) != T_STRING)
Fail("$_ is not a string");
- start = research(re, rb_lastline, 0, ignorecase);
+ start = research(re, rb_lastline, 0);
if (start == -1) {
return Qnil;
}
@@ -371,27 +374,27 @@ Sreg_new(argc, argv, self)
VALUE self;
{
VALUE src, reg;
+ int ci = 0;
if (argc == 0 || argc > 2) {
Fail("wrong # of argument");
}
+ if (argc == 2 && argv[1]) {
+ ci = 1;
+ }
src = argv[0];
switch (TYPE(src)) {
case T_STRING:
- reg = regexp_new_1(self, RREGEXP(src)->ptr, RREGEXP(src)->len);
+ reg = regexp_new_1(self, RREGEXP(src)->ptr, RREGEXP(src)->len, ci);
case T_REGEXP:
- reg = regexp_new_1(self, RREGEXP(src)->str, RREGEXP(src)->len);
+ reg = regexp_new_1(self, RREGEXP(src)->str, RREGEXP(src)->len, ci);
default:
Check_Type(src, T_STRING);
}
- if (argc == 2 && argv[1]) {
- FL_SET(reg, FL_USER1);
- }
-
return Qnil;
}
@@ -429,7 +432,8 @@ static VALUE
Freg_clone(re)
struct RRegexp *re;
{
- return regexp_new_1(CLASS_OF(re), re->str, re->len);
+ int ci = FL_TEST(re, FL_USER1);
+ return regexp_new_1(CLASS_OF(re), re->str, re->len, ci);
}
VALUE