Switch to unified view

a/src/rcldb/daterange.cpp b/src/rcldb/daterange.cpp
...
...
52
}
52
}
53
53
54
Xapian::Query date_range_filter(int y1, int m1, int d1, int y2, int m2, int d2)
54
Xapian::Query date_range_filter(int y1, int m1, int d1, int y2, int m2, int d2)
55
{
55
{
56
    // Xapian uses a smallbuf and snprintf. Can't be bothered, we're
56
    // Xapian uses a smallbuf and snprintf. Can't be bothered, we're
57
    // only doing %d's !
57
    // doing at most 3 %d's !
58
    char buf[200];
58
    char buf[200];
59
    bufprefix(buf, 'D');
60
    sprintf(buf+bpoffs(), "%04d%02d", y1, m1);
61
    vector<Xapian::Query> v;
59
    vector<Xapian::Query> v;
62
60
61
    // Deal with days till the end of the first month if any
62
    bufprefix(buf, 'D');
63
    sprintf(buf + bpoffs(), "%04d%02d", y1, m1);
63
    int d_last = monthdays(m1, y1);
64
    int d_last = monthdays(m1, y1);
64
    int d_end = d_last;
65
    int d_end = d_last;
65
    if (y1 == y2 && m1 == m2 && d2 < d_last) {
66
    if (y1 == y2 && m1 == m2 && d2 < d_last) {
66
    d_end = d2;
67
    d_end = d2;
67
    }
68
    }
68
    // Deal with any initial partial month
69
    if (d1 > 1 || d_end < d_last) {
69
    if (d1 > 1 || d_end < d_last) {
70
        for ( ; d1 <= d_end ; d1++) {
70
        for ( ; d1 <= d_end ; d1++) {
71
        sprintf(buf + 6 + bpoffs(), "%02d", d1);
71
        sprintf(buf + 6 + bpoffs(), "%02d", d1);
72
        v.push_back(Xapian::Query(buf));
72
        v.push_back(Xapian::Query(buf));
73
    }
73
    }
...
...
78
    
78
    
79
    if (y1 == y2 && m1 == m2) {
79
    if (y1 == y2 && m1 == m2) {
80
    return Xapian::Query(Xapian::Query::OP_OR, v.begin(), v.end());
80
    return Xapian::Query(Xapian::Query::OP_OR, v.begin(), v.end());
81
    }
81
    }
82
82
83
    // Months till the end of first year
83
    int m_last = (y1 < y2) ? 12 : m2 - 1;
84
    int m_last = (y1 < y2) ? 12 : m2 - 1;
85
    bufprefix(buf, 'M');
84
    while (++m1 <= m_last) {
86
    while (++m1 <= m_last) {
85
    sprintf(buf + 4 + bpoffs(), "%02d", m1);
87
    sprintf(buf + 4 + bpoffs(), "%02d", m1);
86
  bufprefix(buf, 'M');
87
    v.push_back(Xapian::Query(buf));
88
    v.push_back(Xapian::Query(buf));
88
    }
89
    }
89
  
90
91
    // Years inbetween and first months of the last year
90
    if (y1 < y2) {
92
    if (y1 < y2) {
93
        bufprefix(buf, 'Y');
91
    while (++y1 < y2) {
94
    while (++y1 < y2) {
92
        sprintf(buf + bpoffs(), "%04d", y1);
95
        sprintf(buf + bpoffs(), "%04d", y1);
93
      bufprefix(buf, 'Y');
94
        v.push_back(Xapian::Query(buf));
96
        v.push_back(Xapian::Query(buf));
95
    }
97
    }
98
  bufprefix(buf, 'M');
96
    sprintf(buf + bpoffs(), "%04d", y2);
99
    sprintf(buf + bpoffs(), "%04d", y2);
97
  bufprefix(buf, 'M');
98
    for (m1 = 1; m1 < m2; m1++) {
100
    for (m1 = 1; m1 < m2; m1++) {
99
        sprintf(buf + 4 + bpoffs(), "%02d", m1);
101
        sprintf(buf + 4 + bpoffs(), "%02d", m1);
100
        v.push_back(Xapian::Query(buf));
102
        v.push_back(Xapian::Query(buf));
101
    }
103
    }
102
    }
104
    }
103
  
105
106
    // Last month
104
    sprintf(buf + 2 + bpoffs(), "%02d", m2);
107
    sprintf(buf + 4 + bpoffs(), "%02d", m2);
105
108
106
    // Deal with any final partial month
109
    // Deal with any final partial month
107
    if (d2 < monthdays(m2, y2)) {
110
    if (d2 < monthdays(m2, y2)) {
108
    bufprefix(buf, 'D');
111
    bufprefix(buf, 'D');
109
        for (d1 = 1 ; d1 <= d2; d1++) {
112
        for (d1 = 1 ; d1 <= d2; d1++) {