summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-26 06:12:39 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-26 06:12:39 +0000
commit7194b66fb24db63dc2a23d3141ce25ad85d89777 (patch)
tree6e4a442522711c87eb3fc61bf81efc90af356394 /re.c
parent1d132e648dff057f0a5b42ddbc3704e7816213fc (diff)
* random.c: replace with Mersenne Twister RNG.
* eval.c (jump_tag_but_local_jump): preserve retval in LocalJumpError exceptions. * parse.y (command): no more check for "super outside of method". * eval.c (rb_mod_define_method): should set last_class and last_func in the block->frame. * eval.c (error_handle): should handle TAG_THROW as well. * parse.y (yylex): new decimal notation '0d4567'. * parse.y (yylex): new octal notation '0o777'. * parse.y (string_content): every string_content node should return string only. use NODE_EVSTR to coercing. * eval.c (rb_eval): NODE_EVSTR support. * re.c (rb_reg_quote): avoid unnecessary string allocation. * string.c (get_pat): quote metachracters before compiling a string into a regex. * string.c (rb_str_split_m): special treatment of strings of size 1, but AWK emulation. now uses get_pat(). * string.c (rb_str_match_m): quote metacharacters. * string.c (rb_str_match2): ditto. * ext/socket/socket.c (sock_addrinfo): make all 3 versions of getaddrinfo happy. [ruby-core:00184] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/re.c b/re.c
index 0cb048b..90999a9 100644
--- a/re.c
+++ b/re.c
@@ -1170,26 +1170,39 @@ rb_reg_initialize_m(argc, argv, self)
return self;
}
-static VALUE
-rb_reg_s_quote(argc, argv)
- int argc;
- VALUE *argv;
+VALUE
+rb_reg_quote(str)
+ VALUE str;
{
- VALUE str, kcode;
- int kcode_saved = reg_kcode;
char *s, *send, *t;
VALUE tmp;
int c;
- 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);
s = RSTRING(str)->ptr;
send = s + RSTRING(str)->len;
+ for (; s < send; s++) {
+ c = *s;
+ if (ismbchar(c)) {
+ int n = mbclen(c);
+
+ while (n-- && s < send)
+ s++;
+ s--;
+ continue;
+ }
+ switch (c) {
+ case '\t': case '\f': case '\r': case '\n':
+ case '[': case ']': case '{': case '}':
+ case '(': case ')': case '|': case '-':
+ case '*': case '.': case '\\':
+ case '?': case '+': case '^': case '$':
+ case ' ': case '#':
+ goto meta_found;
+ }
+ }
+ return str;
+
+ meta_found:
tmp = rb_str_new(0, RSTRING(str)->len*2);
t = RSTRING(tmp)->ptr;
@@ -1230,12 +1243,31 @@ rb_reg_s_quote(argc, argv)
}
*t++ = c;
}
- kcode_reset_option();
rb_str_resize(tmp, t - RSTRING(tmp)->ptr);
OBJ_INFECT(tmp, str);
return tmp;
}
+static VALUE
+rb_reg_s_quote(argc, argv)
+ int argc;
+ VALUE *argv;
+{
+ 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;
+}
+
int
rb_kcode()
{