diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-24 15:49:43 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-24 15:49:43 +0000 |
commit | dc54e380415cfdf442dafbc6ede8ab433af41fe2 (patch) | |
tree | 4159315b0f6e7881b79fb93bb32ee8e1f02a5af3 /strftime.c | |
parent | 24602147809f793d9e4086bd2f2e732a35264fb8 (diff) | |
download | ruby-dc54e380415cfdf442dafbc6ede8ab433af41fe2.tar.gz |
strftime.c: Bignum conversion
* strftime.c (format_value): convert from Bignum to String,
instead of rb_str_format.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'strftime.c')
-rw-r--r-- | strftime.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/strftime.c b/strftime.c index 81e56d1f7b..542091d874 100644 --- a/strftime.c +++ b/strftime.c @@ -196,14 +196,11 @@ case_conv(char *s, ptrdiff_t i, int flags) } static VALUE -format_value(const char *fmt, VALUE val, int precision) +format_value(VALUE val, int base) { - struct RString fmtv; - VALUE str = rb_setup_fake_str(&fmtv, fmt, strlen(fmt), 0); - VALUE args[2]; - args[0] = INT2FIX(precision); - args[1] = val; - return rb_str_format(2, args, str); + if (!RB_TYPE_P(val, T_BIGNUM)) + val = rb_Integer(val); + return rb_big2str(val, base); } /* @@ -323,9 +320,14 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len, FMT((def_pad), (def_prec), "l"fmt, FIX2LONG(tmp)); \ } \ else { \ - const char *fmts = FMT_PADDING(fmt, def_pad); \ + const int base = ((fmt[0] == 'x') ? 16 : \ + (fmt[0] == 'o') ? 8 : \ + 10); \ precision = FMT_PRECISION(def_prec); \ - tmp = format_value(fmts, tmp, precision); \ + if (!padding) padding = (def_pad); \ + tmp = format_value(tmp, base); \ + i = RSTRING_LEN(tmp); \ + FILL_PADDING(i); \ rb_str_set_len(ftime, s-start); \ rb_str_append(ftime, tmp); \ RSTRING_GETMEM(ftime, s, len); \ |