ruby-changes:22286
From: tadf <ko1@a...>
Date: Thu, 19 Jan 2012 07:13:42 +0900 (JST)
Subject: [ruby-changes:22286] tadf:r34335 (trunk): ext/date/date_parse.c: .
tadf 2012-01-19 07:13:10 +0900 (Thu, 19 Jan 2012) New Revision: 34335 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34335 Log: ext/date/date_parse.c: [ruby-core:42173]. Modified files: trunk/ChangeLog trunk/ext/date/date_parse.c trunk/test/date/test_date_parse.rb trunk/test/date/test_date_strptime.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34334) +++ ChangeLog (revision 34335) @@ -1,3 +1,7 @@ +Thu Jan 19 07:10:47 2012 Tadayoshi Funaba <tadf@d...> + + * ext/date/date_parse.c: [ruby-core:42173]. + Wed Jan 18 18:11:02 2012 Akinori MUSHA <knu@i...> * misc/rdoc-mode.el (rdoc-mode): Add provide so that requiring Index: ext/date/date_parse.c =================================================================== --- ext/date/date_parse.c (revision 34334) +++ ext/date/date_parse.c (revision 34335) @@ -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: test/date/test_date_strptime.rb =================================================================== --- test/date/test_date_strptime.rb (revision 34334) +++ test/date/test_date_strptime.rb (revision 34335) @@ -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: test/date/test_date_parse.rb =================================================================== --- test/date/test_date_parse.rb (revision 34334) +++ test/date/test_date_parse.rb (revision 34335) @@ -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/