summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-06 12:29:54 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-06 12:29:54 +0000
commit5879bd9c6ad968b6c0b1e41d05f92cd7178b63c1 (patch)
treea18c743c07df523303f798737278e4c26e50c66f /ext
parent234753aed43d93e6a89c5ae67d8e0aba90aeef99 (diff)
merge revision(s) 34335,34337:
* ext/date/date_parse.c: [ruby-core:42173]. * ext/date/date_strptime.c: moved detector of leftover. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/date/date_parse.c48
-rw-r--r--ext/date/date_strptime.c21
2 files changed, 44 insertions, 25 deletions
diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c
index 597c25ac55..903163003c 100644
--- a/ext/date/date_parse.c
+++ b/ext/date/date_parse.c
@@ -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 @@ regcomp(const char *source, long len, int opt)
#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 @@ iso8601_ext_datetime(VALUE str, VALUE hash)
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 @@ iso8601_bas_datetime(VALUE str, VALUE hash)
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 @@ iso8601_ext_time(VALUE str, VALUE hash)
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 @@ iso8601_bas_time(VALUE str, VALUE hash)
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 @@ rfc3339(VALUE str, VALUE hash)
static VALUE pat = Qnil;
REGCOMP_I(pat);
- SUBS(str, pat, rfc3339_cb);
+ MATCH(str, pat, rfc3339_cb);
}
VALUE
@@ -2004,7 +2024,7 @@ xmlschema_datetime(VALUE str, VALUE hash)
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 @@ xmlschema_time(VALUE str, VALUE hash)
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 @@ xmlschema_trunc(VALUE str, VALUE hash)
static VALUE pat = Qnil;
REGCOMP_I(pat);
- SUBS(str, pat, xmlschema_trunc_cb);
+ MATCH(str, pat, xmlschema_trunc_cb);
}
VALUE
@@ -2157,7 +2177,7 @@ rfc2822(VALUE str, VALUE hash)
static VALUE pat = Qnil;
REGCOMP_I(pat);
- SUBS(str, pat, rfc2822_cb);
+ MATCH(str, pat, rfc2822_cb);
}
VALUE
@@ -2215,7 +2235,7 @@ httpdate_type1(VALUE str, VALUE hash)
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 @@ httpdate_type2(VALUE str, VALUE hash)
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 @@ httpdate_type3(VALUE str, VALUE hash)
static VALUE pat = Qnil;
REGCOMP_I(pat);
- SUBS(str, pat, httpdate_type3_cb);
+ MATCH(str, pat, httpdate_type3_cb);
}
VALUE
@@ -2377,7 +2397,7 @@ jisx0301(VALUE str, VALUE hash)
static VALUE pat = Qnil;
REGCOMP_I(pat);
- SUBS(str, pat, jisx0301_cb);
+ MATCH(str, pat, jisx0301_cb);
}
VALUE
diff --git a/ext/date/date_strptime.c b/ext/date/date_strptime.c
index 80b9e03278..eaec8e716b 100644
--- a/ext/date/date_strptime.c
+++ b/ext/date/date_strptime.c
@@ -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 @@ date__strptime_internal(const char *str, size_t slen,
}
}
- {
- VALUE s;
-
- if (slen > si) {
- s = rb_usascii_str_new(&str[si], slen - si);
- set_hash("leftover", s);
- }
- }
-
return si;
}
@@ -657,9 +648,17 @@ VALUE
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;