diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-11-24 14:01:47 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-11-24 14:01:47 +0000 |
commit | bf1d53e2e0c32af95f852f30884bd6d1fcf1a077 (patch) | |
tree | 0b4ad6370e2f1d50b613dfb1afd0dccbd55ccc9c | |
parent | aa498028b28b709db51408c0855163cc8adfbb8b (diff) |
* strftime.c (rb_strftime): A width specifier for %t and %n should
work. [ruby-dev:37160]
* test/ruby/test_time.rb (test_strftime): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | strftime.c | 23 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 12 |
3 files changed, 32 insertions, 10 deletions
@@ -1,3 +1,10 @@ +Mon Nov 24 22:57:25 2008 Shugo Maeda <shugo@ruby-lang.org> + + * strftime.c (rb_strftime): A width specifier for %t and %n should + work. [ruby-dev:37160] + + * test/ruby/test_time.rb (test_strftime): ditto. + Mon Nov 24 22:07:07 2008 Shugo Maeda <shugo@ruby-lang.org> * strftime.c (rb_strftime): The precision of %0N should be 9. diff --git a/strftime.c b/strftime.c index 2c98164c0b..3a88208b1f 100644 --- a/strftime.c +++ b/strftime.c @@ -270,6 +270,16 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept goto unknown; \ } while (0) #define NEEDS(n) do if (s + (n) >= endp - 1) goto err; while (0) +#define FILL_PADDING(i) do { \ + if (!(flags & BIT_OF(LEFT)) && precision > i) { \ + NEEDS(precision); \ + memset(s, padding ? padding : ' ', precision - i); \ + s += precision - i; \ + } \ + else { \ + NEEDS(i); \ + } \ +} while (0); #define FMT(def_pad, def_prec, fmt, val) \ do { \ int l; \ @@ -540,12 +550,12 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept #ifdef SYSV_EXT case 'n': /* same as \n */ - NEEDS(1); + FILL_PADDING(1); *s++ = '\n'; continue; case 't': /* same as \t */ - NEEDS(1); + FILL_PADDING(1); *s++ = '\t'; continue; @@ -741,14 +751,7 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept break; } if (i) { - if (!(flags & BIT_OF(LEFT)) && precision > i) { - NEEDS(precision); - memset(s, padding ? padding : ' ', precision - i); - s += precision - i; - } - else { - NEEDS(i); - } + FILL_PADDING(i); memcpy(s, tp, i); switch (flags & (BIT_OF(UPPER)|BIT_OF(LOWER))) { case BIT_OF(UPPER): diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index b15027c1f8..2f37d57871 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -449,5 +449,17 @@ class TestTime < Test::Unit::TestCase t = Time.mktime(1970, 1, 18) assert_equal("0", t.strftime("%w")) assert_equal("7", t.strftime("%u")) + + # [ruby-dev:37160] + assert_equal("\t", T2000.strftime("%t")) + assert_equal("\t", T2000.strftime("%0t")) + assert_equal("\t", T2000.strftime("%1t")) + assert_equal(" \t", T2000.strftime("%3t")) + assert_equal("00\t", T2000.strftime("%03t")) + assert_equal("\n", T2000.strftime("%n")) + assert_equal("\n", T2000.strftime("%0n")) + assert_equal("\n", T2000.strftime("%1n")) + assert_equal(" \n", T2000.strftime("%3n")) + assert_equal("00\n", T2000.strftime("%03n")) end end |