mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (rb_str_chomp_bang): defer rb_str_modify() to actual
modify point. other methods, replace, tr, delete, squeeze, lstrip, and rstrip as well. * string.c (rb_str_rstrip_bang): remove trailing '\0' at the end of string. * string.c (rb_str_lstrip_bang): do not strip '\0' from the left. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
baf3f1cbac
commit
dbe85f1ef0
4 changed files with 29 additions and 15 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Mon Jul 28 01:35:32 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_str_chomp_bang): defer rb_str_modify() to actual
|
||||||
|
modify point. other methods, replace, tr, delete, squeeze,
|
||||||
|
lstrip, and rstrip as well.
|
||||||
|
|
||||||
|
* string.c (rb_str_rstrip_bang): remove trailing '\0' at the end
|
||||||
|
of string.
|
||||||
|
|
||||||
|
* string.c (rb_str_lstrip_bang): do not strip '\0' from the left.
|
||||||
|
|
||||||
Sun Jul 27 21:16:30 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
Sun Jul 27 21:16:30 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* ext/openssl/extconf.rb: better support MinGW. add
|
* ext/openssl/extconf.rb: better support MinGW. add
|
||||||
|
|
|
@ -1144,7 +1144,7 @@ module Net
|
||||||
|
|
||||||
def range_length
|
def range_length
|
||||||
r = self.content_range
|
r = self.content_range
|
||||||
r and r.length
|
r and r.end - r.begin
|
||||||
end
|
end
|
||||||
|
|
||||||
def basic_auth( account, password )
|
def basic_auth( account, password )
|
||||||
|
|
2
st.h
2
st.h
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#define ST_INCLUDED
|
#define ST_INCLUDED
|
||||||
|
|
||||||
typedef long st_data_t;
|
typedef unsigned long st_data_t;
|
||||||
#define ST_DATA_T_DEFINED
|
#define ST_DATA_T_DEFINED
|
||||||
|
|
||||||
typedef struct st_table st_table;
|
typedef struct st_table st_table;
|
||||||
|
|
29
string.c
29
string.c
|
@ -234,6 +234,7 @@ rb_str_shared_replace(str, str2)
|
||||||
VALUE str, str2;
|
VALUE str, str2;
|
||||||
{
|
{
|
||||||
if (str == str2) return;
|
if (str == str2) return;
|
||||||
|
rb_str_modify(str);
|
||||||
if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr);
|
if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr);
|
||||||
if (NIL_P(str2)) {
|
if (NIL_P(str2)) {
|
||||||
RSTRING(str)->ptr = 0;
|
RSTRING(str)->ptr = 0;
|
||||||
|
@ -1162,7 +1163,6 @@ static VALUE
|
||||||
rb_str_succ_bang(str)
|
rb_str_succ_bang(str)
|
||||||
VALUE str;
|
VALUE str;
|
||||||
{
|
{
|
||||||
rb_str_modify(str);
|
|
||||||
rb_str_shared_replace(str, rb_str_succ(str));
|
rb_str_shared_replace(str, rb_str_succ(str));
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
@ -2246,7 +2246,6 @@ tr_trans(str, src, repl, sflag)
|
||||||
int i, c, modify = 0;
|
int i, c, modify = 0;
|
||||||
char *s, *send;
|
char *s, *send;
|
||||||
|
|
||||||
rb_str_modify(str);
|
|
||||||
StringValue(src);
|
StringValue(src);
|
||||||
StringValue(repl);
|
StringValue(repl);
|
||||||
if (RSTRING(str)->len == 0 || !RSTRING(str)->ptr) return Qnil;
|
if (RSTRING(str)->len == 0 || !RSTRING(str)->ptr) return Qnil;
|
||||||
|
@ -2292,6 +2291,7 @@ tr_trans(str, src, repl, sflag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rb_str_modify(str);
|
||||||
s = RSTRING(str)->ptr; send = s + RSTRING(str)->len;
|
s = RSTRING(str)->ptr; send = s + RSTRING(str)->len;
|
||||||
if (sflag) {
|
if (sflag) {
|
||||||
char *t = s;
|
char *t = s;
|
||||||
|
@ -2395,7 +2395,6 @@ rb_str_delete_bang(argc, argv, str)
|
||||||
if (argc < 1) {
|
if (argc < 1) {
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments");
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
}
|
}
|
||||||
rb_str_modify(str);
|
|
||||||
for (i=0; i<argc; i++) {
|
for (i=0; i<argc; i++) {
|
||||||
VALUE s = argv[i];
|
VALUE s = argv[i];
|
||||||
|
|
||||||
|
@ -2404,6 +2403,7 @@ rb_str_delete_bang(argc, argv, str)
|
||||||
init = 0;
|
init = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rb_str_modify(str);
|
||||||
s = t = RSTRING(str)->ptr;
|
s = t = RSTRING(str)->ptr;
|
||||||
if (!s || RSTRING(str)->len == 0) return Qnil;
|
if (!s || RSTRING(str)->len == 0) return Qnil;
|
||||||
send = s + RSTRING(str)->len;
|
send = s + RSTRING(str)->len;
|
||||||
|
@ -2444,7 +2444,6 @@ rb_str_squeeze_bang(argc, argv, str)
|
||||||
int init = 1;
|
int init = 1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
rb_str_modify(str);
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
for (i=0; i<256; i++) {
|
for (i=0; i<256; i++) {
|
||||||
squeez[i] = 1;
|
squeez[i] = 1;
|
||||||
|
@ -2460,6 +2459,7 @@ rb_str_squeeze_bang(argc, argv, str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rb_str_modify(str);
|
||||||
s = t = RSTRING(str)->ptr;
|
s = t = RSTRING(str)->ptr;
|
||||||
if (!s || RSTRING(str)->len == 0) return Qnil;
|
if (!s || RSTRING(str)->len == 0) return Qnil;
|
||||||
send = s + RSTRING(str)->len;
|
send = s + RSTRING(str)->len;
|
||||||
|
@ -2828,8 +2828,8 @@ rb_str_chomp_bang(argc, argv, str)
|
||||||
rs = rb_rs;
|
rs = rb_rs;
|
||||||
if (rs == rb_default_rs) {
|
if (rs == rb_default_rs) {
|
||||||
smart_chomp:
|
smart_chomp:
|
||||||
rb_str_modify(str);
|
|
||||||
if (RSTRING(str)->ptr[len-1] == '\n') {
|
if (RSTRING(str)->ptr[len-1] == '\n') {
|
||||||
|
rb_str_modify(str);
|
||||||
RSTRING(str)->len--;
|
RSTRING(str)->len--;
|
||||||
if (RSTRING(str)->len > 0 &&
|
if (RSTRING(str)->len > 0 &&
|
||||||
RSTRING(str)->ptr[RSTRING(str)->len-1] == '\r') {
|
RSTRING(str)->ptr[RSTRING(str)->len-1] == '\r') {
|
||||||
|
@ -2837,6 +2837,7 @@ rb_str_chomp_bang(argc, argv, str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (RSTRING(str)->ptr[len-1] == '\r') {
|
else if (RSTRING(str)->ptr[len-1] == '\r') {
|
||||||
|
rb_str_modify(str);
|
||||||
RSTRING(str)->len--;
|
RSTRING(str)->len--;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2850,7 +2851,6 @@ rb_str_chomp_bang(argc, argv, str)
|
||||||
if (len == 0) return Qnil;
|
if (len == 0) return Qnil;
|
||||||
|
|
||||||
StringValue(rs);
|
StringValue(rs);
|
||||||
rb_str_modify(str);
|
|
||||||
rslen = RSTRING(rs)->len;
|
rslen = RSTRING(rs)->len;
|
||||||
if (rslen == 0) {
|
if (rslen == 0) {
|
||||||
while (len>0 && p[len-1] == '\n') {
|
while (len>0 && p[len-1] == '\n') {
|
||||||
|
@ -2921,15 +2921,15 @@ rb_str_lstrip_bang(str)
|
||||||
{
|
{
|
||||||
char *s, *t, *e;
|
char *s, *t, *e;
|
||||||
|
|
||||||
rb_str_modify(str);
|
|
||||||
s = RSTRING(str)->ptr;
|
s = RSTRING(str)->ptr;
|
||||||
if (!s || RSTRING(str)->len == 0) return Qnil;
|
if (!s || RSTRING(str)->len == 0) return Qnil;
|
||||||
e = t = s + RSTRING(str)->len;
|
e = t = s + RSTRING(str)->len;
|
||||||
/* remove spaces at head */
|
/* remove spaces at head */
|
||||||
while (s < t && (ISSPACE(*s) || !*s)) s++;
|
while (s < t && ISSPACE(*s)) s++;
|
||||||
|
|
||||||
RSTRING(str)->len = t-s;
|
|
||||||
if (s > RSTRING(str)->ptr) {
|
if (s > RSTRING(str)->ptr) {
|
||||||
|
rb_str_modify(str);
|
||||||
|
RSTRING(str)->len = t-s;
|
||||||
memmove(RSTRING(str)->ptr, s, RSTRING(str)->len);
|
memmove(RSTRING(str)->ptr, s, RSTRING(str)->len);
|
||||||
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
|
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
|
||||||
return str;
|
return str;
|
||||||
|
@ -2952,16 +2952,19 @@ rb_str_rstrip_bang(str)
|
||||||
{
|
{
|
||||||
char *s, *t, *e;
|
char *s, *t, *e;
|
||||||
|
|
||||||
rb_str_modify(str);
|
|
||||||
s = RSTRING(str)->ptr;
|
s = RSTRING(str)->ptr;
|
||||||
if (!s || RSTRING(str)->len == 0) return Qnil;
|
if (!s || RSTRING(str)->len == 0) return Qnil;
|
||||||
e = t = s + RSTRING(str)->len;
|
e = t = s + RSTRING(str)->len;
|
||||||
|
|
||||||
/* remove trailing spaces */
|
/* remove trailing '\0's */
|
||||||
while (s < t && (ISSPACE(*(t-1)) || !*(t-1))) t--;
|
while (s < t && t[-1] == '\0') t--;
|
||||||
|
|
||||||
|
/* remove trailing spaces */
|
||||||
|
while (s < t && ISSPACE(*(t-1))) t--;
|
||||||
|
|
||||||
RSTRING(str)->len = t-s;
|
|
||||||
if (t < e) {
|
if (t < e) {
|
||||||
|
rb_str_modify(str);
|
||||||
|
RSTRING(str)->len = t-s;
|
||||||
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
|
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue