1 #ifndef _ots_StringMacros_h_
2 #define _ots_StringMacros_h_
4 #include "otsdaq/Macros/CoutMacros.h"
48 static bool wildCardMatch (
const std::string& needle,
const std::string& haystack,
unsigned int* priorityIndex = 0);
49 static bool inWildCardSet (
const std::string& needle,
const std::set<std::string>& haystack);
57 static T& getWildCardMatchFromMap (
58 const std::string& needle,
59 std::map<std::string, T>& haystack,
60 std::string* foundKey = 0);
62 static std::string decodeURIComponent (
const std::string& data);
63 static std::string encodeURIComponent (
const std::string& data);
64 static std::string convertEnvironmentVariables (
const std::string& data);
66 static bool isNumber (
const std::string& stringToCheck);
67 static std::string getNumberType (
const std::string& stringToCheck);
69 static bool getNumber (
const std::string& s, T& retValue);
71 static bool getNumber (
const std::string& s,
bool& retValue);
73 static std::string getTimestampString (
const std::string& linuxTimeInSeconds);
74 static std::string getTimestampString (
const time_t& linuxTimeInSeconds = time(0));
80 static T validateValueForDefaultStringDataType (
81 const std::string& value,
82 bool doConvertEnvironmentVariables =
true);
83 static std::string validateValueForDefaultStringDataType (
84 const std::string& value,
85 bool doConvertEnvironmentVariables =
true);
87 static void getSetFromString (
const std::string& inputString, std::set<std::string>& setToReturn,
const std::set<char>& delimiter = {
',',
'|',
'&'},
const std::set<char>& whitespace = {
' ',
'\t',
'\n',
'\r'});
92 class S = std::string >
93 static void getMapFromString (
94 const std::string& inputString,
95 std::map<S, T>& mapToReturn,
96 const std::set<char>& pairPairDelimiter = {
',',
'|',
'&'},
97 const std::set<char>& nameValueDelimiter = {
'=',
':'},
98 const std::set<char>& whitespace = {
' ',
'\t',
'\n',
'\r'});
99 static void getMapFromString (
100 const std::string& inputString,
101 std::map<std::string, std::string>& mapToReturn,
102 const std::set<char>& pairPairDelimiter = {
',',
'|',
'&'},
103 const std::set<char>& nameValueDelimiter = {
'=',
':'},
104 const std::set<char>& whitespace = {
' ',
'\t',
'\n',
'\r'});
105 static void getVectorFromString (
106 const std::string& inputString,
107 std::vector<std::string>& listToReturn,
108 const std::set<char>& delimiter = {
',',
'|',
'&'},
109 const std::set<char>& whitespace = {
' ',
'\t',
'\n',
'\r'},
110 std::vector<char>* listOfDelimiters = 0);
111 static std::vector<std::string> getVectorFromString (
112 const std::string& inputString,
113 const std::set<char>& delimiter = {
',',
'|',
'&'},
114 const std::set<char>& whitespace = {
' ',
'\t',
'\n',
'\r'},
115 std::vector<char>* listOfDelimiters = 0);
121 static std::string mapToString (
122 const std::map<std::string, T>& mapToReturn,
123 const std::string& primaryDelimeter =
", ",
124 const std::string& secondaryDelimeter =
": ");
126 static std::string mapToString (
127 const std::map<std::pair<std::string, std::string>, T>& mapToReturn,
128 const std::string& primaryDelimeter =
", ",
129 const std::string& secondaryDelimeter =
": ");
131 static std::string mapToString (
132 const std::map<std::pair<std::string, std::pair<std::string, std::string>>, T>&
134 const std::string& primaryDelimeter =
", ",
135 const std::string& secondaryDelimeter =
": ");
137 static std::string mapToString (
138 const std::map<std::string, std::pair<std::string, T>>& mapToReturn,
139 const std::string& primaryDelimeter =
", ",
140 const std::string& secondaryDelimeter =
": ");
142 static std::string mapToString (
143 const std::map<std::string, std::map<std::string, T>>& mapToReturn,
144 const std::string& primaryDelimeter =
", ",
145 const std::string& secondaryDelimeter =
": ");
147 static std::string mapToString (
148 const std::map<std::string, std::set<T>>& mapToReturn,
149 const std::string& primaryDelimeter =
", ",
150 const std::string& secondaryDelimeter =
": ");
152 static std::string mapToString (
153 const std::map<std::string, std::vector<T>>& mapToReturn,
154 const std::string& primaryDelimeter =
", ",
155 const std::string& secondaryDelimeter =
": ");
156 static std::string mapToString (
157 const std::map<std::string, uint8_t>& mapToReturn,
158 const std::string& primaryDelimeter =
", ",
159 const std::string& secondaryDelimeter =
": ");
165 static std::string setToString (
166 const std::set<T>& setToReturn,
167 const std::string& delimeter =
", ");
168 static std::string setToString (
169 const std::set<uint8_t>& setToReturn,
170 const std::string& delimeter =
", ");
171 template<
class S,
class T>
172 static std::string setToString (
173 const std::set<std::pair<S, T>>& setToReturn,
174 const std::string& primaryDelimeter =
", ",
175 const std::string& secondaryDelimeter =
":");
181 static std::string vectorToString (
182 const std::vector<T>& setToReturn,
183 const std::string& delimeter =
", ");
184 static std::string vectorToString (
185 const std::vector<uint8_t>& setToReturn,
186 const std::string& delimeter =
", ");
187 template<
class S,
class T>
188 static std::string vectorToString (
189 const std::vector<std::pair<S, T>>& setToReturn,
190 const std::string& primaryDelimeter =
"; ",
191 const std::string& secondaryDelimeter =
":");
193 static bool extractCommonChunks (
const std::vector<std::string>& haystack, std::vector<std::string>& commonChunksToReturn, std::vector<std::string>& wildcardStrings,
unsigned int& fixedWildcardLength);
195 static std::string demangleTypeName (
const char* name);
197 static std::string getTypeName (
void) {
return StringMacros::demangleTypeName(
typeid(T).name());}
198 static std::string stackTrace (
void);
199 static std::string exec (
const char* cmd);
201 static char* otsGetEnvironmentVarable (
const char* name,
const std::string& location,
const unsigned int& line);
206 bool operator() (
const std::string& lhs,
const std::string& rhs)
const;
212 #include "otsdaq/Macros/StringMacros.icc"