* sprintf.c (rb_f_sprintf): clean up.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c87eaa3af2
commit
a7d4955188
@ -1,3 +1,7 @@
|
|||||||
|
Wed Feb 18 10:23:34 2004 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* sprintf.c (rb_f_sprintf): clean up.
|
||||||
|
|
||||||
Tue Feb 17 23:40:34 2004 Guy Decoux <ts@moulon.inra.fr>
|
Tue Feb 17 23:40:34 2004 Guy Decoux <ts@moulon.inra.fr>
|
||||||
|
|
||||||
* sprintf.c (rb_f_sprintf): preserve original val for
|
* sprintf.c (rb_f_sprintf): preserve original val for
|
||||||
|
22
sprintf.c
22
sprintf.c
@ -444,7 +444,6 @@ rb_f_sprintf(argc, argv)
|
|||||||
long v = 0;
|
long v = 0;
|
||||||
int base, bignum = 0;
|
int base, bignum = 0;
|
||||||
int len, pos;
|
int len, pos;
|
||||||
VALUE tmp;
|
|
||||||
|
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case 'd':
|
case 'd':
|
||||||
@ -514,6 +513,7 @@ rb_f_sprintf(argc, argv)
|
|||||||
default:
|
default:
|
||||||
base = 10; break;
|
base = 10; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bignum) {
|
if (!bignum) {
|
||||||
if (base == 2) {
|
if (base == 2) {
|
||||||
val = rb_int2big(v);
|
val = rb_int2big(v);
|
||||||
@ -537,9 +537,8 @@ rb_f_sprintf(argc, argv)
|
|||||||
}
|
}
|
||||||
sprintf(fbuf, "%%l%c", c);
|
sprintf(fbuf, "%%l%c", c);
|
||||||
sprintf(nbuf, fbuf, v);
|
sprintf(nbuf, fbuf, v);
|
||||||
s = nbuf;
|
|
||||||
goto format_integer;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
s = nbuf;
|
s = nbuf;
|
||||||
if (v < 0) {
|
if (v < 0) {
|
||||||
if (base == 10) {
|
if (base == 10) {
|
||||||
@ -567,10 +566,10 @@ rb_f_sprintf(argc, argv)
|
|||||||
*s = d;
|
*s = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s = nbuf;
|
|
||||||
goto format_integer;
|
|
||||||
}
|
}
|
||||||
|
s = nbuf;
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (sign) {
|
if (sign) {
|
||||||
tmp = rb_big2str(val, base);
|
tmp = rb_big2str(val, base);
|
||||||
s = RSTRING(tmp)->ptr;
|
s = RSTRING(tmp)->ptr;
|
||||||
@ -587,8 +586,8 @@ rb_f_sprintf(argc, argv)
|
|||||||
sc = ' ';
|
sc = ' ';
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
goto format_integer;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (!RBIGNUM(val)->sign) {
|
if (!RBIGNUM(val)->sign) {
|
||||||
val = rb_big_clone(val);
|
val = rb_big_clone(val);
|
||||||
rb_big_2comp(val);
|
rb_big_2comp(val);
|
||||||
@ -598,7 +597,6 @@ rb_f_sprintf(argc, argv)
|
|||||||
if (*s == '-') {
|
if (*s == '-') {
|
||||||
if (base == 10) {
|
if (base == 10) {
|
||||||
rb_warning("negative number for %%u specifier");
|
rb_warning("negative number for %%u specifier");
|
||||||
s++;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
remove_sign_bits(++s, base);
|
remove_sign_bits(++s, base);
|
||||||
@ -617,12 +615,12 @@ rb_f_sprintf(argc, argv)
|
|||||||
if (s[0] != '1') strcpy(t++, "1"); break;
|
if (s[0] != '1') strcpy(t++, "1"); break;
|
||||||
}
|
}
|
||||||
strcpy(t, s);
|
strcpy(t, s);
|
||||||
bignum = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s = RSTRING(tmp)->ptr;
|
s = RSTRING(tmp)->ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
format_integer:
|
|
||||||
pos = -1;
|
pos = -1;
|
||||||
len = strlen(s);
|
len = strlen(s);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user