libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
BaseLib::HelperFunctions Class Reference

This class provides functions to make your life easier. More...

#include <HelperFunctions.h>

Public Member Functions

 HelperFunctions ()
 Dummy constructor for backwards compatibility. More...
 

Static Public Member Functions

static int32_t compareConstant (const std::string &s1, const std::string &s2)
 Compares two strings in constant time. More...
 
static int64_t getTimezoneOffset ()
 
static int64_t getLocalTime ()
 Gets the current local time as unix time stamp in milliseconds. More...
 
static int64_t getTime ()
 Gets the current unix time stamp in milliseconds. More...
 
static int64_t getTimeMicroseconds ()
 Gets the current unix time stamp in microseconds. More...
 
static int64_t getTimeNanoseconds ()
 Gets the current unix time stamp in microseconds. More...
 
static int64_t getTimeSeconds ()
 Gets the current unix time stamp in seconds. More...
 
static int32_t getFileLastModifiedTime (const std::string &filename)
 Gets the last modified time of a file. More...
 
static std::string getTimeString (int64_t time=0)
 Gets the current time as a string like "08/27/14 14:13:53.471". More...
 
static std::string getTimeString (std::string format, int64_t time=0)
 Gets the current time as a string with custom formatting. More...
 
static std::string getTimeUuid ()
 Calculates a Homegear-specific UUID including a time stamp in 100-nanosecond intervals. More...
 
static std::string getUuid1 (bool useRandomNodeId=false)
 Calculates a version 1 UUID (see RFC 4122) including a time stamp in 100-nanosecond intervals. More...
 
static std::string getUuid4 ()
 Calculates a version 4 UUID (see RFC 4122). More...
 
static std::string & ltrim (std::string &s)
 Left trims a string. More...
 
static std::string & rtrim (std::string &s)
 Right trims a string. More...
 
static std::string & trim (std::string &s)
 Trims a string. More...
 
static std::string & toLower (std::string &s)
 Converts all characters of a string to lower case. More...
 
static std::string & toUpper (std::string &s)
 Converts all characters of a string to upper case. More...
 
static size_t utf8StringSize (const std::string &s)
 Returns the size of a UTF-8 string. More...
 
static std::string utf8Substring (const std::string &s, uint32_t start, uint32_t length)
 Returns an UTF-8 substring. More...
 
static std::string & stringReplace (std::string &haystack, const std::string &search, const std::string &replace)
 Replaces substrings within a string. More...
 
static std::string & regexReplace (std::string &haystack, const std::string &search, const std::string &replace, bool ignoreCase)
 Replaces substrings within a string using regex. More...
 
static std::pair< std::string, std::string > splitFirst (std::string string, char delimiter)
 Splits a string at the first occurrence of a delimiter. More...
 
static std::pair< std::string, std::string > splitLast (std::string string, char delimiter)
 Splits a string at the last occurrence of a delimiter. More...
 
static std::vector< std::string > splitAll (std::string string, char delimiter)
 Splits a string at all occurrences of a delimiter. More...
 
static bool isNotAlphaNumeric (char c)
 Checks if a character is not alphanumeric ('_' and '-' are also regarded alphanumeric). More...
 
static bool isAlphaNumeric (std::string &s, std::unordered_set< char > additionalCharacters=std::unordered_set< char >())
 Checks if a string is alphanumeric. More...
 
static std::string stripNonAlphaNumeric (const std::string &s, const std::unordered_set< char > &whitelist=std::unordered_set< char >())
 Strips all non alphanumeric characters from a string ('_' and '-' are also regarded alphanumeric). More...
 
static std::string stripNonPrintable (const std::string &s)
 Strips all non printable characters from a string. More...
 
static PVariable xml2variable (const xml_node *node, bool &isDataNode)
 
static void variable2xml (xml_document *doc, xml_node *parentNode, const PVariable &variable)
 
static bool getBigEndian ()
 Returns the endianess of the system. More...
 
static int32_t getRandomNumber (int32_t min, int32_t max)
 Generates a random integer. More...
 
static std::vector< uint8_t > getRandomBytes (uint32_t size)
 Generates a random byte vector. More...
 
