Generic non-websocket specific utility functions and data structures.
|
std::string | to_lower (std::string const &in) |
| Convert a string to lowercase.
|
|
std::string | to_hex (std::string const &input) |
| Convert std::string to ascii printed string of hex digits.
|
|
std::string | to_hex (uint8_t const *input, size_t length) |
| Convert byte array (uint8_t) to ascii printed string of hex digits.
|
|
std::string | to_hex (char const *input, size_t length) |
| Convert char array to ascii printed string of hex digits.
|
|
std::string | string_replace_all (std::string subject, std::string const &search, std::string const &replace) |
| Replace all occurrances of a substring with another.
|
|
template<typename T > |
T::const_iterator | ci_find_substr (T const &haystack, T const &needle, std::locale const &loc=std::locale()) |
| Find substring (case insensitive)
|
|
template<typename T > |
T::const_iterator | ci_find_substr (T const &haystack, typename T::value_type const *needle, typename T::size_type size, std::locale const &loc=std::locale()) |
| Find substring (case insensitive)
|
|
◆ ci_find_substr() [1/2]
T::const_iterator websocketpp::utility::ci_find_substr |
( |
T const & | haystack, |
|
|
T const & | needle, |
|
|
std::locale const & | loc = std::locale() ) |
- Parameters
-
[in] | haystack | The string to search in |
[in] | needle | The string to search for |
[in] | loc | The locale to use for determining the case of values. Defaults to the current locale. |
- Returns
- An iterator to the first element of the first occurrance of needle in haystack. If the sequence is not found, the function returns haystack.end()
Definition at line 103 of file utilities.hpp.
105{
106 return std::search( haystack.begin(), haystack.end(),
108}
Helper functor for case insensitive find.
◆ ci_find_substr() [2/2]
T::const_iterator websocketpp::utility::ci_find_substr |
( |
T const & | haystack, |
|
|
typename T::value_type const * | needle, |
|
|
typename T::size_type | size, |
|
|
std::locale const & | loc = std::locale() ) |
- Todo
- Is this still used? This method may not make sense.. should use iterators or be less generic. As is it is too tightly coupled to std::string
- Parameters
-
[in] | haystack | The string to search in |
[in] | needle | The string to search for as a char array of values |
[in] | size | Length of needle |
[in] | loc | The locale to use for determining the case of values. Defaults to the current locale. |
- Returns
- An iterator to the first element of the first occurrance of needle in haystack. If the sequence is not found, the function returns haystack.end()
Definition at line 125 of file utilities.hpp.
128{
129 return std::search( haystack.begin(), haystack.end(),
131}
◆ string_replace_all()
std::string websocketpp::utility::string_replace_all |
( |
std::string | subject, |
|
|
std::string const & | search, |
|
|
std::string const & | replace ) |
|
inline |
- Parameters
-
[in] | subject | The string to search in |
[in] | search | The string to search for |
[in] | replace | The string to replace with |
- Returns
- A copy of
subject
with all occurances of search
replaced with replace
Definition at line 73 of file utilities_impl.hpp.
75{
76 size_t pos = 0;
77 while((pos = subject.find(search, pos)) != std::string::npos) {
78 subject.replace(pos, search.length(), replace);
79 pos += replace.length();
80 }
81 return subject;
82}
◆ to_hex() [1/3]
std::string websocketpp::utility::to_hex |
( |
char const * | input, |
|
|
size_t | length ) |
|
inline |
- Parameters
-
[in] | input | The char array to print |
[in] | length | The length of input |
- Returns
- A copy of
input
converted to the printable representation of the hex values of its data.
Definition at line 69 of file utilities_impl.hpp.
69 {
70 return to_hex(
reinterpret_cast<const uint8_t*
>(input),length);
71}
◆ to_hex() [2/3]
std::string websocketpp::utility::to_hex |
( |
std::string const & | input | ) |
|
|
inline |
- Parameters
-
[in] | input | The string to print |
- Returns
- A copy of
input
converted to the printable representation of the hex values of its data.
Definition at line 43 of file utilities_impl.hpp.
43 {
44 std::string output;
45 std::string hex = "0123456789ABCDEF";
46
47 for (size_t i = 0; i < input.size(); i++) {
48 output += hex[(input[i] & 0xF0) >> 4];
49 output += hex[input[i] & 0x0F];
50 output += " ";
51 }
52
53 return output;
54}
◆ to_hex() [3/3]
std::string websocketpp::utility::to_hex |
( |
uint8_t const * | input, |
|
|
size_t | length ) |
|
inline |
- Parameters
-
[in] | input | The byte array to print |
[in] | length | The length of input |
- Returns
- A copy of
input
converted to the printable representation of the hex values of its data.
Definition at line 56 of file utilities_impl.hpp.
56 {
57 std::string output;
58 std::string hex = "0123456789ABCDEF";
59
60 for (size_t i = 0; i < length; i++) {
61 output += hex[(input[i] & 0xF0) >> 4];
62 output += hex[input[i] & 0x0F];
63 output += " ";
64 }
65
66 return output;
67}
◆ to_lower()
std::string websocketpp::utility::to_lower |
( |
std::string const & | in | ) |
|
|
inline |
- Parameters
-
[in] | in | The string to convert |
- Returns
- The converted string
Definition at line 37 of file utilities_impl.hpp.
37 {
38 std::string out = in;
39 std::transform(out.begin(),out.end(),out.begin(),::tolower);
40 return out;
41}