Ruby  2.1.10p492(2016-04-01revision54464)
Data Structures | Macros | Functions | Variables
date_parse.c File Reference
#include "ruby.h"
#include "ruby/encoding.h"
#include "ruby/re.h"
#include <ctype.h>

Go to the source code of this file.

Data Structures

struct  zone
 

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_to_s(x)   rb_funcall(x, rb_intern("to_s"), 0)
 
#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_aref2(o, i, j)   rb_funcall(o, rb_intern("[]"), 2, i, j)
 
#define f_begin(o, i)   rb_funcall(o, rb_intern("begin"), 1, i)
 
#define f_end(o, i)   rb_funcall(o, rb_intern("end"), 1, i)
 
#define f_aset(o, i, v)   rb_funcall(o, rb_intern("[]="), 2, i, v)
 
#define f_aset2(o, i, j, v)   rb_funcall(o, rb_intern("[]="), 3, i, j, v)
 
#define f_sub_bang(s, r, x)   rb_funcall(s, rb_intern("sub!"), 2, r, x)
 
#define f_gsub_bang(s, r, x)   rb_funcall(s, rb_intern("gsub!"), 2, r, x)
 
#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 cstr2num(s)   rb_cstr_to_inum(s, 10, 0)
 
#define str2num(s)   rb_str_to_inum(s, 10, 0)
 
#define issign(c)   ((c) == '-' || (c) == '+')
 
#define asp_string()   rb_str_new(" ", 1)
 
#define DECDIGIT   "0123456789"
 
#define DAYS   "sunday|monday|tuesday|wednesday|thursday|friday|saturday"
 
#define MONTHS   "january|february|march|april|may|june|july|august|september|october|november|december"
 
#define ABBR_DAYS   "sun|mon|tue|wed|thu|fri|sat"
 
#define ABBR_MONTHS   "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec"
 
#define REGCOMP(pat, opt)
 
#define REGCOMP_0(pat)   REGCOMP(pat, 0)
 
#define REGCOMP_I(pat)   REGCOMP(pat, ONIG_OPTION_IGNORECASE)
 
#define MATCH(s, p, c)
 
#define SUBS(s, p, c)
 
#define STD   " standard time"
 
#define DST   " daylight time"
 
#define DST   " dst"
 
#define HAVE_ALPHA   (1<<0)
 
#define HAVE_DIGIT   (1<<1)
 
#define HAVE_DASH   (1<<2)
 
#define HAVE_DOT   (1<<3)
 
#define HAVE_SLASH   (1<<4)
 
#define HAVE_ELEM_P(x)   ((check_class(str) & (x)) == (x))
 
#define SNUM   14
 
#define SNUM   17
 
#define SNUM   5
 
#define iso8601_bas_time_cb   iso8601_ext_time_cb
 
#define SNUM   8
 
#define SNUM   8
 
#define SNUM   5
 
#define SNUM   4
 
#define SNUM   8
 
#define SNUM   8
 
#define SNUM   8
 
#define SNUM   7
 
#define SNUM   9
 

Functions

static void s3e (VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
 
static VALUE regcomp (const char *source, long len, int opt)
 
static int match (VALUE str, VALUE pat, VALUE hash, int(*cb)(VALUE, VALUE))
 
static int subx (VALUE str, VALUE rep, VALUE pat, VALUE hash, int(*cb)(VALUE, VALUE))
 
VALUE date_zone_to_diff (VALUE str)
 
static int day_num (VALUE s)
 
static int mon_num (VALUE s)
 
static int parse_day_cb (VALUE m, VALUE hash)
 
static int parse_day (VALUE str, VALUE hash)
 
static int parse_time2_cb (VALUE m, VALUE hash)
 
static int parse_time_cb (VALUE m, VALUE hash)
 
static int parse_time (VALUE str, VALUE hash)
 

Variables

static const char * abbr_days []
 
static const char * abbr_months []
 
static struct zone zones_source []
 

Macro Definition Documentation

◆ ABBR_DAYS

#define ABBR_DAYS   "sun|mon|tue|wed|thu|fri|sat"

Definition at line 228 of file date_parse.c.

Referenced by parse_day().

◆ ABBR_MONTHS

#define ABBR_MONTHS   "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec"

Definition at line 229 of file date_parse.c.

◆ asp_string

#define asp_string ( )    rb_str_new(" ", 1)

Definition at line 58 of file date_parse.c.

◆ cstr2num

#define cstr2num (   s)    rb_cstr_to_inum(s, 10, 0)

Definition at line 44 of file date_parse.c.

Referenced by date_zone_to_diff(), and s3e().

◆ DAYS

#define DAYS   "sunday|monday|tuesday|wednesday|thursday|friday|saturday"

Definition at line 226 of file date_parse.c.

◆ DECDIGIT

#define DECDIGIT   "0123456789"

Definition at line 66 of file date_parse.c.

Referenced by s3e().

◆ del_hash

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

Definition at line 42 of file date_parse.c.

◆ DST [1/2]

#define DST   " daylight time"

Referenced by date_zone_to_diff().

◆ DST [2/2]

#define DST   " dst"

◆ f_add

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

Definition at line 15 of file date_parse.c.

Referenced by date_zone_to_diff().

◆ f_aref

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

Definition at line 31 of file date_parse.c.

Referenced by date_zone_to_diff().

◆ f_aref2

#define f_aref2 (   o,
  i,
 
)    rb_funcall(o, rb_intern("[]"), 2, i, j)

