![]() |
CARTA Backend
The backend component of CARTA
|
Functions | |
void | SplitString (std::string &input, char delim, std::vector< std::string > &parts) |
Splits a string into parts based on a specified delimiter. | |
bool | HasSuffix (const std::string &haystack, const std::string &needle, bool case_sensitive) |
Checks if a string ends with a specified suffix. | |
bool | ConstantTimeStringCompare (const std::string &a, const std::string &b) |
Performs a constant-time comparison of two strings. | |
std::string | SafeStringEscape (const std::string &input) |
Escapes a string using percent-encoding (URL encoding). | |
std::string | SafeStringUnescape (const std::string &input) |
Decodes a percent-encoded (URL-encoded) string. | |
bool | StringToInt (const std::string &input, int &i) |
Converts a string to an integer. | |
bool ConstantTimeStringCompare | ( | const std::string & | a, |
const std::string & | b | ||
) |
Performs a constant-time comparison of two strings.
This function compares two strings in a way that avoids timing attacks by ensuring that the execution time does not depend on the input values. It XORs each corresponding character and accumulates the differences, preventing early termination.
false
. bool HasSuffix | ( | const std::string & | haystack, |
const std::string & | needle, | ||
bool | case_sensitive | ||
) |
Checks if a string ends with a specified suffix.
This function determines whether the haystack
string ends with the needle
string. It supports both case-sensitive and case-insensitive comparisons.
true
if haystack
ends with needle
, otherwise false
.needle
is longer than haystack
, the function immediately returns false
. std::string SafeStringEscape | ( | const std::string & | input | ) |
Escapes a string using percent-encoding (URL encoding).
This function converts special characters in the input string into percent-encoded format, making it safe for use in URLs or other contexts where special characters need to be encoded. Alphanumeric characters and -
, _
, .
, and ~
are left unchanged.
std::string SafeStringUnescape | ( | const std::string & | input | ) |
Decodes a percent-encoded (URL-encoded) string.
This function converts percent-encoded sequences (e.g., %20
for space) back into their ASCII character equivalents. It scans the input string and replaces any valid XX
hexadecimal escape sequences with their corresponding characters.
void SplitString | ( | std::string & | input, |
char | delim, | ||
std::vector< std::string > & | parts | ||
) |
Splits a string into parts based on a specified delimiter.
This function tokenizes an input string by the given delimiter and stores the resulting substrings in a vector. It also removes trailing carriage return (\r
) characters from each token.
parts
.parts
vector by clearing its contents before adding new elements. bool StringToInt | ( | const std::string & | input, |
int & | i | ||
) |
Converts a string to an integer.
Attempts to parse an integer from the given string. If successful, the parsed integer is stored in the output parameter, and the function returns true
. If the conversion fails due to an invalid format or an out-of-range value, the function returns false
.
i
if the conversion fails.