summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--file.c2
-rw-r--r--hash.c4
-rw-r--r--sprintf.c6
-rw-r--r--string.c15
5 files changed, 27 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 6b720736f7..23faf77d93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/file.c b/file.c
index 01c26eea41..b189a239cb 100644
--- a/file.c
+++ b/file.c
@@ -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
diff --git a/hash.c b/hash.c
index b355d0661e..b36cfa2317 100644
--- a/hash.c
+++ b/hash.c
@@ -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
diff --git a/sprintf.c b/sprintf.c
index 07f8a42694..57ce682b5e 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -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 {
diff --git a/string.c b/string.c
index 0af0be0d09..972da1bcdb 100644
--- a/string.c
+++ b/string.c
@@ -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