Overpass API regression suite coverage (Saxony) / 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
2922114644 q{
3022114644 q int64 rhs_l = 0;
3122114644 q if (try_int64(rhs_s, rhs_l))
3299268 q return to_string(rhs_l);
3421122041 q double rhs_d = 0;
3521122041 q if (try_starts_with_double(rhs_s, rhs_d))
36589556 q return to_string(rhs_d);
3815226539 q return "NaN";
3921122041 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
5021196020 q{
5121196020 q int64 rhs_l = 0;
5221196020 q if (try_int64(rhs_s, rhs_l))
53594 q return "1";
5521190117 q double rhs_d = 0;
5621190117 q if (try_starts_with_double(rhs_s, rhs_d))
57392 q return "1";
5921186216 q return "0";
6021190117 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
7146646954 q{
7246646954 q return double_suffix(rhs_s);
7346646954 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
8435173021 q{
8535173021 q int64 rhs_l = 0;
8635173021 q if (try_int64(rhs_s, rhs_l))
8733301614 q return to_string(std::abs(rhs_l));
891871410 q double rhs_d = 0;
901871410 q if (try_starts_with_double(rhs_s, rhs_d))
91187128 q return to_string(std::abs(rhs_d));
9322 q return "NaN";
941871410 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
10514972737 q{
106 //First run: try for year, month, day, hour, minute, second
10714972737 q std::string::size_type pos = 0;
10924327637 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
110935499 q ++pos;
11114972737 q unsigned int year = 0;
11240121037 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
11325148325 q {
11425148325 q year = 10*year + (rhs_s[pos] - '0');
11525148325 q ++pos;
11625148325 q }
11819878237 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
1194905524 q ++pos;
12014972737 q unsigned int month = 0;
12124757637 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
1229784924 q {
1239784924 q month = 10*month + (rhs_s[pos] - '0');
1249784924 q ++pos;
1259784924 q }
12719862837 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
1284890124 q ++pos;
12914972737 q unsigned int day = 0;
13024751837 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
1319779124 q {
1329779124 q day = 10*day + (rhs_s[pos] - '0');
1339779124 q ++pos;
1349779124 q }
13617559037 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
1372586324 q ++pos;
13814972737 q unsigned int hour = 0;
13920144937 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
1405172223 q {
1415172223 q hour = 10*hour + (rhs_s[pos] - '0');
1425172223 q ++pos;
1435172223 q }
14517558837 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
1462586123 q ++pos;
14714972737 q unsigned int minute = 0;
14820144937 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
1495172223 q {
1505172223 q minute = 10*minute + (rhs_s[pos] - '0');
1515172223 q ++pos;
1525172223 q }
15417558837 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
1552586123 q ++pos;
15614972737 q unsigned int second = 0;
15719689337 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
1584716622 q {
1594716622 q second = 10*second + (rhs_s[pos] - '0');
1604716622 q ++pos;
1614716622 q }
16314972737 q if (year < 1000 || month > 12 || day > 31 || hour > 23 || minute > 59 || second > 60)
16410300819 q return "NaD";
1664671923 q return to_string(year + month/16. + day/(16.*32)
1674671923 q + hour/(16.*32*32) + minute/(16.*32*32*64) + second/(16.*32*32*64*64));
16814972737 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
17969621123 q{
180 //First run: try for year, month, day, hour, minute, second
18169621123 q std::string::size_type pos = 0;
183284886223 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
184215265112 q ++pos;
18569621123 q unsigned int year = 0;
186130311323 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
1876069027 q {
1886069027 q year = 10*year + (rhs_s[pos] - '0');
1896069027 q ++pos;
1906069027 q }
19271510323 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
193188925 q ++pos;
19469621123 q unsigned int month = 0;
19573302223 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
196368115 q {
197368115 q month = 10*month + (rhs_s[pos] - '0');
198368115 q ++pos;
199368115 q }
20171462123 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
202184104 q ++pos;
20369621123 q unsigned int day = 0;
20473301523 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
205368043 q {
206368043 q day = 10*day + (rhs_s[pos] - '0');
207368043 q ++pos;
208368043 q }
21071461323 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
211184023 q ++pos;
21269621123 q unsigned int hour = 0;
21373301523 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
214368043 q {
215368043 q hour = 10*hour + (rhs_s[pos] - '0');
216368043 q ++pos;
217368043 q }
21971461323 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
220184023 q ++pos;
22169621123 q unsigned int minute = 0;
22273301523 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
223368043 q {
224368043 q minute = 10*minute + (rhs_s[pos] - '0');
225368043 q ++pos;
226368043 q }
22871461323 q while (pos < rhs_s.size() && !isdigit(rhs_s[pos]))
229184023 q ++pos;
23069621123 q unsigned int second = 0;
23171489923 q while (pos < rhs_s.size() && isdigit(rhs_s[pos]))
232186882 q {
233186882 q second = 10*second + (rhs_s[pos] - '0');
234186882 q ++pos;
235186882 q }
23769621123 q if (year < 1000 || month > 12 || day > 31 || hour > 23 || minute > 59 || second > 60)
23862596621 q return "0";
240702454 q return "1";
24169621123 q}