11 bool is_hex(
const char *buf,
size_t len)
13 for (
size_t i = 0; i < len; i++) {
14 if (buf[i] >=
'0' && buf[i] <=
'9')
continue;
15 if (buf[i] >=
'A' && buf[i] <=
'F')
continue;
16 if (buf[i] >=
'a' && buf[i] <=
'f')
continue;
22 bool is_dec(
const char *buf,
size_t len)
24 for (
size_t i = 0; i < len; i++) {
25 if (buf[i] >=
'0' && buf[i] <=
'9')
continue;
36 const char hex_pattern[] =
"0x";
37 size_t hex_pattern_len = strlen(hex_pattern);
39 const size_t len = strlen(my_buf);
40 if (len == 0)
return 0;
43 const size_t min_length = 1;
44 if (len > hex_pattern_len) {
46 if (!
is_hex(my_buf + hex_pattern_len, min_length))
return 0;
49 ss << std::hex << my_buf;
54 if (!
is_dec(my_buf, min_length))
return 0;
57 ss << std::dec << my_buf;
64 const char hex_pattern[] =
"0x";
65 size_t hex_pattern_len = strlen(hex_pattern);
67 const size_t len = strlen(my_buf);
68 if (len == 0)
return false;
70 if (len > hex_pattern_len) {
72 if (!
is_hex(my_buf + hex_pattern_len, len - hex_pattern_len))
return false;
77 if (!
is_dec(my_buf, len))
return false;
85 std::transform(searched_str.begin(), searched_str.end(), searched_str.begin(), [](
unsigned char c){ return std::tolower(c); });
87 std::set<std::string>::iterator found = string_list.find(searched_str);
88 if (found != string_list.end()) {
97 std::string&
ltrim(std::string& str,
const std::string& chars =
"\t\n\v\f\r ")
99 str.erase(0, str.find_first_not_of(chars));
103 std::string&
rtrim(std::string& str,
const std::string& chars =
"\t\n\v\f\r ")
105 str.erase(str.find_last_not_of(chars) + 1);
109 std::string&
trim(std::string& str,
const std::string& chars =
"\t\n\v\f\r ")
118 std::string delim(std::string(1, _delim));
120 size_t end = s.find(delim);
121 while (end != std::string::npos)
123 std::string next_str = s.substr(start, end - start);
125 if (next_str.length() > 0) {
127 std::transform(next_str.begin(), next_str.end(), next_str.begin(), [](
unsigned char c){ return std::tolower(c); });
129 elements_list.insert(next_str);
131 start = end + delim.length();
132 end = s.find(delim, start);
134 std::string next_str = s.substr(start, end);
136 if (next_str.length() > 0) {
138 std::transform(next_str.begin(), next_str.end(), next_str.begin(), [](
unsigned char c){ return std::tolower(c); });
140 elements_list.insert(next_str);
142 return elements_list.size();
std::string & ltrim(std::string &str, const std::string &chars="\t\n\v\f\r ")
bool is_hex(const char *buf, size_t len)
bool is_number(const char *buf)
std::string & rtrim(std::string &str, const std::string &chars="\t\n\v\f\r ")
std::string & trim(std::string &str, const std::string &chars="\t\n\v\f\r ")
bool is_cstr_equal(char const *a, char const *b, const size_t max_len)
size_t string_to_list(IN::std::string s, IN char _delim, OUT std::set< std::string > &elements_list, bool to_lower=true)
bool is_in_list(std::string searched_string, std::set< std::string > &string_list, bool to_lower=true)
bool is_dec(const char *buf, size_t len)
long get_number(const char *buf)