Definition at line 32 of file date_parse.c.

◆ f_aset

#define f_aset (   o,
  i,
 
)    rb_funcall(o, rb_intern("[]="), 2, i, v)

Definition at line 35 of file date_parse.c.

◆ f_aset2

#define f_aset2 (   o,
  i,
  j,
 
)    rb_funcall(o, rb_intern("[]="), 3, i, j, v)

Definition at line 36 of file date_parse.c.

Referenced by subx().

◆ f_begin

#define f_begin (   o,
 
)    rb_funcall(o, rb_intern("begin"), 1, i)

Definition at line 33 of file date_parse.c.

Referenced by subx().

◆ f_div

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

Definition at line 18 of file date_parse.c.

◆ f_end

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

Definition at line 34 of file date_parse.c.

Referenced by subx().

◆ f_expt

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

Definition at line 21 of file date_parse.c.

Referenced by date_zone_to_diff(), and parse_time2_cb().

◆ f_ge_p

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

Definition at line 26 of file date_parse.c.

◆ f_gsub_bang

#define f_gsub_bang (   s,
  r,
 
)    rb_funcall(s, rb_intern("gsub!"), 2, r, x)

Definition at line 38 of file date_parse.c.

◆ f_gt_p

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

Definition at line 24 of file date_parse.c.

◆ f_idiv

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

Definition at line 19 of file date_parse.c.

◆ f_le_p

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

Definition at line 25 of file date_parse.c.

◆ f_lt_p

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

Definition at line 23 of file date_parse.c.

◆ f_match

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

Definition at line 30 of file date_parse.c.

Referenced by match(), parse_time_cb(), and subx().

◆ f_mod

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

Definition at line 20 of file date_parse.c.

◆ f_mul

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

Definition at line 17 of file date_parse.c.

Referenced by date_zone_to_diff().

◆ f_negate

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

Definition at line 14 of file date_parse.c.

Referenced by date_zone_to_diff().

◆ f_sub

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

Definition at line 16 of file date_parse.c.

◆ f_sub_bang

#define f_sub_bang (   s,
  r,
 
)    rb_funcall(s, rb_intern("sub!"), 2, r, x)

Definition at line 37 of file date_parse.c.

◆ f_to_s

#define f_to_s (   x)    rb_funcall(x, rb_intern("to_s"), 0)

Definition at line 28 of file date_parse.c.

Referenced by s3e().

◆ HAVE_ALPHA

#define HAVE_ALPHA   (1<<0)

◆ HAVE_DASH

#define HAVE_DASH   (1<<2)

◆ HAVE_DIGIT

#define HAVE_DIGIT   (1<<1)

◆ HAVE_DOT

#define HAVE_DOT   (1<<3)

◆ HAVE_ELEM_P

#define HAVE_ELEM_P (   x)    ((check_class(str) & (x)) == (x))

◆ HAVE_SLASH

#define HAVE_SLASH   (1<<4)

◆ iso8601_bas_time_cb

#define iso8601_bas_time_cb   iso8601_ext_time_cb

◆ issign

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

Definition at line 57 of file date_parse.c.

Referenced by date_zone_to_diff(), and s3e().

◆ MATCH

#define MATCH (   s,
  p,
 
)
Value:
{ \
return match(s, p, hash, c); \
}
struct ComplexDateData c
Definition: date_core.c:284
static unsigned int hash(const char *str, unsigned int len)
Definition: lex.c:56
static int match(VALUE str, VALUE pat, VALUE hash, int(*cb)(VALUE, VALUE))
Definition: date_parse.c:273
struct SimpleDateData s
Definition: date_core.c:283

Definition at line 267 of file date_parse.c.

Referenced by obj_type(), and vm_init_redefined_flag().

◆ MONTHS

#define MONTHS   "january|february|march|april|may|june|july|august|september|october|november|december"

Definition at line 227 of file date_parse.c.

◆ ref_hash

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

Definition at line 41 of file date_parse.c.

◆ REGCOMP

