Ruby: ext/date/date_parse.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Functions
date_parse.c File Reference
`#include "ruby.h"`
`#include "ruby/encoding.h"`
`#include "ruby/re.h"`
`#include <ctype.h>`
`#include "zonetab.h"`

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_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 | 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 | JISX0301_ERA_INITIALS "mtshr"
#define | JISX0301_DEFAULT_ERA 'H' /* obsolete */
#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 5
#define | SNUM 4
#define | SNUM 8
#define | SNUM 7
#define | SNUM 9

## Functions
VALUE | rb_int_positive_pow (long x, unsigned long y)
unsigned long | ruby_scan_digits (const char *str, ssize_t len, int base, size_t *retlen, int *overflow)
VALUE | date_zone_to_diff (VALUE str)
VALUE | date__parse (VALUE str, VALUE comp)
VALUE | date__iso8601 (VALUE str)
VALUE | date__rfc3339 (VALUE str)
VALUE | date__xmlschema (VALUE str)
VALUE | date__rfc2822 (VALUE str)
VALUE | date__httpdate (VALUE str)
VALUE | date__jisx0301 (VALUE str)

## Macro Definition Documentation

## ◆ ABBR_DAYS

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

Definition at line 253 of file date_parse.c.

## ◆ ABBR_MONTHS

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

Definition at line 254 of file date_parse.c.

## ◆ asp_string

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

Definition at line 61 of file date_parse.c.

## ◆ cstr2num

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

Definition at line 47 of file date_parse.c.

## ◆ DAYS

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

Definition at line 251 of file date_parse.c.

## ◆ del_hash

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

Definition at line 45 of file date_parse.c.

## ◆ f_add

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

Definition at line 18 of file date_parse.c.

## ◆ f_aref

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

Definition at line 34 of file date_parse.c.

## ◆ f_aref2

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

Definition at line 35 of file date_parse.c.

## ◆ f_aset

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

Definition at line 38 of file date_parse.c.

## ◆ f_aset2

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

Definition at line 39 of file date_parse.c.

## ◆ f_begin

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

Definition at line 36 of file date_parse.c.

## ◆ f_div

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

Definition at line 21 of file date_parse.c.

## ◆ f_end

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

Definition at line 37 of file date_parse.c.

## ◆ f_expt

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

Definition at line 24 of file date_parse.c.

## ◆ f_ge_p

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

Definition at line 29 of file date_parse.c.

## ◆ f_gsub_bang

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

Definition at line 41 of file date_parse.c.

## ◆ f_gt_p

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

Definition at line 27 of file date_parse.c.

## ◆ f_idiv

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

Definition at line 22 of file date_parse.c.

## ◆ f_le_p

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

Definition at line 28 of file date_parse.c.

## ◆ f_lt_p

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

Definition at line 26 of file date_parse.c.

## ◆ f_match

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

Definition at line 33 of file date_parse.c.

## ◆ f_mod

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

Definition at line 23 of file date_parse.c.

## ◆ f_mul

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

Definition at line 20 of file date_parse.c.

## ◆ f_negate

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

Definition at line 17 of file date_parse.c.

## ◆ f_sub

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

Definition at line 19 of file date_parse.c.

## ◆ f_sub_bang

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

Definition at line 40 of file date_parse.c.

## ◆ f_to_s

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

Definition at line 31 of file date_parse.c.

## ◆ HAVE_ALPHA

#define HAVE_ALPHA (1<<0)

Definition at line 2055 of file date_parse.c.

## ◆ HAVE_DASH

#define HAVE_DASH (1<<2)

Definition at line 2057 of file date_parse.c.

## ◆ HAVE_DIGIT

#define HAVE_DIGIT (1<<1)

Definition at line 2056 of file date_parse.c.

## ◆ HAVE_DOT

#define HAVE_DOT (1<<3)

Definition at line 2058 of file date_parse.c.

## ◆ HAVE_ELEM_P

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

Definition at line 2083 of file date_parse.c.

## ◆ HAVE_SLASH

#define HAVE_SLASH (1<<4)

Definition at line 2059 of file date_parse.c.

## ◆ iso8601_bas_time_cb

#define iso8601_bas_time_cb iso8601_ext_time_cb

Definition at line 2481 of file date_parse.c.

## ◆ issign

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

Definition at line 60 of file date_parse.c.

## ◆ JISX0301_DEFAULT_ERA

#define JISX0301_DEFAULT_ERA 'H' /* obsolete */

Definition at line 1241 of file date_parse.c.

## ◆ JISX0301_ERA_INITIALS

#define JISX0301_ERA_INITIALS "mtshr"

Definition at line 1240 of file date_parse.c.

## ◆ MATCH

#define MATCH | ( |  | s,
|  |  | p,
|  |  | c
| ) |  |

Value:
do { \
return match(s, p, hash, c); \
} while (0)
match
unsigned char match[65280+2]
Definition: gun.c:165

Definition at line 293 of file date_parse.c.

## ◆ MONTHS

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

Definition at line 252 of file date_parse.c.

## ◆ ref_hash

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

Definition at line 44 of file date_parse.c.

