~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal_format.cc

  • Committer: Mark Atwood
  • Date: 2011-10-27 05:08:12 UTC
  • mfrom: (2445.1.11 rf)
  • Revision ID: me@mark.atwood.name-20111027050812-1icvs72lb0u4xdc4
mergeĀ lp:~olafvdspek/drizzle/refactor8

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 * Implementation of the server's date and time string matching utility.
29
29
 */
30
30
 
31
 
#include "config.h"
 
31
#include <config.h>
32
32
 
33
 
#include "drizzled/temporal_format.h"
34
 
#include "drizzled/temporal.h"
 
33
#include <boost/foreach.hpp>
 
34
#include <drizzled/temporal_format.h>
 
35
#include <drizzled/temporal.h>
35
36
 
36
37
#include <string.h>
37
38
#include PCRE_HEADER
41
42
 
42
43
using namespace std;
43
44
 
44
 
namespace drizzled
45
 
{
 
45
namespace drizzled {
46
46
 
47
47
TemporalFormat::TemporalFormat(const char *pattern) :
48
48
  _pattern(pattern)
66
66
                    );
67
67
}
68
68
 
 
69
TemporalFormat::~TemporalFormat()
 
70
{
 
71
  pcre_free(_re);
 
72
}
 
73
 
69
74
bool TemporalFormat::matches(const char *data, size_t data_len, Temporal *to)
70
75
{
71
76
  if (! is_valid()) 
266
271
  /* Compile all the regular expressions for the datetime formats */
267
272
  TemporalFormat *tmp;
268
273
  struct temporal_format_args current_format_args;
269
 
  int32_t x;
270
274
  
271
 
  for (x= 0; x<COUNT_KNOWN_FORMATS; ++x)
 
275
  for (int32_t x= 0; x < COUNT_KNOWN_FORMATS; ++x)
272
276
  {
273
277
    current_format_args= __format_args[x];
274
278
    tmp= new TemporalFormat(current_format_args.pattern);
293
297
      if (current_format_args.second_part_index == 0) /* A time must have seconds. */
294
298
        known_date_formats.push_back(tmp);
295
299
    }
 
300
 
296
301
    if (current_format_args.second_part_index > 0) /* A time must have seconds, but may not have minutes or hours */
297
 
      if (current_format_args.year_part_index == 0) /* A time may not have a date part, and date parts must have a year */
298
 
        known_time_formats.push_back(tmp);
 
302
      known_time_formats.push_back(tmp);
299
303
  }
300
304
  return true;
301
305
}
303
307
/** Free all allocated temporal formats */
304
308
void deinit_temporal_formats()
305
309
{
306
 
  vector<TemporalFormat *>::iterator p= all_temporal_formats.begin();
307
 
  while (p != all_temporal_formats.end())
308
 
  {
309
 
    delete *p;
310
 
    ++p;
311
 
  }
 
310
  BOOST_FOREACH(TemporalFormat* it, all_temporal_formats)
 
311
    delete it;
312
312
  known_date_formats.clear();
313
313
  known_datetime_formats.clear();
314
314
  known_time_formats.clear();