Class: Strptime
- Inherits:
-
Object
- Object
- Strptime
- Defined in:
- ext/strptime/strptime.c,
lib/strptime.rb,
lib/strptime/version.rb,
ext/strptime/strptime.c
Overview
Strptime is a faster way to parse time strings like strptime(3).
Constant Summary collapse
- VERSION =
"0.2.5"
Instance Method Summary collapse
-
#exec(str) ⇒ Time
Parse given string, and return Time object.
-
#execi(str) ⇒ Integer
Parse given string, and return epoch as integer.
-
#new(format) ⇒ Object
constructor
returns parser object.
-
#initialize_copy(self) ⇒ Object
private
For Ruby VM internal.
-
#source ⇒ String
Source format string.
Constructor Details
#new(format) ⇒ Object
returns parser object
632 633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'ext/strptime/strptime.c', line 632
static VALUE
strptime_init(VALUE self, VALUE fmt)
{
struct strptime_object *tobj;
void **isns;
StringValueCStr(fmt);
TypedData_Get_Struct(self, struct strptime_object, &strptime_data_type,
tobj);
isns = strptime_compile(RSTRING_PTR(fmt), RSTRING_LEN(fmt));
tobj->isns = isns;
tobj->fmt = rb_str_new_frozen(fmt);
return self;
}
|
Instance Method Details
#exec(str) ⇒ Time
Parse given string, and return Time object
670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'ext/strptime/strptime.c', line 670
static VALUE
strptime_exec(VALUE self, VALUE str)
{
struct strptime_object *tobj;
int r, gmtoff = INT_MAX;
struct timespec ts;
StringValue(str);
GetStrptimeval(self, tobj);
r = strptime_exec0(tobj->isns, RSTRING_PTR(tobj->fmt), RSTRING_PTR(str),
RSTRING_LEN(str), &ts, &gmtoff);
if (r) rb_raise(rb_eArgError, "string doesn't match");
return rb_time_timespec_new(&ts, gmtoff);
}
|
#execi(str) ⇒ Integer
Parse given string, and return epoch as integer
692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
# File 'ext/strptime/strptime.c', line 692
static VALUE
strptime_execi(VALUE self, VALUE str)
{
struct strptime_object *tobj;
struct timespec ts;
int r, gmtoff = INT_MAX;
StringValue(str);
GetStrptimeval(self, tobj);
r = strptime_exec0(tobj->isns, RSTRING_PTR(tobj->fmt), RSTRING_PTR(str),
RSTRING_LEN(str), &ts, &gmtoff);
if (r) rb_raise(rb_eArgError, "string doesn't match");
return TIMET2NUM(ts.tv_sec);
}
|
#initialize_copy(self) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
For Ruby VM internal.
649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'ext/strptime/strptime.c', line 649
static VALUE
strptime_init_copy(VALUE copy, VALUE self)
{
struct strptime_object *tobj, *tcopy;
if (!OBJ_INIT_COPY(copy, self)) return copy;
GetStrptimeval(self, tobj);
GetNewStrptimeval(copy, tcopy);
MEMCPY(tcopy, tobj, struct strptime_object, 1);
return copy;
}
|
#source ⇒ String
Returns source format string.
711 712 713 714 715 716 717 718 |
# File 'ext/strptime/strptime.c', line 711
static VALUE
strptime_source(VALUE self)
{
struct strptime_object *tobj;
GetStrptimeval(self, tobj);
return tobj->fmt;
}
|