tdaq-develop-2025-02-12
ots::StringMacros Struct Reference

Classes

struct  IgnoreCaseCompareStruct
 

Static Public Member Functions

static bool wildCardMatch (const std::string &needle, const std::string &haystack, unsigned int *priorityIndex=0)
 
static bool inWildCardSet (const std::string &needle, const std::set< std::string > &haystack)
 
template<class T >
static T & getWildCardMatchFromMap (const std::string &needle, std::map< std::string, T > &haystack, std::string *foundKey=0)
 defined in included .icc source More...
 
static std::string decodeURIComponent (const std::string &data)
 
static std::string encodeURIComponent (const std::string &data)
 
static void sanitizeForSQL (std::string &data)
 StringMacros::sanitizeForSQL.
 
static std::string escapeString (std::string inString, bool allowWhiteSpace=false)
 
static std::string convertEnvironmentVariables (const std::string &data)
 
static bool isNumber (const std::string &stringToCheck)
 Note: before call consider use of stringToCheck = StringMacros::convertEnvironmentVariables(stringToCheck) More...
 
static std::string getNumberType (const std::string &stringToCheck)
 Note: before call consider use of stringToCheck = StringMacros::convertEnvironmentVariables(stringToCheck) More...
 
template<class T >
static bool getNumber (const std::string &s, T &retValue)
 
static bool getNumber (const std::string &s, bool &retValue)
 template<> More...
 
static std::string getTimestampString (const std::string &linuxTimeInSeconds)
 
static std::string getTimestampString (const time_t linuxTimeInSeconds=time(0))
 
static std::string getTimeDurationString (const time_t durationInSeconds=time(0))
 
template<class T >
static T validateValueForDefaultStringDataType (const std::string &value, bool doConvertEnvironmentVariables=true)
 
static std::string validateValueForDefaultStringDataType (const std::string &value, bool doConvertEnvironmentVariables=true)
 
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'})
 
template<class T , class S = std::string>
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 ~ More...
 
