Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Macros | Functions | Variables
date_strptime.c File Reference
`#include "ruby.h"`
`#include "ruby/encoding.h"`
`#include "ruby/re.h"`
`#include <ctype.h>`
Include dependency graph for date_strptime.c:

Go to the source code of this file.

## Macros
#define | sizeof_array(o) (sizeof o / sizeof o[0])
#define | f_negate(x) rb_funcall(x, rb_intern("-@"), 0)
#define | f_add(x, y) rb_funcall(x, '+', 1, y)
#define | f_sub(x, y) rb_funcall(x, '-', 1, y)
#define | f_mul(x, y) rb_funcall(x, '*', 1, y)
#define | f_div(x, y) rb_funcall(x, '/', 1, y)
#define | f_idiv(x, y) rb_funcall(x, rb_intern("div"), 1, y)
#define | f_mod(x, y) rb_funcall(x, '%', 1, y)
#define | f_expt(x, y) rb_funcall(x, rb_intern("**"), 1, y)
#define | f_lt_p(x, y) rb_funcall(x, '<', 1, y)
#define | f_gt_p(x, y) rb_funcall(x, '>', 1, y)
#define | f_le_p(x, y) rb_funcall(x, rb_intern("<="), 1, y)
#define | f_ge_p(x, y) rb_funcall(x, rb_intern(">="), 1, y)
#define | f_match(r, s) rb_funcall(r, rb_intern("match"), 1, s)
#define | f_aref(o, i) rb_funcall(o, rb_intern("[]"), 1, i)
#define | f_end(o, i) rb_funcall(o, rb_intern("end"), 1, i)
#define | issign(c) ((c) == '-' || (c) == '+')
#define | NUM_PATTERN_P() num_pattern_p(&fmt[fi + 1])
#define | set_hash(k, v) rb_hash_aset(hash, ID2SYM(rb_intern(k)), v)
#define | ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k)))
#define | del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k)))
#define | fail()
#define | fail_p() (!NIL_P(ref_hash("_fail")))
#define | READ_DIGITS(n, w)
#define | READ_DIGITS_MAX(n) READ_DIGITS(n, LONG_MAX)
#define | recur(fmt)

## Functions
static int | num_pattern_p (const char *s)
static long | read_digits (const char *s, VALUE *n, size_t width)
static int | valid_range_p (VALUE v, int a, int b)
VALUE | date_zone_to_diff (VALUE)
static size_t | date__strptime_internal (const char *str, size_t slen, const char *fmt, size_t flen, VALUE hash)
VALUE | date__strptime (const char *str, size_t slen, const char *fmt, size_t flen, VALUE hash)

## Variables
static const char * | day_names []
static const char * | month_names []
static const char * | merid_names []
static const char * | extz_pats []

## Macro Definition Documentation

#define del_hash | ( |  | k | ) | rb_hash_delete(hash, ID2SYM(rb_intern(k)))

Definition at line 116 of file date_strptime.c.

Referenced by date__strptime().

#define f_add | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, '+', 1, y)

Definition at line 39 of file date_strptime.c.

Referenced by date__strptime().

#define f_aref | ( |  | o,
|  |  | i
| ) |  | rb_funcall(o, rb_intern("[]"), 1, i)

Definition at line 53 of file date_strptime.c.

#define f_div | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, '/', 1, y)

Definition at line 42 of file date_strptime.c.

#define f_end | ( |  | o,
|  |  | i
| ) |  | rb_funcall(o, rb_intern("end"), 1, i)

Definition at line 54 of file date_strptime.c.

Referenced by date__strptime_internal().

#define f_expt | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, rb_intern("**"), 1, y)

Definition at line 45 of file date_strptime.c.

Referenced by date__strptime_internal().

#define f_ge_p | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, rb_intern(">="), 1, y)

Definition at line 50 of file date_strptime.c.

Referenced by date__strptime_internal().

#define f_gt_p | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, '>', 1, y)

Definition at line 48 of file date_strptime.c.

Referenced by valid_range_p().

#define f_idiv | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, rb_intern("div"), 1, y)

Definition at line 43 of file date_strptime.c.

#define f_le_p | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, rb_intern("<="), 1, y)

