summaryrefslogtreecommitdiff
path: root/ext/date/date_core.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-23 12:31:15 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-23 12:31:15 +0000
commit448e0d6668d5df4f63a17db2063b31ed50c39d46 (patch)
treed5c30da2ee2e13b9f1c8ffc91f932447ea1d1c1c /ext/date/date_core.c
parentd5b4cf7f798cf82cb6f33f774690b72f2a12de69 (diff)
* ext/date/date_core.c: replacement of implementation of
_parse. [experimental] * ext/date/date_parse.c: new. * ext/date/lib/date/format.rb: removed ruby version of _parse. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/date/date_core.c')
-rw-r--r--ext/date/date_core.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index a254d3e220..52a1b38eae 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -1417,7 +1417,7 @@ date_s__strptime_internal(int argc, VALUE *argv, VALUE klass,
/*
* call-seq:
- * Date._strptime(string, [format="%F"])
+ * Date._strptime(string[, format="%F"])
*
* Return a hash of parsed elements.
*/
@@ -1427,6 +1427,50 @@ date_s__strptime(int argc, VALUE *argv, VALUE klass)
return date_s__strptime_internal(argc, argv, klass, "%F");
}
+VALUE
+date__parse(VALUE str, VALUE comp);
+
+static VALUE
+date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
+{
+ VALUE vstr, vcomp, hash;
+ const char *str;
+
+ rb_scan_args(argc, argv, "11", &vstr, &vcomp);
+ StringValue(vstr);
+ if (!rb_enc_str_asciicompat_p(vstr))
+ rb_raise(rb_eArgError,
+ "string should have ASCII compatible encoding");
+ str = RSTRING_PTR(vstr);
+ if (argc < 2)
+ vcomp = Qtrue;
+
+ hash = date__parse(vstr, vcomp);
+
+ {
+ VALUE zone = rb_hash_aref(hash, ID2SYM(rb_intern("zone")));
+
+ if (!NIL_P(zone)) {
+ rb_enc_copy(zone, vstr);
+ rb_hash_aset(hash, ID2SYM(rb_intern("zone")), zone);
+ }
+ }
+
+ return hash;
+}
+
+/*
+ * call-seq:
+ * Date._parse(string[, comp=true])
+ *
+ * Return a hash of parsed elements.
+ */
+static VALUE
+date_s__parse(int argc, VALUE *argv, VALUE klass)
+{
+ return date_s__parse_internal(argc, argv, klass);
+}
+
/*
* call-seq:
* d.ajd
@@ -3155,7 +3199,7 @@ datetime_s_now(int argc, VALUE *argv, VALUE klass)
/*
* call-seq:
- * DateTime._strptime(string, [format="%FT%T%z"])
+ * DateTime._strptime(string[, format="%FT%T%z"])
*
* Return a hash of parsed elements.
*/
@@ -4454,6 +4498,7 @@ Init_date_core(void)
rb_define_singleton_method(cDate, "commercial", date_s_commercial, -1);
rb_define_singleton_method(cDate, "today", date_s_today, -1);
rb_define_singleton_method(cDate, "_strptime", date_s__strptime, -1);
+ rb_define_singleton_method(cDate, "_parse", date_s__parse, -1);
rb_define_method(cDate, "ajd", d_lite_ajd, 0);
rb_define_method(cDate, "amjd", d_lite_amjd, 0);