Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/string_endomorphisms.cc

overpass_api/statements/string_endomorphisms.cc

139 of 139 instrumented lines run by the suite (100.0%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#include "../data/tag_store.h"
20#include "../data/utils.h"
21#include "string_endomorphisms.h"
24String_Endom_Statement_Maker< Evaluator_Number > Evaluator_Number::statement_maker;
25String_Endom_Evaluator_Maker< Evaluator_Number > Evaluator_Number::evaluator_maker;
28std::string Evaluator_Number::process(const std::string& rhs_s) const
2913005143 q{
3013005143 q int64 rhs_l = 0;
3113005143 q if (try_int64(rhs_s, rhs_l))
32184 q return to_string(rhs_l);
3413003342 q double rhs_d = 0;
3513003342 q if (try_starts_with_double(rhs_s, rhs_d))
36372609 q return to_string(rhs_d);
389277338 q return "NaN";
3913003342 q}
42//-----------------------------------------------------------------------------
45String_Endom_Statement_Maker< Evaluator_Is_Num > Evaluator_Is_Num::statement_maker;
46String_Endom_Evaluator_Maker< Evaluator_Is_Num > Evaluator_Is_Num::evaluator_maker;
49std::string Evaluator_Is_Num::process(const std::string& rhs_s) const
503828216 q{
513828216 q int64 rhs_l = 0;
523828216 q if (try_int64(rhs_s, rhs_l))
53103 q return "1";
553827213 q double rhs_d = 0;
563827213 q if (try_starts_with_double(rhs_s, rhs_d))
573482 q return "1";
593792411 q return "0";
603827213 q}
63//-----------------------------------------------------------------------------
66String_Endom_Statement_Maker< Evaluator_Suffix > Evaluator_Suffix::statement_maker;
67String_Endom_Evaluator_Maker< Evaluator_Suffix > Evaluator_Suffix::evaluator_maker;
70std::string Evaluator_Suffix::process(const std::string& rhs_s) const
7139614450 q{
7239614450 q return double_suffix(rhs_s);
7339614450 q}
76//-----------------------------------------------------------------------------
79String_Endom_Statement_Maker< Evaluator_Abs > Evaluator_Abs::statement_maker;
80String_Endom_Evaluator_Maker< Evaluator_Abs > Evaluator_Abs::evaluator_maker;
83std::string Evaluator_Abs::process(const std::string& rhs_s) const
847959818 q{
857959818 q int64 rhs_l = 0;
867959818 q if (try_int64(rhs_s, rhs_l))
877508611 q return to_string(std::abs(rhs_l));
8945129 q double rhs_d = 0;
9045129 q if (try_starts_with_double(rhs_s, rhs_d))
9145047 q return to_string(std::abs(rhs_d));
9383 q return "NaN";
9445129 q}
97//-----------------------------------------------------------------------------
100String_Endom_Statement_Maker< Evaluator_Date > Evaluator_Date::statement_maker;
101String_Endom_Evaluator_Maker< Evaluator_Date > Evaluator_Date::evaluator_maker;
104std::string Evaluator_Date::process(const std::string& rhs_s) const
10546256245 q{
106 //First run: try for year, month, day, hour, minute, second
10746256245 q std::string::size_type pos = 0;
10948242145 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
110198598 q ++pos;
11146256245 q unsigned int year = 0;
112138278445 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
11392022229 q {
11492022229 q year = 10*year + (rhs_s[pos] - '0');
11592022229 q ++pos;
11692022229 q }
11868741545 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
11922485326 q ++pos;
12046256245 q unsigned int month = 0;
12191225445 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
12244969226 q {
12344969226 q month = 10*month + (rhs_s[pos] - '0');
12444969226 q ++pos;
12544969226 q }
12768740845 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
12822484626 q ++pos;
12946256245 q unsigned int day = 0;
13091225445 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
13144969226 q {
13244969226 q day = 10*day + (rhs_s[pos] - '0');
13344969226 q ++pos;
13444969226 q }
13668008645 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
13721752426 q ++pos;
13846256245 q unsigned int hour = 0;
13989761045 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
14043504826 q {
14143504826 q hour = 10*hour + (rhs_s[pos] - '0');
14243504826 q ++pos;
14343504826 q }
14568008645 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
14621752426 q ++pos;
14746256245 q unsigned int minute = 0;
14889761045 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
14943504826 q {
15043504826 q minute = 10*minute + (rhs_s[pos] - '0');
15143504826 q ++pos;
15243504826 q }
15468008645 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
15521752426 q ++pos;
15646256245 q unsigned int second = 0;
15789634645 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
15843378425 q {
15943378425 q second = 10*second + (rhs_s[pos] - '0');
16043378425 q ++pos;
16143378425 q }
16346256245 q if (year < 1000 || month > 12 || day > 31 || hour > 23 || minute > 59 || second > 60)
16423827421 q return "NaD";
16622428826 q return to_string(year + month/16. + day/(16.*32)
16722428826 q + hour/(16.*32*32) + minute/(16.*32*32*64) + second/(16.*32*32*64*64));
16846256245 q}
171//-----------------------------------------------------------------------------
174String_Endom_Statement_Maker< Evaluator_Is_Date > Evaluator_Is_Date::statement_maker;
175String_Endom_Evaluator_Maker< Evaluator_Is_Date > Evaluator_Is_Date::evaluator_maker;
178std::string Evaluator_Is_Date::process(const std::string& rhs_s) const
17912535823 q{
180 //First run: try for year, month, day, hour, minute, second
18112535823 q std::string::size_type pos = 0;
18318100323 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
1845564511 q ++pos;
18512535823 q unsigned int year = 0;
18643349723 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
1873081399 q {
1883081399 q year = 10*year + (rhs_s[pos] - '0');
1893081399 q ++pos;
1903081399 q }
19218134223 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
193559846 q ++pos;
19412535823 q unsigned int month = 0;
19523716323 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
1961118055 q {
1971118055 q month = 10*month + (rhs_s[pos] - '0');
1981118055 q ++pos;
1991118055 q }
20118124823 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
202558905 q ++pos;
20312535823 q unsigned int day = 0;
20423713723 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
2051117795 q {
2061117795 q day = 10*day + (rhs_s[pos] - '0');
2071117795 q ++pos;
2081117795 q }
21017869623 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
211533384 q ++pos;
21212535823 q unsigned int hour = 0;
21323203323 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
2141066754 q {
2151066754 q hour = 10*hour + (rhs_s[pos] - '0');
2161066754 q ++pos;
2171066754 q }
21917869523 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
220533373 q ++pos;
22112535823 q unsigned int minute = 0;
22223203223 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
2231066743 q {
2241066743 q minute = 10*minute + (rhs_s[pos] - '0');
2251066743 q ++pos;
2261066743 q }
22817869523 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
229533373 q ++pos;
23012535823 q unsigned int second = 0;
23116449023 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
232391322 q {
233391322 q second = 10*second + (rhs_s[pos] - '0');
234391322 q ++pos;
235391322 q }
23712535823 q if (year < 1000 || month > 12 || day > 31 || hour > 23 || minute > 59 || second > 60)
2388565621 q return "0";
240397024 q return "1";
24112535823 q}