## ◆ REGCOMP

#define REGCOMP | ( |  | pat,
|  |  | opt
| ) |  |

Value:
do { \
if (NIL_P(pat)) \
pat = regcomp(pat##_source, sizeof pat##_source - 1, opt); \
} while (0)
NIL_P
#define NIL_P
Definition: special_consts.h:46

Definition at line 284 of file date_parse.c.

## ◆ REGCOMP_0

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

Definition at line 290 of file date_parse.c.

## ◆ REGCOMP_I

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

Definition at line 291 of file date_parse.c.

## ◆ set_hash

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

Definition at line 43 of file date_parse.c.

## ◆ sizeof_array

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

Definition at line 15 of file date_parse.c.

## ◆ SNUM [1/12]

#define SNUM 14

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [2/12]

#define SNUM 17

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [3/12]

#define SNUM 5

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [4/12]

#define SNUM 8

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [5/12]

#define SNUM 8

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [6/12]

#define SNUM 5

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [7/12]

#define SNUM 4

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [8/12]

#define SNUM 8

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [9/12]

#define SNUM 8

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [10/12]

#define SNUM 8

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [11/12]

#define SNUM 7

Definition at line 2964 of file date_parse.c.

## ◆ SNUM [12/12]

#define SNUM 9

Definition at line 2964 of file date_parse.c.

## ◆ str2num

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

Definition at line 48 of file date_parse.c.

## ◆ SUBS

#define SUBS | ( |  | s,
|  |  | p,
|  |  | c
| ) |  |

Value:
do { \
return subx(s, asp_string(), p, hash, c); \
} while (0)
asp_string
#define asp_string()
Definition: date_parse.c:61

Definition at line 335 of file date_parse.c.

## Function Documentation

## ◆ date__httpdate()

VALUE date__httpdate | ( | VALUE | str | ) |

Definition at line 2941 of file date_parse.c.

References rb_backref_get(), rb_backref_set(), rb_hash_new(), rb_match_busy(), and str.

## ◆ date__iso8601()

VALUE date__iso8601 | ( | VALUE | str | ) |

Definition at line 2508 of file date_parse.c.

References rb_backref_get(), rb_backref_set(), rb_hash_new(), rb_match_busy(), and str.

Referenced by date__jisx0301().

## ◆ date__jisx0301()

VALUE date__jisx0301 | ( | VALUE | str | ) |

Definition at line 3015 of file date_parse.c.

References date__iso8601(), rb_backref_get(), rb_backref_set(), rb_hash_new(), rb_match_busy(), and str.

## ◆ date__parse()

VALUE date__parse | ( | VALUE | str,
|  | VALUE | comp
| ) |  |

Definition at line 2090 of file date_parse.c.

References asp_string, date_zone_to_diff(), del_hash, f_add, f_ge_p, f_gsub_bang, f_le_p, f_negate, HAVE_ALPHA, HAVE_DASH, HAVE_DIGIT, HAVE_DOT, HAVE_ELEM_P, HAVE_SLASH, INT2FIX, NIL_P, Qnil, rb_backref_get(), rb_backref_set(), rb_hash_new(), rb_match_busy(), rb_str_dup(), ref_hash, REGCOMP_0, RTEST, set_hash, and str.

## ◆ date__rfc2822()

VALUE date__rfc2822 | ( | VALUE | str | ) |

Definition at line 2795 of file date_parse.c.

References rb_backref_get(), rb_backref_set(), rb_hash_new(), rb_match_busy(), and str.

## ◆ date__rfc3339()

VALUE date__rfc3339 | ( | VALUE | str | ) |

Definition at line 2576 of file date_parse.c.

References rb_backref_get(), rb_backref_set(), rb_hash_new(), rb_match_busy(), and str.

## ◆ date__xmlschema()

VALUE date__xmlschema | ( | VALUE | str | ) |

Definition at line 2722 of file date_parse.c.

References rb_backref_get(), rb_backref_set(), rb_hash_new(), rb_match_busy(), and str.

## ◆ date_zone_to_diff()

VALUE date_zone_to_diff | ( | VALUE | str | ) |

Definition at line 411 of file date_parse.c.

References ALLOCV_END, ALLOCV_N, f_add, INT2FIX, issign, MAX_WORD_LENGTH, num, zone::offset, Qnil, RB_GC_GUARD, rb_int_positive_pow(), rb_rational_new(), RSTRING_LEN, RSTRING_PTR, ruby_scan_digits(), str, strncasecmp, STRTOUL, and zonetab().

Referenced by date__parse().

## ◆ rb_int_positive_pow()

VALUE rb_int_positive_pow | ( | long | x,
|  | unsigned long | y
| ) |  |

Definition at line 4022 of file numeric.c.

Referenced by date_zone_to_diff(), rb_flt_rationalize(), and rb_str_format().

## ◆ ruby_scan_digits()

unsigned long ruby_scan_digits | ( | const char * | str,
|  | ssize_t | len,
|  | int | base,
|  | size_t * | retlen,
|  | int * | overflow
| ) |  |

Definition at line 101 of file util.c.

Referenced by date_zone_to_diff().