summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-10 08:45:26 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-10 08:45:26 +0000
commit19c42c0740145dec1be93c332647f4310ea19918 (patch)
tree88516eac5daf33e2e935c3d38415e13d542ac131 /sprintf.c
parentff0abdc55e57f42f75204429c9eca471df48d835 (diff)
* variable.c (rb_obj_remove_instance_variable): raise NameError if
specified instance variable is not defined. * variable.c (generic_ivar_remove): modified to check ivar existence. * file.c (rb_file_s_extname): new method based on the proposal (and patch) from Mike Hall. [new] * eval.c (error_handle): default to 1 unless status is set. * eval.c (ruby_options): guard error_handle() with PROT_NONE. * eval.c (ruby_stop): ditto. * math.c (math_acosh): added. [new] * math.c (math_asinh): ditto. * math.c (math_atanh): ditto. * struct.c (rb_struct_each_pair): method added. [new] * class.c (rb_singleton_class): wrong condition; was creating unnecessary singleton class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c106
1 files changed, 28 insertions, 78 deletions
diff --git a/sprintf.c b/sprintf.c
index c1e6b47..e9742f3 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -26,78 +26,26 @@ remove_sign_bits(str, base)
int base;
{
char *s, *t, *end;
+ int len;
s = t = str;
- end = str + strlen(str);
+ len = strlen(str);
+ end = str + len;
if (base == 16) {
- x_retry:
- switch (*t) {
- case 'c': case 'C':
- *t = '4';
- break;
- case 'd': case 'D':
- *t = '5';
- break;
- case 'e': case 'E':
- *t = '2';
- break;
- case 'f': case 'F':
- if (t[1] > '8') {
- t++;
- goto x_retry;
- }
- *t = '1';
- break;
- case '1':
- case '3':
- case '7':
- if (t[1] > '8') {
- t++;
- goto x_retry;
- }
- break;
- }
- switch (*t) {
- case '1': *t = 'f'; break;
- case '2': *t = 'e'; break;
- case '3': *t = 'f'; break;
- case '4': *t = 'c'; break;
- case '5': *t = 'd'; break;
- case '6': *t = 'e'; break;
- case '7': *t = 'f'; break;
+ while (t<end && *t == 'f') {
+ t++;
}
}
else if (base == 8) {
- o_retry:
- switch (*t) {
- case '6':
- *t = '2';
- break;
- case '7':
- if (t[1] > '3') {
- t++;
- goto o_retry;
- }
- *t = '1';
- break;
- case '1':
- case '3':
- if (t[1] > '3') {
- t++;
- goto o_retry;
- }
- break;
- }
- switch (*t) {
- case '1': *t = '7'; break;
- case '2': *t = '6'; break;
- case '3': *t = '7'; break;
+ while (t<end && *t == '7') {
+ t++;
}
}
else if (base == 2) {
- while (t<end && *t == '1') t++;
- t--;
+ while (t<end && *t == '1') {
+ t++;
+ }
}
while (*t) *s++ = *t++;
*s = '\0';
@@ -398,12 +346,12 @@ rb_f_sprintf(argc, argv)
case T_BIGNUM:
bignum = 1;
break;
- default:
- v = NUM2LONG(val);
- break;
case T_FIXNUM:
v = FIX2LONG(val);
break;
+ default:
+ v = NUM2LONG(val);
+ break;
}
if (*p == 'u' || *p == 'd' || *p == 'i') base = 10;
@@ -454,8 +402,7 @@ rb_f_sprintf(argc, argv)
remove_sign_bits(s, base);
switch (base) {
case 16:
- d = 'f';
- break;
+ d = 'f'; break;
case 8:
d = '7'; break;
}
@@ -493,24 +440,27 @@ rb_f_sprintf(argc, argv)
val = rb_big2str(val, base);
s = RSTRING(val)->ptr;
if (*s == '-') {
- remove_sign_bits(++s, base);
- val = rb_str_new(0, 3+strlen(s));
- t = RSTRING(val)->ptr;
if (base == 10) {
rb_warning("negative number for %%u specifier");
+ s++;
}
else {
+ remove_sign_bits(++s, base);
+ val = rb_str_new(0, 3+strlen(s));
+ t = RSTRING(val)->ptr;
strcpy(t, "..");
t += 2;
- }
- switch (base) {
- case 16:
- if (s[0] != 'f') strcpy(t++, "f"); break;
- case 8:
- if (s[0] != '7') strcpy(t++, "7"); break;
+ switch (base) {
+ case 16:
+ if (s[0] != 'f') strcpy(t++, "f"); break;
+ case 8:
+ if (s[0] != '7') strcpy(t++, "7"); break;
+ case 2:
+ if (s[0] != '1') strcpy(t++, "1"); break;
+ }
+ strcpy(t, s);
+ bignum = 2;
}
- strcpy(t, s);
- bignum = 2;
}
s = RSTRING(val)->ptr;