randolf.ca
1.00
Randolf Richardson's C++ classes
|
This rtools class primarily provides a collection of static methods that facilitate a variety of general-purpose computer programming needs. Separate classes may also be added in the future for more sophisticated needs. More...
#include <rtools>
Static Public Member Functions | |
static std::vector< std::string > * | atomize (const char *str, size_t len=0) |
Split string into an std::vector that's perfectly-sized to store all the elements separated by whitespace, but not whitespace that's enclosed within quotation marks (literal quotation marks - " - will not be intrepreted, and will be treated as literal/non-functional non-whitespace characters). | |
static std::vector< std::string > * | atomize (std::string str, size_t len=0) |
Split string into an std::vector that's perfectly-sized to store all the elements separated by whitespace, but not whitespace that's enclosed within quotation marks (literal quotation marks - " - will not be intrepreted, and will be treated as literal/non-functional non-whitespace characters). | |
static std::string | base64_decode (const char *in, const std::string b=base64_set_plus_slash) |
Decode a Base64-encoded ASCIIZ string . | |
static std::string | base64_decode (const std::string &in, const std::string b=base64_set_plus_slash) |
Decode a Base64-encoded std::string . | |
static std::string | base64_encode (const char *in, const std::string b=base64_set_plus_slash) |
Encode an ASCIIZ string into Base64 format. | |
static std::string | base64_encode (const std::string &in, const std::string b=base64_set_plus_slash) |
Encode an std::string into Base64 format. | |
static std::string | insert_commas (const char *value, size_t len=0, bool skip_dot=true, const int digits=3, const char *comma=",", const char *space=" ", const char dot='.') noexcept |
Insert commas into the last numeric sequence of digits in the supplied string and insert spaces before that (commas and spaces are configurable). If a decimal point is found, then comma insertions will only occur before that (this is also configurable). | |
static std::unordered_map< std::string, std::vector< std::string > > | parse_sasl_exchange (const std::string sasl, const bool add_missing_keys=false) |
Parses a SASL exchange, returning an std::unordered_map of the key-value pairs that were encountered. | |
static std::vector< std::string > | split (const char delimiter, const char *str, const size_t len=-1) |
Split string into an std::vector that's perfectly-sized to store all the elements separated by a delimiter character. If no delimiters are encountered, the resulting vector will contain the entire string as its only element. If the string is empty, the resulting vector will contain an empty string as its only element. | |
static std::vector< std::string > | split (const char delimiter, std::string str, const size_t len=-1) |
Split string into an std::vector that's perfectly-sized to store all the elements separated by a delimiter character. If no delimiters are encountered, the resulting vector will contain the entire string as its only element. If the string is empty, the resulting vector will contain an empty string as its only element. | |
static std::string | to_hex (const int i) noexcept |
Convert a 32-bit integer to hexadecimal. | |
static std::string | to_hex (const unsigned int i) noexcept |
Convert a 32-bit unsigned integer to hexadecimal. | |
static std::string | to_hex (const void *data, size_t len=1, const char *delimiter=nullptr) noexcept |
Convert an array of octets (8-bit bytes) to hexadecimal. | |
static std::string | to_hex (std::string data, const char *delimiter=nullptr) noexcept |
Convert an std::string's internal array of octets (8-bit bytes) to hexadecimal. | |
static std::string | to_lower (std::string &str, bool in_place_conversion=false, const int begin=0, const int len=-1) noexcept |
Convert ASCII characters in an std::string to lower case. UTF-8 characters are not converted. | |
static std::string | to_upper (std::string &str, bool in_place_conversion=false, const int begin=0, const int len=-1) noexcept |
Convert ASCII characters in an std::string to upper case. UTF-8 characters are not converted. | |
static std::string | trim_quotes (std::string str) noexcept |
Removes the outer-most/enclosing set of quotation marks from the beginning and end of the specified String, but only if both are present. | |
static void | wipe (char *data, size_t len=-1, unsigned int passes=1) |
Wipe the contents of the supplied data with random data by XOR'ing random unsigned char values with every character in the string. | |
static void | wipe (std::string &str, unsigned int passes=1) |
Wipe the contents of the supplied string with random data by XOR'ing random unsigned char values with every character in the string. The clear() method is not used because it's a waste of CPU cycles for a string that's just going to be de-allocated anyway. | |
Static Public Attributes | |
static const char * | base64_set_minus_underscore = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" |
This character set is suggested by RFC4648 (see page 8) as "safe" for use in URLs and filenames. | |
static const char * | base64_set_plus_comma = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+," |
This character set is normally used to encode IMAP4 mailbox names. | |
static const char * | base64_set_plus_slash = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" |
This character set is the default in every base64_ method in this library because it's the most commonly used for base64 encoding. | |
static const char * | base64_set_plus_tilde = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+~" |
This is an alternate character set that is rarely used, but is mentioned in RFC4648 (see page 7, second paragraph of section 5). | |
This rtools class primarily provides a collection of static methods that facilitate a variety of general-purpose computer programming needs. Separate classes may also be added in the future for more sophisticated needs.
delimiter
parameter to two to_hex methods
|
inlinestatic |
Split string into an std::vector
that's perfectly-sized to store all the elements separated by whitespace, but not whitespace that's enclosed within quotation marks (literal quotation marks - "
- will not be intrepreted, and will be treated as literal/non-functional non-whitespace characters).
Any leading and/or trailing whitespace characters will be ignored.
Multiple whitespace delimiters will be treated as a single delimiter.
Whitespace characters:
std::vector
object str | Source string (to be split into atoms) |
len | Length of string (in bytes), or 0 if str is an ASCIIZ string (NULL-terminated) |
|
inlinestatic |
Split string into an std::vector
that's perfectly-sized to store all the elements separated by whitespace, but not whitespace that's enclosed within quotation marks (literal quotation marks - "
- will not be intrepreted, and will be treated as literal/non-functional non-whitespace characters).
Any leading and/or trailing whitespace characters will be ignored.
Multiple whitespace delimiters will be treated as a single delimiter.
Whitespace characters:
std::vector
object str | Source string (to be split into atoms) |
len | Length of string (in bytes), or 0 if str is an ASCIIZ string (NULL-terminated) |
str | Source string (to be split into atoms) |
len | Length of string (in bytes), or 0 if str is an ASCIIZ string (NULL-terminated) |
|
inlinestatic |
Decode a Base64-encoded ASCIIZ string
.
All invalid characters are simply ignored.
in | ASCIIZ string to decode |
b | Base64 character set to use |
|
inlinestatic |
Decode a Base64-encoded std::string
.
All invalid characters are simply ignored.
in | String to decode |
b | Base64 character set to use |
|
inlinestatic |
Encode an ASCIIZ string
into Base64 format.
All invalid characters are simply ignored.
in | String to encode |
b | Base64 character set to use |
|
inlinestatic |
Encode an std::string
into Base64 format.
All invalid characters are simply ignored.
in | String to encode |
b | Base64 character set to use |
|
inlinestaticnoexcept |
Insert commas into the last numeric sequence of digits in the supplied string and insert spaces before that (commas and spaces are configurable). If a decimal point is found, then comma insertions will only occur before that (this is also configurable).
value | Pointer to ASCII representation of numeric value |
len | Length of value (in bytes), or 0 to auto-detect length if value string is an ASCIIZ string |
skip_dot | Don't insert any commas after the last period (or whatever string is set as the dot character) |
digits | Number of digits between commas |
comma | Pointer to ASCIIZ comma character string (nullptr = disabled) |
space | Pointer to ASCIIZ space character string (nullptr = disabled) used instead of commas for non-digit fill-ins where commas would normally be inserted |
dot | Period character used when skip_dot is enabled |
|
inlinestatic |
Parses a SASL exchange, returning an std::unordered_map
of the key-value pairs that were encountered.
std::runtime_error | If a SASL message is improperly formatted (the error message includes the offset where the format problem occurred) |
sasl | Unparsed SASL exchange string (must not be Base64-encoded) |
add_missing_keys | Ensure the following keys exist, each with one empty string: nonce, nc, cnonce, qop, realm, username, digest-uri, authzid |
|
inlinestatic |
Split string into an std::vector
that's perfectly-sized to store all the elements separated by a delimiter character. If no delimiters are encountered, the resulting vector will contain the entire string as its only element. If the string is empty, the resulting vector will contain an empty string as its only element.
std::vector
object delimiter | Character to use for the delimiter |
str | Source string (to be split) |
len | Length of string (in bytes), or -1 if str is an ASCIIZ string (NULL-terminated) |
delimiter | Character to use for the delimiter |
str | Source string (to be split into atoms) |
len | Length of string (in bytes), or 0 if using the full length of the string |
|
inlinestatic |
Split string into an std::vector
that's perfectly-sized to store all the elements separated by a delimiter character. If no delimiters are encountered, the resulting vector will contain the entire string as its only element. If the string is empty, the resulting vector will contain an empty string as its only element.
std::vector
object delimiter | Character to use for the delimiter |
str | Source string (to be split) |
len | Length of string (in bytes), or -1 if str is an ASCIIZ string (NULL-terminated) |
|
inlinestaticnoexcept |
Convert an array of octets (8-bit bytes) to hexadecimal.
data | Binary data to convert to hexadecimal |
len | Length of array (in 8-bit bytes), which can be as short as 0; if -1, then the length of the data will be measured as an ASCIIZ string; default is 1 if not specified since this is the safest option |
delimiter | Delimiter character sequence (ASCIIZ string) to insert between multiple pairs of nybblesnullptr = no delimiter (default) |
|
inlinestaticnoexcept |
Convert an std::string's internal array of octets (8-bit bytes) to hexadecimal.
data | Binary data to convert to hexadecimal |
delimiter | Delimiter character sequence (ASCIIZ string) to insert between multiple pairs of nybblesnullptr = no delimiter (default) |
|
inlinestaticnoexcept |
Convert a 32-bit integer to hexadecimal.
This method is needed because std::to_string() doesn't include an option to specify the radix.
i | Integer to convert to hexadecimal |
|
inlinestaticnoexcept |
Convert a 32-bit unsigned integer to hexadecimal.
This method is needed because std::to_string() doesn't include an option to specify the radix.
i | Integer to convert to hexadecimal |
|
inlinestaticnoexcept |
Convert ASCII characters in an std::string to lower case. UTF-8 characters are not converted.
str | Source string |
in_place_conversion | Perform in-place conversion (default is FALSE / non-destructive) |
begin | Begin conversion from this position (0 = first character) Negative positions are caculated backward from the end of the string |
len | Number of characters to convert (values exceeding string length will not cause any exceptions as the excess will be effectively ignored) -1 = maximum number of characters (a.k.a., until end of string) |
|
inlinestaticnoexcept |
Convert ASCII characters in an std::string to upper case. UTF-8 characters are not converted.
str | Source string |
in_place_conversion | Perform in-place conversion (default is FALSE / non-destructive) |
begin | Begin conversion from this position (0 = first character) Negative positions are caculated backward from the end of the string |
len | Number of characters to convert (values exceeding string length will not cause any exceptions as the excess will be effectively ignored) -1 = maximum number of characters (a.k.a., until end of string) |
|
inlinestaticnoexcept |
Removes the outer-most/enclosing set of quotation marks from the beginning and end of the specified String, but only if both are present.
str | Source string |
|
inlinestatic |
Wipe the contents of the supplied string with random data by XOR'ing random unsigned char values with every character in the string. The clear() method is not used because it's a waste of CPU cycles for a string that's just going to be de-allocated anyway.
srand()
with high resolution time once before starting the loop that calls the std::rand()
function. (Only the first 8 bits returned by std::rand()
are used; the remaining higher bits are not used.) str | String to wipe |
passes | Number of passes (default is 1) |
|
inlinestatic |
Wipe the contents of the supplied data with random data by XOR'ing random unsigned char values with every character in the string.
srand()
with high resolution time once before starting the loop that calls the std::rand()
function. (Only the first 8 bits returned by std::rand()
are used; the remaining higher bits are not used.) data | String to wipe |
len | Length of string (-1 = ASCIIZ string) |
passes | Number of passes (default is 1) |
|
inlinestatic |
This character set is suggested by RFC4648 (see page 8) as "safe" for use in URLs and filenames.
|
inlinestatic |
This character set is normally used to encode IMAP4 mailbox names.
|
inlinestatic |
This character set is the default in every base64_
method in this library because it's the most commonly used for base64 encoding.
|
inlinestatic |
This is an alternate character set that is rarely used, but is mentioned in RFC4648 (see page 7, second paragraph of section 5).