Definition at line 49 of file date_strptime.c.

#define f_lt_p | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, '<', 1, y)

Definition at line 47 of file date_strptime.c.

Referenced by valid_range_p().

#define f_match | ( |  | r,
|  |  | s
| ) |  | rb_funcall(r, rb_intern("match"), 1, s)

Definition at line 52 of file date_strptime.c.

Referenced by date__strptime_internal().

#define f_mod | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, '%', 1, y)

Definition at line 44 of file date_strptime.c.

Referenced by date__strptime().

#define f_mul | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, '*', 1, y)

Definition at line 41 of file date_strptime.c.

Referenced by date__strptime().

#define f_negate | ( |  | x | ) | rb_funcall(x, rb_intern("-@"), 0)

Definition at line 38 of file date_strptime.c.

Referenced by date__strptime_internal().

#define f_sub | ( |  | x,
|  |  | y
| ) |  | rb_funcall(x, '-', 1, y)

Definition at line 40 of file date_strptime.c.

#define fail | ( |  | ) |

Value:
{ \
set_hash("_fail", Qtrue); \
return 0; \
}
return
return
Definition: bigdecimal.c:5800
Qtrue
return Qtrue
Definition: tcltklib.c:9610
set_hash
#define set_hash(k, v)
Definition: date_strptime.c:114

Definition at line 118 of file date_strptime.c.

Referenced by allocate_converted_string(), backward_search_range(), date__strptime_internal(), match_at(), output_hex_charref(), rb_econv_insert_output(), ruby_qsort(), ruby_setenv(), and run_exec_dup2().

#define fail_p | ( |  | ) | (!NIL_P(ref_hash("_fail")))

Definition at line 124 of file date_strptime.c.

Referenced by date__strptime().

#define issign | ( |  | c | ) | ((c) == '-' || (c) == '+')

Definition at line 56 of file date_strptime.c.

Referenced by date__strptime_internal().

#define NUM_PATTERN_P | ( |  | ) | num_pattern_p(&fmt[fi + 1])

Definition at line 75 of file date_strptime.c.

Referenced by date__strptime_internal().

#define READ_DIGITS | ( |  | n,
|  |  | w
| ) |  |

Value:
{ \
size_t l; \
l = read_digits(&str[si], &n, w); \
if (l == 0) \
fail(); \
si += l; \
}
n
ssize_t n
Definition: bigdecimal.c:5655
fail
#define fail()
Definition: date_strptime.c:118
str
static VALUE char * str
Definition: tcltklib.c:3547
read_digits
static long read_digits(const char *s, VALUE *n, size_t width)
Definition: date_strptime.c:78
if
if(RB_TYPE_P(r, T_FLOAT))
Definition: bigdecimal.c:1186

Definition at line 126 of file date_strptime.c.

Referenced by date__strptime_internal().

#define READ_DIGITS_MAX | ( |  | n | ) | READ_DIGITS(n, LONG_MAX)

Definition at line 135 of file date_strptime.c.

Referenced by date__strptime_internal().

#define recur | ( |  | fmt | ) |

Value:
{ \
size_t l; \
l = date__strptime_internal(&str[si], slen - si, \
fmt, sizeof fmt - 1, hash); \
if (fail_p()) \
return 0; \
si += l; \
}
fail_p
#define fail_p()
Definition: date_strptime.c:124
return
return
Definition: bigdecimal.c:5800
fmt
const char * fmt
Definition: tcltklib.c:841
hash
VALUE hash
Definition: tkutil.c:267
str
static VALUE char * str
Definition: tcltklib.c:3547
if
if(RB_TYPE_P(r, T_FLOAT))
Definition: bigdecimal.c:1186
date__strptime_internal
static size_t date__strptime_internal(const char *str, size_t slen, const char *fmt, size_t flen, VALUE hash)
Definition: date_strptime.c:160

Definition at line 147 of file date_strptime.c.

Referenced by class_instance_method_list(), date__strptime_internal(), rb_mod_const_defined(), rb_mod_const_get(), rb_obj_methods(), and rb_obj_singleton_methods().

#define ref_hash | ( |  | k | ) | rb_hash_aref(hash, ID2SYM(rb_intern(k)))

