From 19c42c0740145dec1be93c332647f4310ea19918 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 10 Apr 2002 08:45:26 +0000 Subject: * 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 --- sprintf.c | 106 +++++++++++++++++--------------------------------------------- 1 file changed, 28 insertions(+), 78 deletions(-) (limited to 'sprintf.c') diff --git a/sprintf.c b/sprintf.c index c1e6b47f84..e9742f3fd5 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 '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 (tptr; 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; -- cgit v1.2.1