30 template<
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();
69 template<
class StringType,
class UnaryPredicate>
72 const std::string& str,
73 const UnaryPredicate& accept,
78 out.resize(str.length());
84 const char c = str[i];
96 template<
class StringType>
99 const StringType& str,
105 if (str.empty() || !delim)
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());
132 template<
class StringType>
135 const StringType& str,
136 const std::string& delim,
141 if (str.empty() || delim.empty())
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());
168 template<
class StringType>
171 const StringType& str,
172 const std::string& delim
176 if (str.empty() || delim.empty())
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());
209 template<
class StringType>
212 const StringType& str,
218 if (str.empty() || !width)
223 const auto len = str.size();
224 lst.reserve(1 + (len / width));
228 const auto end = (
pos + width);
233 lst.
append(str.cbegin() +
pos, str.cend());
244 template<
class StringType>
247 const StringType& str
250 return splitAny(str,
"\t\n\v\f\r ");
Foam::SubStrings< StringType > split(const StringType &str, const char delim, const bool keepEmpty=false)
Split string into sub-strings at the delimiter character.
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.
Sub-ranges of a string with a structure similar to std::match_results, but without the underlying reg...
StringType quotemeta(const StringType &str, const UnaryPredicate &meta, const char quote='\\')
Quote any meta-characters in given string.
StringType validate(const std::string &str, const UnaryPredicate &accept, const bool invert=false)
Return a copy of the input string with validated characters.
dimensionedScalar pos(const dimensionedScalar &ds)
graph_traits< Graph >::vertices_size_type size_type
void append(const typename StringType::const_iterator &b, const typename StringType::const_iterator &e)
Append sub-string defined by begin/end iterators.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Foam::SubStrings< StringType > splitSpace(const StringType &str)
Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC)
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Foam::SubStrings< StringType > splitAny(const StringType &str, const std::string &delim)
Split string into sub-strings using any characters in delimiter.
const dimensionedScalar c
Speed of light in a vacuum.