ifw-core 7.0.0
 
Loading...
Searching...
No Matches
string.hpp
Go to the documentation of this file.
1
6
7#ifndef IFW_CORE_UTILS_STRING_HPP_
8#define IFW_CORE_UTILS_STRING_HPP_
9
11
12
14
16 std::string Upper(const std::string& str);
17
19 std::string Lower(const std::string& str);
20
22 std::string Trim(const std::string& str,
23 const std::string& trim_chars);
24
26 std::string Replace(const std::string& str,
27 const std::string& old_sub_str,
28 const std::string& new_sub_str);
29
31 std::string Truncate(const std::string& text,
32 const int32_t max_len,
33 const std::string& truncation_indicator = "...");
34
35 // TODO: Remove ifw::core::utils::string::Split(). boost::algorithm::split() does the same.
37 void Split(const std::string& str,
38 const std::string& separator,
39 std::vector<std::string>& str_els,
40 int32_t exp_nb_elements = -1);
41
43 std::vector<std::string> Split(const std::string& str,
44 const std::string& separator,
45 int32_t exp_nb_elements = -1);
46
48 void SplitBuffer(const std::string buffer,
49 std::vector<std::string>& buffer_lines,
50 const bool strip = true,
51 const bool remove_empty_lines = true,
52 const std::string remove_comments = "");
53
55 template <class TYPE>
56 std::string Concat(const std::vector<TYPE>& list,
57 const std::string& sep = "") {
58 std::stringstream tmp_buf;
59 for (const auto& el : list) {
60 tmp_buf << el << sep;
61 }
62 return tmp_buf.str().substr(0, (tmp_buf.str().size() - sep.size()));
63 }
64
67 void StringCopy(char* dest_buf,
68 const char* src_buf,
69 const int32_t max_bytes,
70 const bool truncate = false);
71
73 bool Match(const std::string& str,
74 const std::string& reg_exp);
75
76}
77
78#endif // IFW_CORE_UTILS_STRING_HPP_
Definition string.hpp:13
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:72
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:58
std::string Upper(const std::string &str)
Uppercase string.
Definition string.cpp:17
std::string Lower(const std::string &str)
Lower case string.
Definition string.cpp:24
bool Match(const std::string &str, const std::string &reg_exp)
Carry out a regular expression match on the given string.
Definition string.cpp:153
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:129
std::string Trim(const std::string &str, const std::string &trim_chars)
Trim input string for leading/trailing characters.
Definition string.cpp:31
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:56
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:42
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:109