diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-05-01 09:42:38 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-05-01 09:42:38 +0000 |
commit | fedf48986da718580062d081dda38c4ee182c254 (patch) | |
tree | 65e06d76c544a8d80296d686bf88ec3af41fdc50 /string.c | |
parent | acbb1c943457d3b8802f099ee0e34331bc78bd38 (diff) |
2000-05-01
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 39 |
1 files changed, 24 insertions, 15 deletions
@@ -1,4 +1,4 @@ -/************************************************ +/********************************************************************** string.c - @@ -7,8 +7,10 @@ created at: Mon Aug 9 17:12:58 JST 1993 Copyright (C) 1993-2000 Yukihiro Matsumoto + Copyright (C) 2000 Network Applied Communication Laboratory, Inc. + Copyright (C) 2000 Information-technology Promotion Agancy, Japan -************************************************/ +**********************************************************************/ #include "ruby.h" #include "re.h" @@ -767,29 +769,36 @@ rb_str_succ(orig) VALUE str, str2; char *sbeg, *s; int c = -1; + int n = 0; str = rb_str_new(RSTRING(orig)->ptr, RSTRING(orig)->len); + OBJ_INFECT(str, orig); + if (RSTRING(str)->len == 0) return str; sbeg = RSTRING(str)->ptr; s = sbeg + RSTRING(str)->len - 1; while (sbeg <= s) { - if (ISALNUM(*s) && (c = succ_char(s)) == 0) break; + if (ISALNUM(*s)) { + if ((c = succ_char(s)) == 0) break; + n = s - sbeg; + } s--; } - if (s < sbeg) { - if (c == -1 && RSTRING(str)->len > 0) { - RSTRING(str)->ptr[RSTRING(str)->len-1] += 1; - } - else { - str2 = rb_str_new(0, RSTRING(str)->len+1); - RSTRING(str2)->ptr[0] = c; - memcpy(RSTRING(str2)->ptr+1, RSTRING(str)->ptr, RSTRING(str)->len); - str = str2; + if (c == -1) { /* str contains no alnum */ + sbeg = RSTRING(str)->ptr; s = sbeg + RSTRING(str)->len - 1; + c = '\001'; + while (sbeg <= s) { + *s += 1; + if (*s-- != 0) break; } } - - if (OBJ_TAINTED(orig)) { - OBJ_TAINT(str); + if (s < sbeg) { + REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len + 1); + s = RSTRING(str)->ptr + n; + memmove(s+1, s, RSTRING(str)->len - n); + *s = c; + RSTRING(str)->len += 1; + } return str; |