diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-05-30 04:24:17 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-05-30 04:24:17 +0000 |
commit | 9a1716fdb289e7bcdabf9050bfdf051106e2cce0 (patch) | |
tree | f08529a845b5a16b93635eeb06b58553252692c9 /re.c | |
parent | 869b1efeb4eea77338863faff98da2432acb4b5d (diff) |
2000-05-30
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 45 |
1 files changed, 40 insertions, 5 deletions
@@ -211,17 +211,17 @@ rb_reg_expr_str(str, s, len) int len; { const char *p, *pend; - int slash = 0; + int need_escape = 0; p = s; pend = p + len; while (p<pend) { - if (*p == '/') { - slash = 1; + if (*p == '/' || (!ISPRINT(*p) && !ismbchar(*p))) { + need_escape = 1; break; } p++; } - if (!slash) { + if (!need_escape) { rb_str_cat(str, s, len); } else { @@ -232,9 +232,44 @@ rb_reg_expr_str(str, s, len) rb_str_cat(str, &c, 1); rb_str_cat(str, p, 1); } - else { + else if (ismbchar(*p)) { + rb_str_cat(str, p, mbclen(*p)); + p += mbclen(*p); + continue; + } + else if (ISPRINT(*p)) { rb_str_cat(str, p, 1); } + else { + 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; + } + } p++; } } |