Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
websocketpp::utility Namespace Reference

Generic non-websocket specific utility functions and data structures.

Classes

struct  ci_less
 Helper less than functor for case insensitive find. More...
 
struct  my_equal
 Helper functor for case insensitive find. More...
 

Functions

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)
 

Function Documentation

◆ ci_find_substr() [1/2]

template<typename T >
T::const_iterator websocketpp::utility::ci_find_substr ( T const & haystack,
T const & needle,
std::locale const & loc = std::locale() )
Parameters
[in]haystackThe string to search in
[in]needleThe string to search for
[in]locThe 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(),
107 needle.begin(), needle.end(), my_equal<typename T::value_type>(loc) );
108}
Helper functor for case insensitive find.
Definition utilities.hpp:49
Here is the caller graph for this function:

◆ ci_find_substr() [2/2]

template<typename T >
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]haystackThe string to search in
[in]needleThe string to search for as a char array of values
[in]sizeLength of needle
[in]locThe 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(),
130 needle, needle+size, my_equal<typename T::value_type>(loc) );
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]subjectThe string to search in
[in]searchThe string to search for
[in]replaceThe 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}
Here is the caller graph for this function:

◆ to_hex() [1/3]

std::string websocketpp::utility::to_hex ( char const * input,
size_t length )
inline
Parameters
[in]inputThe char array to print
[in]lengthThe 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}
unsigned char uint8_t
Definition stdint.h:124
Here is the call graph for this function:

◆ to_hex() [2/3]

std::string websocketpp::utility::to_hex ( std::string const & input)
inline
Parameters
[in]inputThe 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}
Here is the caller graph for this function:

◆ to_hex() [3/3]

std::string websocketpp::utility::to_hex ( uint8_t const * input,
size_t length )
inline
Parameters
[in]inputThe byte array to print
[in]lengthThe 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]inThe 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}
Here is the caller graph for this function: