diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | file.c | 2 | ||||
-rw-r--r-- | hash.c | 4 | ||||
-rw-r--r-- | sprintf.c | 6 | ||||
-rw-r--r-- | string.c | 15 |
5 files changed, 27 insertions, 9 deletions
@@ -1,3 +1,12 @@ +Tue Feb 10 17:29:08 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * string.c (str_aset): string insertion by `str[n] = str2'. + + * string.c (str_oct): does recognize `0x'. + + * sprintf.c (f_sprintf): use baes 10 for conversion from string to + integer. + Mon Feb 9 14:51:56 1998 Yukihiro Matsumoto <matz@netlab.co.jp> * numeric.c (do_coerce): proper error message. @@ -46,6 +46,7 @@ struct timeval { char *strrchr(); #endif +#include <sys/types.h> #include <sys/stat.h> #ifndef NT @@ -261,7 +262,6 @@ file_path(obj) return str_new2(fptr->path); } -#include <sys/types.h> #ifndef NT #include <sys/file.h> #else @@ -14,9 +14,7 @@ #include "st.h" #include "sig.h" -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif +#include <sys/types.h> #include <sys/stat.h> #ifndef HAVE_STRING_H @@ -327,7 +327,7 @@ f_sprintf(argc, argv) bignum = 1; break; case T_STRING: - val = str2inum(RSTRING(val)->ptr, 0); + val = str2inum(RSTRING(val)->ptr, 10); goto bin_retry; case T_BIGNUM: bignum = 1; @@ -339,10 +339,10 @@ f_sprintf(argc, argv) if (*p == 'x') base = 16; else if (*p == 'o') base = 8; - else if (*p == 'u') base = 10; + else if (*p == 'u' || *p == 'd') base = 10; else if (*p == 'b' || *p == 'B') base = 2; if (!bignum) { - if (*p == 'b' || *p == 'B') { + if (base == 2) { val = int2big(v); } else { @@ -1034,7 +1034,12 @@ str_aset(str, indx, val) if (idx < 0 || RSTRING(str)->len <= idx) { IndexError("index %d out of range [0..%d]", idx, RSTRING(str)->len-1); } - RSTRING(str)->ptr[idx] = FIX2INT(val) & 0xff; + if (TYPE(val) == T_STRING) { + str_replace(str, idx, 1, val); + } + else { + RSTRING(str)->ptr[idx] = NUM2INT(val) & 0xff; + } return val; case T_REGEXP: @@ -2243,7 +2248,13 @@ static VALUE str_oct(str) VALUE str; { - return str2inum(RSTRING(str)->ptr, 8); + int base = 8; + + if (RSTRING(str)->len > 2 && RSTRING(str)->ptr[0] == '0' && + (RSTRING(str)->ptr[1] == 'x' || RSTRING(str)->ptr[1] == 'X')) { + base = 16; + } + return str2inum(RSTRING(str)->ptr, base); } static VALUE |