* sprintf.c (rb_f_sprintf): remove extra sign digit.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2004-07-17 23:14:52 +00:00
parent e6401638f4
commit 6d27ddd289
2 changed files with 17 additions and 13 deletions

View File

@ -1,3 +1,7 @@
Sun Jul 18 08:13:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (rb_f_sprintf): remove extra sign digit.
Sun Jul 18 03:19:14 2004 Akinori MUSHA <knu@iDaemons.org> Sun Jul 18 03:19:14 2004 Akinori MUSHA <knu@iDaemons.org>
* dir.c (bracket): use NULL instead of 0. * dir.c (bracket): use NULL instead of 0.

View File

@ -25,31 +25,30 @@ remove_sign_bits(str, base)
char *str; char *str;
int base; int base;
{ {
char *s, *t, *end; char *s, *t;
unsigned long len;
s = t = str; s = t = str;
len = strlen(str);
end = str + len;
if (base == 16) { if (base == 16) {
while (t<end && *t == 'f') { while (*t == 'f') {
t++; t++;
} }
} }
else if (base == 8) { else if (base == 8) {
if (*t == '3') t++; if (*t == '3') t++;
while (t<end && *t == '7') { while (*t == '7') {
t++; t++;
} }
} }
else if (base == 2) { else if (base == 2) {
while (t<end && *t == '1') { while (*t == '1') {
t++; t++;
} }
} }
while (*t) *s++ = *t++; if (t > s) {
*s = '\0'; while (*t) *s++ = *t++;
*s = '\0';
}
return str; return str;
} }
@ -57,7 +56,7 @@ remove_sign_bits(str, base)
static char static char
sign_bits(base, p) sign_bits(base, p)
int base; int base;
char *p; const char *p;
{ {
char c = '.'; char c = '.';
@ -234,7 +233,8 @@ rb_f_sprintf(argc, argv)
VALUE *argv; VALUE *argv;
{ {
VALUE fmt; VALUE fmt;
char *buf, *p, *end; const char *p, *end;
char *buf;
int blen, bsiz; int blen, bsiz;
VALUE result; VALUE result;
@ -257,7 +257,7 @@ rb_f_sprintf(argc, argv)
buf = RSTRING(result)->ptr; buf = RSTRING(result)->ptr;
for (; p < end; p++) { for (; p < end; p++) {
char *t; const char *t;
int n; int n;
for (t = p; t < end && *t != '%'; t++) ; for (t = p; t < end && *t != '%'; t++) ;
@ -549,7 +549,7 @@ rb_f_sprintf(argc, argv)
s += 2; s += 2;
} }
} }
sprintf(fbuf, "%%l%c", *p); sprintf(fbuf, "%%l%c", *p == 'X' ? 'x' : *p);
sprintf(s, fbuf, v); sprintf(s, fbuf, v);
if (v < 0) { if (v < 0) {
char d = 0; char d = 0;