diff --git a/src/beast/beast/http/rfc2616.h b/src/beast/beast/http/rfc2616.h index 0e3819eff..108a6517c 100644 --- a/src/beast/beast/http/rfc2616.h +++ b/src/beast/beast/http/rfc2616.h @@ -24,6 +24,8 @@ #include #include +#include + namespace beast { namespace http { @@ -230,6 +232,44 @@ for_each_element (FwdIter first, FwdIter last, Function func) } } +// Parse a comma-delimited list of values. +template +std::vector> +parse_csv (std::basic_string const& in, + std::ostream& log) +{ + auto first = in.cbegin(); + auto const last = in.cend(); + std::vector> result; + if (first != last) + { + static boost::regex const re( + "^" // start of line + "(?:\\s*)" // whitespace (optional) + "([a-zA-Z][_a-zA-Z0-9]*)" // identifier + "(?:\\s*)" // whitespace (optional) + "(?:,?)" // comma (optional) + "(?:\\s*)" // whitespace (optional) + , boost::regex_constants::optimize + ); + for(;;) + { + boost::smatch m; + if (! boost::regex_search(first, last, m, re, + boost::regex_constants::match_continuous)) + { + log << "Expected \n"; + throw std::exception(); + } + result.push_back(m[1]); + first = m[0].second; + if (first == last) + break; + } + } + return result; +} + } // rfc2616 } // http