Belle II Software development
StringUtil Struct Reference

Static Public Member Functions

static StringList split (const std::string &str, const char type, size_t max=0)
 
static std::string join (StringList str_v, const std::string &s, size_t start=0, size_t end=0)
 
static std::string replace (const std::string &source, const std::string &pattern, const std::string &placement)
 
static std::string form (const std::string &string,...)
 
static std::string toupper (const std::string &str)
 
static std::string tolower (const std::string &str)
 
static int atoi (const std::string &str)
 
static double atof (const std::string &str)
 
static long long atoll (const std::string &str)
 
static bool find (const std::string &s, const std::string &str)
 
static bool isdigit (const std::string &s)
 

Detailed Description

Definition at line 22 of file StringUtil.h.

Member Function Documentation

◆ atof()

double atof ( const std::string &  str)
static

Definition at line 94 of file StringUtil.cc.

95{
96 return std::atof(str.c_str());
97}

◆ atoi()

int atoi ( const std::string &  str)
static

Definition at line 89 of file StringUtil.cc.

90{
91 return std::atoi(str.c_str());
92}

◆ atoll()

long long atoll ( const std::string &  str)
static

Definition at line 99 of file StringUtil.cc.

100{
101 return std::atoll(str.c_str());
102}

◆ find()

bool find ( const std::string &  s,
const std::string &  str 
)
static

Definition at line 104 of file StringUtil.cc.

105{
106 return s.find(str) != std::string::npos;
107}

◆ form()

std::string form ( const std::string &  string,
  ... 
)
static

Definition at line 65 of file StringUtil.cc.

66{
67 va_list ap;
68 static __thread char ss[1024 * 10];
69 va_start(ap, str);
70 vsnprintf(ss, sizeof(ss), str.c_str(), ap);
71 va_end(ap);
72 return ss;
73}

◆ isdigit()

bool isdigit ( const std::string &  s)
static

Definition at line 109 of file StringUtil.cc.

110{
111 if (s.find("0x") == 0) return true;
112 for (size_t i = 0; i < s.size(); i++) {
113 if (i == 0 && s.at(0) == '-') continue;
114 if (!::isdigit(s.at(i))) return false;
115 }
116 return s.size() > 0 && s != "-";
117}

◆ join()

std::string join ( StringList  str_v,
const std::string &  s,
size_t  start = 0,
size_t  end = 0 
)
static

Definition at line 35 of file StringUtil.cc.

36{
37 std::stringstream ss;
38 for (size_t i = start; i < str_v.size();) {
39 ss << str_v[i];
40 i++;
41 if ((end > 0 && i == end) || i == str_v.size()) break;
42 ss << s;
43 }
44 return ss.str();
45}

◆ replace()

std::string replace ( const std::string &  source,
const std::string &  pattern,
const std::string &  placement 
)
static

Definition at line 47 of file StringUtil.cc.

50{
51 std::string result;
52 std::string::size_type pos_before = 0;
53 std::string::size_type pos = 0;
54 std::string::size_type len = pattern.size();
55 while ((pos = source.find(pattern, pos)) != std::string::npos) {
56 result.append(source, pos_before, pos - pos_before);
57 result.append(placement);
58 pos += len;
59 pos_before = pos;
60 }
61 result.append(source, pos_before, source.size() - pos_before);
62 return result;
63}

◆ split()

StringList split ( const std::string &  str,
const char  type,
size_t  max = 0 
)
static

Definition at line 18 of file StringUtil.cc.

19{
20 StringList str_v;
21 size_t current = 0, found;
22 while ((found = str.find_first_of(type, current)) != std::string::npos) {
23 str_v.push_back(std::string(str, current, found - current));
24 current = found + 1;
25 }
26 if (str.size() - current > 0) {
27 str_v.push_back(std::string(str, current, str.size() - current));
28 }
29 while (max > 0 && str_v.size() < max) {
30 str_v.push_back("");
31 }
32 return str_v;
33}

◆ tolower()

std::string tolower ( const std::string &  str)
static

Definition at line 82 of file StringUtil.cc.

83{
84 std::string s = str;
85 transform(s.begin(), s.end(), s.begin(), ::tolower);
86 return s;
87}

◆ toupper()

std::string toupper ( const std::string &  str)
static

Definition at line 75 of file StringUtil.cc.

76{
77 std::string s = str;
78 transform(s.begin(), s.end(), s.begin(), ::toupper);
79 return s;
80}

The documentation for this struct was generated from the following files: