Rocprofiler SDK Developer API: rocprofiler-sdk/cxx/details/delimit.hpp Source File
Rocprofiler SDK Developer API 0.4.0
ROCm Profiling API and tools
|
Go to the documentation of this file.
43 auto ss = std::stringstream{str};
53 auto ss = std::stringstream{cstr};
61template <
typename ContainerT = std::vector<std::
string>,
62 typename ValueT =
typename ContainerT::value_type,
63 typename PredicateT = std::function<ValueT(ValueT&&)>>
66 std::string_view line,
67 std::string_view delimiters =
"\"',;: ",
68 PredicateT&& predicate = [](ValueT&& s) -> ValueT {
return s; })
70 using value_type = ValueT;
74 ContainerT _result = {};
80 if(delimiters.find(itr) != std::string::npos) ++_nmax;
84 while(_beginp < line.length() && _delimp < line.length())
87 _beginp = line.find_first_not_of(delimiters, _delimp);
90 if(_beginp == std::string::npos)
break;
92 _delimp = line.find_first_of(delimiters, _beginp);
94 auto _tmp = value_type{};
97 if(_beginp < line.length()) _tmp = line.substr(_beginp, _delimp - _beginp);
102 mpl::emplace(_result, std::forward<PredicateT>(predicate)(std::move(_tmp)));
110template <
typename PredicateT = std::function<std::
string(const std::
string&)>>
113 std::string_view _begin,
114 std::string_view _end,
115 PredicateT&& predicate)
119 std::string _result = std::string{input};
120 while(_beg_pos < _result.length() && _end_pos < _result.length())
123 _beg_pos = _result.find(_begin, _end_pos);
126 if(_beg_pos == std::string::npos)
break;
130 _end_pos = _result.find(_end, _beg_pos + 1);
132 _end_pos = _beg_pos + _begin.length();
135 if(_end_pos == std::string::npos)
break;
138 auto _len = _end_pos - _beg_pos;
141 auto _sub = _result.substr(_beg_pos, _len);
144 auto _transformed = predicate(_sub);
147 if(_sub != _transformed)
149 _result = _result.replace(_beg_pos, _len, _transformed);
151 _end_pos = _beg_pos + _transformed.length();
auto emplace(ContainerT &_c, Args &&... _args)
auto reserve(ContainerT &_c, ArgT _arg)
ContainerT tokenize(std::string_view line, std::string_view delimiters="\"',;: ", PredicateT &&predicate=[](ValueT &&s) -> ValueT { return s;})
tokenize a string into a set
std::string str_transform(std::string_view input, std::string_view _begin, std::string_view _end, PredicateT &&predicate)
apply a string transformation to substring in between a common delimiter.
Tp from_string(const std::string &str)