Electroneum
Loading...
Searching...
No Matches
epee::string_tools Namespace Reference

Functions

std::string buff_to_hex_nodelimer (const std::string &src)
bool parse_hexstr_to_binbuff (const epee::span< const char > s, epee::span< char > &res)
bool parse_hexstr_to_binbuff (const std::string &s, std::string &res)
template<class XType>
PUSH_WARNINGS bool get_xtype_from_string (OUT XType &val, const std::string &str_id)
template<class XType>
POP_WARNINGS bool xtype_to_string (const XType &val, std::string &str)
std::string get_ip_string_from_int32 (uint32_t ip)
bool get_ip_int32_from_string (uint32_t &ip, const std::string &ip_str)
bool parse_peer_from_string (uint32_t &ip, uint16_t &port, const std::string &addres)
std::string num_to_string_fast (int64_t val)
std::string to_string_hex (uint32_t val)
bool compare_no_case (const std::string &str1, const std::string &str2)
std::string & get_current_module_name ()
std::string & get_current_module_folder ()
bool set_module_name_and_folder (const std::string &path_to_process_)
bool trim_left (std::string &str)
bool trim_right (std::string &str)
std::string & trim (std::string &str)
std::string trim (const std::string &str_)
std::string pad_string (std::string s, size_t n, char c=' ', bool prepend=false)
template<class t_pod_type>
std::string pod_to_hex (const t_pod_type &s)
template<class t_pod_type>
bool hex_to_pod (const std::string &hex_str, t_pod_type &s)
template<class t_pod_type>
bool hex_to_pod (const std::string &hex_str, tools::scrubbed< t_pod_type > &s)
template<class t_pod_type>
bool hex_to_pod (const std::string &hex_str, epee::mlocked< t_pod_type > &s)
bool validate_hex (uint64_t length, const std::string &str)
std::string get_extension (const std::string &str)
std::string cut_off_extension (const std::string &str)

Function Documentation

◆ buff_to_hex_nodelimer()

std::string epee::string_tools::buff_to_hex_nodelimer ( const std::string & src)
inline

Definition at line 87 of file string_tools.h.

88 {
90 }
span< const std::uint8_t > to_byte_span(const span< const T > src) noexcept
Definition span.h:145
constexpr span< const typename T::value_type > to_span(const T &src)
Definition span.h:123
static std::string string(const span< const std::uint8_t > src)
Definition hex.cpp:68
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_no_case()

bool epee::string_tools::compare_no_case ( const std::string & str1,
const std::string & str2 )
inline

Definition at line 221 of file string_tools.h.

222 {
223
224 return !boost::iequals(str1, str2);
225 }
Here is the caller graph for this function:

◆ cut_off_extension()

std::string epee::string_tools::cut_off_extension ( const std::string & str)
inline

Definition at line 358 of file string_tools.h.

359 {
360 std::string res;
361 std::string::size_type pos = str.rfind('.');
362 if(std::string::npos == pos)
363 return str;
364
365 res = str.substr(0, pos);
366 return res;
367 }
const char * res

◆ get_current_module_folder()

std::string & epee::string_tools::get_current_module_folder ( )
inline

Definition at line 233 of file string_tools.h.

234 {
235 static std::string module_folder;
236 return module_folder;
237 }
Here is the caller graph for this function:

◆ get_current_module_name()

std::string & epee::string_tools::get_current_module_name ( )
inline

Definition at line 227 of file string_tools.h.

228 {
229 static std::string module_name;
230 return module_name;
231 }
Here is the caller graph for this function:

◆ get_extension()

std::string epee::string_tools::get_extension ( const std::string & str)
inline

Definition at line 347 of file string_tools.h.

348 {
349 std::string res;
350 std::string::size_type pos = str.rfind('.');
351 if(std::string::npos == pos)
352 return res;
353
354 res = str.substr(pos+1, str.size()-pos);
355 return res;
356 }

◆ get_ip_int32_from_string()

bool epee::string_tools::get_ip_int32_from_string ( uint32_t & ip,
const std::string & ip_str )

Definition at line 53 of file string_tools.cpp.

54 {
55 ip = inet_addr(ip_str.c_str());
56 if(INADDR_NONE == ip)
57 return false;
58
59 return true;
60 }
Here is the caller graph for this function:

◆ get_ip_string_from_int32()

std::string epee::string_tools::get_ip_string_from_int32 ( uint32_t ip)

Definition at line 42 of file string_tools.cpp.