static void memcpyBigEndian (char *to, const char *from, const uint32_t &length)
 Copies binary values from one memory location to another reversing the byte order when the system is little endian. More...
 
static void memcpyBigEndian (uint8_t *to, const uint8_t *from, const uint32_t &length)
 Copies binary values from one memory location to another reversing the byte order when the system is little endian. More...
 
static void memcpyBigEndian (int32_t &to, const std::vector< uint8_t > &from)
 Copies binary values from a vector to an integer reversing the byte order when the system is little endian. More...
 
static void memcpyBigEndian (std::vector< uint8_t > &to, const int32_t &from)
 Copies binary values from an integer to a vector reversing the byte order when the system is little endian. More...
 
static void memcpyBigEndian (int64_t &to, const std::vector< uint8_t > &from)
 Copies binary values from a vector to an integer reversing the byte order when the system is little endian. More...
 
static void memcpyBigEndian (std::vector< uint8_t > &to, const int64_t &from)
 Copies binary values from an integer to a vector reversing the byte order when the system is little endian. More...
 
static std::vector< uint8_t > hexToBin (const std::string &data)
 Converts a hex string to a byte array. More...
 
static std::string getHexString (const uint8_t *buffer, uint32_t size)
 Converts a byte array to a hex string. More...
 
static std::string getHexString (const char *buffer, uint32_t size)
 Converts a byte array to a hex string. More...
 
static std::string getHexString (const std::vector< char > &data)
 Converts a byte array to a hex string. More...
 
static std::string getHexString (const std::string &data)
 Converts a byte array to a hex string. More...
 
static std::string getHexString (const std::vector< uint8_t > &data)
 Converts a byte array to a hex string. More...
 
static std::string getHexString (const std::vector< uint16_t > &data)
 Converts an int16 array to a hex string. More...
 
static std::string getHexString (int32_t number, int32_t width=-1)
 Converts an integer to a hex string. More...
 
static std::string getHexString (uint32_t number, int32_t width=-1)
 Converts an integer to a hex string. More...
 
static std::string getHexString (int64_t number, int32_t width=-1)
 Converts an integer to a hex string. More...
 
static std::string getHexString (uint64_t number, int32_t width=-1)
 Converts an integer to a hex string. More...
 
static char getHexChar (int32_t nibble)
 Converts a nibble to a hex character. More...
 
static std::vector< char > getBinary (const std::string &hexString)
 Converts a hex string to a char vector. More...
 
static std::vector< uint8_t > getUBinary (const std::string &hexString)
 Converts a hex string to an unsigned char vector. More...
 
static std::vector< uint8_t > & getUBinary (const std::string &hexString, uint32_t size, std::vector< uint8_t > &binary)
 Converts a hex string to an unsigned char vector. More...
 
static std::vector< uint8_t > getUBinary (const std::vector< uint8_t > &hexData)
 Converts an unsigned char vector filled with ASCII characters to an unsigned char vector. More...
 
static std::string getBinaryString (const std::string &hexString)
 Converts a hex string to a binary array of type string. More...
 
static uid_t userId (const std::string &username)
 Gets the UID of a user. More...
 
static gid_t groupId (const std::string &groupname)
 Gets the GID of a group. More...
 
static std::string getGNUTLSCertVerificationError (uint32_t errorCode)
 Converts GNUTLS certificate verification error codes to human readable error messages. More...
 
static bool isShortCliCommand (const std::string &command)
 Checks if a command is a short CLI command. More...
 
static bool checkCliCommand (const std::string &command, const std::string &longCommand, const std::string &shortCommand1, const std::string &shortCommand2, uint32_t minArgumentCount, std::vector< std::string > &arguments, bool &showHelp)
 Checks if a string contains a CLI command and checks and returns the arguments. More...
 
static void * memrchr (const void *s, int c, size_t n)
 Reverse memchr(). More...
 

Detailed Description

This class provides functions to make your life easier.

Constructor & Destructor Documentation

§ HelperFunctions()

BaseLib::HelperFunctions::HelperFunctions ( )

Dummy constructor for backwards compatibility.

Member Function Documentation

§ checkCliCommand()

