Kea 2.7.6
|
Classes | |
class | StringSanitizer |
Implements a regular expression based string scrubber. More... | |
class | StringSanitizerImpl |
class | StringTokenError |
A Set of C++ Utilities for Manipulating Strings. More... | |
Typedefs | |
using | StringSanitizerImplPtr = std::shared_ptr<StringSanitizerImpl> |
Type representing the pointer to the StringSanitizerImpl . | |
using | StringSanitizerPtr = std::unique_ptr<StringSanitizer> |
Type representing the pointer to the StringSanitizer . | |
Functions | |
void | decodeColonSeparatedHexString (const std::string &hex_string, std::vector< uint8_t > &binary) |
Converts a string of hexadecimal digits with colons into a vector. | |
void | decodeFormattedHexString (const std::string &hex_string, std::vector< uint8_t > &binary) |
Converts a formatted string of hexadecimal digits into a vector. | |
void | decodeSeparatedHexString (const std::string &hex_string, const std::string &sep, std::vector< uint8_t > &binary) |
Converts a string of separated hexadecimal digits into a vector. | |
string | dumpAsHex (const uint8_t *data, size_t length) |
Dumps a buffer of bytes as a string of hexadecimal digits. | |
string | dumpDouble (double val, size_t precision=5) |
Converts a double to a string with given precision. | |
bool | isPrintable (const std::string &content) |
Check if a string is printable. | |
bool | isPrintable (const std::vector< uint8_t > &content) |
Check if a byte vector is printable. | |
void | lowercase (std::string &text) |
Convert string to lowercase. | |
vector< uint8_t > | quotedStringToBinary (const std::string "ed_string) |
Converts a string in quotes into vector. | |
template<typename Iterator > | |
Iterator | seekTrimmed (Iterator const &begin, Iterator end, uint8_t const trim_val) |
Finds the "trimmed" end of a buffer. | |
vector< string > | tokens (const std::string &text, const std::string &delim=" \t\n", bool escape=false) |
Split string into tokens. | |
char | toLower (char const chr) |
Convert character to lowercase. | |
char | toUpper (char const chr) |
Convert character to uppercase. | |
string | trim (const std::string &input) |
Trim leading and trailing spaces. | |
void | uppercase (std::string &text) |
Convert string to uppercase. | |
using isc::util::str::StringSanitizerImplPtr = std::shared_ptr<StringSanitizerImpl> |
Type representing the pointer to the StringSanitizerImpl
.
using isc::util::str::StringSanitizerPtr = std::unique_ptr<StringSanitizer> |
Type representing the pointer to the StringSanitizer
.
void isc::util::str::decodeColonSeparatedHexString | ( | const std::string & | hex_string, |
std::vector< uint8_t > & | binary ) |
Converts a string of hexadecimal digits with colons into a vector.
hex_string | Input string. |
binary | Vector receiving converted string into binary. |
isc::BadValue | if the format of the input string is invalid. |
Definition at line 158 of file str.cc.
References decodeSeparatedHexString().
Referenced by isc::dhcp::HWAddr::fromText().
void isc::util::str::decodeFormattedHexString | ( | const std::string & | hex_string, |
std::vector< uint8_t > & | binary ) |
Converts a formatted string of hexadecimal digits into a vector.
This function supports the following formats:
decodeSeparatedHexString
If there is an odd number of hexadecimal digits in the input string, the '0' is prepended to the string before decoding.
hex_string | Input string. |
binary | Vector receiving converted string into binary. |
isc::BadValue | if the format of the input string is invalid. |
Definition at line 212 of file str.cc.
References isc::util::encode::decodeHex(), decodeSeparatedHexString(), and isc_throw.
Referenced by isc::dhcp::OptionDataParser::createOption(), isc::dhcp::IdentifierType< min_size, max_size >::fromText(), isc::dhcp::Dhcpv4Srv::recoverStashedAgentOption(), isc::dhcp::Host::setIdentifier(), isc::dhcp::LeaseMgr::upgradeLease4ExtendedInfo(), and isc::dhcp::LeaseMgr::upgradeLease6ExtendedInfo().
void isc::util::str::decodeSeparatedHexString | ( | const std::string & | hex_string, |
const std::string & | sep, | ||
std::vector< uint8_t > & | binary ) |
Converts a string of separated hexadecimal digits into a vector.
Octets may contain 1 or 2 digits. For example, using a colon for a separator all of the following are valid:
If the decoded string doesn't match any of the supported formats, an exception is thrown.
hex_string | Input string. |
sep | character to use as a separator. |
binary | Vector receiving converted string into binary. |
isc::BadValue | if the format of the input string is invalid. |
Definition at line 163 of file str.cc.
References isc_throw.
Referenced by decodeColonSeparatedHexString(), and decodeFormattedHexString().
std::string isc::util::str::dumpAsHex | ( | const uint8_t * | data, |
size_t | length ) |
Dumps a buffer of bytes as a string of hexadecimal digits.
data | Pointer to the data to dump. |
length | Number of bytes to dump. Caller should ensure the length does not exceed the buffer. |
Definition at line 330 of file str.cc.
Referenced by isc::tcp::TcpStreamRequest::logFormatRequest(), and isc::dhcp::Lease4::toText().
std::string isc::util::str::dumpDouble | ( | double | val, |
size_t | precision = 5 ) |
Converts a double to a string with given precision.
val | double to convert |
precision | number of maximum number decimal places to output |
Definition at line 344 of file str.cc.
Referenced by isc::dhcp::calculateDdnsTtl().
bool isc::util::str::isPrintable | ( | const std::string & | content | ) |
Check if a string is printable.
content | String to check for printable characters. |
Definition at line 310 of file str.cc.
Referenced by isc::flex_option::FlexOptionImpl::logAction(), isc::flex_option::FlexOptionImpl::logSubAction(), and isc::dhcp::Option::toText().
bool isc::util::str::isPrintable | ( | const std::vector< uint8_t > & | content | ) |
void isc::util::str::lowercase | ( | std::string & | text | ) |
Convert string to lowercase.
text | String to be lower-cased. |
Definition at line 134 of file str.cc.
References toLower().
Referenced by isc::http::BasicHttpAuthConfig::checkAuth(), isc::http::HttpHeader::getLowerCaseName(), isc::http::HttpHeader::getLowerCaseValue(), and isc::http::HttpHeader::isValueEqual().
std::vector< uint8_t > isc::util::str::quotedStringToBinary | ( | const std::string & | quoted_string | ) |
Converts a string in quotes into vector.
A converted string is first trimmed. If a trimmed string is in quotes, the quotes are removed and the resulting string is copied into a vector. If the string is not in quotes, an empty vector is returned.
The resulting string is copied to a vector and returned.
This function is intended to be used by the server configuration parsers to convert string values surrounded with quotes into binary form.
quoted_string | String to be converted. |
Definition at line 139 of file str.cc.
References trim().
Referenced by isc::dhcp::OptionDataParser::createOption(), isc::yang::AdaptorHost::quoteIdentifier(), and isc::dhcp::Host::setIdentifier().
Iterator isc::util::str::seekTrimmed | ( | Iterator const & | begin, |
Iterator | end, | ||
uint8_t const | trim_val ) |
Finds the "trimmed" end of a buffer.
Works backward from the end of the buffer, looking for the first character not equal to the trim value, and returns an iterator pointing to that position.
begin | - Forward iterator pointing to the beginning of the buffer to trim. |
end | - Forward iterator pointing to the untrimmed end of the buffer to trim. |
trim_val | - byte value to trim off |
Definition at line 65 of file str.h.
Referenced by isc::dhcp::OptionDataTypeUtil::readString(), isc::dhcp::OptionString::setValue(), and isc::dhcp::OptionString::unpack().
std::vector< std::string > isc::util::str::tokens | ( | const std::string & | text, |
const std::string & | delim = " \t\n", | ||
bool | escape = false ) |
Split string into tokens.
Splits a string into tokens (the tokens being delimited by one or more of the delimiter characters) and returns the tokens in a vector. Adjacent delimiters are considered to be a single delimiter.
Special use cases are:
The reasoning behind this is that the string can be thought of as having invisible leading and trailing delimiter characters. Therefore both cases reduce to a set of contiguous delimiters, which are considered a single delimiter (so getting rid of the string). Optional escape allows to escape delimiter characters (and only them and the escape character itself) using backslash.
We could use Boost for this, but this (simple) function eliminates one dependency in the code.
text | String to be split. Passed by value as the internal copy is altered during the processing. |
delim | Delimiter characters |
escape | Use backslash to escape delimiter characters |
Definition at line 52 of file str.cc.
Referenced by isc::dhcp::OptionDataParser::createOption(), isc::dhcp::OptionDefParser::parse(), isc::dhcp::DnrInstance::parseDnrInstanceConfigData(), isc::flex_option::FlexOptionImpl::process(), and splitNamespace().
char isc::util::str::toLower | ( | char const | chr | ) |
Convert character to lowercase.
Used in lowercase() to pass as a parameter to std::transform(). The function std::tolower() can't be used as it takes an "int" as its parameter; this confuses the template expansion mechanism because dereferencing a string::iterator returns a char.
chr | Character to be lower-cased. |
Definition at line 129 of file str.cc.
Referenced by lowercase().
char isc::util::str::toUpper | ( | char const | chr | ) |
Convert character to uppercase.
Used in uppercase() to pass as a parameter to std::transform(). The function std::toupper() can't be used as it takes an "int" as its parameter; this confuses the template expansion mechanism because dereferencing a string::iterator returns a char.
chr | Character to be upper-cased. |
Definition at line 119 of file str.cc.
Referenced by uppercase().
std::string isc::util::str::trim | ( | const std::string & | input | ) |
Trim leading and trailing spaces.
Returns a copy of the input string but with any leading or trailing spaces or tabs removed.
input | Input string to modify. |
Definition at line 32 of file str.cc.
Referenced by isc::dhcp::ClientClasses::ClientClasses(), isc::dhcp::OptionDescriptor::addClientClass(), isc::http::BasicHttpAuthConfig::checkAuth(), isc::dhcp::OptionDefinition::optionFactory(), isc::db::DatabaseConnection::parse(), isc::hooks::HooksLibrariesParser::parse(), isc::dhcp::DnrInstance::parseDnrInstanceConfigData(), isc::log::MessageReader::processLine(), quotedStringToBinary(), isc::util::file::Path::replaceExtension(), isc::util::file::Path::replaceParentPath(), isc::dhcp::Option4ClientFqdnImpl::setDomainName(), isc::dhcp::Option6ClientFqdnImpl::setDomainName(), isc::dhcp::CfgDUID::setIdentifier(), isc::ha::HAConfig::PeerConfig::setName(), isc::ha::HAConfig::setThisServerName(), and isc::dhcp::CfgIface::use().
void isc::util::str::uppercase | ( | std::string & | text | ) |
Convert string to uppercase.
text | String to be upper-cased. |
Definition at line 124 of file str.cc.
References toUpper().
Referenced by sentinel().