Overpass API regression suite coverage (Saxony) / overpass_api/statements/string_endomorphisms.h
overpass_api/statements/string_endomorphisms.h
53 of 54 instrumented lines run by the suite (98.1%) 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 modify6 * it under the terms of the GNU Affero General Public License as7 * published by the Free Software Foundation, either version 3 of the8 * 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 of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU General Public License for more details.14 *15 * You should have received a copy of the GNU Affero General Public License16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.17 */19#ifndef DE__OSM3S___OVERPASS_API__STATEMENTS__STRING_ENDOMORPHISMS_H20#define DE__OSM3S___OVERPASS_API__STATEMENTS__STRING_ENDOMORPHISMS_H23#include "../data/tag_store.h"24#include "../data/utils.h"25#include "evaluator.h"26#include "statement.h"27#include "unary_functions.h"29#include <map>30#include <string>33/* === String Endomorphisms ===35String endomorphisms are functions with one argument.36Many of them help to normalize or check the value of its argument.37They always first let their argument be evaluated.38Their syntax is always40 <Function Name>(<Evaluator>)41*/43template< typename Evaluator_ >44struct String_Endom_Statement_Maker : public Generic_Statement_Maker< Evaluator_ >45{4616608692 q String_Endom_Statement_Maker() : Generic_Statement_Maker< Evaluator_ >(Evaluator_::stmt_name()) {}47};50template< typename Evaluator_ >51struct String_Endom_Evaluator_Maker : public Statement::Evaluator_Maker52{53 virtual Statement* create_evaluator(const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,54 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)561384131 q if (!tree_it.assert_is_function(error_output) || !tree_it.assert_has_input_set(error_output, false)611380131 q Statement* result = new Evaluator_(tree_it->line_col.first, attributes, global_settings);75 String_Endom_Evaluator_Maker()79};82template< typename Evaluator_ >83struct Evaluator_String_Endom_Syntax : public Evaluator_Unary_Function84{85 Evaluator_String_Endom_Syntax(int line_number_, const std::map< std::string, std::string >& input_attributes)92 virtual std::string dump_xml(const std::string& indent) const99 virtual std::string dump_compact_ql(const std::string&) const101690131 q return Evaluator_::stmt_func_name() + "(" + (rhs ? rhs->dump_compact_ql("") : "") + ")";105};108/* ==== Number Check, Normalizer and Suffix ====110The function <em>number</em> turns its argument into a number.111If its argument starts with a number then <em>number</em> returns that number in a normalized format.112Otherwise it returns "NaN".113The function <em>is_number</em> checks whether its argument starts with a number.114It returns "1" if its argument can be parsed as a number and "0" otherwise.115The function <em>suffix</em> returns the suffix if any after the number in its argument.116If the argument does not start with a number then it returns the empty string.118Their syntaxes are120 number(<Evaluator>)122resp.124 is_number(<Evaluator>)126resp.128 suffix(<Evaluator>)130*/132class Evaluator_Number : public Evaluator_String_Endom_Syntax< Evaluator_Number >133{134public:135 static String_Endom_Statement_Maker< Evaluator_Number > statement_maker;136 static String_Endom_Evaluator_Maker< Evaluator_Number > evaluator_maker;140 Evaluator_Number(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)143 virtual std::string process(const std::string& rhs_result) const;144};147class Evaluator_Is_Num : public Evaluator_String_Endom_Syntax< Evaluator_Is_Num >148{149public:150 static String_Endom_Statement_Maker< Evaluator_Is_Num > statement_maker;151 static String_Endom_Evaluator_Maker< Evaluator_Is_Num > evaluator_maker;155 Evaluator_Is_Num(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)158 virtual std::string process(const std::string& rhs_result) const;159};162class Evaluator_Suffix : public Evaluator_String_Endom_Syntax< Evaluator_Suffix >163{164public:165 static String_Endom_Statement_Maker< Evaluator_Suffix > statement_maker;166 static String_Endom_Evaluator_Maker< Evaluator_Suffix > evaluator_maker;170 Evaluator_Suffix(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)173 virtual std::string process(const std::string& rhs_result) const;174};177/* ==== Processing numbers ====179The function <em>abs</em> returns the absolute value of its argument.180If its argument starts with a number then <em>abs</em> still returns the absolute value of its argument.181Otherwise it returns "NaN".183Its syntax is185 abs(<Evaluator>)187*/189class Evaluator_Abs : public Evaluator_String_Endom_Syntax< Evaluator_Abs >190{191public:192 static String_Endom_Statement_Maker< Evaluator_Abs > statement_maker;193 static String_Endom_Evaluator_Maker< Evaluator_Abs > evaluator_maker;197 Evaluator_Abs(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)200 virtual std::string process(const std::string& rhs_result) const;201};204/* ==== Date Check and Normalizer ====206The function <em>date</em> turns its argument into a number representing a date.207If its argument is a date then <em>date</em> returns the number representing its argument's value.208Otherwise it returns "NaD".209The function <em>is_date</em> checks whether its argument represents a date.210It returns "1" if its argument can be parsed as a date and "0" otherwise.212A string is parsed for a date as follows:213* the first group of digits is understood as year214* the next group of digits if present is understood as month215* then the next group if present is understood as day216* if more groups of digits are present then they are understood as hour, minute, second217To be a date the year must be bigger than 1000,218the month if present less or equal 12,219the day if present less or equal 31,220the hour if present less or equal 24,221and the minute and second if present less or equal 60.223The date parser may get more liberal in future versions and accept more representations of dates.225The functions' syntaxes are227 date(<Evaluator>)229resp.231 is_date(<Evaluator>)232*/234class Evaluator_Date : public Evaluator_String_Endom_Syntax< Evaluator_Date >235{236public:237 static String_Endom_Statement_Maker< Evaluator_Date > statement_maker;238 static String_Endom_Evaluator_Maker< Evaluator_Date > evaluator_maker;242 Evaluator_Date(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)245 virtual std::string process(const std::string& rhs_result) const;246};249class Evaluator_Is_Date : public Evaluator_String_Endom_Syntax< Evaluator_Is_Date >250{251public:252 static String_Endom_Statement_Maker< Evaluator_Is_Date > statement_maker;253 static String_Endom_Evaluator_Maker< Evaluator_Is_Date > evaluator_maker;257 Evaluator_Is_Date(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)260 virtual std::string process(const std::string& rhs_result) const;261};264#endif