Definition at line 115 of file date_strptime.c.

Referenced by date__strptime().

#define set_hash | ( |  | k,
|  |  | v
| ) |  | rb_hash_aset(hash, ID2SYM(rb_intern(k)), v)

Definition at line 114 of file date_strptime.c.

Referenced by date__strptime(), and date__strptime_internal().

#define sizeof_array | ( |  | o | ) | (sizeof o / sizeof o[0])

Definition at line 36 of file date_strptime.c.

Referenced by date__strptime_internal().

## Function Documentation

VALUE date__strptime | ( | const char * | str,
|  | size_t | slen,
|  | const char * | fmt,
|  | size_t | flen,
|  | VALUE | hash
| ) |  |

Definition at line 649 of file date_strptime.c.

References date__strptime_internal(), del_hash, f_add, f_mod, f_mul, fail_p, hash, INT2FIX, NIL_P(), Qnil, rb_usascii_str_new(), ref_hash, s, and set_hash.

Referenced by date_s__strptime_internal().

static size_t date__strptime_internal | ( | const char * | str,
|  | size_t | slen,
|  | const char * | fmt,
|  | size_t | flen,
|  | VALUE | hash
| ) |  |
| static

Definition at line 160 of file date_strptime.c.

References b, c, date_zone_to_diff(), day_names, extz_pats, f_end, f_expt, f_ge_p, f_match, f_negate, fail, i, int, INT2FIX, issign, m, merid_names, month_names, n, NIL_P(), NUM2LONG, NUM_PATTERN_P, ONIG_OPTION_IGNORECASE, pat, Qnil, rb_backref_get(), rb_backref_set(), rb_gc_register_mark_object(), rb_match_busy(), rb_rational_new2, rb_reg_new(), rb_reg_nth_match(), rb_usascii_str_new2, READ_DIGITS, READ_DIGITS_MAX, recur, s, set_hash, sizeof_array, strchr(), strlen(), strncasecmp, ULONG2NUM, and valid_range_p().

Referenced by date__strptime().

VALUE date_zone_to_diff | ( | VALUE |  | ) |

Definition at line 420 of file date_parse.c.

References a, ALLOCA_N, b, cstr2num, d, DST, dst, f_add, f_aref, f_expt, f_mul, f_negate, i, int, INT2FIX, issign, LONG2NUM, min(), name, NIL_P(), zone::offset, p, Qnil, RB_GC_GUARD, rb_gc_register_mark_object(), rb_hash_aset(), rb_hash_new(), rb_rational_new2, rb_str_new(), rb_str_new2, RSTRING_LEN, RSTRING_PTR, s, sizeof_array, STD, str, str2num, strchr(), strcpy(), strlen(), T_STRING, and TYPE.

static int num_pattern_p | ( | const char * | s | ) |
| static

Definition at line 59 of file date_strptime.c.

References strchr().

static long read_digits | ( | const char * | s,
|  | VALUE * | n,
|  | size_t | width
| ) |  |
| static

Definition at line 78 of file date_strptime.c.

References ALLOCA_N, CHAR_BIT, LONG2NUM, memcpy(), rb_cstr_to_inum(), s, and v.

static int valid_range_p | ( | VALUE | v,
|  | int | a,
|  | int | b
| ) |  |
| static

Definition at line 138 of file date_strptime.c.

References b, f_gt_p, f_lt_p, FIX2INT, FIXNUM_P, and INT2NUM.

Referenced by date__strptime_internal().

## Variable Documentation

const char* day_names[]
| static

Initial value:
= {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday",
"Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat"
}

Definition at line 10 of file date_strptime.c.

Referenced by date__strptime_internal().

const char* extz_pats[]
| static

Initial value:
= {
":z",
"::z",
":::z"
}

Definition at line 30 of file date_strptime.c.

Referenced by date__strptime_internal().

const char* merid_names[]
| static

Initial value:
= {
"am", "pm",
"a.m.", "p.m."
}

Definition at line 25 of file date_strptime.c.

Referenced by date__strptime_internal().

const char* month_names[]
| static

Initial value:
= {
"January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December",
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}

Definition at line 17 of file date_strptime.c.

Referenced by date__strptime_internal().