home_run 0.9.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/LICENSE +19 -0
- data/README.rdoc +314 -0
- data/Rakefile +136 -0
- data/bench/cpu_bench.rb +279 -0
- data/bench/dt_garbage_bench.rb +11 -0
- data/bench/dt_mem_bench.rb +14 -0
- data/bench/garbage_bench.rb +11 -0
- data/bench/mem_bench.rb +14 -0
- data/bin/home_run +91 -0
- data/default.mspec +12 -0
- data/ext/1.8/date_ext.so +0 -0
- data/ext/1.9/date_ext.so +0 -0
- data/ext/date.rb +7 -0
- data/ext/date/format.rb +842 -0
- data/ext/date_ext.c +4548 -0
- data/ext/date_parser.c +367 -0
- data/ext/date_parser.rl +134 -0
- data/ext/datetime.c +2804 -0
- data/ext/extconf.rb +6 -0
- data/spec/date/accessor_spec.rb +176 -0
- data/spec/date/add_month_spec.rb +26 -0
- data/spec/date/add_spec.rb +23 -0
- data/spec/date/boat_spec.rb +38 -0
- data/spec/date/civil_spec.rb +147 -0
- data/spec/date/commercial_spec.rb +153 -0
- data/spec/date/constants_spec.rb +44 -0
- data/spec/date/conversions_spec.rb +246 -0
- data/spec/date/day_spec.rb +73 -0
- data/spec/date/downto_spec.rb +17 -0
- data/spec/date/eql_spec.rb +16 -0
- data/spec/date/format_spec.rb +52 -0
- data/spec/date/gregorian_spec.rb +52 -0
- data/spec/date/hash_spec.rb +11 -0
- data/spec/date/julian_spec.rb +129 -0
- data/spec/date/leap_spec.rb +19 -0
- data/spec/date/minus_month_spec.rb +25 -0
- data/spec/date/minus_spec.rb +51 -0
- data/spec/date/next_prev_spec.rb +108 -0
- data/spec/date/ordinal_spec.rb +83 -0
- data/spec/date/parse_spec.rb +442 -0
- data/spec/date/parsing_spec.rb +77 -0
- data/spec/date/relationship_spec.rb +28 -0
- data/spec/date/step_spec.rb +109 -0
- data/spec/date/strftime_spec.rb +223 -0
- data/spec/date/strptime_spec.rb +201 -0
- data/spec/date/succ_spec.rb +20 -0
- data/spec/date/today_spec.rb +15 -0
- data/spec/date/upto_spec.rb +17 -0
- data/spec/datetime/accessor_spec.rb +218 -0
- data/spec/datetime/add_month_spec.rb +26 -0
- data/spec/datetime/add_spec.rb +36 -0
- data/spec/datetime/boat_spec.rb +43 -0
- data/spec/datetime/constructor_spec.rb +142 -0
- data/spec/datetime/conversions_spec.rb +54 -0
- data/spec/datetime/day_spec.rb +73 -0
- data/spec/datetime/downto_spec.rb +39 -0
- data/spec/datetime/eql_spec.rb +17 -0
- data/spec/datetime/format_spec.rb +59 -0
- data/spec/datetime/hash_spec.rb +11 -0
- data/spec/datetime/leap_spec.rb +19 -0
- data/spec/datetime/minus_month_spec.rb +25 -0
- data/spec/datetime/minus_spec.rb +77 -0
- data/spec/datetime/next_prev_spec.rb +138 -0
- data/spec/datetime/now_spec.rb +18 -0
- data/spec/datetime/parse_spec.rb +390 -0
- data/spec/datetime/parsing_spec.rb +77 -0
- data/spec/datetime/relationship_spec.rb +28 -0
- data/spec/datetime/step_spec.rb +155 -0
- data/spec/datetime/strftime_spec.rb +118 -0
- data/spec/datetime/strptime_spec.rb +117 -0
- data/spec/datetime/succ_spec.rb +24 -0
- data/spec/datetime/upto_spec.rb +39 -0
- data/spec/spec_helper.rb +59 -0
- metadata +154 -0
data/ext/date_parser.c
ADDED
@@ -0,0 +1,367 @@
|
|
1
|
+
|
2
|
+
#line 1 "date_parser.rl"
|
3
|
+
|
4
|
+
#define RHRR_ISO_PARSER 0x1
|
5
|
+
|
6
|
+
#define RHRR_ISO_TIME_SET 0x1
|
7
|
+
#define RHRR_ISO_ZONE_SET 0x2
|
8
|
+
|
9
|
+
|
10
|
+
#line 11 "date_parser.c"
|
11
|
+
static const char _date_parser_actions[] = {
|
12
|
+
0, 1, 0, 1, 1, 1, 2, 1,
|
13
|
+
3, 1, 4, 1, 5, 1, 6, 1,
|
14
|
+
9, 1, 10, 2, 7, 9, 2, 9,
|
15
|
+
10, 3, 7, 9, 10, 3, 8, 7,
|
16
|
+
9, 4, 8, 7, 9, 10
|
17
|
+
};
|
18
|
+
|
19
|
+
static const char _date_parser_key_offsets[] = {
|
20
|
+
0, 0, 6, 8, 10, 12, 14, 15,
|
21
|
+
17, 19, 20, 24, 26, 28, 29, 31,
|
22
|
+
33, 34, 36, 38, 40, 42, 43, 45,
|
23
|
+
47, 49, 52, 54, 56, 58, 62, 65,
|
24
|
+
71, 76
|
25
|
+
};
|
26
|
+
|
27
|
+
static const char _date_parser_trans_keys[] = {
|
28
|
+
32, 45, 9, 13, 48, 57, 48, 57,
|
29
|
+
48, 57, 48, 57, 48, 57, 45, 48,
|
30
|
+
49, 49, 57, 45, 48, 51, 49, 50,
|
31
|
+
49, 57, 48, 57, 58, 48, 53, 48,
|
32
|
+
57, 58, 48, 53, 48, 57, 48, 57,
|
33
|
+
48, 57, 58, 48, 57, 48, 57, 48,
|
34
|
+
52, 50, 48, 49, 48, 57, 48, 49,
|
35
|
+
48, 50, 32, 84, 9, 13, 32, 9,
|
36
|
+
13, 32, 50, 9, 13, 48, 49, 32,
|
37
|
+
43, 45, 9, 13, 32, 9, 13, 0
|
38
|
+
};
|
39
|
+
|
40
|
+
static const char _date_parser_single_lengths[] = {
|
41
|
+
0, 2, 0, 0, 0, 0, 1, 2,
|
42
|
+
0, 1, 2, 0, 0, 1, 0, 0,
|
43
|
+
1, 0, 0, 0, 0, 1, 0, 0,
|
44
|
+
0, 1, 0, 0, 0, 2, 1, 2,
|
45
|
+
3, 1
|
46
|
+
};
|
47
|
+
|
48
|
+
static const char _date_parser_range_lengths[] = {
|
49
|
+
0, 2, 1, 1, 1, 1, 0, 0,
|
50
|
+
1, 0, 1, 1, 1, 0, 1, 1,
|
51
|
+
0, 1, 1, 1, 1, 0, 1, 1,
|
52
|
+
1, 1, 1, 1, 1, 1, 1, 2,
|
53
|
+
1, 1
|
54
|
+
};
|
55
|
+
|
56
|
+
static const char _date_parser_index_offsets[] = {
|
57
|
+
0, 0, 5, 7, 9, 11, 13, 15,
|
58
|
+
18, 20, 22, 26, 28, 30, 32, 34,
|
59
|
+
36, 38, 40, 42, 44, 46, 48, 50,
|
60
|
+
52, 54, 57, 59, 61, 63, 67, 70,
|
61
|
+
75, 80
|
62
|
+
};
|
63
|
+
|
64
|
+
static const char _date_parser_indicies[] = {
|
65
|
+
0, 2, 0, 3, 1, 4, 1, 5,
|
66
|
+
1, 6, 1, 7, 1, 8, 1, 9,
|
67
|
+
10, 1, 11, 1, 12, 1, 13, 15,
|
68
|
+
14, 1, 16, 1, 17, 1, 18, 1,
|
69
|
+
19, 1, 20, 1, 21, 1, 22, 1,
|
70
|
+
23, 1, 24, 1, 25, 1, 26, 1,
|
71
|
+
27, 1, 28, 1, 17, 1, 30, 29,
|
72
|
+
1, 16, 1, 16, 1, 11, 1, 32,
|
73
|
+
33, 31, 1, 34, 34, 1, 34, 30,
|
74
|
+
34, 29, 1, 35, 36, 36, 35, 1,
|
75
|
+
37, 37, 1, 0
|
76
|
+
};
|
77
|
+
|
78
|
+
static const char _date_parser_trans_targs[] = {
|
79
|
+
1, 0, 2, 3, 3, 4, 5, 6,
|
80
|
+
7, 8, 28, 9, 10, 11, 26, 27,
|
81
|
+
29, 13, 14, 15, 16, 17, 18, 32,
|
82
|
+
20, 21, 22, 23, 33, 12, 24, 30,
|
83
|
+
31, 25, 30, 30, 19, 30
|
84
|
+
};
|
85
|
+
|
86
|
+
static const char _date_parser_trans_actions[] = {
|
87
|
+
0, 0, 1, 1, 0, 0, 0, 0,
|
88
|
+
0, 3, 3, 0, 0, 5, 5, 5,
|
89
|
+
0, 0, 0, 9, 0, 0, 11, 0,
|
90
|
+
0, 0, 0, 0, 0, 7, 7, 15,
|
91
|
+
15, 0, 0, 19, 13, 29
|
92
|
+
};
|
93
|
+
|
94
|
+
static const char _date_parser_eof_actions[] = {
|
95
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
96
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
97
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
98
|
+
0, 0, 0, 0, 0, 22, 17, 17,
|
99
|
+
25, 33
|
100
|
+
};
|
101
|
+
|
102
|
+
static const int date_parser_start = 1;
|
103
|
+
static const int date_parser_first_final = 29;
|
104
|
+
static const int date_parser_error = 0;
|
105
|
+
|
106
|
+
static const int date_parser_en_main = 1;
|
107
|
+
|
108
|
+
|
109
|
+
#line 59 "date_parser.rl"
|
110
|
+
|
111
|
+
|
112
|
+
VALUE rhrd__ragel_parse(char * p, long len) {
|
113
|
+
VALUE hash;
|
114
|
+
long state = 0;
|
115
|
+
long parsers = 0;
|
116
|
+
|
117
|
+
long year = 0;
|
118
|
+
long month = 0;
|
119
|
+
long day = 0;
|
120
|
+
|
121
|
+
long hour = 0;
|
122
|
+
long minute = 0;
|
123
|
+
long second = 0;
|
124
|
+
|
125
|
+
VALUE rzone;
|
126
|
+
char * zone = NULL;
|
127
|
+
long zone_len = 0;
|
128
|
+
long offset = 0;
|
129
|
+
|
130
|
+
long iso_state = 0;
|
131
|
+
char * t_iso_year = NULL;
|
132
|
+
char * t_iso_month = NULL;
|
133
|
+
char * t_iso_day = NULL;
|
134
|
+
char * t_iso_hour= NULL;
|
135
|
+
char * t_iso_minute = NULL;
|
136
|
+
char * t_iso_second = NULL;
|
137
|
+
char * t_iso_zone = NULL;
|
138
|
+
|
139
|
+
int cs = 0;
|
140
|
+
char * eof;
|
141
|
+
char * pe;
|
142
|
+
pe = p + len;
|
143
|
+
eof = pe;
|
144
|
+
|
145
|
+
|
146
|
+
#line 147 "date_parser.c"
|
147
|
+
{
|
148
|
+
cs = date_parser_start;
|
149
|
+
}
|
150
|
+
|
151
|
+
#line 95 "date_parser.rl"
|
152
|
+
|
153
|
+
#line 154 "date_parser.c"
|
154
|
+
{
|
155
|
+
int _klen;
|
156
|
+
unsigned int _trans;
|
157
|
+
const char *_acts;
|
158
|
+
unsigned int _nacts;
|
159
|
+
const char *_keys;
|
160
|
+
|
161
|
+
if ( p == pe )
|
162
|
+
goto _test_eof;
|
163
|
+
if ( cs == 0 )
|
164
|
+
goto _out;
|
165
|
+
_resume:
|
166
|
+
_keys = _date_parser_trans_keys + _date_parser_key_offsets[cs];
|
167
|
+
_trans = _date_parser_index_offsets[cs];
|
168
|
+
|
169
|
+
_klen = _date_parser_single_lengths[cs];
|
170
|
+
if ( _klen > 0 ) {
|
171
|
+
const char *_lower = _keys;
|
172
|
+
const char *_mid;
|
173
|
+
const char *_upper = _keys + _klen - 1;
|
174
|
+
while (1) {
|
175
|
+
if ( _upper < _lower )
|
176
|
+
break;
|
177
|
+
|
178
|
+
_mid = _lower + ((_upper-_lower) >> 1);
|
179
|
+
if ( (*p) < *_mid )
|
180
|
+
_upper = _mid - 1;
|
181
|
+
else if ( (*p) > *_mid )
|
182
|
+
_lower = _mid + 1;
|
183
|
+
else {
|
184
|
+
_trans += (_mid - _keys);
|
185
|
+
goto _match;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
_keys += _klen;
|
189
|
+
_trans += _klen;
|
190
|
+
}
|
191
|
+
|
192
|
+
_klen = _date_parser_range_lengths[cs];
|
193
|
+
if ( _klen > 0 ) {
|
194
|
+
const char *_lower = _keys;
|
195
|
+
const char *_mid;
|
196
|
+
const char *_upper = _keys + (_klen<<1) - 2;
|
197
|
+
while (1) {
|
198
|
+
if ( _upper < _lower )
|
199
|
+
break;
|
200
|
+
|
201
|
+
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
|
202
|
+
if ( (*p) < _mid[0] )
|
203
|
+
_upper = _mid - 2;
|
204
|
+
else if ( (*p) > _mid[1] )
|
205
|
+
_lower = _mid + 2;
|
206
|
+
else {
|
207
|
+
_trans += ((_mid - _keys)>>1);
|
208
|
+
goto _match;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
_trans += _klen;
|
212
|
+
}
|
213
|
+
|
214
|
+
_match:
|
215
|
+
_trans = _date_parser_indicies[_trans];
|
216
|
+
cs = _date_parser_trans_targs[_trans];
|
217
|
+
|
218
|
+
if ( _date_parser_trans_actions[_trans] == 0 )
|
219
|
+
goto _again;
|
220
|
+
|
221
|
+
_acts = _date_parser_actions + _date_parser_trans_actions[_trans];
|
222
|
+
_nacts = (unsigned int) *_acts++;
|
223
|
+
while ( _nacts-- > 0 )
|
224
|
+
{
|
225
|
+
switch ( *_acts++ )
|
226
|
+
{
|
227
|
+
case 0:
|
228
|
+
#line 10 "date_parser.rl"
|
229
|
+
{ t_iso_year = p; }
|
230
|
+
break;
|
231
|
+
case 1:
|
232
|
+
#line 11 "date_parser.rl"
|
233
|
+
{ t_iso_month = p; }
|
234
|
+
break;
|
235
|
+
case 2:
|
236
|
+
#line 12 "date_parser.rl"
|
237
|
+
{ t_iso_day = p; }
|
238
|
+
break;
|
239
|
+
case 3:
|
240
|
+
#line 13 "date_parser.rl"
|
241
|
+
{ t_iso_hour = p; }
|
242
|
+
break;
|
243
|
+
case 4:
|
244
|
+
#line 14 "date_parser.rl"
|
245
|
+
{ t_iso_minute = p; }
|
246
|
+
break;
|
247
|
+
case 5:
|
248
|
+
#line 15 "date_parser.rl"
|
249
|
+
{ t_iso_second = p; }
|
250
|
+
break;
|
251
|
+
case 6:
|
252
|
+
#line 16 "date_parser.rl"
|
253
|
+
{ t_iso_zone = p; }
|
254
|
+
break;
|
255
|
+
case 7:
|
256
|
+
#line 18 "date_parser.rl"
|
257
|
+
{ iso_state |= RHRR_ISO_TIME_SET; }
|
258
|
+
break;
|
259
|
+
case 8:
|
260
|
+
#line 19 "date_parser.rl"
|
261
|
+
{ iso_state |= RHRR_ISO_ZONE_SET; }
|
262
|
+
break;
|
263
|
+
case 9:
|
264
|
+
#line 20 "date_parser.rl"
|
265
|
+
{ parsers |= RHRR_ISO_PARSER; }
|
266
|
+
break;
|
267
|
+
#line 268 "date_parser.c"
|
268
|
+
}
|
269
|
+
}
|
270
|
+
|
271
|
+
_again:
|
272
|
+
if ( cs == 0 )
|
273
|
+
goto _out;
|
274
|
+
if ( ++p != pe )
|
275
|
+
goto _resume;
|
276
|
+
_test_eof: {}
|
277
|
+
if ( p == eof )
|
278
|
+
{
|
279
|
+
const char *__acts = _date_parser_actions + _date_parser_eof_actions[cs];
|
280
|
+
unsigned int __nacts = (unsigned int) *__acts++;
|
281
|
+
while ( __nacts-- > 0 ) {
|
282
|
+
switch ( *__acts++ ) {
|
283
|
+
case 7:
|
284
|
+
#line 18 "date_parser.rl"
|
285
|
+
{ iso_state |= RHRR_ISO_TIME_SET; }
|
286
|
+
break;
|
287
|
+
case 8:
|
288
|
+
#line 19 "date_parser.rl"
|
289
|
+
{ iso_state |= RHRR_ISO_ZONE_SET; }
|
290
|
+
break;
|
291
|
+
case 9:
|
292
|
+
#line 20 "date_parser.rl"
|
293
|
+
{ parsers |= RHRR_ISO_PARSER; }
|
294
|
+
break;
|
295
|
+
case 10:
|
296
|
+
#line 22 "date_parser.rl"
|
297
|
+
{
|
298
|
+
switch(parsers) {
|
299
|
+
case RHRR_ISO_PARSER:
|
300
|
+
year = atol(t_iso_year);
|
301
|
+
month = atol(t_iso_month);
|
302
|
+
day = atol(t_iso_day);
|
303
|
+
state |= RHRR_YEAR_SET | RHRR_MONTH_SET | RHRR_DAY_SET;
|
304
|
+
if (iso_state & RHRR_ISO_TIME_SET) {
|
305
|
+
hour = atol(t_iso_hour);
|
306
|
+
minute = atol(t_iso_minute);
|
307
|
+
second = atol(t_iso_second);
|
308
|
+
state |= RHRR_HOUR_SET | RHRR_MINUTE_SET | RHRR_SECOND_SET;
|
309
|
+
}
|
310
|
+
if (iso_state & RHRR_ISO_ZONE_SET) {
|
311
|
+
zone = t_iso_zone;
|
312
|
+
zone_len = p - zone;
|
313
|
+
offset = atol(zone) * 3600 + atol(zone + 4) * 60;
|
314
|
+
state |= RHRR_ZONE_SET | RHRR_OFFSET_SET;
|
315
|
+
}
|
316
|
+
break;
|
317
|
+
}
|
318
|
+
}
|
319
|
+
break;
|
320
|
+
#line 321 "date_parser.c"
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
_out: {}
|
326
|
+
}
|
327
|
+
|
328
|
+
#line 96 "date_parser.rl"
|
329
|
+
|
330
|
+
if (!state) {
|
331
|
+
return Qnil;
|
332
|
+
}
|
333
|
+
|
334
|
+
hash = rb_hash_new();
|
335
|
+
if(state & RHRR_YEAR_SET) {
|
336
|
+
rb_hash_aset(hash, rhrd_sym_year, INT2NUM(year));
|
337
|
+
}
|
338
|
+
if(state & RHRR_MONTH_SET) {
|
339
|
+
rb_hash_aset(hash, rhrd_sym_mon, INT2NUM(month));
|
340
|
+
}
|
341
|
+
if(state & RHRR_DAY_SET) {
|
342
|
+
rb_hash_aset(hash, rhrd_sym_mday, INT2NUM(day));
|
343
|
+
}
|
344
|
+
if(state & RHRR_HOUR_SET) {
|
345
|
+
rb_hash_aset(hash, rhrd_sym_hour, INT2NUM(hour));
|
346
|
+
}
|
347
|
+
if(state & RHRR_MINUTE_SET) {
|
348
|
+
rb_hash_aset(hash, rhrd_sym_min, INT2NUM(minute));
|
349
|
+
}
|
350
|
+
if(state & RHRR_SECOND_SET) {
|
351
|
+
rb_hash_aset(hash, rhrd_sym_sec, INT2NUM(second));
|
352
|
+
}
|
353
|
+
if(state & RHRR_ZONE_SET) {
|
354
|
+
rzone = rb_str_new(zone, zone_len);
|
355
|
+
rb_hash_aset(hash, rhrd_sym_zone, rzone);
|
356
|
+
if (state & RHRR_OFFSET_SET) {
|
357
|
+
rb_hash_aset(hash, rhrd_sym_offset, INT2NUM(offset));
|
358
|
+
} else {
|
359
|
+
rzone = rhrd_s_zone_to_diff(rzone, rzone);
|
360
|
+
if(RTEST(rzone)) {
|
361
|
+
rb_hash_aset(hash, rhrd_sym_offset, rzone);
|
362
|
+
}
|
363
|
+
}
|
364
|
+
}
|
365
|
+
|
366
|
+
return hash;
|
367
|
+
}
|
data/ext/date_parser.rl
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
|
2
|
+
#define RHRR_ISO_PARSER 0x1
|
3
|
+
|
4
|
+
#define RHRR_ISO_TIME_SET 0x1
|
5
|
+
#define RHRR_ISO_ZONE_SET 0x2
|
6
|
+
|
7
|
+
%%{
|
8
|
+
machine date_parser;
|
9
|
+
|
10
|
+
action tag_iso_year { t_iso_year = p; }
|
11
|
+
action tag_iso_month { t_iso_month = p; }
|
12
|
+
action tag_iso_day { t_iso_day = p; }
|
13
|
+
action tag_iso_hour { t_iso_hour = p; }
|
14
|
+
action tag_iso_minute { t_iso_minute = p; }
|
15
|
+
action tag_iso_second { t_iso_second = p; }
|
16
|
+
action tag_iso_zone { t_iso_zone = p; }
|
17
|
+
|
18
|
+
action set_iso_time { iso_state |= RHRR_ISO_TIME_SET; }
|
19
|
+
action set_iso_zone { iso_state |= RHRR_ISO_ZONE_SET; }
|
20
|
+
action set_parser_iso { parsers |= RHRR_ISO_PARSER; }
|
21
|
+
|
22
|
+
action set_values {
|
23
|
+
switch(parsers) {
|
24
|
+
case RHRR_ISO_PARSER:
|
25
|
+
year = atol(t_iso_year);
|
26
|
+
month = atol(t_iso_month);
|
27
|
+
day = atol(t_iso_day);
|
28
|
+
state |= RHRR_YEAR_SET | RHRR_MONTH_SET | RHRR_DAY_SET;
|
29
|
+
if (iso_state & RHRR_ISO_TIME_SET) {
|
30
|
+
hour = atol(t_iso_hour);
|
31
|
+
minute = atol(t_iso_minute);
|
32
|
+
second = atol(t_iso_second);
|
33
|
+
state |= RHRR_HOUR_SET | RHRR_MINUTE_SET | RHRR_SECOND_SET;
|
34
|
+
}
|
35
|
+
if (iso_state & RHRR_ISO_ZONE_SET) {
|
36
|
+
zone = t_iso_zone;
|
37
|
+
zone_len = p - zone;
|
38
|
+
offset = atol(zone) * 3600 + atol(zone + 4) * 60;
|
39
|
+
state |= RHRR_ZONE_SET | RHRR_OFFSET_SET;
|
40
|
+
}
|
41
|
+
break;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
iso_year = ('-'? . digit{4}) >tag_iso_year;
|
46
|
+
iso_month = ('0' . [1-9] | '1' . [0-2]) >tag_iso_month;
|
47
|
+
iso_day = ('0' . [1-9] | [12] . [0-9] | '3' . [01]) >tag_iso_day;
|
48
|
+
iso_hour = ([0-1] . [0-9] | '2' . [0-4]) >tag_iso_hour;
|
49
|
+
iso_minute = ([0-5] . [0-9]) >tag_iso_minute;
|
50
|
+
iso_second = ([0-5] . [0-9]) >tag_iso_second;
|
51
|
+
iso_zone = ([+\-] . digit{2} . ':' . digit{2}) > tag_iso_zone;
|
52
|
+
iso_date = (iso_year . '-' . iso_month . '-' . iso_day);
|
53
|
+
iso_time = (iso_hour . ':' . iso_minute . ':' . iso_second . (iso_zone %set_iso_zone)?) %set_iso_time;
|
54
|
+
iso_date_time = (iso_date . ([T ] . iso_time)?) %set_parser_iso;
|
55
|
+
date_time = (iso_date_time);
|
56
|
+
|
57
|
+
main := (space* . date_time . space*) %/set_values;
|
58
|
+
write data;
|
59
|
+
}%%
|
60
|
+
|
61
|
+
VALUE rhrd__ragel_parse(char * p, long len) {
|
62
|
+
VALUE hash;
|
63
|
+
long state = 0;
|
64
|
+
long parsers = 0;
|
65
|
+
|
66
|
+
long year = 0;
|
67
|
+
long month = 0;
|
68
|
+
long day = 0;
|
69
|
+
|
70
|
+
long hour = 0;
|
71
|
+
long minute = 0;
|
72
|
+
long second = 0;
|
73
|
+
|
74
|
+
VALUE rzone;
|
75
|
+
char * zone = NULL;
|
76
|
+
long zone_len = 0;
|
77
|
+
long offset = 0;
|
78
|
+
|
79
|
+
long iso_state = 0;
|
80
|
+
char * t_iso_year = NULL;
|
81
|
+
char * t_iso_month = NULL;
|
82
|
+
char * t_iso_day = NULL;
|
83
|
+
char * t_iso_hour= NULL;
|
84
|
+
char * t_iso_minute = NULL;
|
85
|
+
char * t_iso_second = NULL;
|
86
|
+
char * t_iso_zone = NULL;
|
87
|
+
|
88
|
+
int cs = 0;
|
89
|
+
char * eof;
|
90
|
+
char * pe;
|
91
|
+
pe = p + len;
|
92
|
+
eof = pe;
|
93
|
+
|
94
|
+
%%write init;
|
95
|
+
%%write exec;
|
96
|
+
|
97
|
+
if (!state) {
|
98
|
+
return Qnil;
|
99
|
+
}
|
100
|
+
|
101
|
+
hash = rb_hash_new();
|
102
|
+
if(state & RHRR_YEAR_SET) {
|
103
|
+
rb_hash_aset(hash, rhrd_sym_year, INT2NUM(year));
|
104
|
+
}
|
105
|
+
if(state & RHRR_MONTH_SET) {
|
106
|
+
rb_hash_aset(hash, rhrd_sym_mon, INT2NUM(month));
|
107
|
+
}
|
108
|
+
if(state & RHRR_DAY_SET) {
|
109
|
+
rb_hash_aset(hash, rhrd_sym_mday, INT2NUM(day));
|
110
|
+
}
|
111
|
+
if(state & RHRR_HOUR_SET) {
|
112
|
+
rb_hash_aset(hash, rhrd_sym_hour, INT2NUM(hour));
|
113
|
+
}
|
114
|
+
if(state & RHRR_MINUTE_SET) {
|
115
|
+
rb_hash_aset(hash, rhrd_sym_min, INT2NUM(minute));
|
116
|
+
}
|
117
|
+
if(state & RHRR_SECOND_SET) {
|
118
|
+
rb_hash_aset(hash, rhrd_sym_sec, INT2NUM(second));
|
119
|
+
}
|
120
|
+
if(state & RHRR_ZONE_SET) {
|
121
|
+
rzone = rb_str_new(zone, zone_len);
|
122
|
+
rb_hash_aset(hash, rhrd_sym_zone, rzone);
|
123
|
+
if (state & RHRR_OFFSET_SET) {
|
124
|
+
rb_hash_aset(hash, rhrd_sym_offset, INT2NUM(offset));
|
125
|
+
} else {
|
126
|
+
rzone = rhrd_s_zone_to_diff(rzone, rzone);
|
127
|
+
if(RTEST(rzone)) {
|
128
|
+
rb_hash_aset(hash, rhrd_sym_offset, rzone);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
return hash;
|
134
|
+
}
|