6#ifndef IFW_CORE_UTILS_STRING_HPP_
7#define IFW_CORE_UTILS_STRING_HPP_
15 std::string
Upper(
const std::string& str);
18 std::string
Lower(
const std::string& str);
21 std::string
Trim(
const std::string& str,
22 const std::string& trim_chars);
25 std::string
Replace(
const std::string& str,
26 const std::string& old_sub_str,
27 const std::string& new_sub_str);
30 std::string
Truncate(
const std::string& text,
31 const int32_t max_len,
32 const std::string& truncation_indicator =
"...");
36 void Split(
const std::string& str,
37 const std::string& separator,
38 std::vector<std::string>& str_els,
39 int32_t exp_nb_elements = -1);
42 std::vector<std::string>
Split(
const std::string& str,
43 const std::string& separator,
44 int32_t exp_nb_elements = -1);
48 std::vector<std::string>& buffer_lines,
49 const bool strip =
true,
50 const bool remove_empty_lines =
true,
51 const std::string remove_comments =
"");
55 std::string
Concat(
const std::vector<TYPE>& list,
56 const std::string& sep =
"") {
57 std::stringstream tmp_buf;
58 for (
const auto& el : list) {
61 return tmp_buf.str().substr(0, (tmp_buf.str().size() - sep.size()));
68 const int32_t max_bytes,
69 const bool truncate =
false);
72 bool Match(
const std::string& str,
73 const std::string& reg_exp);
void Split(const std::string &str, const std::string &separator, std::vector< std::string > &str_els, int32_t exp_nb_elements=-1)
Split "str" according to the sequence of separator characters given.
Definition string.cpp:71
std::string Truncate(const std::string &text, const int32_t max_len, const std::string &truncation_indicator="...")
Truncate "str" if longer than "max_len".
Definition string.cpp:57
std::string Upper(const std::string &str)
Uppercase string.
Definition string.cpp:16
std::string Lower(const std::string &str)
Lower case string.
Definition string.cpp:23
bool Match(const std::string &str, const std::string ®_exp)
Carry out a regular expression match on the given string.
Definition string.cpp:152
void SplitBuffer(const std::string buffer, std::vector< std::string > &buffer_lines, const bool strip=true, const bool remove_empty_lines=true, const std::string remove_comments="")
Split a buffer, typically a file buffer, with newline characters.
Definition string.cpp:128
std::string Trim(const std::string &str, const std::string &trim_chars)
Trim input string for leading/trailing characters.
Definition string.cpp:30
std::string Concat(const std::vector< TYPE > &list, const std::string &sep="")
Concatenate elements of the given type, contained in the list.
Definition string.hpp:55
std::string Replace(const std::string &str, const std::string &old_sub_str, const std::string &new_sub_str)
Replace occurences of "old_sub_str" with "new_sub_str" in "str".
Definition string.cpp:41
void StringCopy(char *dest_buf, const char *src_buf, const int32_t max_bytes, const bool truncate=false)
Safe string copy. If the length of “src_buf” exceeds “max_bytes” the string may either be truncated o...
Definition string.cpp:108