29 #ifndef _STRING_TOOLS_H_ 30 #define _STRING_TOOLS_H_ 34 # include <winsock2.h> 42 #include <type_traits> 43 #include <boost/lexical_cast.hpp> 44 #include <boost/algorithm/string/predicate.hpp> 58 #ifdef WINDOWS_PLATFORM 59 #pragma comment (lib, "Rpcrt4.lib") 62 static const constexpr
unsigned char isx[256] =
64 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
65 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
66 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
67 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
68 0xff, 10, 11, 12, 13, 14, 15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
69 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
70 0xff, 10, 11, 12, 13, 14, 15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
71 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
72 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
73 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
74 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
75 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
76 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
77 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
78 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
79 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
84 namespace string_tools
97 unsigned char *dst = (
unsigned char *)&
res[0];
98 const unsigned char *src = (
const unsigned char *)s.
data();
99 for(
size_t i = 0; i < s.
size(); i += 2)
103 if (tmp == 0xff)
return false;
106 if (
t2 == 0xff)
return false;
107 *dst++ = (tmp << 4) |
t2;
117 res.resize(s.size() / 2);
124 template<
class XType>
129 for (
char c : str_id)
138 val = boost::lexical_cast<XType>(str_id);
141 catch(
const std::exception& )
155 template<
class XType>
177 std::string::size_type p = addres.find(
':');
179 if(p == std::string::npos)
186 ip_str = addres.substr(0, p);
187 port_str = addres.substr(p+1, addres.size());
213 std::stringstream ss;
214 ss << std::hex << val;
224 return !boost::iequals(str1, str2);
236 return module_folder;
242 char pname [5000] = {0};
243 GetModuleFileNameA( NULL, pname,
sizeof(pname));
244 pname[
sizeof(pname)-1] = 0;
253 path_to_process = get_current_module_path();
255 std::string::size_type
a = path_to_process.rfind(
'\\' );
256 if(
a == std::string::npos )
258 a = path_to_process.rfind(
'/' );
260 if (
a != std::string::npos )
273 for(std::string::iterator it = str.begin(); it!= str.end() &&
isspace(static_cast<unsigned char>(*it));)
274 str.erase(str.begin());
282 for(std::string::reverse_iterator it = str.rbegin(); it!= str.rend() &&
isspace(static_cast<unsigned char>(*it));)
283 str.erase( --((it++).base()));
311 s.append(n - s.size(), c);
316 template<
class t_pod_type>
319 static_assert(std::is_standard_layout<t_pod_type>(),
"expected standard layout type");
323 template<
class t_pod_type>
327 if(
sizeof(s)*2 != hex_str.size())
333 template<
class t_pod_type>
339 template<
class t_pod_type>
350 std::string::size_type pos = str.rfind(
'.');
351 if(std::string::npos == pos)
354 res = str.substr(pos+1, str.size()-pos);
361 std::string::size_type pos = str.rfind(
'.');
362 if(std::string::npos == pos)
365 res = str.substr(0, pos);
374 int wstr_size = MultiByteToWideChar(CP_UTF8, 0, &str[0], str.size(), NULL, 0);
377 throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).
message());
380 if (!MultiByteToWideChar(CP_UTF8, 0, &str[0], str.size(), &wstr[0], wstr_size))
382 throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).
message());
390 int str_size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), NULL, 0, NULL, NULL);
393 throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).
message());
396 if (!WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), &str[0], str_size, NULL, NULL))
398 throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).
message());
405 #endif //_STRING_TOOLS_H_
#define DISABLE_GCC_WARNING
span< const std::uint8_t > as_byte_span(const T &src) noexcept
Non-owning sequence of data. Does not deep copy.
constexpr std::size_t size() const noexcept
unsigned __int64 uint64_t
std::string message("Message requiring signing")
boost::endian::big_uint32_t ip
boost::endian::big_uint16_t port
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
constexpr span< const typename T::value_type > to_span(const T &src)
const GenericPointer< typename T::ValueType > T2 value
T & unwrap(mlocked< T > &src)
static std::string string(const span< const std::uint8_t > src)
span< const std::uint8_t > to_byte_span(const span< const T > src) noexcept
constexpr pointer data() const noexcept