bool BaseLib::HelperFunctions::checkCliCommand ( const std::string &  command,
const std::string &  longCommand,
const std::string &  shortCommand1,
const std::string &  shortCommand2,
uint32_t  minArgumentCount,
std::vector< std::string > &  arguments,
bool &  showHelp 
)
static

Checks if a string contains a CLI command and checks and returns the arguments.

Parameters
commandThe CLI command.
longCommandThe long CLI command to search for at the beginning of command.
shortCommand1An optional short CLI command to search for at the beginning of command.
shortCommand2An optional second short CLI command to search for at the beginning of command. Set to empty string if not needed.
minArgumentCountThe minimum number of arguments.
[out]argumentsA string vector which is filled with the arguments.
[out]showHelpSet to true when help is requested.
Returns
Returns true on success and false if "command" doesn't start with "longCommand", "shortCommand1" or "shortCommand2".

§ compareConstant()

int32_t BaseLib::HelperFunctions::compareConstant ( const std::string &  s1,
const std::string &  s2 
)
static

Compares two strings in constant time.

Parameters
s1
s2
Returns
Returns 0 if the strings are equal. In all other cases a non-zero result is returned.

§ getBigEndian()

bool BaseLib::HelperFunctions::getBigEndian ( )
static

Returns the endianess of the system.

Returns
Returns true if the system is big endian, otherwise false.

§ getBinary()

std::vector< char > BaseLib::HelperFunctions::getBinary ( const std::string &  hexString)
static

Converts a hex string to a char vector.

Parameters
hexStringThe string to convert.
Returns
Returns a vector of type char.

§ getBinaryString()

std::string BaseLib::HelperFunctions::getBinaryString ( const std::string &  hexString)
static

Converts a hex string to a binary array of type string.

Parameters
hexStringThe hex string to convert.
Returns
Returns a string containing the binary data.

§ getFileLastModifiedTime()

static int32_t BaseLib::HelperFunctions::getFileLastModifiedTime ( const std::string &  filename)
static

Gets the last modified time of a file.

Parameters
filenameThe file to get the last modified time for.
Returns
The unix time stamp of the last modified time.

§ getGNUTLSCertVerificationError()

std::string BaseLib::HelperFunctions::getGNUTLSCertVerificationError ( uint32_t  errorCode)
static

Converts GNUTLS certificate verification error codes to human readable error messages.

Parameters
errorCodeThe GNUTLS certificate verification error code.
Returns
Returns the error message for the provided error code.

§ getHexChar()

char BaseLib::HelperFunctions::getHexChar ( int32_t  nibble)
static

Converts a nibble to a hex character.

Parameters
nibbleThe nibble to convert.
Returns
Returns the hex character of the nibble.

§ getHexString() [1/10]

std::string BaseLib::HelperFunctions::getHexString ( const uint8_t *  buffer,
uint32_t  size 
)
static

Converts a byte array to a hex string.

Parameters
bufferThe byte array to convert.
sizeThe size of the buffer.
Returns
Returns the hex string of the byte array.

§ getHexString() [2/10]

std::string BaseLib::HelperFunctions::getHexString ( const char *  buffer,
uint32_t  size 
)
static

Converts a byte array to a hex string.

Parameters
bufferThe byte array to convert.
sizeThe size of the buffer.
Returns
Returns the hex string of the byte array.

§ getHexString() [3/10]

std::string BaseLib::HelperFunctions::getHexString ( const std::vector< char > &  data)
static

Converts a byte array to a hex string.

Parameters
dataThe byte array to convert.
Returns
Returns the hex string of the byte array.

§ getHexString() [4/10]

std::string BaseLib::HelperFunctions::getHexString ( const std::string &  data)
static

Converts a byte array to a hex string.

Parameters
dataThe byte array to convert.
Returns
Returns the hex string of the byte array.

§ getHexString() [5/10]

std::string BaseLib::HelperFunctions::getHexString ( const std::vector< uint8_t > &  data)
static

Converts a byte array to a hex string.

Parameters
dataThe byte array to convert.
Returns
Returns the hex string of the byte array.

§ getHexString() [6/10]

std::string BaseLib::HelperFunctions::getHexString ( const std::vector< uint16_t > &  data)
static

Converts an int16 array to a hex string.

Parameters
dataThe array to convert.
Returns
Returns the hex string of the array.

§ getHexString() [7/10]

std::string BaseLib::HelperFunctions::getHexString ( int32_t  number,
int32_t  width = -1 
)
static

Converts an integer to a hex string.

Parameters
numberThe integer to convert.
widthThe minimal width of the hex string (default -1). If the hex string is smaller, it is prefixed with zeros.
Returns
Returns the hex string of the integer.

§ getHexString() [8/10]

std::string BaseLib::HelperFunctions::getHexString ( uint32_t  number,
int32_t  width = -1 
)
static

Converts an integer to a hex string.

Parameters
numberThe integer to convert.
widthThe minimal width of the hex string (default -1). If the hex string is smaller, it is prefixed with zeros.
Returns
Returns the hex string of the integer.

§ getHexString() [9/10]

std::string BaseLib::HelperFunctions::getHexString ( int64_t  number,
int32_t  width = -1 
)
static

Converts an integer to a hex string.

Parameters
numberThe integer to convert.
widthThe minimal width of the hex string (default -1). If the hex string is smaller, it is prefixed with zeros.
Returns
Returns the hex string of the integer.

§ getHexString() [10/10]

std::string BaseLib::HelperFunctions::getHexString ( uint64_t  number,
int32_t  width = -1 
)
static

Converts an integer to a hex string.

Parameters
numberThe integer to convert.
widthThe minimal width of the hex string (default -1). If the hex string is smaller, it is prefixed with zeros.
Returns
Returns the hex string of the integer.

§ getLocalTime()

int64_t BaseLib::HelperFunctions::getLocalTime ( )
static

Gets the current local time as unix time stamp in milliseconds.

Returns
The current local time as unix time stamp in milliseconds.

§ getRandomBytes()

std::vector< uint8_t > BaseLib::HelperFunctions::getRandomBytes ( uint32_t  size)
static

Generates a random byte vector.

Parameters
sizeThe number of bytes to generate.
Returns
Returns a random byte vector of size "size".

§ getRandomNumber()

int32_t BaseLib::HelperFunctions::getRandomNumber ( int32_t  min,
int32_t  max 
)
static

Generates a random integer.

Parameters
minThe minimal value of the random integer.
maxThe maximum value of the random integer.
Returns
Returns a random integer between (and including) min and max.

§ getTime()

int64_t BaseLib::HelperFunctions::getTime ( )
static

Gets the current unix time stamp in milliseconds.

See also
getTimeSeconds()
getTimeMicroseconds()
getTimeNanoseconds()
Returns
The current unix time stamp in milliseconds.

§ getTimeMicroseconds()

int64_t BaseLib::HelperFunctions::getTimeMicroseconds ( )
static

Gets the current unix time stamp in microseconds.

See also
getTimeSeconds()
getTime()
getTimeNanoseconds()
Returns
The current unix time stamp in microseconds.

§ getTimeNanoseconds()

int64_t BaseLib::HelperFunctions::getTimeNanoseconds ( )
static

Gets the current unix time stamp in microseconds.

See also
getTimeMicroseconds()
getTimeSeconds()
getTime()
Returns
The current unix time stamp in microseconds.

§ getTimeSeconds()

int64_t BaseLib::HelperFunctions::getTimeSeconds ( )
static

Gets the current unix time stamp in seconds.

See also
getTime()
getTimeMicroseconds()
getTimeNanoseconds()
Returns
The current unix time stamp in seconds.

§ getTimeString() [1/2]

std::string BaseLib::HelperFunctions::getTimeString ( int64_t  time = 0)
static

Gets the current time as a string like "08/27/14 14:13:53.471".

Parameters
timeThe unix time stamp in milliseconds to get the time string for. If "0" the current time is returned.
Returns
Returns a time string like "08/27/14 14:13:53.471".

§ getTimeString() [2/2]

std::string BaseLib::HelperFunctions::getTimeString ( std::string  format,
int64_t  time = 0 
)
static

Gets the current time as a string with custom formatting.