static void getMapFromString (const std::string &inputString, std::map< std::string, std::string > &mapToReturn, const std::set< char > &pairPairDelimiter={',', '|', '&'}, const std::set< char > &nameValueDelimiter={'=', ':'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
 
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::vector< std::string > getVectorFromString (const std::string &inputString, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'}, std::vector< char > *listOfDelimiters=0, bool decodeURIComponents=false)
 
template<class T >
static std::string mapToString (const std::map< std::string, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
 
template<class T >
static std::string mapToString (const std::map< std::pair< std::string, std::string >, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
 
template<class T >
static std::string mapToString (const std::map< std::pair< std::string, std::pair< std::string, std::string >>, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
 
template<class T >
static std::string mapToString (const std::map< std::string, std::pair< std::string, T >> &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
 
template<class T >
static std::string mapToString (const std::map< std::string, std::map< std::string, T >> &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
 
template<class T >
static std::string mapToString (const std::map< std::string, std::set< T >> &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
 
template<class T >
static std::string mapToString (const std::map< std::string, std::vector< T >> &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
 
static std::string mapToString (const std::map< std::string, uint8_t > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
 mapToString
 
template<class T >
static std::string setToString (const std::set< T > &setToReturn, const std::string &delimeter=", ")
 setToString ~ More...
 
static std::string setToString (const std::set< uint8_t > &setToReturn, const std::string &delimeter=", ")
 setToString
 
template<class S , class T >
static std::string setToString (const std::set< std::pair< S, T >> &setToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=":")
 
template<class T >
static std::string vectorToString (const std::vector< T > &setToReturn, const std::string &delimeter=", ")
 vectorToString ~ More...
 
static std::string vectorToString (const std::vector< uint8_t > &setToReturn, const std::string &delimeter=", ")
 vectorToString
 
template<class S , class T >
static std::string vectorToString (const std::vector< std::pair< S, T >> &setToReturn, const std::string &primaryDelimeter="; ", const std::string &secondaryDelimeter=":")
 
static bool extractCommonChunks (const std::vector< std::string > &haystack, std::vector< std::string > &commonChunksToReturn, std::vector< std::string > &wildcardStrings, unsigned int &fixedWildcardLength)
 
static std::string demangleTypeName (const char *name)
 
template<class T >
static std::string getTypeName (void)
 
static std::string stackTrace (void)
 
static std::string exec (const char *cmd)
 
static char * otsGetEnvironmentVarable (const char *name, const std::string &location, const unsigned int &line)
 
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 &quoteType="'")
 
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 &quoteType="'")
 

Detailed Description

Definition at line 14 of file StringMacros.h.

Member Function Documentation

◆ convertEnvironmentVariables()

std::string StringMacros::convertEnvironmentVariables ( const std::string &  data)
static

convertEnvironmentVariables ~ static recursive function

allows environment variables entered as $NAME or ${NAME}

Definition at line 378 of file StringMacros.cc.

◆ decodeURIComponent()

std::string StringMacros::decodeURIComponent ( const std::string &  data)
static

decodeURIComponent converts all %## to the ascii character

Definition at line 115 of file StringMacros.cc.

◆ demangleTypeName()

std::string StringMacros::demangleTypeName ( const char *  name)
static

demangleTypeName

Definition at line 1662 of file StringMacros.cc.

◆ escapeString()

std::string StringMacros::escapeString ( std::string  inString,
bool  allowWhiteSpace = false 
)
static

StringMacros::escapeString convert quotes to html quote characters ' = ' and " = " remove new line characters and (if !allowWhiteSpace) remove white space (so that read from file white space artifact removed)

convert & = & if(allowWhiteSpace) convert \t to 8 &#160; spaces and
to

Definition at line 196 of file StringMacros.cc.

◆ exec()

std::string StringMacros::exec ( const char *  cmd)
static

exec run linux command and get result back in string

Definition at line 1340 of file StringMacros.cc.

◆ extractCommonChunks()

bool StringMacros::extractCommonChunks ( const std::vector< std::string > &  haystack,
std::vector< std::string > &  commonChunksToReturn,
std::vector< std::string > &  wildcardStringsToReturn,
unsigned int &  fixedWildcardLength 
)
static

extractCommonChunks return the common chunks from the vector of strings e.g. if the strings were created from a template string like reader*_east*, this function will return a vector of size 3 := {"reader","_east",""} and a vector of wildcards that would replace the *

Returns true if common chunks and wildcards found, returns false if all inputs were the same (i.e. no wildcards needed)

Definition at line 1060 of file StringMacros.cc.

◆ extractXmlField()

std::string StringMacros::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 &  quoteType = "'" 
)
static

extract valueField for field from xml looking forwards from after occurence = 0 is first occurence

Definition at line 1477 of file StringMacros.cc.

◆ getMapFromString() [1/2]

template<class T , class S = std::string>
static void ots::StringMacros::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'} 
)
static

getMapFromString ~

Parameters
inputStringdefined in included .icc source

◆ getMapFromString() [2/2]

void StringMacros::getMapFromString ( const std::string &  inputString,
std::map< std::string, std::string > &  mapToReturn,
const std::set< char > &  pairPairDelimiter = {',', '|', '&'},
const std::set< char > &  nameValueDelimiter = {'=', ':'},
const std::set< char > &  whitespace = {' ', '\t', '\n', '\r'} 
)
static

getMapFromString extracts the map of name-value pairs from string that uses two delimiters ignoring whitespace

Definition at line 890 of file StringMacros.cc.

◆ getNumber() [1/2]

bool StringMacros::getNumber ( const std::string &  s,
bool &  retValue 
)
static

template<>

defined in included .icc source // Note: before call consider use of stringToCheck = StringMacros::convertEnvironmentVariables(stringToCheck)

for bool, but not all other number types return false if string is not a bool template<> inline bool StringMacros::getNumber<bool>(const std::string& s, bool& retValue)

Definition at line 605 of file StringMacros.cc.

◆ getNumber() [2/2]

template<class T >
static bool ots::StringMacros::getNumber ( const std::string &  s,
T &  retValue 
)
static

defined in included .icc source // Note: before call consider use of stringToCheck = StringMacros::convertEnvironmentVariables(stringToCheck)

◆ getNumberType()

std::string StringMacros::getNumberType ( const std::string &  s)
static

Note: before call consider use of stringToCheck = StringMacros::convertEnvironmentVariables(stringToCheck)

getNumberType ~~ returns string of number type: "unsigned long long", "double" or else "nan" for not-a-number

Numbers can be hex ("0x.."), binary("b..."), or base10.

Definition at line 525 of file StringMacros.cc.

◆ getSetFromString()

void StringMacros::getSetFromString ( const std::string &  inputString,
std::set< std::string > &  setToReturn,
const std::set< char > &  delimiter = {',', '|', '&'},
const std::set< char > &  whitespace = {' ', '\t', '\n', '\r'} 
)
static

getSetFromString extracts the set of elements from string that uses a delimiter ignoring whitespace

Definition at line 702 of file StringMacros.cc.

◆ getTimeDurationString()

std::string StringMacros::getTimeDurationString ( const time_t  durationInSeconds = time(0))
static

getTimeDurationString returns the duration HH:MM:SS with consideration for day(s)

Definition at line 661 of file StringMacros.cc.

◆ getTimestampString() [1/2]

std::string StringMacros::getTimestampString ( const std::string &  linuxTimeInSeconds)
static

getTimestampString ~~ returns ots style timestamp string of known fixed size: Thu Aug 23 14:55:02 2001 CST

Definition at line 636 of file StringMacros.cc.

◆ getTimestampString() [2/2]

std::string StringMacros::getTimestampString ( const time_t  linuxTimeInSeconds = time(0))
static

getTimestampString ~~ returns ots style timestamp string of known fixed size: Thu Aug 23 14:55:02 2001 CST

Definition at line 646 of file StringMacros.cc.

◆ getVectorFromString() [1/2]

std::vector< std::string > StringMacros::getVectorFromString ( const std::string &  inputString,
const std::set< char > &  delimiter = {',', '|', '&'},
const std::set< char > &  whitespace = {' ', '\t', '\n', '\r'},
std::vector< char > *  listOfDelimiters = 0,
bool  decodeURIComponents = false 
)
static

getVectorFromString extracts the list of elements from string that uses a delimiter ignoring whitespace optionally returns the list of delimiters encountered, which may be useful for extracting which operator was used.

Note: lists are returned as vectors Note: the size() of delimiters will be one less than the size() of the returned values unless there is a leading delimiter, in which case vectors will have the same size.

Definition at line 868 of file StringMacros.cc.

◆ getVectorFromString() [2/2]

void StringMacros::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

getVectorFromString extracts the list of elements from string that uses a delimiter ignoring whitespace optionally returns the list of delimiters encountered, which may be useful for extracting which operator was used.

Note: lists are returned as vectors Note: the size() of delimiters will be one less than the size() of the returned values unless there is a leading delimiter, in which case vectors will have the same size.

Definition at line 749 of file StringMacros.cc.

◆ getWildCardMatchFromMap()

template<class T >
static T& ots::StringMacros::getWildCardMatchFromMap ( const std::string &  needle,
std::map< std::string, T > &  haystack,
std::string *  foundKey = 0 
)
static

defined in included .icc source

getWildCardMatchFromMap ~ returns value if needle is in haystack otherwise throws exception (considering wildcards AND match priority as defined by StringMacros::wildCardMatch)

◆ inWildCardSet()

bool StringMacros::inWildCardSet ( const std::string &  needle,
const std::set< std::string > &  haystack 
)
static

inWildCardSet ~ returns true if needle is in haystack (considering wildcards) allow inverted haystack strings by first character being '!'

Definition at line 94 of file StringMacros.cc.

◆ isNumber()

bool StringMacros::isNumber ( const std::string &  s)
static

Note: before call consider use of stringToCheck = StringMacros::convertEnvironmentVariables(stringToCheck)

isNumber ~~ returns true if one or many numbers separated by operations (+,-,/,*) is present in the string. Numbers can be hex ("0x.."), binary("b..."), or base10.

Definition at line 448 of file StringMacros.cc.

◆ mapToString()

template<class T >
static std::string ots::StringMacros::mapToString ( const std::map< std::string, T > &  mapToReturn,
const std::string &  primaryDelimeter = ", ",
const std::string &  secondaryDelimeter = ": " 
)
static

mapToString ~ *ToString declarations (template definitions are in included .icc source)

Parameters
mapToReturndefined in included .icc source

◆ otsGetEnvironmentVarable()

char * StringMacros::otsGetEnvironmentVarable ( const char *  name,
const std::string &  location,
const unsigned int &  line 
)
static

otsGetEnvironmentVarable declare special ots environment variable get, that throws exception instead of causing crashes with null pointer. Note: usually called with ENV(X) in CoutMacros.h

Definition at line 1459 of file StringMacros.cc.

◆ rextractXmlField()

std::string StringMacros::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 &  quoteType = "'" 
)
static

extract valueField for field from xml looking backwards from before occurence = 0 is first occurence

Definition at line 1562 of file StringMacros.cc.

◆ setToString()

template<class T >
static std::string ots::StringMacros::setToString ( const std::set< T > &  setToReturn,
const std::string &  delimeter = ", " 
)
static

setToString ~

Parameters
setToReturndefined in included .icc source

◆ stackTrace()

std::string StringMacros::stackTrace ( void  )
static

◆ validateValueForDefaultStringDataType() [1/2]

template<class T >
static T ots::StringMacros::validateValueForDefaultStringDataType ( const std::string &  value,
bool  doConvertEnvironmentVariables = true 
)
static

validateValueForDefaultStringDataType ~ special validation ignoring any table info - just assuming type string

Parameters
valuedefined in included .icc source

◆ validateValueForDefaultStringDataType() [2/2]

std::string StringMacros::validateValueForDefaultStringDataType ( const std::string &  value,
bool  doConvertEnvironmentVariables = true 
)
static

validateValueForDefaultStringDataType

Definition at line 683 of file StringMacros.cc.

◆ vectorToString()

template<class T >
static std::string ots::StringMacros::vectorToString ( const std::vector< T > &  setToReturn,
const std::string &  delimeter = ", " 
)
static

vectorToString ~

Parameters
setToReturndefined in included .icc source

◆ wildCardMatch()

bool StringMacros::wildCardMatch ( const std::string &  needle,
const std::string &  haystack,
unsigned int *  priorityIndex = 0 
)
static

Here is the list of static helper functions:

wildCardMatch
inWildCardSet
getWildCardMatchFromMap

decodeURIComponent
convertEnvironmentVariables
isNumber
getNumber
getTimestampString
getTimeDurationString

validateValueForDefaultStringDataType

getSetFromString
getVectorFromString
getMapFromString

setToString
vectorToString
mapToString

demangleTypeName
getTypeName
stackTrace
exec
otsGetEnvironmentVarable
extractXmlField
rextractXmlField

End list of static helper functions:

wildCardMatch find needle in haystack allow needle to have leading and/or trailing wildcard '*' consider priority in matching, no matter the order in the haystack:

  • 0: no match!
  • 1: highest priority is exact match
  • 2: next highest is partial TRAILING-wildcard match
  • 3: next highest is partial LEADING-wildcard match
  • 4: lowest priority is partial full-wildcard match return priority found by reference

Definition at line 18 of file StringMacros.cc.


The documentation for this struct was generated from the following files: