33 #include <boost/foreach.hpp>
47 TemporalFormat::TemporalFormat(
const char *pattern) :
52 , _month_part_index(0)
55 , _minute_part_index(0)
56 , _second_part_index(0)
57 , _usecond_part_index(0)
58 , _nsecond_part_index(0)
61 _re= pcre_compile(pattern
69 TemporalFormat::~TemporalFormat()
79 int32_t match_vector[OUT_VECTOR_SIZE];
82 memset(match_vector, 0,
sizeof(match_vector));
85 int32_t result= pcre_exec(
_re
98 case PCRE_ERROR_NOMATCH:
106 int32_t expected_match_count= (_year_part_index > 1 ? 1 : 0)
107 + (_month_part_index > 1 ? 1 : 0)
108 + (_day_part_index > 1 ? 1 : 0)
109 + (_hour_part_index > 1 ? 1 : 0)
110 + (_minute_part_index > 1 ? 1 : 0)
111 + (_second_part_index > 1 ? 1 : 0)
112 + (_usecond_part_index > 1 ? 1 : 0)
113 + (_nsecond_part_index > 1 ? 1 : 0)
115 if (result != expected_match_count)
119 string copy_data(data, data_len);
129 if (_year_part_index > 1)
131 size_t year_start= match_vector[_year_part_index];
132 size_t year_len= match_vector[_year_part_index + 1] - match_vector[_year_part_index];
133 to->_years= atoi(copy_data.substr(year_start, year_len).c_str());
135 to->_years+= (to->_years >= DRIZZLE_YY_PART_YEAR ? 1900 : 2000);
137 if (_month_part_index > 1)
139 size_t month_start= match_vector[_month_part_index];
140 size_t month_len= match_vector[_month_part_index + 1] - match_vector[_month_part_index];
141 to->_months= atoi(copy_data.substr(month_start, month_len).c_str());
143 if (_day_part_index > 1)
145 size_t day_start= match_vector[_day_part_index];
146 size_t day_len= match_vector[_day_part_index + 1] - match_vector[_day_part_index];
147 to->_days= atoi(copy_data.substr(day_start, day_len).c_str());
149 if (_hour_part_index > 1)
151 size_t hour_start= match_vector[_hour_part_index];
152 size_t hour_len= match_vector[_hour_part_index + 1] - match_vector[_hour_part_index];
153 to->_hours= atoi(copy_data.substr(hour_start, hour_len).c_str());
155 if (_minute_part_index > 1)
157 size_t minute_start= match_vector[_minute_part_index];
158 size_t minute_len= match_vector[_minute_part_index + 1] - match_vector[_minute_part_index];
159 to->_minutes= atoi(copy_data.substr(minute_start, minute_len).c_str());
161 if (_second_part_index > 1)
163 size_t second_start= match_vector[_second_part_index];
164 size_t second_len= match_vector[_second_part_index + 1] - match_vector[_second_part_index];
165 to->_seconds= atoi(copy_data.substr(second_start, second_len).c_str());
167 if (_usecond_part_index > 1)
169 size_t usecond_start= match_vector[_usecond_part_index];
170 size_t usecond_len= match_vector[_usecond_part_index + 1] - match_vector[_usecond_part_index];
177 uint32_t multiplier= 1;
178 int32_t x= usecond_len;
184 to->_useconds= atoi(copy_data.substr(usecond_start, usecond_len).c_str()) * multiplier;
186 if (_nsecond_part_index > 1)
188 size_t nsecond_start= match_vector[_nsecond_part_index];
189 size_t nsecond_len= match_vector[_nsecond_part_index + 1] - match_vector[_nsecond_part_index];
196 uint32_t multiplier= 1;
197 int32_t x= nsecond_len;
203 to->_nseconds= atoi(copy_data.substr(nsecond_start, nsecond_len).c_str()) * multiplier;
209 #define COUNT_KNOWN_FORMATS 19
214 int32_t year_part_index;
215 int32_t month_part_index;
216 int32_t day_part_index;
217 int32_t hour_part_index;
218 int32_t minute_part_index;
219 int32_t second_part_index;
220 int32_t usecond_part_index;
221 int32_t nsecond_part_index;
238 {
"^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})\\.(\\d{1,6})$", 1, 2, 3, 4, 5, 6, 7, 0}
239 , {
"^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})$", 1, 2, 3, 4, 5, 6, 0, 0}
240 , {
"^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{1,6})$", 1, 2, 3, 4, 5, 6, 7, 0}
241 , {
"^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})$", 1, 2, 3, 4, 5, 6, 0, 0}
242 , {
"^(\\d{2})[-/.](\\d{1,2})[-/.](\\d{1,2})[\\s+](\\d{2}):(\\d{2}):(\\d{2})$", 1, 2, 3, 4, 5, 6, 0, 0}
243 , {
"^(\\d{2})[-/.](\\d{1,2})[-/.](\\d{1,2})[\\s+](\\d{2}):(\\d{2})$", 1, 2, 3, 4, 5, 0, 0, 0}
244 , {
"^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[\\s+](\\d{2}):(\\d{2})$", 1, 2, 3, 4, 5, 0, 0, 0}
245 , {
"^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})$", 1, 2, 3, 0, 0, 0, 0, 0}
246 , {
"^(\\d{4})(\\d{2})(\\d{2})$", 1, 2, 3, 0, 0, 0, 0, 0}
247 , {
"^(\\d{2})[-/.]*(\\d{2})[-/.]*(\\d{4})$", 3, 1, 2, 0, 0, 0, 0, 0}
248 , {
"^(\\d{2})[-/.]*(\\d{2})[-/.]*(\\d{2})$", 1, 2, 3, 0, 0, 0, 0, 0}
249 , {
"^(\\d{2})[-/.]*(\\d{1,2})[-/.]*(\\d{1,2})$", 1, 2, 3, 0, 0, 0, 0, 0}
250 , {
"^(\\d{4})[-/.]*(\\d{1,2})[-/.]*(\\d{1,2})$", 1, 2, 3, 0, 0, 0, 0, 0}
251 , {
"^(\\d{2}):*(\\d{2}):*(\\d{2})\\.(\\d{1,6})$", 0, 0, 0, 1, 2, 3, 4, 0}
252 , {
"^(\\d{1,2}):*(\\d{2}):*(\\d{2})$", 0, 0, 0, 1, 2, 3, 0, 0}
253 , {
"^(\\d{1,2}):(\\d{1,2}):(\\d{1,2})$", 0, 0, 0, 1, 2, 3, 0, 0}
254 , {
"^(\\d{1,2}):*(\\d{2})$", 0, 0, 0, 0, 1, 2, 0, 0}
255 , {
"^(\\d{1,2})$", 0, 0, 0, 0, 0, 1, 0, 0}
256 , {
"^(\\d{1,2})\\.(\\d{1,6})$", 0, 0, 0, 0, 0, 1, 2, 0}
259 vector<TemporalFormat *> known_datetime_formats;
260 vector<TemporalFormat *> known_date_formats;
261 vector<TemporalFormat *> known_time_formats;
262 vector<TemporalFormat *> all_temporal_formats;
275 for (int32_t x= 0; x < COUNT_KNOWN_FORMATS; ++x)
292 all_temporal_formats.push_back(tmp);
294 if (current_format_args.year_part_index > 0)
296 known_datetime_formats.push_back(tmp);
297 if (current_format_args.second_part_index == 0)
298 known_date_formats.push_back(tmp);
301 if (current_format_args.second_part_index > 0)
302 known_time_formats.push_back(tmp);
312 known_date_formats.clear();
313 known_datetime_formats.clear();
314 known_time_formats.clear();
315 all_temporal_formats.clear();
static struct temporal_format_args __format_args[COUNT_KNOWN_FORMATS]
bool init_temporal_formats()
void deinit_temporal_formats()