Kea 2.5.8
str.h
Go to the documentation of this file.
1// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef KEA_UTIL_STR_H
8#define KEA_UTIL_STR_H
9
11
12#include <algorithm>
13#include <cstddef>
14#include <cstdint>
15#include <memory>
16#include <sstream>
17#include <string>
18#include <vector>
19
20#include <boost/lexical_cast.hpp>
21
22namespace isc {
23namespace util {
24namespace str {
25
27
32public:
33 StringTokenError(const char* file, size_t line, const char* what)
34 : isc::Exception(file, line, what) {
35 }
36};
37
46std::string
47trim(const std::string& input);
48
63template <typename Iterator>
64Iterator
65seekTrimmed(Iterator const& begin, Iterator end, uint8_t const trim_val) {
66 while (end != begin && *(end - 1) == trim_val) {
67 --end;
68 }
69
70 return (end);
71}
72
100std::vector<std::string>
101tokens(const std::string& text, const std::string& delim = " \t\n", bool escape = false);
102
113char
114toUpper(char const chr);
115
119void
120uppercase(std::string& text);
121
132char
133toLower(char const chr);
134
138void
139lowercase(std::string& text);
140
158std::vector<uint8_t>
159quotedStringToBinary(const std::string& quoted_string);
160
179void
180decodeSeparatedHexString(const std::string& hex_string,
181 const std::string& sep,
182 std::vector<uint8_t>& binary);
183
191void
192decodeColonSeparatedHexString(const std::string& hex_string, std::vector<uint8_t>& binary);
193
212void
213decodeFormattedHexString(const std::string& hex_string, std::vector<uint8_t>& binary);
214
216class StringSanitizerImpl;
217
219using StringSanitizerImplPtr = std::shared_ptr<StringSanitizerImpl>;
220
223public:
238 StringSanitizer(const std::string& char_set, const std::string& char_replacement);
239
248 std::string scrub(const std::string& original);
249
255 static const uint32_t MAX_DATA_SIZE;
256
257private:
260};
261
263using StringSanitizerPtr = std::unique_ptr<StringSanitizer>;
264
270bool
271isPrintable(const std::string& content);
272
278bool
279isPrintable(const std::vector<uint8_t>& content);
280
286std::string
287dumpAsHex(const uint8_t* data, size_t length);
288
289} // namespace str
290} // namespace util
291} // namespace isc
292
293#endif // KEA_UTIL_STR_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Implements a regular expression based string scrubber.
Definition: str.h:222
static const uint32_t MAX_DATA_SIZE
The maximum size for regex parameters.
Definition: str.h:255
std::string scrub(const std::string &original)
Returns a scrubbed copy of a given string.
Definition: str.cc:305
A Set of C++ Utilities for Manipulating Strings.
Definition: str.h:31
StringTokenError(const char *file, size_t line, const char *what)
Definition: str.h:33
Iterator seekTrimmed(Iterator const &begin, Iterator end, uint8_t const trim_val)
Finds the "trimmed" end of a buffer.
Definition: str.h:65
string dumpAsHex(const uint8_t *data, size_t length)
Dumps a buffer of bytes as a string of hexadecimal digits.
Definition: str.cc:330
void lowercase(string &text)
Convert string to lowercase.
Definition: str.cc:134
void decodeSeparatedHexString(const string &hex_string, const string &sep, vector< uint8_t > &binary)
Converts a string of separated hexadecimal digits into a vector.
Definition: str.cc:163
char toUpper(char const chr)
Convert character to uppercase.
Definition: str.cc:119
void decodeFormattedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
Definition: str.cc:212
bool isPrintable(const string &content)
Check if a string is printable.
Definition: str.cc:310
char toLower(char const chr)
Convert character to lowercase.
Definition: str.cc:129
vector< string > tokens(const string &text, const string &delim, bool escape)
Split string into tokens.
Definition: str.cc:52
vector< uint8_t > quotedStringToBinary(const string &quoted_string)
Converts a string in quotes into vector.
Definition: str.cc:139
void decodeColonSeparatedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a string of hexadecimal digits with colons into a vector.
Definition: str.cc:158
std::shared_ptr< StringSanitizerImpl > StringSanitizerImplPtr
Type representing the pointer to the StringSanitizerImpl.
Definition: str.h:219
string trim(const string &input)
Trim leading and trailing spaces.
Definition: str.cc:32
void uppercase(string &text)
Convert string to uppercase.
Definition: str.cc:124
std::unique_ptr< StringSanitizer > StringSanitizerPtr
Type representing the pointer to the StringSanitizer.
Definition: str.h:263
Defines the logger used by the top-level component of kea-lfc.