Parameters
formatThe format like described for strftime
timeThe unix time stamp in milliseconds to get the time string for. If "0" the current time is returned.
Returns
Returns a time string like "08/27/14 14:13:53.471".

§ getTimeUuid()

std::string BaseLib::HelperFunctions::getTimeUuid ( )
static

Calculates a Homegear-specific UUID including a time stamp in 100-nanosecond intervals.

Returns
Returns a time UUID.

§ getTimezoneOffset()

int64_t BaseLib::HelperFunctions::getTimezoneOffset ( )
static

§ getUBinary() [1/3]

std::vector< uint8_t > BaseLib::HelperFunctions::getUBinary ( const std::string &  hexString)
static

Converts a hex string to an unsigned char vector.

See also
getUBinary()
Parameters
hexStringThe string to convert.
Returns
Returns a vector of type unsigned char.

§ getUBinary() [2/3]

std::vector< uint8_t > & BaseLib::HelperFunctions::getUBinary ( const std::string &  hexString,
uint32_t  size,
std::vector< uint8_t > &  binary 
)
static

Converts a hex string to an unsigned char vector.

See also
getBinary()
Parameters
hexStringThe string to convert.
sizeThe maximum number of characters to convert.
binaryThe unsigned char vector to append the converted bytes to. Already existing elements will not be cleared.
Returns
Returns a reference to "binary".

§ getUBinary() [3/3]

std::vector< uint8_t > BaseLib::HelperFunctions::getUBinary ( const std::vector< uint8_t > &  hexData)
static

Converts an unsigned char vector filled with ASCII characters to an unsigned char vector.

See also
getBinary()
Parameters
hexDataThe vector with ASCII characters to convert.
Returns
Returns a vector of type unsigned char.

§ getUuid1()

std::string BaseLib::HelperFunctions::getUuid1 ( bool  useRandomNodeId = false)
static

Calculates a version 1 UUID (see RFC 4122) including a time stamp in 100-nanosecond intervals.

Calling this method is thread safe. Please note that UUIDs are only unique within one process. Collisions are impossible if the following conditions are met:

  1. The MAC address of the network interface was issued by the OUI (i. e. is unique)
  2. There are not more than 16384 UUIDs generated within one 100 nanosecond block

When the MAC address is not unique or a random node ID is used, collisions are not impossible but very improbable.

Parameters
useRandomNodeIdWhen set to true a random node ID is generated with every start of the program (i. e. every initialization of the base library) and used instead of the computers MAC address.
Returns
Returns a version 1 UUID.

§ getUuid4()

std::string BaseLib::HelperFunctions::getUuid4 ( )
static

Calculates a version 4 UUID (see RFC 4122).

Calling this method is thread safe. Please note that collisions are very improbable but not impossible:

Returns
Returns a version 4 UUID.

§ groupId()

gid_t BaseLib::HelperFunctions::groupId ( const std::string &  groupname)
static

Gets the GID of a group.

Parameters
groupnameThe name of the group to get the GID for.
Returns
Returns the group ID or "-1" on error.

§ hexToBin()

std::vector< uint8_t > BaseLib::HelperFunctions::hexToBin ( const std::string &  data)
static

Converts a hex string to a byte array.

Parameters
dataThe hex string to convert.
Returns
Returns the byte array encoded by the hex string.

§ isAlphaNumeric()

static bool BaseLib::HelperFunctions::isAlphaNumeric ( std::string &  s,
std::unordered_set< char >  additionalCharacters = std::unordered_set<char>() 
)
inlinestatic

Checks if a string is alphanumeric.

See also
isNotAlphaNumeric()
stripNonAlphaNumeric
Parameters
sThe string to check.
additionalCharactersAdditional characters to accept.
Returns
Returns true if the string is alphanumeric, or contains '_' or '-', otherwise false.

§ isNotAlphaNumeric()

static bool BaseLib::HelperFunctions::isNotAlphaNumeric ( char  c)
inlinestatic

Checks if a character is not alphanumeric ('_' and '-' are also regarded alphanumeric).

See also
isAlphaNumeric()
stripNonAlphaNumeric
Parameters
cThe character to check.
Returns
Returns false if the character is alphanumeric, '_' or '-', otherwise true.

