ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
str_util.h
Go to the documentation of this file.
1 
4 #ifndef ILANG_UTIL_STR_UTIL_H__
5 #define ILANG_UTIL_STR_UTIL_H__
6 
7 #include <algorithm>
8 #include <functional>
9 #include <string>
10 #include <vector>
11 
13 namespace ilang {
14 
15 // (itoa is not part of the standard actually,
16 // so I hesitated whether to use it actually)
17 // on the other hand, snprintf only supports 8/10/16
19 std::string IntToStrCustomBase(uint64_t value, unsigned base, bool uppercase);
20 
22 std::string StrToUpper(const std::string& str);
23 
25 std::string StrToLower(const std::string& str);
26 
28 bool StrToBool(const std::string& str);
29 
31 int StrToInt(const std::string& str, int base = 10);
32 
34 long long StrToLong(const std::string& str, int base = 10);
35 
37 unsigned long long StrToULongLong(const std::string& str, int base = 10);
38 
39 
40 
42 void StrLeftTrim(std::string& s);
43 
45 void StrRightTrim(std::string& s);
46 
48 void StrTrim(std::string &s);
49 
50 
52 std::vector<std::string> Split(const std::string& str,
53  const std::string& delim);
54 
56 std::vector<std::string> SplitSpaceTabEnter(const std::string& str);
57 
59 std::string Join(const std::vector<std::string>& in, const std::string& delim);
60 
62 std::string RemoveWhiteSpace(const std::string & in);
63 
65 std::string ReplaceAll(const std::string& str, const std::string& a,
66  const std::string& b);
67 
69 std::vector<std::string> ReFindList(const std::string& s,
70  const std::string& re);
71 
74 std::vector<std::string> ReFindAndDo(const std::string& s,
75  const std::string& re,
76  std::function<std::string(std::string)> f);
77 
78 bool IsRExprUsable();
79 
81 bool StrEndsWith(const std::string& str, const std::string& suffix);
82 
84 bool StrStartsWith(const std::string& str, const std::string& prefix);
85 
86 
87 } // namespace ilang
88 
89 #endif // ILANG_UTIL_STR_UTIL_H__
std::string RemoveWhiteSpace(const std::string &in)
Remove whitespace &quot; \n\t\r\f\v&quot; from the input string.
std::string IntToStrCustomBase(uint64_t value, unsigned base, bool uppercase)
Transform int to string with different bases.
std::vector< std::string > ReFindAndDo(const std::string &s, const std::string &re, std::function< std::string(std::string)> f)
std::vector< std::string > ReFindList(const std::string &s, const std::string &re)
Filter out a list of substring by the regular expression.
void StrLeftTrim(std::string &s)
Trim a string from start (in place)
std::vector< std::string > SplitSpaceTabEnter(const std::string &str)
Python-style split behavior, delim: space tab enter and their combiniations.
bool StrStartsWith(const std::string &str, const std::string &prefix)
Finds out if str starts with prefix.
std::string StrToLower(const std::string &str)
Transform basic string to lower case.
bool StrToBool(const std::string &str)
Return true if string is &quot;true&quot; or &quot;True&quot;.
void StrRightTrim(std::string &s)
Trim a string from end (in place)
std::string ReplaceAll(const std::string &str, const std::string &a, const std::string &b)
Replace all occurrance of substring a by substring b.
unsigned long long StrToULongLong(const std::string &str, int base=10)
Return the value represented in the string in unsigned long long, e.g. &quot;10&quot;.
void StrTrim(std::string &s)
Trim a string from both ends (in place)
long long StrToLong(const std::string &str, int base=10)
Return the value represented in the string in long type, e.g. &quot;10&quot;.
std::string StrToUpper(const std::string &str)
Transform basic string to upper case.
std::vector< std::string > Split(const std::string &str, const std::string &delim)
Python-style split , return a vector of splitted strings.
std::string Join(const std::vector< std::string > &in, const std::string &delim)
Python-style join, return a string that joins the list by the delim.
bool StrEndsWith(const std::string &str, const std::string &suffix)
Finds out if str ends with suffix.
int StrToInt(const std::string &str, int base=10)
Return the value represented in the string, e.g. &quot;10&quot;.