8#include "daq/slc/base/StringUtil.h"
18StringList StringUtil::split(
const std::string& str,
const char type,
size_t max)
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));
26 if (str.size() - current > 0) {
27 str_v.push_back(std::string(str, current, str.size() - current));
29 while (max > 0 && str_v.size() < max) {
35std::string StringUtil::join(StringList str_v,
const std::string& s,
size_t start,
size_t end)
38 for (
size_t i = start; i < str_v.size();) {
41 if ((end > 0 && i == end) || i == str_v.size())
break;
47std::string StringUtil::replace(
const std::string& source,
48 const std::string& pattern,
49 const std::string& placement)
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);
61 result.append(source, pos_before, source.size() - pos_before);
65std::string StringUtil::form(
const std::string& str, ...)
68 static __thread
char ss[1024 * 10];
70 vsnprintf(ss,
sizeof(ss), str.c_str(), ap);
75std::string StringUtil::toupper(
const std::string& str)
78 transform(s.begin(), s.end(), s.begin(), ::toupper);
82std::string StringUtil::tolower(
const std::string& str)
85 transform(s.begin(), s.end(), s.begin(), ::tolower);
89int StringUtil::atoi(
const std::string& str)
91 return std::atoi(str.c_str());
94double StringUtil::atof(
const std::string& str)
96 return std::atof(str.c_str());
99long long StringUtil::atoll(
const std::string& str)
101 return std::atoll(str.c_str());
104bool StringUtil::find(
const std::string& s,
const std::string& str)
106 return s.find(str) != std::string::npos;
109bool StringUtil::isdigit(
const std::string& s)
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;
116 return s.size() > 0 && s !=
"-";
Abstract base class for different kinds of events.