diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-01 09:38:01 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-01 09:38:01 +0000 |
commit | 8145a071a9acc46541a8967d031a872d15065842 (patch) | |
tree | 082ba11a11351baf7b1afad6e267ff9ca1968c1b /re.c | |
parent | 11a1286fe10c6e6fd3b56708958f04b5d0189f2b (diff) |
* file.c (rb_find_file): load must be done from an abolute path if
$SAFE >= 4.
* re.c (rb_reg_s_quote): quote whitespaces for /x cases.
* eval.c (rb_thread_cleanup): should not terminate main_thread by
Fatal error.
* regex.c (is_in_list): need to not exclude NUL and NEWLINE.
* re.c (rb_reg_expr_str): wrong backslash escapement.
* re.c (rb_reg_expr_str): do not escape embedded space
characters.
* eval.c (rb_thread_cleanup): current thread may be THREAD_STOPPED,
for example when terminated from signal handler.
* re.c (rb_reg_expr_str): should treat backslash specially in
escaping.
* bignum.c (rb_big_eq): check `y == x' if y is neither Fixnum,
Bignum, nor Float.
* pack.c (pack_unpack): should treat 'U' in character unit, not in
byte unit.
* marshal.c (w_uclass): should check based on rb_obj_class(), not
CLASS_OF().
* io.c (io_write): check error if written data is less than
specified size to detect EPIPE.
* eval.c (assign): ruby_verbose should be surrounded by RTEST().
* object.c (rb_str2cstr): ditto.
* parse.y (void_expr): ditto.
* parse.y (void_stmts): ditto.
* variable.c (rb_ivar_get): ditto.
* variable.c (rb_cvar_set): ditto.
* variable.c (rb_cvar_get): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@2419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 78 |
1 files changed, 37 insertions, 41 deletions
@@ -220,7 +220,7 @@ rb_reg_expr_str(str, s, len) need_escape = 1; break; } - p++; + p += mbclen(*p); } if (!need_escape) { rb_str_cat(str, s, len); @@ -228,7 +228,7 @@ rb_reg_expr_str(str, s, len) else { p = s; while (p<pend) { - if (*p == '/') { + if (*p == '/' && (s == p || p[-1] != '\\')) { char c = '\\'; rb_str_cat(str, &c, 1); rb_str_cat(str, p, 1); @@ -241,35 +241,14 @@ rb_reg_expr_str(str, s, len) else if (ISPRINT(*p)) { rb_str_cat(str, p, 1); } - else { + else if (!ISSPACE(*p)) { char b[8]; - switch (*p) { - case '\r': - rb_str_cat(str, "\\r", 2); - break; - case '\n': - rb_str_cat(str, "\\n", 2); - break; - case '\t': - rb_str_cat(str, "\\t", 2); - break; - case '\f': - rb_str_cat(str, "\\f", 2); - break; - case 007: - rb_str_cat(str, "\\a", 2); - break; - case 013: - rb_str_cat(str, "\\v", 2); - break; - case 033: - rb_str_cat(str, "\\e", 2); - break; - default: - sprintf(b, "\\%03o", *p & 0377); - rb_str_cat(str, b, 4); - break; - } + + sprintf(b, "\\%03o", *p & 0377); + rb_str_cat(str, b, 4); + } + else { + rb_str_cat(str, p, 1); } p++; } @@ -1063,7 +1042,7 @@ rb_reg_s_quote(argc, argv) int kcode_saved = reg_kcode; char *s, *send, *t; VALUE tmp; - int len; + int len, c; rb_scan_args(argc, argv, "11", &str, &kcode); if (!NIL_P(kcode)) { @@ -1077,24 +1056,41 @@ rb_reg_s_quote(argc, argv) t = RSTRING(tmp)->ptr; for (; s < send; s++) { - if (ismbchar(*s)) { - int n = mbclen(*s); + c = *s; + if (ismbchar(c)) { + int n = mbclen(c); while (n-- && s < send) *t++ = *s++; s--; continue; } - if (*s == '[' || *s == ']' - || *s == '{' || *s == '}' - || *s == '(' || *s == ')' - || *s == '|' || *s == '-' - || *s == '*' || *s == '.' || *s == '\\' - || *s == '?' || *s == '+' - || *s == '^' || *s == '$') { + switch (c) { + case '\t': + c = 't'; *t++ = '\\'; + break; + case '\f': + c = 'f'; + *t++ = '\\'; + break; + case '\r': + c = 'r'; + *t++ = '\\'; + break; + case '\n': + c = 'n'; + *t++ = '\\'; + break; + case '[': case ']': case '{': case '}': + case '(': case ')': case '|': case '-': + case '*': case '.': case '\\': + case '?': case '+': case '^': case '$': + case ' ': + *t++ = '\\'; + break; } - *t++ = *s; + *t++ = c; } kcode_reset_option(); rb_str_resize(tmp, t - RSTRING(tmp)->ptr); |