ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
string.hpp
Go to the documentation of this file.
1 
6 #ifndef IFW_CTD_STRING_HPP_
7 #define IFW_CTD_STRING_HPP_
8 
9 
10 #include "ctd/defines/defines.hpp"
11 
12 
13 namespace ctd {
14 namespace string {
15 
17  std::string Upper(const std::string& str);
18 
20  std::string Lower(const std::string& str);
21 
23  std::string Trim(const std::string& str,
24  const std::string& trim_chars);
25 
27  std::string Replace(const std::string& str,
28  const std::string& old_sub_str,
29  const std::string& new_sub_str);
30 
32  std::string Truncate(const std::string& text,
33  const int32_t max_len,
34  const std::string& truncation_indicator = "...");
35 
37  void Split(const std::string& str,
38  const std::string& separator,
40 
42  void SplitBuffer(const std::string buffer,
43  ctd::defines::List<std::string>& buffer_lines,
44  const bool strip = true,
45  const bool remove_empty_lines = true,
46  const std::string remove_comments = "");
47 
49  template <class TYPE> std::string Concat(const ctd::defines::List<TYPE>& list,
50  const std::string& sep = "") {
51  RAD_LOG_TRACE();
52 
53  std::stringstream tmp_buf;
54  for (auto list_it = list.begin(); list_it != list.end(); list_it++) {
55  tmp_buf << *list_it << sep;
56  }
57  return tmp_buf.str().substr(0, (tmp_buf.str().size() - sep.size()));
58  }
59 
62  void StringCopy(char* dest_buf,
63  const char* src_buf,
64  const int32_t max_bytes,
65  const bool truncate = false);
66 
68  bool Match(const std::string& str,
69  const std::string& reg_exp);
70 
71 
72 } // namespace string
73 } // namespace ctd
74 
75 #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:67
std::string Lower(const std::string &str)
Lower case string.
Definition: string.cpp:26
std::string Upper(const std::string &str)
Uppercase string.
Definition: string.cpp:17
std::string Trim(const std::string &str, const std::string &trim_chars)
rim input string for leading/trailing characters.
Definition: string.cpp:35
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:87
void Split(const std::string &str, const std::string &separator, ctd::defines::List< std::string > &str_els)
Split &quot;str&quot; according to the sequence of separator characters given.
Definition: string.cpp:104
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:127
void SplitBuffer(const std::string buffer, ctd::defines::List< 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:149
#define RAD_LOG_TRACE()
Definition: Logger.hpp:319
std::string Concat(const ctd::defines::List< TYPE > &list, const std::string &sep="")
Concatenate elements of the given type, contained in the list.
Definition: string.hpp:49
bool Match(const std::string &str, const std::string &reg_exp)
Carry out a regular expression match on the given string.
Definition: string.cpp:176