ruby-changes:22397
From: naruse <ko1@a...>
Date: Mon, 6 Feb 2012 21:30:04 +0900 (JST)
Subject: [ruby-changes:22397] naruse:r34446 (ruby_1_9_3): merge revision(s) 34335,34337:
naruse 2012-02-06 21:29:54 +0900 (Mon, 06 Feb 2012) New Revision: 34446 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34446 Log: merge revision(s) 34335,34337: * ext/date/date_parse.c: [ruby-core:42173]. * ext/date/date_strptime.c: moved detector of leftover. Modified files: branches/ruby_1_9_3/ext/date/date_parse.c branches/ruby_1_9_3/ext/date/date_strptime.c branches/ruby_1_9_3/test/date/test_date_parse.rb branches/ruby_1_9_3/test/date/test_date_strptime.rb Index: ruby_1_9_3/ext/date/date_strptime.c =================================================================== --- ruby_1_9_3/ext/date/date_strptime.c (revision 34445) +++ ruby_1_9_3/ext/date/date_strptime.c (revision 34446) @@ -1,5 +1,5 @@ /* - date_strptime.c: Coded by Tadayoshi Funaba 2011 + date_strptime.c: Coded by Tadayoshi Funaba 2011,2012 */ #include "ruby.h" @@ -641,15 +641,6 @@ } } - { - VALUE s; - - if (slen > si) { - s = rb_usascii_str_new(&str[si], slen - si); - set_hash("leftover", s); - } - } - return si; } @@ -657,10 +648,18 @@ date__strptime(const char *str, size_t slen, const char *fmt, size_t flen, VALUE hash) { + size_t si; VALUE cent, merid; - date__strptime_internal(str, slen, fmt, flen, hash); + si = date__strptime_internal(str, slen, fmt, flen, hash); + if (slen > si) { + VALUE s; + + s = rb_usascii_str_new(&str[si], slen - si); + set_hash("leftover", s); + } + if (fail_p()) return Qnil; Index: ruby_1_9_3/ext/date/date_parse.c =================================================================== --- ruby_1_9_3/ext/date/date_parse.c (revision 34445) +++ ruby_1_9_3/ext/date/date_parse.c (revision 34446) @@ -1,5 +1,5 @@ /* - date_parse.c: Coded by Tadayoshi Funaba 2011 + date_parse.c: Coded by Tadayoshi Funaba 2011,2012 */ #include "ruby.h" @@ -236,6 +236,26 @@ #define REGCOMP_0(pat) REGCOMP(pat, 0) #define REGCOMP_I(pat) REGCOMP(pat, ONIG_OPTION_IGNORECASE) +#define MATCH(s,p,c) \ +{ \ + return match(s, p, hash, c); \ +} + +static int +match(VALUE str, VALUE pat, VALUE hash, int (*cb)(VALUE, VALUE)) +{ + VALUE m; + + m = f_match(pat, str); + + if (NIL_P(m)) + return 0; + + (*cb)(m, hash); + + return 1; +} + #define SUBS(s,p,c) \ { \ return subs(s, p, hash, c); \ @@ -1726,7 +1746,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, iso8601_ext_datetime_cb); + MATCH(str, pat, iso8601_ext_datetime_cb); } #undef SNUM @@ -1817,7 +1837,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, iso8601_bas_datetime_cb); + MATCH(str, pat, iso8601_bas_datetime_cb); } #undef SNUM @@ -1860,7 +1880,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, iso8601_ext_time_cb); + MATCH(str, pat, iso8601_ext_time_cb); } static int @@ -1872,7 +1892,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, iso8601_bas_time_cb); + MATCH(str, pat, iso8601_bas_time_cb); } VALUE @@ -1940,7 +1960,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, rfc3339_cb); + MATCH(str, pat, rfc3339_cb); } VALUE @@ -2004,7 +2024,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, xmlschema_datetime_cb); + MATCH(str, pat, xmlschema_datetime_cb); } #undef SNUM @@ -2045,7 +2065,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, xmlschema_time_cb); + MATCH(str, pat, xmlschema_time_cb); } #undef SNUM @@ -2086,7 +2106,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, xmlschema_trunc_cb); + MATCH(str, pat, xmlschema_trunc_cb); } VALUE @@ -2157,7 +2177,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, rfc2822_cb); + MATCH(str, pat, rfc2822_cb); } VALUE @@ -2215,7 +2235,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, httpdate_type1_cb); + MATCH(str, pat, httpdate_type1_cb); } #undef SNUM @@ -2262,7 +2282,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, httpdate_type2_cb); + MATCH(str, pat, httpdate_type2_cb); } #undef SNUM @@ -2303,7 +2323,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, httpdate_type3_cb); + MATCH(str, pat, httpdate_type3_cb); } VALUE @@ -2377,7 +2397,7 @@ static VALUE pat = Qnil; REGCOMP_I(pat); - SUBS(str, pat, jisx0301_cb); + MATCH(str, pat, jisx0301_cb); } VALUE Index: ruby_1_9_3/test/date/test_date_strptime.rb =================================================================== --- ruby_1_9_3/test/date/test_date_strptime.rb (revision 34445) +++ ruby_1_9_3/test/date/test_date_strptime.rb (revision 34446) @@ -475,4 +475,12 @@ end end + def test_given_string + s = '2001-02-03T04:05:06Z' + s0 = s.dup + + assert_not_equal({}, Date._strptime(s, '%FT%T%Z')) + assert_equal(s0, s) + end + end Index: ruby_1_9_3/test/date/test_date_parse.rb =================================================================== --- ruby_1_9_3/test/date/test_date_parse.rb (revision 34445) +++ ruby_1_9_3/test/date/test_date_parse.rb (revision 34446) @@ -1060,4 +1060,38 @@ assert_equal(Date::ITALY + 10, d.start) end + def test_given_string + s = '2001-02-03T04:05:06Z' + s0 = s.dup + + assert_not_equal({}, Date._parse(s)) + assert_equal(s0, s) + + assert_not_equal({}, Date._iso8601(s)) + assert_equal(s0, s) + + assert_not_equal({}, Date._rfc3339(s)) + assert_equal(s0, s) + + assert_not_equal({}, Date._xmlschema(s)) + assert_equal(s0, s) + + s = 'Sat, 3 Feb 2001 04:05:06 UT' + s0 = s.dup + assert_not_equal({}, Date._rfc2822(s)) + assert_equal(s0, s) + assert_not_equal({}, Date._rfc822(s)) + assert_equal(s0, s) + + s = 'Sat, 03 Feb 2001 04:05:06 GMT' + s0 = s.dup + assert_not_equal({}, Date._httpdate(s)) + assert_equal(s0, s) + + s = 'H13.02.03T04:05:06,07Z' + s0 = s.dup + assert_not_equal({}, Date._jisx0301(s)) + assert_equal(s0, s) + end + end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/