30template<
class StringType,
class UnaryPredicate>
33 const StringType& str,
34 const UnaryPredicate& meta,
38 if (str.empty() || !quote)
44 result.reserve(1.5*str.size());
47 for (
const char c : str)
64 result.shrink_to_fit();
69template<
class StringType,
class UnaryPredicate>
72 const std::string& str,
73 const UnaryPredicate& accept,
78 out.resize(str.length());
80 std::string::size_type len = 0;
82 for (std::string::size_type i = 0; i < str.length(); ++i)
84 const char c = str[i];
96template<
class StringType>
99 const StringType& str,
105 if (str.empty() || !delim)
112 std::string::size_type beg = 0, end = 0;
113 while ((end = str.find(delim, beg)) != std::string::npos)
115 if (keepEmpty || (beg < end))
117 lst.
append(str.cbegin() + beg, str.cbegin() + end);
123 if (keepEmpty ? (beg == str.size()) : (beg < str.size()))
125 lst.
append(str.cbegin() + beg, str.cend());
132template<
class StringType>
135 const StringType& str,
136 const std::string& delim,
141 if (str.empty() || delim.empty())
148 std::string::size_type beg = 0, end = 0;
149 while ((end = str.find(delim, beg)) != std::string::npos)
151 if (keepEmpty || (beg < end))
153 lst.
append(str.cbegin() + beg, str.cbegin() + end);
155 beg = end + delim.size();
159 if (keepEmpty ? (beg == str.size()) : (beg < str.size()))
161 lst.
append(str.cbegin() + beg, str.cend());
168template<
class StringType>
171 const StringType& str,
172 const std::string& delim
176 if (str.empty() || delim.empty())
185 std::string::size_type
pos = 0;
186 (
pos = str.find_first_not_of(delim,
pos)) != std::string::npos;
190 const auto end = str.find_first_of(delim,
pos);
192 if (end == std::string::npos)
195 lst.
append(str.cbegin() +
pos, str.cend());
200 lst.
append(str.cbegin() +
pos, str.cbegin() + end);
209template<
class StringType>
212 const StringType& str,
213 const std::string::size_type width,
214 const std::string::size_type start
218 if (str.empty() || !width)
223 const auto len = str.size();
224 lst.reserve(1 + (len / width));
226 for (std::string::size_type
pos = start;
pos < len;
pos += width)
228 const auto end = (
pos + width);
233 lst.
append(str.cbegin() +
pos, str.cend());
237 lst.
append(str.cbegin() +
pos, str.cbegin() + end);
244template<
class StringType>
247 const StringType& str
250 return splitAny(str,
"\t\n\v\f\r ");
Sub-ranges of a string with a structure similar to std::match_results, but without the underlying reg...
void append(const typename StringType::const_iterator &b, const typename StringType::const_iterator &e)
Append sub-string defined by begin/end iterators.
StringType quotemeta(const StringType &str, const UnaryPredicate &meta, const char quote='\\')
Quote any meta-characters in given string.
Foam::SubStrings< StringType > splitFixed(const StringType &str, const std::string::size_type width, const std::string::size_type start=0)
Split string into sub-strings using a fixed field width.
Foam::SubStrings< StringType > splitSpace(const StringType &str)
Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC)
StringType validate(const std::string &str, const UnaryPredicate &accept, const bool invert=false)
Return a copy of the input string with validated characters.
Foam::SubStrings< StringType > splitAny(const StringType &str, const std::string &delim)
Split string into sub-strings using any characters in delimiter.
Foam::SubStrings< StringType > split(const StringType &str, const char delim, const bool keepEmpty=false)
Split string into sub-strings at the delimiter character.
dimensionedScalar pos(const dimensionedScalar &ds)
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.