1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* Copyright (C) 2008 Sun Microsystems
*
* Authors:
*
* Jay Pipes <jay.pipes@sun.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
*
* Defines the API for matching datetime formats.
*/
#ifndef DRIZZLED_TEMPORAL_FORMAT_H
#define DRIZZLED_TEMPORAL_FORMAT_H
#include PCRE_HEADER
/* Output vector size for pcre matching. Should be multiple of 3. */
#define OUT_VECTOR_SIZE 30
namespace drizzled
{
/* Forward declaration needed */
class Temporal;
class TemporalFormat
{
protected:
const char *_pattern; /**< The regular expression string to match */
pcre *_re; /**< The compiled regular expression struct */
int32_t _error_offset; /**< Any error encountered during compilation or matching */
const char *_error;
int32_t _match_vector[OUT_VECTOR_SIZE]; /**< Stores match substring indexes */
/* Index of the pattern which is a specific temporal part */
uint32_t _year_part_index;
uint32_t _month_part_index;
uint32_t _day_part_index;
uint32_t _hour_part_index;
uint32_t _minute_part_index;
uint32_t _second_part_index;
uint32_t _usecond_part_index;
uint32_t _nsecond_part_index;
public:
/**
* Constructor which takes a regex string as
* it's only parameter.
*
* @param Pattern to use in matching
*/
TemporalFormat(const char *pattern);
/**
* Returns whether the instance is compiled
* and contains a valid regular expression.
*/
inline bool is_valid() const {return _re && (_error == NULL);}
/**
* Sets the index for the year part of the pattern.
*
* @param index of the temporal part
*/
inline void set_year_part_index(int32_t index) {_year_part_index= ((index - 1) * 2) + 2;}
/**
* Sets the index for the month part of the pattern.
*
* @param index of the temporal part
*/
inline void set_month_part_index(int32_t index) {_month_part_index= ((index - 1) * 2) + 2;}
/**
* Sets the index for the day part of the pattern.
*
* @param index of the temporal part
*/
inline void set_day_part_index(int32_t index) {_day_part_index= ((index - 1) * 2) + 2;}
/**
* Sets the index for the hour part of the pattern.
*
* @param index of the temporal part
*/
inline void set_hour_part_index(int32_t index) {_hour_part_index= ((index - 1) * 2) + 2;}
/**
* Sets the index for the minute part of the pattern.
*
* @param index of the temporal part
*/
inline void set_minute_part_index(int32_t index) {_minute_part_index= ((index - 1) * 2) + 2;}
/**
* Sets the index for the second part of the pattern.
*
* @param index of the temporal part
*/
inline void set_second_part_index(int32_t index) {_second_part_index= ((index - 1) * 2) + 2;}
/**
* Sets the index for the microsecond part of the pattern.
*
* @param index of the temporal part
*/
inline void set_usecond_part_index(int32_t index) {_usecond_part_index= ((index - 1) * 2) + 2;}
/**
* Sets the index for the nanosecond part of the pattern.
*
* @param index of the temporal part
*/
inline void set_nsecond_part_index(int32_t index) {_nsecond_part_index= ((index - 1) * 2) + 2;}
/**
* Returns true or false whether a supplied
* string matches the internal pattern for this
* temporal format string.
*
* @param Subject to match
* @param Length of subject string
*/
bool matches(const char *data, size_t data_len, Temporal *to);
};
} /* end namespace drizzled */
/**
* Initializes the regular expressions used by the datetime
* string matching conversion functions.
*
* Returns whether initialization was successful.
*
* @note
*
* This function is not thread-safe. Call before threading
* is initialized on server init.
*/
bool init_temporal_formats();
/**
* Frees all memory allocated for temporal format objects
*/
void deinit_temporal_formats();
#endif /* DRIZZLED_TEMPORAL_FORMAT_H */
|