#ifndef QUERY_STRING_HPP #define QUERY_STRING_HPP #include "matador/utils/types.hpp" #include #include namespace matador::utils { /** * Splits a string by a delimiter and * add the string tokens to a vector. The * size of the vector is returned. * * @param str The string to split. * @param delim The delimiter character. * @return The the vector with split strings. */ std::vector split(const std::string &str, char delim); /** * Replaces all occurrences of string from in given string * with string to. * * @param in Source string where the replacement takes place * @param from The string to be replaced * @param to The new string */ void replace_all(std::string &in, const std::string &from, const std::string &to); const std::string& to_string(const std::string &str); std::string to_string(const blob &data); /** * Joins a range of elements as string within a list * with a given delimiter and writes it to the * given stream * * @tparam R Type og the range (e.g. map, list, vector, etc) * @param range The range with the elements to join * @param delim The delimiter for the elements * @return The ostream reference */ template < class R > std::string join(R &range, const std::string &delim) { std::string result {}; if (range.size() < 2) { for (const auto &i : range) { result += to_string(i); } } else { auto it = range.begin(); result += to_string(*it++); for (;it != range.end(); ++it) { result += delim + to_string(*it); } } return result; } } #endif //QUERY_STRING_HPP