ifw-core  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
string.hpp
Go to the documentation of this file.
1 
9 #ifndef IFW_CTD_STRING_HPP_
10 #define IFW_CTD_STRING_HPP_
11 
12 #include "ctd/defines/defines.hpp"
13 
14 
15 namespace ctd {
16  namespace string {
17 
19  std::string Upper(const std::string& str);
20 
22  std::string Lower(const std::string& str);
23 
24 
26  std::string Trim(const std::string& str,
27  const std::string& trim_chars);
28 
30  std::string Replace(const std::string& str,
31  const std::string& old_sub_str,
32  const std::string& new_sub_str);
33 
35  std::string Truncate(const std::string& text,
36  const int32_t max_len,
37  const std::string& truncation_indicator = "...");
38 
40  void Split(const std::string& str,
41  const std::string& separator,
42  std::vector<std::string>& str_els);
43 
45  void SplitBuffer(const std::string buffer,
46  std::vector<std::string>& buffer_lines,
47  const bool strip = true,
48  const bool remove_empty_lines = true,
49  const std::string remove_comments = "");
50 
52  template <class TYPE>
53  std::string Concat(const std::vector<TYPE>& list,
54  const std::string& sep = "") {
55  RAD_LOG_TRACE();
56 
57  std::stringstream tmp_buf;
58  for (const auto& el : list) {
59  tmp_buf << el << sep;
60  }
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 
79 #endif // IFW_CTD_STRING_HPP_
std::string Replace(const std::string &str, const std::string &old_sub_str, const std::string &new_sub_str)
Replace occurences of &quot;old_sub_str&quot; with &quot;new_sub_str&quot; in &quot;str&quot;.
Definition: string.cpp:43
std::string Lower(const std::string &str)
Lower case string.
Definition: string.cpp:21
std::string Upper(const std::string &str)
Uppercase string.
Definition: string.cpp:12
std::string Trim(const std::string &str, const std::string &trim_chars)
Trim input string for leading/trailing characters.
Definition: string.cpp:30
void Split(const std::string &str, const std::string &separator, std::vector< std::string > &str_els)
Split &quot;str&quot; according to the sequence of separator characters given.
Definition: string.cpp:78
Common definitions.
std::string Truncate(const std::string &text, const int32_t max_len, const std::string &truncation_indicator="...")
Truncate &quot;str&quot; if longer than &quot;max_len&quot;.
Definition: string.cpp:61
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:53
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:101
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:123
bool Match(const std::string &str, const std::string &reg_exp)
Carry out a regular expression match on the given string.
Definition: string.cpp:150