36 StringValueRangeProcessor::operator()(
string &begin,
string &end)
45 begin.erase(0,
str.size());
48 end.erase(0,
str.size());
56 end.resize(end.size() -
str.size());
59 begin.resize(begin.size() -
str.size());
73 if (s.size() < 5 || s.size() > 10)
return false;
74 size_t i = s.find_first_not_of(
"0123456789");
75 if (i < 1 || i > 2 || !(s[i] ==
'/' || s[i] ==
'-' || s[i] ==
'.'))
77 size_t j = s.find_first_not_of(
"0123456789", i + 1);
78 if (j - (i + 1) < 1 || j - (i + 1) > 2 ||
79 !(s[j] ==
'/' || s[j] ==
'-' || s[j] ==
'.'))
81 if (s.size() - j > 4 + 1)
return false;
82 if (s.find_first_not_of(
"0123456789", j + 1) != string::npos)
85 if (x1 < 1 || x1 > 31)
return false;
86 x2 = atoi(s.c_str() + i + 1);
87 if (x2 < 1 || x2 > 31)
return false;
88 y = atoi(s.c_str() + j + 1);
97 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
103 if (m == -1)
return true;
104 if (m > 12 || m < 1)
return false;
105 if (d < 1 || d > max_month_length[m - 1])
return false;
113 return (s.find_first_not_of(
"0123456789") == 4 &&
114 s.find_first_not_of(
"0123456789", 5) == 7 &&
115 s.find_first_not_of(
"0123456789", 8) == string::npos &&
117 (s[4] ==
'-' || s[4] ==
'.' || s[4] ==
'/'));
130 p[w] =
'0' + (v % 10);
144 DateValueRangeProcessor::operator()(
string &begin,
string &end)
146 if (StringValueRangeProcessor::operator()(begin, end) ==
BAD_VALUENO)
149 if ((begin.size() == 8 || begin.size() == 0) &&
150 (end.size() == 8 || end.size() == 0) &&
151 begin.find_first_not_of(
"0123456789") == string::npos &&
152 end.find_first_not_of(
"0123456789") == string::npos) {
156 if ((begin.size() == 10 || begin.size() == 0) &&
157 (end.size() == 10 || end.size() == 0)) {
161 if (!begin.empty()) {
180 if (!prefer_mdy &&
vet_dm(b_d, b_m) &&
vet_dm(e_d, e_m) &&
181 (b_y != e_y || b_m < e_m || (b_m == e_m && b_d <= e_d))) {
184 (b_y != e_y || b_d < e_d || (b_d == e_d && b_m <= e_m))) {
187 }
else if (prefer_mdy &&
vet_dm(b_d, b_m) &&
vet_dm(e_d, e_m) &&
188 (b_y != e_y || b_m < e_m || (b_m == e_m && b_d <= e_d))) {
195 if (!begin.empty()) {
198 if (b_y < epoch_year) b_y += 100;
201 begin.assign(buf, 8);
206 if (e_y < epoch_year) e_y += 100;
215 NumberValueRangeProcessor::operator()(
string &begin,
string &end)
217 if (StringValueRangeProcessor::operator()(begin, end) ==
BAD_VALUENO)
223 if (!begin.empty()) {
225 const char * startptr = begin.c_str();
227 beginnum = strtod(startptr, &endptr);
228 if (endptr != startptr + begin.size())
241 const char * startptr = end.c_str();
243 double endnum = strtod(startptr, &endptr);
244 if (endptr != startptr + end.size())
253 if (!begin.empty()) {
261 RangeProcessor::check_range(
const string& b,
const string& e)
264 return operator()(b, e);
266 size_t off_b = 0, len_b = string::npos;
267 size_t off_e = 0, len_e = string::npos;
289 len_e = e.size() -
str.size();
292 len_b = b.size() -
str.size();
296 return operator()(
string(b, off_b, len_b),
string(e, off_e, len_e));
303 RangeProcessor::operator()(
const string& b,
const string& e)
311 DateRangeProcessor::operator()(
const string& b,
const string& e)
313 if ((b.size() == 8 || b.size() == 0) &&
314 (e.size() == 8 || e.size() == 0) &&
315 b.find_first_not_of(
"0123456789") == string::npos &&
316 e.find_first_not_of(
"0123456789") == string::npos) {
318 return RangeProcessor::operator()(b, e);
320 if ((b.size() == 10 || b.size() == 0) &&
321 (e.size() == 10 || e.size() == 0)) {
324 string begin = b, end = e;
326 if (!begin.empty()) {
334 return RangeProcessor::operator()(begin, end);
346 if (!prefer_mdy &&
vet_dm(b_d, b_m) &&
vet_dm(e_d, e_m) &&
347 (b_y != e_y || b_m < e_m || (b_m == e_m && b_d <= e_d))) {
350 (b_y != e_y || b_d < e_d || (b_d == e_d && b_m <= e_m))) {
353 }
else if (prefer_mdy &&
vet_dm(b_d, b_m) &&
vet_dm(e_d, e_m) &&
354 (b_y != e_y || b_m < e_m || (b_m == e_m && b_d <= e_d))) {
361 char buf_b[8], buf_e[8];
362 size_t len_b = 0, len_e = 0;
366 if (b_y < epoch_year) b_y += 100;
374 if (e_y < epoch_year) e_y += 100;
379 return RangeProcessor::operator()(
string(buf_b, len_b),
380 string(buf_e, len_e));
388 NumberRangeProcessor::operator()(
const string& b,
const string& e)
395 const char * startptr = b.c_str();
397 num_b = strtod(startptr, &endptr);
398 if (endptr != startptr + b.size() || errno) {
409 const char * startptr = e.c_str();
411 num_e = strtod(startptr, &endptr);
412 if (endptr != startptr + e.size() || errno) {
421 return RangeProcessor::operator()(
The Xapian namespace contains public interfaces for the Xapian library.
bool endswith(const std::string &s, char sfx)
static void format_yyyymmdd(char *p, int y, int m, int d)
static const char max_month_length[12]
static bool is_yyyy_mm_dd(const string &s)
static void format_int_fixed_width(char *p, int v, int w)
std::string sortable_serialise(double value)
Convert a floating point number to a string, preserving sort order.
Match only documents where a value slot is >= a given value.
Match only documents where a value slot is within a given range.
string str(int value)
Convert int to std::string.
bool startswith(const std::string &s, char pfx)
Construct an invalid query.
unsigned valueno
The number for a value slot in a document.
Various handy helpers which std::string really should provide.
static bool vet_dm(int d, int m)
Class representing a query.
const valueno BAD_VALUENO
Reserved value to indicate "no valueno".
static bool decode_xxy(const string &s, int &x1, int &x2, int &y)
parsing a user query string to build a Xapian::Query object