25 #ifndef OPTIONPP_UTILITY_HPP
26 #define OPTIONPP_UTILITY_HPP
60 template <
typename OutputIt>
61 void split(
const std::string& str, OutputIt dest,
62 const std::string& delims =
" \t\n\r",
63 const std::string& quotes =
"\"\'",
64 char escape_char =
'\\',
65 bool allow_empty =
false);
85 std::string
wrap_text(
const std::string& str,
110 std::string
wrap_text(
const std::string& str,
113 int first_line_indent);
135 std::string::size_type pos = 0) noexcept;
144 template <
typename OutputIt>
146 const std::string& delims,
147 const std::string& quotes,
150 using size_type = decltype(str.size());
152 bool escape_next{
false};
153 bool in_quotes{
false};
154 size_type quote_index{0};
155 std::string cur_token;
156 while (pos < str.size()) {
159 if (escape_next || str[pos] != quotes[quote_index]) {
160 if (!escape_next && str[pos] == escape_char)
163 cur_token.push_back(str[pos]);
171 if (escape_next || delims.find(str[pos]) == std::string::npos) {
172 if (!escape_next && str[pos] == escape_char)
174 else if (escape_next) {
175 cur_token.push_back(str[pos]);
179 quote_index = quotes.find(str[pos]);
180 if (quote_index != std::string::npos)
183 cur_token.push_back(str[pos]);
186 if (!cur_token.empty() || allow_empty)
196 if (!cur_token.empty() || allow_empty)