Kea
1.9.9-git
|
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 | |
typedef boost::shared_ptr< StringSanitizer > | StringSanitizerPtr |
Functions | |
void | decodeColonSeparatedHexString (const std::string &hex_string, std::vector< uint8_t > &binary) |
Converts a string of hexadecimal digits with colons into a vector. More... | |
void | decodeFormattedHexString (const std::string &hex_string, std::vector< uint8_t > &binary) |
Converts a formatted string of hexadecimal digits into a vector. More... | |
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. More... | |
std::string | format (const std::string &format, const std::vector< std::string > &args) |
Apply Formatting. More... | |
std::string | getToken (std::istringstream &iss) |
Returns one token from the given stringstream. More... | |
bool | isPrintable (const std::string &content) |
Check if a string is printable. More... | |
bool | isPrintable (const std::vector< uint8_t > &content) |
Check if a byte vector is printable. More... | |
void | lowercase (std::string &text) |
Lowercase String. More... | |
void | normalizeSlash (std::string &name) |
Normalize Backslash. More... | |
std::vector< uint8_t > | quotedStringToBinary (const std::string "ed_string) |
Converts a string in quotes into vector. More... | |
template<typename Iterator > | |
Iterator | seekTrimmed (Iterator begin, Iterator end, uint8_t trim_val) |
Finds the "trimmed" end of a buffer. More... | |
vector< string > | tokens (const std::string &text, const std::string &delim=std::string(" \t\n"), bool escape=false) |
Split String into Tokens. More... | |
template<typename NumType , int BitSize> | |
NumType | tokenToNum (const std::string &num_token) |
Converts a string token to an unsigned integer. More... | |
char | toLower (char chr) |
Lowercase Character. More... | |
char | toUpper (char chr) |
Uppercase Character. More... | |
string | trim (const std::string &instring) |
Trim Leading and Trailing Spaces. More... | |
void | uppercase (std::string &text) |
Uppercase String. More... | |
typedef boost::shared_ptr<StringSanitizer> isc::util::str::StringSanitizerPtr |
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.
Convenience method which calls decodeSeparatedHexString()
passing in a colon for the separator.
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 215 of file strutil.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 273 of file strutil.cc.
References isc::util::encode::decodeHex(), decodeSeparatedHexString(), and isc_throw.
Referenced by isc::dhcp::DUID::fromText(), isc::dhcp::ClientId::fromText(), and isc::dhcp::Host::setIdentifier().
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 a a separator. |
binary | Vector receiving converted string into binary. |
isc::BadValue | if the format of the input string is invalid. |
Definition at line 221 of file strutil.cc.
References isc_throw.
Referenced by decodeColonSeparatedHexString(), and decodeFormattedHexString().
std::string isc::util::str::format | ( | const std::string & | format, |
const std::vector< std::string > & | args | ||
) |
Apply Formatting.
Given a printf-style format string containing only "%s" place holders (others are ignored) and a vector of strings, this produces a single string with the placeholders replaced.
format | Format string |
args | Vector of argument strings |
Definition at line 157 of file strutil.cc.
Referenced by isc::db::PgSqlExchange::dumpRow(), isc::yang::TranslatorOptionData::getOptionDataKea(), isc::yang::TranslatorOptionData::setOptionDataKea(), and isc::yang::TranslatorConfig::setServerKeaDhcpCommon().
std::string isc::util::str::getToken | ( | std::istringstream & | iss | ) |
Returns one token from the given stringstream.
Using the >> operator, with basic error checking
StringTokenError | if the token cannot be read from the stream |
iss | stringstream to read one token from |
Definition at line 186 of file strutil.cc.
References isc_throw.
|
inline |
Check if a string is printable.
content | String to check for printable characters |
Definition at line 355 of file strutil.h.
Referenced by isc::flex_option::FlexOptionImpl::logAction().
|
inline |
|
inline |
Lowercase String.
A convenience function to lowercase a string
text | String to be lower-cased. |
Definition at line 151 of file strutil.h.
References toLower().
Referenced by isc::http::BasicHttpAuthConfig::checkAuth(), isc::http::HttpHeader::getLowerCaseName(), isc::http::HttpHeader::getLowerCaseValue(), and isc::http::HttpHeader::isValueEqual().
void isc::util::str::normalizeSlash | ( | std::string & | name | ) |
Normalize Backslash.
Only relevant to Windows, this replaces all "\" in a string with "/" and returns the result. On other systems it is a no-op. Note that Windows does recognize file names with the "\" replaced by "/" (at least in system calls, if not the command line).
name | Name to be substituted |
Definition at line 41 of file strutil.cc.
Referenced by isc::util::Filename::expandWithDefault(), isc::util::Filename::setName(), and isc::util::Filename::useAsDefault().
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 196 of file strutil.cc.
References trim().
Referenced by isc::yang::AdaptorHost::quoteIdentifier(), and isc::dhcp::Host::setIdentifier().
Iterator isc::util::str::seekTrimmed | ( | Iterator | begin, |
Iterator | end, | ||
uint8_t | 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 that 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 72 of file strutil.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 = std::string(" \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 array. Note that adjacent delimiters are considered to be a single delimiter.
Special 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 77 of file strutil.cc.
Referenced by isc::dhcp::OptionDefParser::parse(), isc::db::DatabaseConnection::parse(), isc::flex_option::FlexOptionImpl::process(), and splitNamespace().
NumType isc::util::str::tokenToNum | ( | const std::string & | num_token | ) |
Converts a string token to an unsigned integer.
The value is converted using a lexical cast, with error and bounds checking.
NumType is a signed integral type (e.g. int32_t) that is sufficiently wide to store resulting integers.
BitSize is the maximum number of bits that the resulting integer can take. This function first checks whether the given token can be converted to an integer of NumType type. It then confirms the conversion result is within the valid range, i.e., [0, 2^BitSize - 1]. The second check is necessary because lexical_cast<T> where T is an unsigned integer type doesn't correctly reject negative numbers when compiled with SunStudio.
StringTokenError | if the value is out of range, or if it could not be converted |
num_token | the string token to convert |
Definition at line 204 of file strutil.h.
References isc_throw.
|
inline |
Lowercase Character.
Used in lowercase() to pass as an argument to std::transform(). The function std::tolower() can't be used as it takes an "int" as its argument; this confuses the template expansion mechanism because dereferencing a string::iterator returns a char.
chr | Character to be lower-cased. |
Definition at line 142 of file strutil.h.
Referenced by lowercase().
|
inline |
Uppercase Character.
Used in uppercase() to pass as an argument to std::transform(). The function std::toupper() can't be used as it takes an "int" as its argument; this confuses the template expansion mechanism because dereferencing a string::iterator returns a char.
chr | Character to be upper-cased. |
Definition at line 118 of file strutil.h.
Referenced by uppercase().
std::string isc::util::str::trim | ( | const std::string & | instring | ) |
Trim Leading and Trailing Spaces.
Returns a copy of the input string but with any leading or trailing spaces or tabs removed.
instring | Input string to modify |
Definition at line 53 of file strutil.cc.
Referenced by isc::http::BasicHttpAuthConfig::checkAuth(), isc::dhcp::ClientClasses::ClientClasses(), isc::util::Filename::expandWithDefault(), isc::dhcp::OptionDefinition::optionFactory(), isc::hooks::HooksLibrariesParser::parse(), isc::dhcp::OptionDefParser::parse(), isc::db::DatabaseConnection::parse(), isc::log::MessageReader::processLine(), quotedStringToBinary(), isc::dhcp::Option6ClientFqdnImpl::setDomainName(), isc::dhcp::Option4ClientFqdnImpl::setDomainName(), isc::dhcp::CfgDUID::setIdentifier(), isc::util::Filename::setName(), isc::ha::HAConfig::PeerConfig::setName(), isc::ha::HAConfig::setThisServerName(), isc::dhcp::CfgIface::use(), and isc::util::Filename::useAsDefault().
|
inline |
Uppercase String.
A convenience function to uppercase a string.
text | String to be upper-cased. |
Definition at line 127 of file strutil.h.
References toUpper().
Referenced by sentinel().