home_run 0.9.0-x86-mingw32 → 0.9.1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +46 -0
- data/README.rdoc +45 -33
- data/Rakefile +26 -67
- data/bench/cpu_bench.rb +1 -54
- data/bench/cpu_bench_util.rb +55 -0
- data/bench/parser_bench.rb +20 -0
- data/bin/home_run +14 -17
- data/default.mspec +1 -1
- data/ext/{date_ext.c → date_ext/date_ext.c} +95 -208
- data/ext/date_ext/date_ext.h +187 -0
- data/ext/date_ext/date_parser.c +852 -0
- data/ext/date_ext/date_parser.rl +352 -0
- data/ext/{datetime.c → date_ext/datetime.c} +120 -77
- data/ext/date_ext/extconf.rb +6 -0
- data/lib/1.8/date_ext.so +0 -0
- data/lib/1.9/date_ext.so +0 -0
- data/{ext → lib}/date/format.rb +1 -1
- data/lib/date.rb +7 -0
- data/lib/home_run.rb +5 -0
- data/spec/date/allocate_spec.rb +7 -0
- data/spec/date/encoding_spec.rb +42 -0
- data/spec/date/limits_spec.rb +121 -0
- data/spec/date/parse_spec.rb +154 -0
- data/spec/date/parsing_spec.rb +11 -0
- data/spec/date/step_spec.rb +22 -0
- data/spec/date/strptime_spec.rb +35 -3
- data/spec/datetime/add_spec.rb +4 -4
- data/spec/datetime/allocate_spec.rb +7 -0
- data/spec/datetime/encoding_spec.rb +42 -0
- data/spec/datetime/limits_spec.rb +170 -0
- data/spec/datetime/parse_spec.rb +73 -0
- data/spec/datetime/parsing_spec.rb +4 -0
- data/spec/datetime/step_spec.rb +22 -0
- data/spec/datetime/strptime_spec.rb +10 -0
- metadata +24 -14
- data/ext/1.8/date_ext.so +0 -0
- data/ext/1.9/date_ext.so +0 -0
- data/ext/date.rb +0 -7
- data/ext/date_parser.c +0 -367
- data/ext/date_parser.rl +0 -134
- data/ext/extconf.rb +0 -6
@@ -0,0 +1,352 @@
|
|
1
|
+
#include "date_ext.h"
|
2
|
+
|
3
|
+
#define RHRR_ISO_PARSER 0x1
|
4
|
+
#define RHRR_RFC_PARSER 0x2
|
5
|
+
#define RHRR_CLF_PARSER 0x4
|
6
|
+
|
7
|
+
#define RHRR_ISO_TIME_SET 0x1
|
8
|
+
#define RHRR_ISO_ZONE_SET 0x2
|
9
|
+
|
10
|
+
#define RHRR_RFC_TIME_SET 0x1
|
11
|
+
#define RHRR_RFC_ZONE_SET 0x2
|
12
|
+
#define RHRR_RFC_ZONE_NUM_SET 0x4
|
13
|
+
#define RHRR_RFC_ZONE_NAME_SET 0x8
|
14
|
+
|
15
|
+
#define RHRR_CLF_TIME_SET 0x1
|
16
|
+
#define RHRR_CLF_ZONE_SET 0x2
|
17
|
+
|
18
|
+
#define RHRR_BAD_OFFSET 86400
|
19
|
+
|
20
|
+
extern const char * rhrd__abbr_month_names[];
|
21
|
+
extern const char * rhrd__abbr_day_names[];
|
22
|
+
|
23
|
+
extern VALUE rhrd_sym_hour;
|
24
|
+
extern VALUE rhrd_sym_mday;
|
25
|
+
extern VALUE rhrd_sym_min;
|
26
|
+
extern VALUE rhrd_sym_mon;
|
27
|
+
extern VALUE rhrd_sym_offset;
|
28
|
+
extern VALUE rhrd_sym_sec;
|
29
|
+
extern VALUE rhrd_sym_wday;
|
30
|
+
extern VALUE rhrd_sym_year;
|
31
|
+
extern VALUE rhrd_sym_zone;
|
32
|
+
|
33
|
+
const char * rhrd__rfc_zone_names[] = {"UT", "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT",
|
34
|
+
"A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L", "M",
|
35
|
+
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
|
36
|
+
long rhrd__rfc_zone_offsets[] = {0, 0, -18000, -14400, -21600, -18000, -25200, -21600, -28800, -25200,
|
37
|
+
3600, 7200, 10800, 14400, 18000, 21600, 25200, 28800, 32400, 36000, 39600, 43200,
|
38
|
+
-3600, -7200, -10800, -14400, -18000, -21600, -25200, -28800, -32400, -36000, -39600, -43200, 0};
|
39
|
+
|
40
|
+
long rhrd__rfc_zone_offset(char * str) {
|
41
|
+
int i;
|
42
|
+
|
43
|
+
for(i = 0; i < 36; i++) {
|
44
|
+
if(strcasecmp(rhrd__rfc_zone_names[i], str) == 0) {
|
45
|
+
return rhrd__rfc_zone_offsets[i];
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
return RHRR_BAD_OFFSET;
|
50
|
+
}
|
51
|
+
|
52
|
+
long rhrd__month_num(char * str) {
|
53
|
+
int i;
|
54
|
+
|
55
|
+
for(i = 1; i < 13; i++) {
|
56
|
+
if(strncasecmp(str, rhrd__abbr_month_names[i], 3) == 0) {
|
57
|
+
return i;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
return atol(str);
|
62
|
+
}
|
63
|
+
|
64
|
+
long rhrd__weekday_num(char * str) {
|
65
|
+
int i;
|
66
|
+
|
67
|
+
for(i = 0; i < 7; i++) {
|
68
|
+
if(strncasecmp(str, rhrd__abbr_day_names[i], 3) == 0) {
|
69
|
+
return i;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
return 7;
|
74
|
+
}
|
75
|
+
|
76
|
+
%%{
|
77
|
+
machine date_parser;
|
78
|
+
|
79
|
+
# Shared
|
80
|
+
|
81
|
+
abbr_month_name = /jan/i | /feb/i | /mar/i | /apr/i | /may/i | /jun/i |
|
82
|
+
/jul/i | /aug/i | /sep/i | /oct/i | /nov/i | /dec/i;
|
83
|
+
# ISO 8601
|
84
|
+
|
85
|
+
action tag_iso_year { t_iso_year = p; }
|
86
|
+
action tag_iso_month { t_iso_month = p; }
|
87
|
+
action tag_iso_day { t_iso_day = p; }
|
88
|
+
action tag_iso_hour { t_iso_hour = p; }
|
89
|
+
action tag_iso_minute { t_iso_minute = p; }
|
90
|
+
action tag_iso_second { t_iso_second = p; }
|
91
|
+
action tag_iso_zone { t_iso_zone = p; }
|
92
|
+
|
93
|
+
action set_iso_time { iso_state |= RHRR_ISO_TIME_SET; }
|
94
|
+
action set_iso_zone {
|
95
|
+
t_iso_zone_end = p;
|
96
|
+
iso_state |= RHRR_ISO_ZONE_SET;
|
97
|
+
}
|
98
|
+
action set_parser_iso { parsers |= RHRR_ISO_PARSER; }
|
99
|
+
|
100
|
+
iso_year = ('-'? . digit{4}) >tag_iso_year;
|
101
|
+
iso_month = ('0' . [1-9] | '1' . [0-2]) >tag_iso_month;
|
102
|
+
iso_day = ('0' . [1-9] | [12] . [0-9] | '3' . [01]) >tag_iso_day;
|
103
|
+
iso_hour = ([0-1] . [0-9] | '2' . [0-4]) >tag_iso_hour;
|
104
|
+
iso_minute = ([0-5] . [0-9]) >tag_iso_minute;
|
105
|
+
iso_second = ([0-5] . [0-9]) >tag_iso_second;
|
106
|
+
iso_zone = ([+\-] . digit{2} . ':' . digit{2}) > tag_iso_zone;
|
107
|
+
|
108
|
+
iso_date = (iso_year . [\-/] . iso_month . [\-/] . iso_day);
|
109
|
+
iso_time = (iso_hour . ':' . iso_minute . ':' . iso_second . (iso_zone %set_iso_zone)?) %set_iso_time;
|
110
|
+
iso_date_time = (iso_date . ([Tt ] . iso_time)? . space*) %/set_parser_iso;
|
111
|
+
|
112
|
+
# RFC 2822 / HTTP
|
113
|
+
|
114
|
+
action tag_rfc_wday { t_rfc_wday = p; }
|
115
|
+
action tag_rfc_day { t_rfc_day = p; }
|
116
|
+
action tag_rfc_month { t_rfc_month = p; }
|
117
|
+
action tag_rfc_year { t_rfc_year = p; }
|
118
|
+
action tag_rfc_hour { t_rfc_hour = p; }
|
119
|
+
action tag_rfc_minute { t_rfc_minute = p; }
|
120
|
+
action tag_rfc_second { t_rfc_second = p; }
|
121
|
+
action tag_rfc_zone { t_rfc_zone = p; }
|
122
|
+
|
123
|
+
action set_rfc_time { rfc_state |= RHRR_RFC_TIME_SET; }
|
124
|
+
action set_rfc_zone_num {
|
125
|
+
t_rfc_zone_end = p;
|
126
|
+
rfc_state |= RHRR_RFC_ZONE_SET | RHRR_RFC_ZONE_NUM_SET;
|
127
|
+
}
|
128
|
+
action set_rfc_zone_name {
|
129
|
+
t_rfc_zone_end = p;
|
130
|
+
rfc_state |= RHRR_RFC_ZONE_SET | RHRR_RFC_ZONE_NAME_SET;
|
131
|
+
}
|
132
|
+
action set_parser_rfc { parsers |= RHRR_RFC_PARSER; }
|
133
|
+
|
134
|
+
rfc_wday = (/sun/i | /mon/i | /tue/i | /wed/i | /thu/i | /fri/i | /sat/i) >tag_rfc_wday;
|
135
|
+
rfc_day = ([ 0] . [1-9] | [12] . [0-9] | '3' . [01]) >tag_rfc_day;
|
136
|
+
rfc_month = abbr_month_name >tag_rfc_month;
|
137
|
+
rfc_year = ('-'? . digit{4}) >tag_rfc_year;
|
138
|
+
rfc_hour = ([0-1] . [0-9] | '2' . [0-4]) >tag_rfc_hour;
|
139
|
+
rfc_minute = ([0-5] . [0-9]) >tag_rfc_minute;
|
140
|
+
rfc_second = ([0-5] . [0-9]) >tag_rfc_second;
|
141
|
+
rfc_zone_num = ([+\-] . digit{4}) >tag_rfc_zone %set_rfc_zone_num;
|
142
|
+
rfc_zone_name = (/[a-ik-z]/i | /gmt/i | /ut/i | /[ecmp][ds]t/i) >tag_rfc_zone %set_rfc_zone_name;
|
143
|
+
rfc_zone = space* . (rfc_zone_num | rfc_zone_name );
|
144
|
+
|
145
|
+
rfc_date = (rfc_wday . ',' . space* . rfc_day . space* . rfc_month . space* . rfc_year);
|
146
|
+
rfc_time = (rfc_hour . ':' . rfc_minute . ':' . rfc_second . (space* . rfc_zone)?) %set_rfc_time;
|
147
|
+
rfc_date_time = (rfc_date . (space* . rfc_time)? . space*) %/set_parser_rfc;
|
148
|
+
|
149
|
+
# Common Log Format
|
150
|
+
|
151
|
+
action tag_clf_day { t_clf_day = p; }
|
152
|
+
action tag_clf_month { t_clf_month = p; }
|
153
|
+
action tag_clf_year { t_clf_year = p; }
|
154
|
+
action tag_clf_hour { t_clf_hour = p; }
|
155
|
+
action tag_clf_minute { t_clf_minute = p; }
|
156
|
+
action tag_clf_second { t_clf_second = p; }
|
157
|
+
action tag_clf_zone { t_clf_zone = p; }
|
158
|
+
|
159
|
+
action set_clf_time { clf_state |= RHRR_CLF_TIME_SET; }
|
160
|
+
action set_clf_zone {
|
161
|
+
t_clf_zone_end = p;
|
162
|
+
clf_state |= RHRR_CLF_ZONE_SET;
|
163
|
+
}
|
164
|
+
action set_parser_clf { parsers |= RHRR_CLF_PARSER; }
|
165
|
+
|
166
|
+
clf_year = ('-'? . digit{4}) >tag_clf_year;
|
167
|
+
clf_month = abbr_month_name >tag_clf_month;
|
168
|
+
clf_day = ('0' . [1-9] | [12] . [0-9] | '3' . [01]) >tag_clf_day;
|
169
|
+
clf_hour = ([0-1] . [0-9] | '2' . [0-4]) >tag_clf_hour;
|
170
|
+
clf_minute = ([0-5] . [0-9]) >tag_clf_minute;
|
171
|
+
clf_second = ([0-5] . [0-9]) >tag_clf_second;
|
172
|
+
clf_zone = ([+\-] . digit{4}) > tag_clf_zone;
|
173
|
+
|
174
|
+
clf_date = (clf_day . '/' . clf_month . '/' . clf_year);
|
175
|
+
clf_time = (clf_hour . ':' . clf_minute . ':' . clf_second . (space* . clf_zone %set_clf_zone)?) %set_clf_time;
|
176
|
+
clf_date_time = (clf_date . (':' . clf_time)? . space*) %/set_parser_clf;
|
177
|
+
|
178
|
+
date_time = (iso_date_time | rfc_date_time | clf_date_time);
|
179
|
+
main := (space* . date_time);
|
180
|
+
write data;
|
181
|
+
}%%
|
182
|
+
|
183
|
+
VALUE rhrd__ragel_parse(char * p, long len) {
|
184
|
+
VALUE hash;
|
185
|
+
long state = 0;
|
186
|
+
long parsers = 0;
|
187
|
+
|
188
|
+
long year = 0;
|
189
|
+
long month = 0;
|
190
|
+
long day = 0;
|
191
|
+
long wday = 0;
|
192
|
+
|
193
|
+
long hour = 0;
|
194
|
+
long minute = 0;
|
195
|
+
long second = 0;
|
196
|
+
|
197
|
+
VALUE rzone;
|
198
|
+
char * zone = NULL;
|
199
|
+
long zone_len = 0;
|
200
|
+
long offset = 0;
|
201
|
+
|
202
|
+
long iso_state = 0;
|
203
|
+
char * t_iso_year = NULL;
|
204
|
+
char * t_iso_month = NULL;
|
205
|
+
char * t_iso_day = NULL;
|
206
|
+
char * t_iso_hour= NULL;
|
207
|
+
char * t_iso_minute = NULL;
|
208
|
+
char * t_iso_second = NULL;
|
209
|
+
char * t_iso_zone = NULL;
|
210
|
+
char * t_iso_zone_end = NULL;
|
211
|
+
|
212
|
+
long rfc_state = 0;
|
213
|
+
char * t_rfc_wday = NULL;
|
214
|
+
char * t_rfc_year = NULL;
|
215
|
+
char * t_rfc_month = NULL;
|
216
|
+
char * t_rfc_day = NULL;
|
217
|
+
char * t_rfc_hour= NULL;
|
218
|
+
char * t_rfc_minute = NULL;
|
219
|
+
char * t_rfc_second = NULL;
|
220
|
+
char * t_rfc_zone = NULL;
|
221
|
+
char * t_rfc_zone_end = NULL;
|
222
|
+
|
223
|
+
long clf_state = 0;
|
224
|
+
char * t_clf_year = NULL;
|
225
|
+
char * t_clf_month = NULL;
|
226
|
+
char * t_clf_day = NULL;
|
227
|
+
char * t_clf_hour= NULL;
|
228
|
+
char * t_clf_minute = NULL;
|
229
|
+
char * t_clf_second = NULL;
|
230
|
+
char * t_clf_zone = NULL;
|
231
|
+
char * t_clf_zone_end = NULL;
|
232
|
+
|
233
|
+
int cs = 0;
|
234
|
+
char * eof;
|
235
|
+
char * pe;
|
236
|
+
pe = p + len;
|
237
|
+
eof = pe;
|
238
|
+
|
239
|
+
%%write init;
|
240
|
+
%%write exec;
|
241
|
+
|
242
|
+
switch(parsers) {
|
243
|
+
case RHRR_ISO_PARSER:
|
244
|
+
year = atol(t_iso_year);
|
245
|
+
month = atol(t_iso_month);
|
246
|
+
day = atol(t_iso_day);
|
247
|
+
state |= RHRR_YEAR_SET | RHRR_MONTH_SET | RHRR_DAY_SET;
|
248
|
+
if (iso_state & RHRR_ISO_TIME_SET) {
|
249
|
+
hour = atol(t_iso_hour);
|
250
|
+
minute = atol(t_iso_minute);
|
251
|
+
second = atol(t_iso_second);
|
252
|
+
state |= RHRR_HOUR_SET | RHRR_MINUTE_SET | RHRR_SECOND_SET;
|
253
|
+
if (iso_state & RHRR_ISO_ZONE_SET) {
|
254
|
+
zone = t_iso_zone;
|
255
|
+
zone_len = t_iso_zone_end - zone;
|
256
|
+
offset = atol(zone) * 3600 + atol(zone + 4) * 60;
|
257
|
+
state |= RHRR_ZONE_SET | RHRR_OFFSET_SET;
|
258
|
+
}
|
259
|
+
}
|
260
|
+
break;
|
261
|
+
case RHRR_RFC_PARSER:
|
262
|
+
wday = rhrd__weekday_num(t_rfc_wday);
|
263
|
+
day = atol(t_rfc_day);
|
264
|
+
month = rhrd__month_num(t_rfc_month);
|
265
|
+
year = atol(t_rfc_year);
|
266
|
+
state |= RHRR_WDAY_SET | RHRR_YEAR_SET | RHRR_MONTH_SET | RHRR_DAY_SET;
|
267
|
+
if (rfc_state & RHRR_RFC_TIME_SET) {
|
268
|
+
hour = atol(t_rfc_hour);
|
269
|
+
minute = atol(t_rfc_minute);
|
270
|
+
second = atol(t_rfc_second);
|
271
|
+
state |= RHRR_HOUR_SET | RHRR_MINUTE_SET | RHRR_SECOND_SET;
|
272
|
+
if (rfc_state & RHRR_RFC_ZONE_SET) {
|
273
|
+
zone = t_rfc_zone;
|
274
|
+
zone_len = t_rfc_zone_end - zone;
|
275
|
+
state |= RHRR_ZONE_SET;
|
276
|
+
if (rfc_state & RHRR_RFC_ZONE_NUM_SET) {
|
277
|
+
offset = atol(zone);
|
278
|
+
offset = (offset/100) * 3600 + (labs(offset) % 100) * 60 * (offset < 0 ? -1 : 1);
|
279
|
+
state |= RHRR_OFFSET_SET;
|
280
|
+
} else if (rfc_state & RHRR_RFC_ZONE_NAME_SET) {
|
281
|
+
offset = rhrd__rfc_zone_offset(zone);
|
282
|
+
if (offset == RHRR_BAD_OFFSET) {
|
283
|
+
state = 0;
|
284
|
+
} else {
|
285
|
+
state |= RHRR_OFFSET_SET;
|
286
|
+
}
|
287
|
+
}
|
288
|
+
}
|
289
|
+
}
|
290
|
+
break;
|
291
|
+
case RHRR_CLF_PARSER:
|
292
|
+
year = atol(t_clf_year);
|
293
|
+
month = rhrd__month_num(t_clf_month);
|
294
|
+
day = atol(t_clf_day);
|
295
|
+
state |= RHRR_YEAR_SET | RHRR_MONTH_SET | RHRR_DAY_SET;
|
296
|
+
if (clf_state & RHRR_ISO_TIME_SET) {
|
297
|
+
hour = atol(t_clf_hour);
|
298
|
+
minute = atol(t_clf_minute);
|
299
|
+
second = atol(t_clf_second);
|
300
|
+
state |= RHRR_HOUR_SET | RHRR_MINUTE_SET | RHRR_SECOND_SET;
|
301
|
+
if (clf_state & RHRR_ISO_ZONE_SET) {
|
302
|
+
zone = t_clf_zone;
|
303
|
+
zone_len = t_clf_zone_end - zone;
|
304
|
+
offset = atol(zone);
|
305
|
+
offset = (offset/100) * 3600 + (labs(offset) % 100) * 60 * (offset < 0 ? -1 : 1);
|
306
|
+
state |= RHRR_ZONE_SET | RHRR_OFFSET_SET;
|
307
|
+
}
|
308
|
+
}
|
309
|
+
break;
|
310
|
+
}
|
311
|
+
|
312
|
+
if (!state) {
|
313
|
+
return Qnil;
|
314
|
+
}
|
315
|
+
|
316
|
+
hash = rb_hash_new();
|
317
|
+
if(state & RHRR_WDAY_SET) {
|
318
|
+
rb_hash_aset(hash, rhrd_sym_wday, INT2NUM(wday));
|
319
|
+
}
|
320
|
+
if(state & RHRR_YEAR_SET) {
|
321
|
+
rb_hash_aset(hash, rhrd_sym_year, INT2NUM(year));
|
322
|
+
}
|
323
|
+
if(state & RHRR_MONTH_SET) {
|
324
|
+
rb_hash_aset(hash, rhrd_sym_mon, INT2NUM(month));
|
325
|
+
}
|
326
|
+
if(state & RHRR_DAY_SET) {
|
327
|
+
rb_hash_aset(hash, rhrd_sym_mday, INT2NUM(day));
|
328
|
+
}
|
329
|
+
if(state & RHRR_HOUR_SET) {
|
330
|
+
rb_hash_aset(hash, rhrd_sym_hour, INT2NUM(hour));
|
331
|
+
}
|
332
|
+
if(state & RHRR_MINUTE_SET) {
|
333
|
+
rb_hash_aset(hash, rhrd_sym_min, INT2NUM(minute));
|
334
|
+
}
|
335
|
+
if(state & RHRR_SECOND_SET) {
|
336
|
+
rb_hash_aset(hash, rhrd_sym_sec, INT2NUM(second));
|
337
|
+
}
|
338
|
+
if(state & RHRR_ZONE_SET) {
|
339
|
+
rzone = rb_str_new(zone, zone_len);
|
340
|
+
rb_hash_aset(hash, rhrd_sym_zone, rzone);
|
341
|
+
if (state & RHRR_OFFSET_SET) {
|
342
|
+
rb_hash_aset(hash, rhrd_sym_offset, INT2NUM(offset));
|
343
|
+
} else {
|
344
|
+
rzone = rhrd_s_zone_to_diff(rzone, rzone);
|
345
|
+
if(RTEST(rzone)) {
|
346
|
+
rb_hash_aset(hash, rhrd_sym_offset, rzone);
|
347
|
+
}
|
348
|
+
}
|
349
|
+
}
|
350
|
+
|
351
|
+
return hash;
|
352
|
+
}
|