§ isShortCliCommand()

bool BaseLib::HelperFunctions::isShortCliCommand ( const std::string &  command)
static

Checks if a command is a short CLI command.

Parameters
commandThe CLI command.
Returns
Returns "true" when the command is a short command, otherwise "false"

§ ltrim()

static std::string& BaseLib::HelperFunctions::ltrim ( std::string &  s)
inlinestatic

Left trims a string.

See also
rtrim()
trim()
Parameters
[in,out]sThe string to left trim.
Returns
Returns a reference to the left trimmed string.

§ memcpyBigEndian() [1/6]

void BaseLib::HelperFunctions::memcpyBigEndian ( char *  to,
const char *  from,
const uint32_t &  length 
)
static

Copies binary values from one memory location to another reversing the byte order when the system is little endian.

Parameters
[out]toThe destination array. No memory is allocated, so make sure, the array is large enough.
[in]fromThe source array.
lengthThe number of bytes to copy.

§ memcpyBigEndian() [2/6]

void BaseLib::HelperFunctions::memcpyBigEndian ( uint8_t *  to,
const uint8_t *  from,
const uint32_t &  length 
)
static

Copies binary values from one memory location to another reversing the byte order when the system is little endian.

Parameters
[out]toThe destination array. No memory is allocated, so make sure, the array is large enough.
[in]fromThe source array.
lengthThe number of bytes to copy.

§ memcpyBigEndian() [3/6]

void BaseLib::HelperFunctions::memcpyBigEndian ( int32_t &  to,
const std::vector< uint8_t > &  from 
)
static

Copies binary values from a vector to an integer reversing the byte order when the system is little endian.

Parameters
[out]toThe destination integer.
[in]fromThe source array. A length less than 4 bytes is allowed.

§ memcpyBigEndian() [4/6]

void BaseLib::HelperFunctions::memcpyBigEndian ( std::vector< uint8_t > &  to,
const int32_t &  from 
)
static

Copies binary values from an integer to a vector reversing the byte order when the system is little endian.

Note that leading zero bytes are trimmed, so 0x0000FFFF becomes {0xFF, 0xFF}.

Parameters
[out]toThe destination array.
[in]fromThe source integer.

§ memcpyBigEndian() [5/6]

void BaseLib::HelperFunctions::memcpyBigEndian ( int64_t &  to,
const std::vector< uint8_t > &  from 
)
static

Copies binary values from a vector to an integer reversing the byte order when the system is little endian.

Parameters
[out]toThe destination integer.
[in]fromThe source array. A length less than 4 bytes is allowed.

§ memcpyBigEndian() [6/6]

void BaseLib::HelperFunctions::memcpyBigEndian ( std::vector< uint8_t > &  to,
const int64_t &  from 
)
static

Copies binary values from an integer to a vector reversing the byte order when the system is little endian.

Note that leading zero bytes are trimmed, so 0x0000000000FFFFFF becomes {0xFF, 0xFF, 0xFF}.

Parameters
[out]toThe destination array.
[in]fromThe source integer.

§ memrchr()

void * BaseLib::HelperFunctions::memrchr ( const void *  s,
int  c,
size_t  n 
)
static

Reverse memchr().

Searches the initial n bytes of buffer s for the last occurrence of 'c'.

§ regexReplace()

std::string & BaseLib::HelperFunctions::regexReplace ( std::string &  haystack,
const std::string &  search,
const std::string &  replace,
bool  ignoreCase 
)
static

Replaces substrings within a string using regex.

Parameters
[in,out]haystackThe string to search the substring in.
regexThe regex to search.
replaceThe substring to replace "search" with.
ignoreCaseSet to true, to ignore the case.
Returns
Returns a reference to the modified string.

§ rtrim()

static std::string& BaseLib::HelperFunctions::rtrim ( std::string &  s)
inlinestatic

Right trims a string.

See also
ltrim()
trim()
Parameters
[in,out]sThe string to right trim.
Returns
Returns a reference to the right trimmed string.

§ splitAll()

std::vector< std::string > BaseLib::HelperFunctions::splitAll ( std::string  string,
char  delimiter 
)
static

