![]() |
Kea 2.2.0
|
Implements a regular expression based string scrubber. More...
#include <strutil.h>
Public Member Functions | |
| StringSanitizer (const std::string &char_set, const std::string &char_replacement) | |
| Constructor. More... | |
| ~StringSanitizer () | |
| Destructor. More... | |
| std::string | scrub (const std::string &original) |
| Returns a scrubbed copy of a given string. More... | |
Static Public Attributes | |
| static const uint32_t | MAX_DATA_SIZE = 4096 |
| The maximum size for regex parameters. More... | |
Implements a regular expression based string scrubber.
The implementation uses C++11 regex IF the environment supports it (tested in configure.ac). If not it falls back to C lib regcomp/regexec. Older compilers, such as pre Gnu g++ 4.9.0, provided only experimental implementations of regex which are recognized as buggy.
| isc::util::str::StringSanitizer::StringSanitizer | ( | const std::string & | char_set, |
| const std::string & | char_replacement | ||
| ) |
Constructor.
Compiles the given character set into a regular expression, and retains the given character replacement. Thereafter, the instance may be used to scrub an arbitrary number of strings.
| char_set | string containing a regular expression (POSIX extended syntax) that describes the characters to replace. If you wanted to sanitize hostnames for example, you could specify the inversion of valid characters "[^A-Za-z0-9_-]". |
| char_replacement | string of one or more characters to use as the replacement for invalid characters. |
| BadValue | if given an invalid regular expression |
Definition at line 438 of file strutil.cc.
| isc::util::str::StringSanitizer::~StringSanitizer | ( | ) |
| std::string isc::util::str::StringSanitizer::scrub | ( | const std::string & | original | ) |
Returns a scrubbed copy of a given string.
Replaces all occurrences of characters described by the regular expression with the character replacement.
| original | the string to scrub |
| Unexpected | if an error occurs during scrubbing |
Definition at line 447 of file strutil.cc.
|
static |
The maximum size for regex parameters.
Definition at line 350 of file strutil.h.
Referenced by isc::util::str::StringSanitizerImpl::StringSanitizerImpl().