Rocprofiler SDK Developer API: rocprofiler-sdk/cxx/details/tokenize.hpp Source File
Rocprofiler SDK Developer API 0.5.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 ContainerT = std::vector<std::
string>,
111 typename DelimT = std::
string_view,
112 typename ValueT =
typename ContainerT::value_type,
113 typename PredicateT = ValueT (*)(DelimT&&)>
116 std::string_view line,
117 const std::vector<DelimT>& delimiters,
118 PredicateT&& predicate = [](DelimT&& s) -> ValueT {
return ValueT{s}; })
120 ContainerT _result = {};
122 size_t _end = std::string::npos;
124 while(_start != std::string::npos)
126 _end = std::string::npos;
129 for(
const auto& itr : delimiters)
131 size_t pos = line.find(itr, _start);
132 if(pos != std::string::npos && (_end == std::string::npos || pos < _end))
139 if(_end != std::string::npos)
142 std::forward<PredicateT>(predicate)(line.substr(_start, _end - _start)));
146 for(
const auto& delimiter : delimiters)
148 if(line.compare(_start, delimiter.size(), delimiter) == 0)
150 _start += delimiter.size();
158 mpl::emplace(_result, std::forward<PredicateT>(predicate)(line.substr(_start)));
168template <
typename PredicateT = std::function<std::
string(const std::
string&)>>
171 std::string_view _begin,
172 std::string_view _end,
173 PredicateT&& predicate)
177 std::string _result = std::string{input};
178 while(_beg_pos < _result.length() && _end_pos < _result.length())
181 _beg_pos = _result.find(_begin, _end_pos);
184 if(_beg_pos == std::string::npos)
break;
188 _end_pos = _result.find(_end, _beg_pos + 1);
190 _end_pos = _beg_pos + _begin.length();
193 if(_end_pos == std::string::npos)
break;
196 auto _len = _end_pos - _beg_pos;
199 auto _sub = _result.substr(_beg_pos, _len);
202 auto _transformed = predicate(_sub);
205 if(_sub != _transformed)
207 _result = _result.replace(_beg_pos, _len, _transformed);
209 _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)