Splits a string at all occurrences of a delimiter.

See also
split()
Parameters
stringThe string to split.
delimiterThe delimiter to split the string at.
Returns
Returns an array with all split parts.

§ splitFirst()

std::pair< std::string, std::string > BaseLib::HelperFunctions::splitFirst ( std::string  string,
char  delimiter 
)
static

Splits a string at the first occurrence of a delimiter.

See also
splitAll()
splitLast
Parameters
stringThe string to split.
delimiterThe delimiter to split the string at.
Returns
Returns a pair with the two parts.

§ splitLast()

std::pair< std::string, std::string > BaseLib::HelperFunctions::splitLast ( std::string  string,
char  delimiter 
)
static

Splits a string at the last occurrence of a delimiter.

See also
splitAll()
splitFirst()
Parameters
stringThe string to split.
delimiterThe delimiter to split the string at.
Returns
Returns a pair with the two parts.

§ stringReplace()

std::string & BaseLib::HelperFunctions::stringReplace ( std::string &  haystack,
const std::string &  search,
const std::string &  replace 
)
static

Replaces substrings within a string.

Parameters
[in,out]haystackThe string to search the substring in.
searchThe substring to search.
replaceThe substring to replace "search" with.
Returns
Returns a reference to the modified string.

§ stripNonAlphaNumeric()

std::string BaseLib::HelperFunctions::stripNonAlphaNumeric ( const std::string &  s,
const std::unordered_set< char > &  whitelist = std::unordered_set<char>() 
)
static

Strips all non alphanumeric characters from a string ('_' and '-' are also regarded alphanumeric).

See also
isNotAlphaNumeric()
isAlphaNumeric()
Parameters
sThe string to strip.
whitelistA list of characters not to be stripped.
Returns
Returns the stripped string.

§ stripNonPrintable()

std::string BaseLib::HelperFunctions::stripNonPrintable ( const std::string &  s)
static

Strips all non printable characters from a string.

Parameters
sThe string to strip.
Returns
Returns the stripped string.

§ toLower()

static std::string& BaseLib::HelperFunctions::toLower ( std::string &  s)
inlinestatic

Converts all characters of a string to lower case.

See also
toUpper()
Parameters
[in,out]sThe string to convert all characters to lower case for.
Returns
Returns a reference to the lower case string.

§ toUpper()

static std::string& BaseLib::HelperFunctions::toUpper ( std::string &  s)
inlinestatic

Converts all characters of a string to upper case.

See also
toLower()
Parameters
[in,out]sThe string to convert all characters to upper case for.
Returns
Returns a reference to the upper case string.

§ trim()

static std::string& BaseLib::HelperFunctions::trim ( std::string &  s)
inlinestatic

Trims a string.

See also
ltrim()
rtrim()
Parameters
[in,out]sThe string to trim.
Returns
Returns a reference to the trimmed string.

§ userId()

uid_t BaseLib::HelperFunctions::userId ( const std::string &  username)
static

Gets the UID of a user.

Parameters
usernameThe name of the user to get the UID for.
Returns
Returns the user ID or "-1" on error.

§ utf8StringSize()

static size_t BaseLib::HelperFunctions::utf8StringSize ( const std::string &  s)
inlinestatic

Returns the size of a UTF-8 string.

This method is needed, because std::string::size() and std::string::length() return the size in bytes.

Parameters
sThe string to get the size for.
Returns
Returns the size of the UTF-8 encoded string.

§ utf8Substring()

static std::string BaseLib::HelperFunctions::utf8Substring ( const std::string &  s,
uint32_t  start,
uint32_t  length 
)
inlinestatic

Returns an UTF-8 substring.

This method is needed, because std::string::substr() counts bytes and not characters.

Parameters
sThe string to get the substring from.
startThe start position of the substring.
lengthThe substring size.
Returns
Returns the substring of the UTF-8 encoded string.

§ variable2xml()

void BaseLib::HelperFunctions::variable2xml ( xml_document doc,
xml_node parentNode,
const PVariable variable 
)
static

§ xml2variable()

PVariable BaseLib::HelperFunctions::xml2variable ( const xml_node node,
bool &  isDataNode 
)
static

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