32 std::ostringstream oss;
33 oss << std::hex << std::setw(8) << std::setfill(
'0') << (val >> 32)
34 <<
"_" << std::setw(8) << (val & 0xffffffff);
46 std::ostringstream oss;
47 oss << std::hex << std::setw(8) << std::setfill(
'0') << val;
58 std::ostringstream ss;
59 return (
static_cast<std::ostringstream*
>( &(ss << val))->str());
69 std::ostringstream ss;
70 return (
static_cast<std::ostringstream*
>( &(ss << val))->str());
79 std::ostringstream ss;
80 return (
static_cast<std::ostringstream*
>( &(ss << val))->str());
90 std::ostringstream ss;
91 return (
static_cast<std::ostringstream*
>( &(ss << val))->str());
100 std::ostringstream ss;
101 return (
static_cast<std::ostringstream*
>( &(ss << std::boolalpha << val))->str());
108inline std::string
bin_to_hexstr(
const uint8_t *data,
size_t size,
const std::string &sep=
" ")
110 std::stringstream ss;
111 ss << std::hex << std::setfill(
'0');
112 for (
size_t i = size; i > 0; --i) {
113 ss << std::setw(2) << (uint32_t)data[i - 1];
125inline std::string
bin_to_bitstr(
const uint8_t *data,
size_t size,
const std::string &sep=
" ")
127 std::stringstream ss;
129 for (
size_t i = size; i > 0; --i) {
130 const auto byte = data[i - 1];
131 for (
size_t b = 8; b > 0; --b) {
132 const auto mask = 1 << (b - 1);
134 ss << ((
byte & mask) ?
'1' :
'0');
150 std::string strip_str = str;
151 strip_str.erase(std::remove_if(strip_str.begin(), strip_str.end(), ::isspace),
162 const std::string STR_WHITESPACE =
" \t\n\r";
164 size_t start_pos = str.find_first_not_of(STR_WHITESPACE);
165 size_t end_pos = str.find_last_not_of(STR_WHITESPACE);
167 return str.substr(start_pos, end_pos-start_pos + 1);
178 const std::string & str)
181 size_t start_pos = str.find(pat);
184 start_pos += pat.length();
191 size_t end_pos = str.rfind(pat);
192 if(end_pos == 0 || (end_pos + pat.length()) != str.length()) {
194 end_pos = std::string::npos;
197 end_pos -= start_pos;
200 return str.substr(start_pos, end_pos);
211inline void tokenize(
const std::string &in_str, std::vector<std::string> & str_vector,
const std::string &delimiters =
" ")
215 while ((cur_pos = in_str.find_first_of(delimiters, prev_pos)) != std::string::npos) {
216 str_vector.push_back(in_str.substr(prev_pos, cur_pos - prev_pos));
217 prev_pos = cur_pos + 1;
220 str_vector.push_back(in_str.substr(prev_pos));
249 std::vector<std::vector<std::string>> & str_vectors,
250 const std::string & delimiters =
" ",
251 const char line_separator =
'\n')
254 while (std::getline(in_stream, line, line_separator)) {
255 str_vectors.emplace_back(std::vector<std::string>());
256 tokenize(line, str_vectors.back(), delimiters);
269inline void tokenize(
const char *in_char_str, std::vector<std::string> & str_vector,
const std::string &delimiters =
" ")
272 std::string in_str = in_char_str;
274 tokenize(in_str, str_vector, delimiters);
282inline void tokenize_strip_whitespace(
const std::string &in_str, std::vector<std::string> & str_vector,
const std::string &delimiters =
" ")
286 while ((cur_pos = in_str.find_first_of(delimiters, prev_pos)) != std::string::npos) {
287 str_vector.push_back(
strip_whitespace(in_str.substr(prev_pos, cur_pos - prev_pos)));
288 prev_pos = cur_pos + 1;
303inline void tokenize_strip_whitespace(
const char *in_char_str, std::vector<std::string> & str_vector,
const std::string &delimiters =
" ")
306 std::string in_str = in_char_str;
320 const std::string DELIMITER =
" \t\n\r";
324 while ((cur_pos = in_str.find_first_of(DELIMITER, prev_pos)) != std::string::npos) {
325 if (cur_pos != prev_pos) {
326 str_vector.push_back(in_str.substr(prev_pos, cur_pos - prev_pos));
328 prev_pos = cur_pos + 1;
331 if (prev_pos != in_str.size()) {
332 str_vector.push_back(in_str.substr(prev_pos));
346 std::string in_str = in_char_str;
357 if (s1 !=
nullptr && s2 !=
nullptr) {
358 return !std::strcmp(s1, s2);
360 if (s1 ==
nullptr && s2 ==
nullptr) {
378 const char * t,
size_t m)
382 std::unique_ptr<size_t[]> dptr(
new size_t[n * m]);
383 size_t * d = dptr.get();
385 memset(d, 0,
sizeof(
size_t) * n * m);
386 for (
size_t i = 1, im = 0; i < m; ++i, ++im) {
387 for (
size_t j = 1, jn = 0; j < n; ++j, ++jn) {
388 if (s[jn] == t[im]) {
389 d[(i * n) + j] = d[((i - 1) * n) + (j - 1)];
391 d[(i * n) + j] = std::min({
392 d[(i - 1) * n + j] + 1,
393 d[(i - 1) * n + j] + 1,
394 d[(i - 1) * n + (j - 1)] + 1
407template <
class AppliedTransform>
439 return str_ == rhs.str_;
443 return str_ != rhs.str_;
446 inline bool operator==(
const std::string & rhs)
const {
450 inline bool operator!=(
const std::string & rhs)
const {
454 inline bool operator==(
const char * rhs)
const {
455 return strcmp(str_.c_str(), rhs) == 0;
458 inline bool operator!=(
const char * rhs)
const {
459 return strcmp(str_.c_str(), rhs) != 0;
462 inline const std::string & getString()
const {
466 inline operator std::string()
const {
471 void applyTransform_() {
472 std::transform(str_.begin(), str_.end(), str_.begin(), transformer_);
476 AppliedTransform transformer_;
481 int operator()(
const int ch)
const {
482 return std::tolower(ch);
488 int operator()(
const int ch)
const {
489 return std::toupper(ch);
501template <
class AppliedTransform>
505 return one.getString() < two.getString();
515template <
class AppliedTransform>
516inline bool operator==(
const std::string & one,
519 return one == two.getString();
522template <
class AppliedTransform>
523inline bool operator!=(
const std::string & one,
524 const TransformedString<AppliedTransform> & two)
526 return one != two.getString();
void split_lines_around_tokens(std::istream &in_stream, std::vector< std::vector< std::string > > &str_vectors, const std::string &delimiters=" ", const char line_separator='\n')
function tokenize()
bool strcmp_with_null(const char *s1, const char *s2)
function tokenize()
std::string uint64_to_hexstr(uint64_t val)
std::string bool_to_str(bool val)
void tokenize_strip_whitespace(const std::string &in_str, std::vector< std::string > &str_vector, const std::string &delimiters=" ")
function tokenize()
void tokenize(const std::string &in_str, std::vector< std::string > &str_vector, const std::string &delimiters=" ")
function strip_string_pattern()
std::string uint32_to_str(uint32_t val)
uint32_t LevenshteinDistance(const char *s, size_t n, const char *t, size_t m)
std::string bin_to_hexstr(const uint8_t *data, size_t size, const std::string &sep=" ")
std::string int32_to_str(int32_t val)
std::string int64_to_str(int64_t val)
std::string strip_string_pattern(const std::string &pat, const std::string &str)
function strip_whitespace()
std::string strip_whitespace(const std::string &str)
function eliminate_whitespace()
std::string uint64_to_str(uint64_t val)
std::string bin_to_bitstr(const uint8_t *data, size_t size, const std::string &sep=" ")
void tokenize_on_whitespace(const std::string &in_str, std::vector< std::string > &str_vector)
function tokenize_strip_whitespace()
std::string eliminate_whitespace(const std::string &str)
std::string uint32_to_hexstr(uint32_t val)
bool operator<(const TransformedString< AppliedTransform > &one, const TransformedString< AppliedTransform > &two)
Macros for handling exponential backoff.