1 #include "otsdaq/Macros/StringMacros.h"
20 const std::string& haystack,
21 unsigned int* priorityIndex)
29 if(needle.size() == 0)
45 if(needle == haystack)
53 if(needle[needle.size() - 1] ==
'*' &&
54 needle.substr(0, needle.size() - 1) == haystack.substr(0, needle.size() - 1))
62 if(needle[0] ==
'*' &&
63 needle.substr(1) == haystack.substr(haystack.size() - (needle.size() - 1)))
71 if(needle[0] ==
'*' && needle[needle.size() - 1] ==
'*' &&
72 std::string::npos != haystack.find(needle.substr(1, needle.size() - 2)))
96 const std::set<std::string>& haystack)
98 for(
const auto& haystackString : haystack)
101 if(haystackString.size() && haystackString[0] ==
'!')
118 std::string decodeURIString(data.size(), 0);
120 for(
unsigned int i = 0; i < data.size(); ++i, ++j)
125 if(data[i + 1] >
'9')
126 decodeURIString[j] += (data[i + 1] - 55) * 16;
128 decodeURIString[j] += (data[i + 1] - 48) * 16;
131 if(data[i + 2] >
'9')
132 decodeURIString[j] += (data[i + 2] - 55);
134 decodeURIString[j] += (data[i + 2] - 48);
139 decodeURIString[j] = data[i];
141 decodeURIString.resize(j);
142 return decodeURIString;
146 std::string StringMacros::encodeURIComponent(
const std::string& sourceStr)
148 std::string retStr =
"";
150 for(
const auto& c : sourceStr)
151 if((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z') || (c >=
'0' && c <=
'9'))
155 sprintf(encodeStr,
"%%%2.2X", (uint8_t)c);
165 std::map<char, std::string> replacements = {
173 while(pos < str.size())
175 auto it = replacements.find(str[pos]);
176 if(it != replacements.end())
178 str.replace(pos, 1, it->second);
179 pos += it->second.size();
198 bool allowWhiteSpace )
200 unsigned int ws = -1;
203 __COUTVS__(30, allowWhiteSpace);
205 for(
unsigned int i = 0; i < inString.length(); i++)
206 if(inString[i] !=
' ')
208 __COUTS__(30) << i <<
". " << inString[i] <<
":" << (int)inString[i]
212 if(inString[i] ==
'\r' || inString[i] ==
'\n' ||
213 inString[i] ==
'\t' ||
216 (inString[i] >
char(126) &&
217 inString[i] <
char(161)))
224 if(i + 2 < inString.size() && inString[i] == char(0xE2) &&
225 inString[i + 1] == char(0x80) &&
244 if(inString[i] ==
'\n')
248 sprintf(htmlTmp,
"&#%3.3d", inString[i]);
250 i, std::string(htmlTmp));
259 else if(inString[i] ==
'\t')
267 "        ");
269 i, std::string(htmlTmp));
277 sprintf(htmlTmp,
"	");
279 i, std::string(htmlTmp));
291 inString.erase(i, 1);
294 __COUTS__(31) << inString << std::endl;
298 __COUTS__(31) << inString << std::endl;
301 if(inString[i] ==
'\"' || inString[i] ==
'\'')
304 (inString[i] ==
'\'')
307 inString.replace(i + 5, 1, 1,
';');
311 else if(inString[i] ==
'&')
313 inString.insert(i,
"&");
314 inString.replace(i + 4, 1, 1,
';');
317 else if(inString[i] ==
'<' || inString[i] ==
'>')
324 inString.replace(i + 3, 1, 1,
';');
327 else if(inString[i] >=
char(161) &&
328 inString[i] <=
char(255))
330 sprintf(htmlTmp,
"&#%3.3d", inString[i]);
331 inString.insert(i, std::string(htmlTmp));
332 inString.replace(i + 5, 1, 1,
';');
336 __COUTS__(30) << inString << std::endl;
340 else if(allowWhiteSpace)
348 inString.insert(i,
" ");
351 inString.insert(i,
" ");
352 inString.replace(i + 5, 1, 1,
';');
357 __COUTS__(30) << inString.size() <<
" " << ws << std::endl;
361 __COUTS__(30) << inString.size() <<
" " << inString << std::endl;
367 if(ws == (
unsigned int)-1)
369 return inString.substr(0, ws + 1);
378 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](
unsigned char ch) {
379 return !std::isspace(ch);
383 s.erase(std::find_if(
384 s.rbegin(), s.rend(), [](
unsigned char ch) { return !std::isspace(ch); })
398 size_t begin = data.find(
"$");
399 if(begin != std::string::npos)
402 std::string envVariable;
403 std::string converted = data;
405 while(begin && begin != std::string::npos &&
406 converted[begin - 1] ==
409 converted.replace(begin - 1, 1,
"");
410 begin = data.find(
"$", begin + 1);
411 if(begin == std::string::npos)
413 __COUTS__(50) <<
"Only found escaped $'s that will not be converted: "
414 << converted << __E__;
419 if(data[begin + 1] ==
'{')
421 end = data.find(
"}", begin + 2);
422 envVariable = data.substr(begin + 2, end - begin - 2);
428 for(end = begin + 1; end < data.size(); ++end)
429 if(!((data[end] >=
'0' && data[end] <=
'9') ||
430 (data[end] >=
'A' && data[end] <=
'Z') ||
431 (data[end] >=
'a' && data[end] <=
'z') || data[end] ==
'-' ||
432 data[end] ==
'_' || data[end] ==
'.' || data[end] ==
':'))
434 envVariable = data.substr(begin + 1, end - begin - 1);
436 __COUTVS__(50, data);
437 __COUTVS__(50, envVariable);
438 char* envResult = __ENV__(envVariable.c_str());
444 converted.replace(begin, end - begin, envResult));
448 __SS__ << (
"The environmental variable '" + envVariable +
449 "' is not set! Please make sure you set it before continuing!")
455 __COUTS__(50) <<
"Result: " << data << __E__;
467 std::vector<std::string> numbers;
468 std::vector<char> ops;
476 std::set<char>({
'+',
'-',
'*',
'/'}),
477 std::set<char>({
' ',
'\t',
'\n',
'\r'}),
483 for(
const auto& number : numbers)
485 if(number.size() == 0)
488 if(number.find(
"0x") == 0)
491 for(
unsigned int i = 2; i < number.size(); ++i)
493 if(!((number[i] >=
'0' && number[i] <=
'9') ||
494 (number[i] >=
'A' && number[i] <=
'F') ||
495 (number[i] >=
'a' && number[i] <=
'f')))
503 else if(number[0] ==
'b')
507 for(
unsigned int i = 1; i < number.size(); ++i)
509 if(!((number[i] >=
'0' && number[i] <=
'1')))
519 for(
unsigned int i = 0; i < number.size(); ++i)
520 if(!((number[i] >=
'0' && number[i] <=
'9') || number[i] ==
'.' ||
521 number[i] ==
'+' || number[i] ==
'-'))
544 std::vector<std::string> numbers;
545 std::vector<char> ops;
547 bool hasDecimal =
false;
552 std::set<char>({
'+',
'-',
'*',
'/'}),
553 std::set<char>({
' ',
'\t',
'\n',
'\r'}),
559 for(
const auto& number : numbers)
561 if(number.size() == 0)
564 if(number.find(
"0x") == 0)
567 for(
unsigned int i = 2; i < number.size(); ++i)
569 if(!((number[i] >=
'0' && number[i] <=
'9') ||
570 (number[i] >=
'A' && number[i] <=
'F') ||
571 (number[i] >=
'a' && number[i] <=
'f')))
579 else if(number[0] ==
'b')
583 for(
unsigned int i = 1; i < number.size(); ++i)
585 if(!((number[i] >=
'0' && number[i] <=
'1')))
595 for(
unsigned int i = 0; i < number.size(); ++i)
596 if(!((number[i] >=
'0' && number[i] <=
'9') || number[i] ==
'.' ||
597 number[i] ==
'+' || number[i] ==
'-'))
599 else if(number[i] ==
'.')
612 return "unsigned long long";
625 __COUT_ERR__ <<
"Invalid empty bool string " << s << __E__;
630 if(s.find(
"1") != std::string::npos || s ==
"true" || s ==
"True" || s ==
"TRUE")
637 if(s.find(
"0") != std::string::npos || s ==
"false" || s ==
"False" || s ==
"FALSE")
643 __COUT_ERR__ <<
"Invalid bool string " << s << __E__;
654 time_t timestamp(strtol(linuxTimeInSeconds.c_str(), 0, 10));
664 std::string retValue(30,
'\0');
667 ::localtime_r(&linuxTimeInSeconds, &tmstruct);
668 ::strftime(&retValue[0], 30,
"%c %Z", &tmstruct);
669 retValue.resize(strlen(retValue.c_str()));
681 std::stringstream ss;
682 int days = t / 60 / 60 / 24;
685 ss << days <<
" day" << (days > 1 ?
"s" :
"") <<
", ";
686 t -= days * 60 * 60 * 24;
690 ss << std::setw(2) << std::setfill(
'0') << (t / 60 / 60) <<
":" << std::setw(2)
691 << std::setfill(
'0') << ((t % (60 * 60)) / 60) <<
":" << std::setw(2)
692 << std::setfill(
'0') << (t % 60);
700 const std::string& value,
bool doConvertEnvironmentVariables)
703 return doConvertEnvironmentVariables
707 catch(
const std::runtime_error& e)
709 __SS__ <<
"Failed to validate value for default string data type. " << __E__
710 << e.what() << __E__;
719 std::set<std::string>& setToReturn,
720 const std::set<char>& delimiter,
721 const std::set<char>& whitespace)
728 for(; j < inputString.size(); ++j)
729 if((whitespace.find(inputString[j]) !=
731 delimiter.find(inputString[j]) != delimiter.end()) &&
734 else if((whitespace.find(inputString[j]) !=
737 delimiter.find(inputString[j]) != delimiter.end()) &&
743 setToReturn.emplace(inputString.substr(i, j - i));
750 setToReturn.emplace(inputString.substr(i, j - i));
766 std::vector<std::string>& listToReturn,
767 const std::set<char>& delimiter,
768 const std::set<char>& whitespace,
769 std::vector<char>* listOfDelimiters,
770 bool decodeURIComponents)
775 std::set<char>::iterator delimeterSearchIt;
776 char lastDelimiter = 0;
785 for(; c < inputString.size(); ++c)
789 delimeterSearchIt = delimiter.find(inputString[c]);
790 isDelimiter = delimeterSearchIt != delimiter.end();
795 if(whitespace.find(inputString[c]) !=
804 else if(whitespace.find(inputString[c]) != whitespace.end() &&
814 if(listOfDelimiters && listToReturn.size())
821 listOfDelimiters->push_back(lastDelimiter);
824 inputString.substr(i, j - i))
825 : inputString.substr(i, j - i));
835 lastDelimiter = *delimeterSearchIt;
844 if(listOfDelimiters && listToReturn.size())
850 listOfDelimiters->push_back(lastDelimiter);
853 inputString.substr(i, j - i))
854 : inputString.substr(i, j - i));
858 if(listOfDelimiters && listToReturn.size() - 1 != listOfDelimiters->size() &&
859 listToReturn.size() != listOfDelimiters->size())
861 __SS__ <<
"There is a mismatch in delimiters to entries (should be equal or one "
863 << listOfDelimiters->size() <<
" vs " << listToReturn.size() << __E__
885 const std::string& inputString,
886 const std::set<char>& delimiter,
887 const std::set<char>& whitespace,
888 std::vector<char>* listOfDelimiters,
889 bool decodeURIComponents)
891 std::vector<std::string> listToReturn;
898 decodeURIComponents);
907 std::map<std::string, std::string>& mapToReturn,
908 const std::set<char>& pairPairDelimiter,
909 const std::set<char>& nameValueDelimiter,
910 const std::set<char>& whitespace)
916 bool needValue =
false;
920 for(; j < inputString.size(); ++j)
923 if((whitespace.find(inputString[j]) !=
925 pairPairDelimiter.find(inputString[j]) != pairPairDelimiter.end()) &&
928 else if((whitespace.find(inputString[j]) !=
931 nameValueDelimiter.find(inputString[j]) !=
932 nameValueDelimiter.end()) &&
938 name = inputString.substr(i, j - i);
948 if((whitespace.find(inputString[j]) !=
950 nameValueDelimiter.find(inputString[j]) != nameValueDelimiter.end()) &&
953 else if(whitespace.find(inputString[j]) !=
956 pairPairDelimiter.find(inputString[j]) !=
957 pairPairDelimiter.end())
964 mapToReturn.emplace(std::pair<std::string, std::string>(
967 inputString.substr(i, j - i))
970 if(!emplaceReturn.second)
972 __COUT__ <<
"Ignoring repetitive value ('"
973 << inputString.substr(i, j - i)
974 <<
"') and keeping current value ('"
975 << emplaceReturn.first->second <<
"'). " << __E__;
988 mapToReturn.emplace(std::pair<std::string, std::string>(
991 inputString.substr(i, j - i))
994 if(!emplaceReturn.second)
996 __COUT__ <<
"Ignoring repetitive value ('" << inputString.substr(i, j - i)
997 <<
"') and keeping current value ('" << emplaceReturn.first->second
1002 catch(
const std::runtime_error& e)
1004 __SS__ <<
"Error while extracting a map from the string '" << inputString
1005 <<
"'... is it a valid map?" << __E__ << e.what() << __E__;
1012 const std::string& primaryDelimeter,
1013 const std::string& secondaryDelimeter)
1015 std::stringstream ss;
1017 for(
auto& mapPair : mapToReturn)
1022 ss << primaryDelimeter;
1023 ss << mapPair.first << secondaryDelimeter << (
unsigned int)mapPair.second;
1031 const std::string& delimeter)
1033 std::stringstream ss;
1035 for(
auto& setValue : setToReturn)
1041 ss << (
unsigned int)setValue;
1049 const std::string& delimeter)
1051 std::stringstream ss;
1053 if(delimeter ==
"\n")
1055 for(
auto& setValue : setToReturn)
1061 ss << (
unsigned int)setValue;
1077 std::vector<std::string>& commonChunksToReturn,
1078 std::vector<std::string>& wildcardStringsToReturn,
1079 unsigned int& fixedWildcardLength)
1081 fixedWildcardLength = 0;
1106 std::pair<
unsigned int ,
unsigned int > wildcardBounds(
1107 std::make_pair(-1, 0));
1110 for(
unsigned int n = 1; n < haystack.size(); ++n)
1111 for(
unsigned int i = 0, j = 0;
1112 i < haystack[0].length() && j < haystack[n].length();
1115 if(i < wildcardBounds.first)
1117 if(haystack[0][i] != haystack[n][j])
1119 wildcardBounds.first = i;
1126 __COUTS__(3) <<
"Low side = " << wildcardBounds.first <<
" "
1127 << haystack[0].substr(0, wildcardBounds.first) << __E__;
1130 for(
unsigned int n = 1; n < haystack.size(); ++n)
1131 for(
int i = haystack[0].length() - 1, j = haystack[n].length() - 1;
1132 i >= (int)wildcardBounds.first && j >= (
int)wildcardBounds.first;
1135 if(i > (
int)wildcardBounds.second)
1137 if(haystack[0][i] != haystack[n][j])
1139 wildcardBounds.second = i + 1;
1147 __COUTS__(3) <<
"High side = " << wildcardBounds.second <<
" "
1148 << haystack[0].substr(wildcardBounds.second) << __E__;
1151 commonChunksToReturn.push_back(haystack[0].substr(0, wildcardBounds.first));
1153 if(wildcardBounds.first != (
unsigned int)-1)
1156 for(
int i = (wildcardBounds.first + wildcardBounds.second) / 2 + 1;
1157 i < (
int)wildcardBounds.second;
1159 if(haystack[0][wildcardBounds.first] == haystack[0][i] &&
1160 haystack[0].substr(wildcardBounds.first, wildcardBounds.second - i) ==
1161 haystack[0].substr(i, wildcardBounds.second - i))
1163 std::string multiWildcardString =
1164 haystack[0].substr(i, wildcardBounds.second - i);
1165 __COUT__ <<
"Potential multi-wildcard found: " << multiWildcardString
1166 <<
" at position i=" << i << __E__;
1168 std::vector<
unsigned int > wildCardInstances;
1170 wildCardInstances.push_back(wildcardBounds.first);
1172 unsigned int offset =
1173 wildCardInstances[0] + multiWildcardString.size() + 1;
1174 std::string middleString = haystack[0].substr(offset, (i - 1) - offset);
1175 __COUTV__(middleString);
1179 while((k = middleString.find(multiWildcardString)) != std::string::npos)
1181 __COUT__ <<
"Multi-wildcard found at " << k << __E__;
1183 wildCardInstances.push_back(offset + k);
1186 middleString.substr(k + multiWildcardString.size() + 1);
1187 offset += k + multiWildcardString.size() + 1;
1188 __COUTV__(middleString);
1192 wildCardInstances.push_back(i);
1194 for(
unsigned int w = 0; w < wildCardInstances.size() - 1; ++w)
1196 __COUTV__(wildCardInstances[w]);
1197 __COUTV__(wildCardInstances[w + 1]);
1198 __COUTV__(wildCardInstances.size());
1199 commonChunksToReturn.push_back(haystack[0].substr(
1200 wildCardInstances[w] + multiWildcardString.size(),
1201 wildCardInstances[w + 1] -
1202 (wildCardInstances[w] + multiWildcardString.size())));
1208 for(
unsigned int c = 1; c < commonChunksToReturn.size(); ++c)
1210 __COUT__ <<
"Checking [" << c <<
"]: " << commonChunksToReturn[c] << __E__;
1211 for(
unsigned int n = 1; n < haystack.size(); ++n)
1213 __COUT__ <<
"Checking chunks work with haystack [" << n
1214 <<
"]: " << haystack[n] << __E__;
1215 __COUTV__(commonChunksToReturn[0].size());
1216 std::string wildCardValue = haystack[n].substr(
1217 commonChunksToReturn[0].size(),
1218 haystack[n].find(commonChunksToReturn[1],
1219 commonChunksToReturn[0].size() + 1) -
1220 commonChunksToReturn[0].size());
1221 __COUTTV__(wildCardValue);
1223 std::string builtString =
"";
1224 for(
unsigned int cc = 0; cc < commonChunksToReturn.size(); ++cc)
1225 builtString += commonChunksToReturn[cc] + wildCardValue;
1226 __COUTTV__(builtString);
1227 __COUTTV__(wildCardValue);
1229 if(haystack[n].find(builtString) != 0)
1231 __COUT__ <<
"Dropping common chunk " << commonChunksToReturn[c]
1232 <<
", built '" << builtString <<
"' not found in "
1233 << haystack[n] << __E__;
1234 commonChunksToReturn.erase(commonChunksToReturn.begin() + c);
1239 __COUTT__ <<
"Found built '" << builtString <<
"' in " << haystack[n]
1245 __COUTTV__(commonChunksToReturn[0].size());
1247 __COUTTV__(fixedWildcardLength);
1249 for(
unsigned int i = 0; i < commonChunksToReturn[0].size(); ++i)
1250 if(commonChunksToReturn[0][commonChunksToReturn[0].size() - 1 - i] ==
'0')
1252 ++fixedWildcardLength;
1253 __COUTT__ <<
"Trying for added fixed length +1 to " << fixedWildcardLength
1260 for(
unsigned int c = 0; c < commonChunksToReturn.size(); ++c)
1262 unsigned int cnt = 0;
1263 for(
unsigned int i = 0; i < commonChunksToReturn[c].size(); ++i)
1264 if(commonChunksToReturn[c][commonChunksToReturn[c].size() - 1 - i] ==
'0')
1269 if(fixedWildcardLength < cnt)
1270 fixedWildcardLength = cnt;
1271 else if(fixedWildcardLength > cnt)
1273 __SS__ <<
"Invalid fixed length found, please simplify indexing between "
1274 "these common chunks: "
1279 __COUTTV__(fixedWildcardLength);
1281 if(fixedWildcardLength)
1282 for(
unsigned int c = 0; c < commonChunksToReturn.size(); ++c)
1283 commonChunksToReturn[c] = commonChunksToReturn[c].substr(
1284 0, commonChunksToReturn[c].size() - fixedWildcardLength);
1287 commonChunksToReturn.push_back(haystack[0].substr(wildcardBounds.second));
1294 unsigned int ioff = fixedWildcardLength;
1295 bool wildcardsNeeded =
false;
1296 bool someLeadingZeros =
false;
1297 bool allWildcardsSameSize =
true;
1299 for(
unsigned int n = 0; n < haystack.size(); ++n)
1301 std::string wildcard =
"";
1303 i = ioff + commonChunksToReturn[0].size();
1305 if(commonChunksToReturn.size() == 1)
1306 wildcard = haystack[n].substr(i);
1308 for(
unsigned int c = 1; c < commonChunksToReturn.size(); ++c)
1310 if(c == commonChunksToReturn.size() - 1)
1311 k = haystack[n].rfind(commonChunksToReturn[c]);
1313 k = haystack[n].find(commonChunksToReturn[c], i + 1);
1320 __COUTVS__(3, k - i);
1322 wildcard = haystack[n].substr(i, k - i);
1323 if(fixedWildcardLength && n == 0)
1324 fixedWildcardLength += wildcard.size();
1326 __COUTS__(3) <<
"name[" << n <<
"] = " << wildcard <<
" fixed @ "
1327 << fixedWildcardLength << __E__;
1332 wildcard != haystack[n].substr(i, k - i))
1334 __SS__ <<
"Invalid wildcard! for name[" << n <<
"] = " << haystack[n]
1335 <<
" - the extraction algorithm is confused, please simplify "
1336 "your naming convention."
1346 wildcardsNeeded =
true;
1349 if(wildcard[0] ==
'0' && !fixedWildcardLength)
1351 someLeadingZeros =
true;
1352 if(wildcardStringsToReturn.size() &&
1353 wildcard.size() != wildcardStringsToReturn[0].size())
1354 allWildcardsSameSize =
false;
1357 wildcardStringsToReturn.push_back(wildcard);
1364 if(someLeadingZeros && allWildcardsSameSize)
1366 __COUTTV__(fixedWildcardLength);
1367 fixedWildcardLength = wildcardStringsToReturn[0].size();
1368 __COUT__ <<
"Enforce wildcard size of " << fixedWildcardLength << __E__;
1371 if(wildcardStringsToReturn.size() != haystack.size())
1373 __SS__ <<
"There was a problem during common chunk extraction!" << __E__;
1377 return wildcardsNeeded;
1386 const std::string& rhs)
const
1392 for(
unsigned int i = 0; i < lhs.size() && i < rhs.size(); ++i)
1395 if((lhs[i] >=
'A' && lhs[i] <=
'Z' && rhs[i] >=
'A' && rhs[i] <=
'Z') ||
1396 (lhs[i] >=
'a' && lhs[i] <=
'z' && rhs[i] >=
'a' && rhs[i] <=
'z'))
1398 if(lhs[i] == rhs[i])
1400 return (lhs[i] < rhs[i]);
1403 else if(lhs[i] >=
'A' && lhs[i] <=
'Z')
1405 if(lhs[i] + 32 == rhs[i])
1407 return (lhs[i] + 32 < rhs[i]);
1409 else if(rhs[i] >=
'A' && rhs[i] <=
'Z')
1411 if(lhs[i] == rhs[i] + 32)
1413 return (lhs[i] < rhs[i] + 32);
1417 if(lhs[i] == rhs[i])
1419 return (lhs[i] < rhs[i]);
1424 return lhs.size() < rhs.size();
1434 std::array<char, 128> buffer;
1436 std::shared_ptr<FILE> pipe(popen(cmd,
"r"), pclose);
1438 __THROW__(
"popen() failed!");
1439 while(!feof(pipe.get()))
1441 if(fgets(buffer.data(), 128, pipe.get()) !=
nullptr)
1442 result += buffer.data();
1453 #include <execinfo.h>
1457 __SS__ <<
"ots::stackTrace:\n";
1463 size = backtrace(array, 10);
1467 char** messages = backtrace_symbols(array, size);
1471 for(
unsigned int i = 1; i < size && messages != NULL; ++i)
1484 char *mangled_name = 0, *offset_begin = 0, *offset_end = 0;
1487 for(
char* p = messages[i]; *p; ++p)
1505 if(mangled_name && offset_begin && offset_end && mangled_name < offset_begin)
1507 *mangled_name++ =
'\0';
1508 *offset_begin++ =
'\0';
1509 *offset_end++ =
'\0';
1512 char* real_name = abi::__cxa_demangle(mangled_name, 0, 0, &status);
1517 ss <<
"[" << i <<
"] " << messages[i] <<
" : " << real_name <<
"+"
1518 << offset_begin << offset_end << std::endl;
1523 ss <<
"[" << i <<
"] " << messages[i] <<
" : " << mangled_name <<
"+"
1524 << offset_begin << offset_end << std::endl;
1531 ss <<
"[" << i <<
"] " << messages[i] << std::endl;
1550 const std::string& location,
1551 const unsigned int& line)
1553 char* environmentVariablePtr = getenv(name);
1554 if(!environmentVariablePtr)
1556 __SS__ <<
"Environment variable '$" << name <<
"' not defined at " << location
1557 <<
":" << line << __E__;
1561 return environmentVariablePtr;
1568 const std::string& field,
1569 uint32_t occurrence,
1571 size_t* returnFindPos ,
1572 const std::string& valueField ,
1573 const std::string& quoteType )
1576 *returnFindPos = std::string::npos;
1578 __COUTVS__(41, xml);
1580 size_t lo, findpos = after, hi;
1581 for(uint32_t i = 0; i <= occurrence; ++i)
1583 bool anyFound =
false;
1585 xml.find(
"<" + field,
1586 findpos)) != std::string::npos &&
1587 findpos + 1 + field.size() < xml.size())
1589 __COUTS__(40) <<
"find: ---- '<" << field <<
" findpos=" << findpos
1590 <<
"findpos " << findpos <<
" " << xml[findpos] <<
" "
1591 << xml[findpos + 1 + field.size()] <<
" "
1592 << (int)xml[findpos + 1 + field.size()] << __E__;
1600 if((quoteType ==
">" && xml[findpos] ==
'>') || xml[findpos] ==
' ' ||
1601 xml[findpos] ==
'\n' || xml[findpos] ==
'\t')
1610 __COUTS__(40) <<
"Field '" << field <<
"' not found" << __E__;
1615 lo = xml.find(valueField + quoteType, findpos) + valueField.size() + quoteType.size();
1617 if(TTEST(40) && quoteType.size())
1619 __COUTS__(40) <<
"Neighbors of field '" << field <<
"' and value '" << valueField
1620 <<
"' w/quote = " << quoteType << __E__;
1621 for(
size_t i = lo - valueField.size(); i < lo + 10 && i < xml.size(); ++i)
1622 __COUTS__(40) <<
"xml[" << i <<
"] " << xml[i] <<
" vs " << quoteType <<
" ? "
1623 << (int)xml[i] <<
" vs " << (
int)quoteType[0] << __E__;
1627 quoteType ==
">" ?
"<" : quoteType,
1628 lo)) == std::string::npos)
1630 __COUTS__(40) <<
"Value closing not found" << __E__;
1635 *returnFindPos = findpos - (1 + field.size());
1637 __COUTS__(40) <<
"after: " << after <<
", findpos: " << findpos <<
", hi/lo: " << hi
1638 <<
"/" << lo <<
", size: " << xml.size() << __E__;
1639 __COUTVS__(40, xml.substr(lo, hi - lo));
1640 return xml.substr(lo, hi - lo);
1647 const std::string& field,
1648 uint32_t occurrence,
1650 size_t* returnFindPos ,
1651 const std::string& valueField ,
1652 const std::string& quoteType )
1655 *returnFindPos = std::string::npos;
1657 __COUTVS__(41, xml);
1659 size_t lo = 0, hi, findpos = before;
1660 for(uint32_t i = 0; i <= occurrence; ++i)
1662 bool anyFound =
false;
1664 xml.rfind(
"<" + field,
1665 findpos)) != std::string::npos &&
1666 findpos + 1 + field.size() < xml.size())
1668 __COUTS__(40) <<
"rfind: ---- '<" << field <<
" findpos=" << findpos <<
" "
1669 << xml[findpos] <<
" " << xml[findpos + 1 + field.size()] <<
" "
1670 << (int)xml[findpos + 1 + field.size()] << __E__;
1672 findpos += 1 + field.size();
1675 if((quoteType ==
">" && xml[findpos] ==
'>') || xml[findpos] ==
' ' ||
1676 xml[findpos] ==
'\n' || xml[findpos] ==
'\t')
1682 findpos -= 1 + field.size() + 1;
1686 __COUTS__(40) <<
"Field '" << field <<
"' not found" << __E__;
1691 lo = xml.find(valueField + quoteType, findpos) + valueField.size() + quoteType.size();
1693 if(TTEST(40) && quoteType.size())
1695 __COUTS__(40) <<
"Neighbors?" << __E__;
1696 for(
size_t i = findpos; i < lo + 10 && i < xml.size(); ++i)
1697 __COUTS__(40) <<
"xml[" << i <<
"] " << xml[i] <<
" vs " << quoteType <<
" ? "
1698 << (int)xml[i] <<
" vs " << (
int)quoteType[0] << __E__;
1702 quoteType ==
">" ?
"<" : quoteType,
1703 lo)) == std::string::npos)
1705 __COUTS__(40) <<
"Value closing not found" << __E__;
1711 findpos - (1 + field.size());
1713 __COUTS__(40) <<
"before: " << before <<
", findpos: " << findpos <<
", hi/lo: " << hi
1714 <<
"/" << lo <<
", size: " << xml.size() << __E__;
1715 __COUTVS__(40, xml.substr(lo, hi - lo));
1716 return xml.substr(lo, hi - lo);
1724 const std::set<char>& delimiter )
1728 for(
const auto& split : splitArr)
1729 __COUTS__(lvl) << split;
1744 std::unique_ptr<char, void (*)(
void*)> res{
1745 abi::__cxa_demangle(name, NULL, NULL, &status), std::free};
1747 return (status == 0) ? res.get() : name;
bool operator()(const std::string &lhs, const std::string &rhs) const
<get string in order ignoring letter case
static std::string getTimestampString(const std::string &linuxTimeInSeconds)
static const std::string & trim(std::string &s)
static std::string extractXmlField(const std::string &xml, const std::string &field, uint32_t occurrence, size_t after, size_t *returnFindPos=nullptr, const std::string &valueField="value=", const std::string "eType="'")
static void getVectorFromString(const std::string &inputString, std::vector< std::string > &listToReturn, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'}, std::vector< char > *listOfDelimiters=0, bool decodeURIComponents=false)
static std::string exec(const char *cmd)
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'})
static std::string setToString(const std::set< T > &setToReturn, const std::string &delimeter=", ")
setToString ~
static T validateValueForDefaultStringDataType(const std::string &value, bool doConvertEnvironmentVariables=true)
static char * otsGetEnvironmentVarable(const char *name, const std::string &location, const unsigned int &line)
static std::string escapeString(std::string inString, bool allowWhiteSpace=false)
static void sanitizeForSQL(std::string &data)
StringMacros::sanitizeForSQL.
static void coutSplit(const std::string &str, uint8_t traceLevel=TLVL_DEBUG, const std::set< char > &delimiter={',', '\n', ';'})
static std::string vectorToString(const std::vector< T > &setToReturn, const std::string &delimeter=", ")
vectorToString ~
static std::string convertEnvironmentVariables(const std::string &data)
static std::string getNumberType(const std::string &stringToCheck)
Note: before call consider use of stringToCheck = StringMacros::convertEnvironmentVariables(stringToC...
static std::string demangleTypeName(const char *name)
static std::string rextractXmlField(const std::string &xml, const std::string &field, uint32_t occurrence, size_t before, size_t *returnFindPos=nullptr, const std::string &valueField="value=", const std::string "eType="'")
static bool extractCommonChunks(const std::vector< std::string > &haystack, std::vector< std::string > &commonChunksToReturn, std::vector< std::string > &wildcardStrings, unsigned int &fixedWildcardLength)
static bool inWildCardSet(const std::string &needle, const std::set< std::string > &haystack)
static bool isNumber(const std::string &stringToCheck)
Note: before call consider use of stringToCheck = StringMacros::convertEnvironmentVariables(stringToC...
static std::string mapToString(const std::map< std::string, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
static void getMapFromString(const std::string &inputString, std::map< S, T > &mapToReturn, const std::set< char > &pairPairDelimiter={',', '|', '&'}, const std::set< char > &nameValueDelimiter={'=', ':'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
getMapFromString ~
static std::string getTimeDurationString(const time_t durationInSeconds=time(0))
static bool wildCardMatch(const std::string &needle, const std::string &haystack, unsigned int *priorityIndex=0)
static std::string decodeURIComponent(const std::string &data)
static std::string stackTrace(void)
static bool getNumber(const std::string &s, T &retValue)