Scid  4.6.5
date.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////
2 //
3 // FILE: date.cpp
4 // Date functions.
5 //
6 // Part of: Scid (Shane's Chess Information Database)
7 // Version: 1.9
8 //
9 // Notice: Copyright (c) 1999 Shane Hudson. All rights reserved.
10 //
11 // Author: Shane Hudson (sgh@users.sourceforge.net)
12 //
13 //////////////////////////////////////////////////////////////////////
14 
15 
16 #include "common.h"
17 #include "date.h"
18 #include "misc.h"
19 
20 bool
21 date_ValidString (const char * str)
22 {
23  uint maxValues[3] = { YEAR_MAX, 12, 31 };
24 
25  // Check year, then month, then day:
26  for (uint i=0; i < 3; i++) {
27  uint maxValue = maxValues[i];
28  bool seenQuestion, seenDigit, seenOther;
29  seenQuestion = seenDigit = seenOther = false;
30  const char * start = str;
31  while (*str != 0 && *str != '.') {
32  char ch = *str;
33  if (ch >= '0' && ch <= '9') {
34  seenDigit = true;
35  } else if (ch == '?') {
36  seenQuestion = true;
37  } else {
38  seenOther = true;
39  }
40  str++;
41  }
42  // Here, we should have seen question marks or digits, not both:
43  if (seenOther) { return false; }
44  if (seenQuestion && seenDigit) { return false; }
45  if (seenDigit) {
46  // Check that the value is not too large:
47  uint value = strGetUnsigned (start);
48  if (value > maxValue) { return false; }
49  }
50  if (*str == 0) { return true; } else { str++; }
51  }
52  return false;
53 }
54 
55 //////////////////////////////////////////////////////////////////////
56 // EOF: date.cpp
57 //////////////////////////////////////////////////////////////////////
58 
const uint YEAR_MAX
Definition: date.h:42
uint32_t uint
Definition: common.h:99
uint32_t strGetUnsigned(const char *str)
Definition: misc.h:276
bool date_ValidString(const char *str)
Definition: date.cpp:21