Source · fairmq/tools/
Strings.hpublic header
Described in Helpers in fair::mq::tools.
1/********************************************************************************2 * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *3 * *4 * This software is distributed under the terms of the *5 * GNU Lesser General Public Licence (LGPL) version 3, *6 * copied verbatim in the file "LICENSE" *7 ********************************************************************************/8 9#ifndef FAIR_MQ_TOOLS_STRINGS_H10#define FAIR_MQ_TOOLS_STRINGS_H11 12#include <array>13#include <initializer_list>14#include <sstream>15#include <string>16#include <vector>17 18namespace fair::mq::tools19{20 21/// @brief concatenates a variable number of args with the << operator via a stringstream22/// @param t objects to be concatenated23/// @return concatenated string24template<typename ... T>25auto ToString(T&&... t) -> std::string26{27 std::stringstream ss;28 (void)std::initializer_list<int>{(ss << t, 0)...};29 return ss.str();30}31 32/// @brief convert command line arguments from main function to vector of strings33inline auto ToStrVector(const int argc, char*const* argv, const bool dropProgramName = true) -> std::vector<std::string>34{35 if (dropProgramName) {36 return std::vector<std::string>(argv + 1, argv + argc);37 } else {38 return std::vector<std::string>(argv, argv + argc);39 }40}41 42inline bool StrStartsWith(std::string const& str, std::string const& start)43{44 if (str.length() >= start.length()) {45 return (0 == str.compare(0, start.length(), start));46 } else {47 return false;48 }49}50 51inline bool StrEndsWith(std::string const& str, std::string const& end)52{53 if (str.length() >= end.length()) {54 return (0 == str.compare(str.length() - end.length(), end.length(), end));55 } else {56 return false;57 }58}59 60} // namespace fair::mq::tools61 62#endif /* FAIR_MQ_TOOLS_STRINGS_H */