#define REGCOMP (   pat,
  opt 
)
Value:
{ \
if (NIL_P(pat)) \
pat = regcomp(pat##_source, sizeof pat##_source - 1, opt); \
}
static VALUE regcomp(const char *source, long len, int opt)
Definition: date_parse.c:249
#define NIL_P(v)
Definition: ruby.h:438

Definition at line 258 of file date_parse.c.

◆ REGCOMP_0

#define REGCOMP_0 (   pat)    REGCOMP(pat, 0)

Definition at line 264 of file date_parse.c.

◆ REGCOMP_I

#define REGCOMP_I (   pat)    REGCOMP(pat, ONIG_OPTION_IGNORECASE)

Definition at line 265 of file date_parse.c.

Referenced by parse_day(), parse_time(), and parse_time_cb().

◆ set_hash

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

Definition at line 40 of file date_parse.c.

Referenced by parse_day_cb(), parse_time2_cb(), parse_time_cb(), and s3e().

◆ sizeof_array

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

Definition at line 12 of file date_parse.c.

Referenced by date_zone_to_diff(), day_num(), and mon_num().

◆ SNUM [1/12]

#define SNUM   14

◆ SNUM [2/12]

#define SNUM   17

◆ SNUM [3/12]

#define SNUM   5

◆ SNUM [4/12]

#define SNUM   8

◆ SNUM [5/12]

#define SNUM   8

◆ SNUM [6/12]

#define SNUM   5

◆ SNUM [7/12]

#define SNUM   4

◆ SNUM [8/12]

#define SNUM   8

◆ SNUM [9/12]

#define SNUM   8

◆ SNUM [10/12]

#define SNUM   8

◆ SNUM [11/12]

#define SNUM   7

◆ SNUM [12/12]

#define SNUM   9

◆ STD

#define STD   " standard time"

Referenced by date_zone_to_diff().

◆ str2num

#define str2num (   s)    rb_str_to_inum(s, 10, 0)

Definition at line 45 of file date_parse.c.

Referenced by date_zone_to_diff(), and parse_time2_cb().

◆ SUBS

#define SUBS (   s,
  p,
 
)
Value:
{ \
return subx(s, asp_string(), p, hash, c); \
}
struct ComplexDateData c
Definition: date_core.c:284
static int subx(VALUE str, VALUE rep, VALUE pat, VALUE hash, int(*cb)(VALUE, VALUE))
Definition: date_parse.c:288
#define asp_string()
Definition: date_parse.c:58
static unsigned int hash(const char *str, unsigned int len)
Definition: lex.c:56
struct SimpleDateData s
Definition: date_core.c:283

Definition at line 309 of file date_parse.c.

Referenced by parse_day(), and parse_time().

Function Documentation

◆ date_zone_to_diff()

VALUE date_zone_to_diff ( VALUE  str)

◆ day_num()

static int day_num ( VALUE  s)
static

Definition at line 612 of file date_parse.c.

References abbr_days, RSTRING_PTR, sizeof_array, and strncasecmp.

Referenced by parse_day_cb().

◆ match()

static int match ( VALUE  str,
VALUE  pat,
VALUE  hash,
int(*)(VALUE, VALUE cb 
)
static

◆ mon_num()

static int mon_num ( VALUE  s)
static

Definition at line 623 of file date_parse.c.

References abbr_months, RSTRING_PTR, sizeof_array, and strncasecmp.

◆ parse_day()

static int parse_day ( VALUE  str,
VALUE  hash 
)
static

Definition at line 644 of file date_parse.c.

References ABBR_DAYS, parse_day_cb(), Qnil, REGCOMP_I, and SUBS.

◆ parse_day_cb()

static int parse_day_cb ( VALUE  m,
VALUE  hash 
)
static

Definition at line 634 of file date_parse.c.

References day_num(), INT2FIX, rb_reg_nth_match(), and set_hash.

Referenced by parse_day().

◆ parse_time()

static int parse_time ( VALUE  str,
VALUE  hash 
)
static

Definition at line 740 of file date_parse.c.

References parse_time_cb(), Qnil, REGCOMP_I, and SUBS.

◆ parse_time2_cb()

static int parse_time2_cb ( VALUE  m,
VALUE  hash 
)
static

◆ parse_time_cb()

static int parse_time_cb ( VALUE  m,
VALUE  hash 
)
static

Definition at line 707 of file date_parse.c.

References f_match, hash(), NIL_P, parse_time2_cb(), Qnil, rb_reg_nth_match(), REGCOMP_I, and set_hash.

Referenced by parse_time().

◆ regcomp()

static VALUE regcomp ( const char *  source,
long  len,
int  opt 
)
static

Definition at line 249 of file date_parse.c.

References rb_gc_register_mark_object(), and rb_reg_new().

◆ s3e()

static void s3e ( VALUE  hash,
VALUE  y,
VALUE  m,
VALUE  d,
int  bc 
)
static

◆ subx()

static int subx ( VALUE  str,
VALUE  rep,
VALUE  pat,
VALUE  hash,
int(*)(VALUE, VALUE cb 
)
static

Definition at line 288 of file date_parse.c.

References f_aset2, f_begin, f_end, f_match, hash(), INT2FIX, LONG2NUM, NIL_P, and NUM2LONG.

Variable Documentation

◆ abbr_days

const char* abbr_days[]
static
Initial value:
= {
"sun", "mon", "tue", "wed",
"thu", "fri", "sat"
}

Definition at line 47 of file date_parse.c.

Referenced by day_num().

◆ abbr_months

const char* abbr_months[]
static
Initial value:
= {
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec"
}

Definition at line 52 of file date_parse.c.

Referenced by mon_num().

◆ zones_source

struct zone zones_source[]
static

Definition at line 341 of file date_parse.c.

Referenced by date_zone_to_diff().