43 {
44 in_addr adr;
45 adr.s_addr = ip;
46 const char* pbuf = inet_ntoa(adr);
47 if(pbuf)
48 return pbuf;
49 else
50 return "[failed]";
51 }
Here is the caller graph for this function:

◆ get_xtype_from_string()

template<class XType>
PUSH_WARNINGS bool epee::string_tools::get_xtype_from_string ( OUT XType & val,
const std::string & str_id )
inline

Definition at line 125 of file string_tools.h.

126 {
127 if (std::is_integral<XType>::value && !std::numeric_limits<XType>::is_signed && !std::is_same<XType, bool>::value)
128 {
129 for (char c : str_id)
130 {
132 return false;
133 }
134 }
135
136 try
137 {
138 val = boost::lexical_cast<XType>(str_id);
139 return true;
140 }
141 catch(const std::exception& /*e*/)
142 {
143 //const char* pmsg = e.what();
144 return false;
145 }
146 catch(...)
147 {
148 return false;
149 }
150
151 return true;
152 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hex_to_pod() [1/3]

template<class t_pod_type>
bool epee::string_tools::hex_to_pod ( const std::string & hex_str,
epee::mlocked< t_pod_type > & s )

Definition at line 340 of file string_tools.h.

341 {
342 return hex_to_pod(hex_str, unwrap(s));
343 }
bool hex_to_pod(const std::string &hex_str, t_pod_type &s)
T & unwrap(mlocked< T > &src)
Definition mlocker.h:80
Here is the call graph for this function:

◆ hex_to_pod() [2/3]

template<class t_pod_type>
bool epee::string_tools::hex_to_pod ( const std::string & hex_str,
t_pod_type & s )

Definition at line 324 of file string_tools.h.

325 {
326 static_assert(std::is_pod<t_pod_type>::value, "expected pod type");
327 if(sizeof(s)*2 != hex_str.size())
328 return false;
329 epee::span<char> rspan((char*)&s, sizeof(s));
330 return parse_hexstr_to_binbuff(epee::to_span(hex_str), rspan);
331 }
Non-owning sequence of data. Does not deep copy.
Definition span.h:57
bool parse_hexstr_to_binbuff(const epee::span< const char > s, epee::span< char > &res)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hex_to_pod() [3/3]

template<class t_pod_type>
bool epee::string_tools::hex_to_pod ( const std::string & hex_str,
tools::scrubbed< t_pod_type > & s )

Definition at line 334 of file string_tools.h.

335 {
336 return hex_to_pod(hex_str, unwrap(s));
337 }
Here is the call graph for this function:

◆ num_to_string_fast()

std::string epee::string_tools::num_to_string_fast ( int64_t val)
inline

Definition at line 202 of file string_tools.h.

203 {
204 /*
205 char buff[30] = {0};
206 i64toa_s(val, buff, sizeof(buff)-1, 10);
207 return buff;*/
208 return boost::lexical_cast<std::string>(val);
209 }

◆ pad_string()

std::string epee::string_tools::pad_string ( std::string s,
size_t n,
char c = ' ',
bool prepend = false )
inline

Definition at line 304 of file string_tools.h.

305 {
306 if (s.size() < n)
307 {
308 if (prepend)
309 s = std::string(n - s.size(), c) + s;
310 else
311 s.append(n - s.size(), c);
312 }
313 return s;
314 }
Here is the caller graph for this function:

◆ parse_hexstr_to_binbuff() [1/2]

bool epee::string_tools::parse_hexstr_to_binbuff ( const epee::span< const char > s,
epee::span< char > & res )
inline

Definition at line 92 of file string_tools.h.

93 {
94 if (s.size() != res.size() * 2)
95 return false;
96
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)
100 {
101 int tmp = *src++;
102 tmp = isx[tmp];
103 if (tmp == 0xff) return false;
104 int t2 = *src++;
105 t2 = isx[t2];
106 if (t2 == 0xff) return false;
107 *dst++ = (tmp << 4) | t2;
108 }
109
110 return true;
111 }
constexpr std::size_t size() const noexcept
Definition span.h:111
constexpr pointer data() const noexcept
Definition span.h:110
t2
Definition pow22523.h:103
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_hexstr_to_binbuff() [2/2]

bool epee::string_tools::parse_hexstr_to_binbuff ( const std::string & s,
std::string & res )
inline

Definition at line 113 of file string_tools.h.

114 {
115 if (s.size() & 1)
116 return false;
117 res.resize(s.size() / 2);
118 epee::span<char> rspan((char*)&res[0], res.size());
119 return parse_hexstr_to_binbuff(epee::to_span(s), rspan);
120 }
Here is the call graph for this function:

