1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
8
* Jay Pipes <jay.pipes@sun.com>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
* Defines the API for matching datetime formats.
31
#ifndef DRIZZLED_TEMPORAL_FORMAT_MATCH_H
32
#define DRIZZLED_TEMPORAL_FORMAT_MATCH_H
36
/* Output vector size for pcre matching. Should be multiple of 3. */
37
#define OUT_VECTOR_SIZE 30
42
/* Forward declaration needed */
48
const char *_pattern; /**< The regular expression string to match */
49
pcre *_re; /**< The compiled regular expression struct */
50
int32_t _error_offset; /**< Any error encountered during compilation or matching */
52
int32_t _match_vector[OUT_VECTOR_SIZE]; /**< Stores match substring indexes */
53
/* Index of the pattern which is a specific temporal part */
54
uint32_t _year_part_index;
55
uint32_t _month_part_index;
56
uint32_t _day_part_index;
57
uint32_t _hour_part_index;
58
uint32_t _minute_part_index;
59
uint32_t _second_part_index;
60
uint32_t _usecond_part_index;
63
* Constructor which takes a regex string as
64
* it's only parameter.
66
* @param Pattern to use in matching
68
TemporalFormat(const char *pattern);
70
* Returns whether the instance is compiled
71
* and contains a valid regular expression.
73
inline bool is_valid() const {return _re && (_error == NULL);}
75
* Sets the index for the year part of the pattern.
77
* @param index of the temporal part
79
inline void set_year_part_index(int32_t index) {_year_part_index= ((index - 1) * 2) + 2;}
81
* Sets the index for the month part of the pattern.
83
* @param index of the temporal part
85
inline void set_month_part_index(int32_t index) {_month_part_index= ((index - 1) * 2) + 2;}
87
* Sets the index for the day part of the pattern.
89
* @param index of the temporal part
91
inline void set_day_part_index(int32_t index) {_day_part_index= ((index - 1) * 2) + 2;}
93
* Sets the index for the hour part of the pattern.
95
* @param index of the temporal part
97
inline void set_hour_part_index(int32_t index) {_hour_part_index= ((index - 1) * 2) + 2;}
99
* Sets the index for the minute part of the pattern.
101
* @param index of the temporal part
103
inline void set_minute_part_index(int32_t index) {_minute_part_index= ((index - 1) * 2) + 2;}
105
* Sets the index for the second part of the pattern.
107
* @param index of the temporal part
109
inline void set_second_part_index(int32_t index) {_second_part_index= ((index - 1) * 2) + 2;}
111
* Sets the index for the second part of the pattern.
113
* @param index of the temporal part
115
inline void set_usecond_part_index(int32_t index) {_usecond_part_index= ((index - 1) * 2) + 2;}
117
* Returns true or false whether a supplied
118
* string matches the internal pattern for this
119
* temporal format string.
121
* @param Subject to match
122
* @param Length of subject string
124
bool matches(const char *data, size_t data_len, Temporal *to);
127
} /* end namespace drizzled */
130
* Initializes the regular expressions used by the datetime
131
* string matching conversion functions.
133
* Returns whether initialization was successful.
137
* This function is not thread-safe. Call before threading
138
* is initialized on server init.
140
bool init_temporal_formats();
142
#endif /* DRIZZLED_TEMPORAL_FORMAT_MATCH_H */