![]() |
CARTA Backend
The backend component of CARTA
|
#include <string>
#include <vector>
Functions | |
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. | |
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=false) |
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. | |
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.
[in] | a | The first string to compare. |
[in] | b | The second string to compare. |
true
if both strings are equal, otherwise false
.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.
[in] | haystack | The string to be checked. |
[in] | needle | The suffix to look for. |
[in] | case_sensitive | If true , performs a case-sensitive comparison; if false , ignores case differences. |
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).
[in] | input | The string to be escaped. |
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.
[in] | input | The percent-encoded string to be decoded. |
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.
[in] | input | The string to be split. |
[in] | delim | The character delimiter used to separate the input string. |
[out] | parts | A vector to store the resulting substrings. It is cleared before new values are added. |
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.
[in] | input | The string to be converted to an integer. |
[out] | i | Reference to an integer where the result will be stored if conversion succeeds. |
true
if the conversion is successful, false
otherwise.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.