◆ parse_peer_from_string()

bool epee::string_tools::parse_peer_from_string ( uint32_t & ip,
uint16_t & port,
const std::string & addres )
inline

Definition at line 174 of file string_tools.h.

175 {
176 //parse ip and address
177 std::string::size_type p = addres.find(':');
178 std::string ip_str, port_str;
179 if(p == std::string::npos)
180 {
181 port = 0;
182 ip_str = addres;
183 }
184 else
185 {
186 ip_str = addres.substr(0, p);
187 port_str = addres.substr(p+1, addres.size());
188 }
189
190 if(!get_ip_int32_from_string(ip, ip_str))
191 {
192 return false;
193 }
194
195 if(p != std::string::npos && !get_xtype_from_string(port, port_str))
196 {
197 return false;
198 }
199 return true;
200 }
PUSH_WARNINGS bool get_xtype_from_string(OUT XType &val, const std::string &str_id)
bool get_ip_int32_from_string(uint32_t &ip, const std::string &ip_str)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pod_to_hex()

template<class t_pod_type>
std::string epee::string_tools::pod_to_hex ( const t_pod_type & s)

Definition at line 317 of file string_tools.h.

318 {
319 static_assert(std::is_standard_layout<t_pod_type>(), "expected standard layout type");
320 return to_hex::string(as_byte_span(s));
321 }
span< const std::uint8_t > as_byte_span(const T &src) noexcept
Definition span.h:153
Here is the call graph for this function:

◆ set_module_name_and_folder()

bool epee::string_tools::set_module_name_and_folder ( const std::string & path_to_process_)
inline

Definition at line 249 of file string_tools.h.

250 {
251 std::string path_to_process = path_to_process_;
252#ifdef _WIN32
253 path_to_process = get_current_module_path();
254#endif
255 std::string::size_type a = path_to_process.rfind( '\\' );
256 if(a == std::string::npos )
257 {
258 a = path_to_process.rfind( '/' );
259 }
260 if ( a != std::string::npos )
261 {
262 get_current_module_name() = path_to_process.substr(a+1, path_to_process.size());
263 get_current_module_folder() = path_to_process.substr(0, a);
264 return true;
265 }else
266 return false;
267
268 }
std::string & get_current_module_name()
std::string & get_current_module_folder()
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_string_hex()

std::string epee::string_tools::to_string_hex ( uint32_t val)
inline

Definition at line 211 of file string_tools.h.

212 {
213 std::stringstream ss;
214 ss << std::hex << val;
215 std::string s;
216 ss >> s;
217 return s;
218 }
Here is the caller graph for this function:

◆ trim() [1/2]

std::string epee::string_tools::trim ( const std::string & str_)
inline

Definition at line 296 of file string_tools.h.

297 {
298 std::string str = str_;
299 trim_left(str);
300 trim_right(str);
301 return str;
302 }
bool trim_left(std::string &str)
bool trim_right(std::string &str)
Here is the call graph for this function:

◆ trim() [2/2]

std::string & epee::string_tools::trim ( std::string & str)
inline

Definition at line 288 of file string_tools.h.

289 {
290
291 trim_left(str);
292 trim_right(str);
293 return str;
294 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ trim_left()

bool epee::string_tools::trim_left ( std::string & str)
inline

Definition at line 271 of file string_tools.h.

272 {
273 for(std::string::iterator it = str.begin(); it!= str.end() && isspace(static_cast<unsigned char>(*it));)
274 str.erase(str.begin());
275
276 return true;
277 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ trim_right()

bool epee::string_tools::trim_right ( std::string & str)
inline

Definition at line 279 of file string_tools.h.

280 {
281
282 for(std::string::reverse_iterator it = str.rbegin(); it!= str.rend() && isspace(static_cast<unsigned char>(*it));)
283 str.erase( --((it++).base()));
284
285 return true;
286 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate_hex()

bool epee::string_tools::validate_hex ( uint64_t length,
const std::string & str )

Definition at line 62 of file string_tools.cpp.

63 {
64 if (str.size() != length)
65 return false;
66 for (char c: str)
67 if (!isxdigit(c))
68 return false;
69 return true;
70 }
Here is the caller graph for this function:

◆ xtype_to_string()

template<class XType>
POP_WARNINGS bool epee::string_tools::xtype_to_string ( const XType & val,
std::string & str )
inline

Definition at line 156 of file string_tools.h.

157 {
158 try
159 {
160 str = boost::lexical_cast<std::string>(val);
161 }
162 catch(...)
163 {
164 return false;
165 }
166
167 return true;
168 }