Canonicalizes Spaces in Semicolon Stringlists, fixes #3086

This commit is contained in:
Daniel J. Hofmann
2016-10-18 09:58:39 -07:00
parent 18bc02f087
commit ab1a9271c8
5 changed files with 74 additions and 17 deletions
@@ -4,6 +4,11 @@
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <algorithm>
#include <cctype>
#include <iterator>
#include <limits>
#include <string>
@@ -112,7 +117,24 @@ inline std::string applyAccessTokens(const std::string &lane_string,
{
return extractor::guidance::applyAccessTokens(lane_string, access_tokens);
}
}
// Takes a string representing a list separated by delim and canonicalizes containing spaces.
// Example: "aaa;bbb; ccc; d;dd" => "aaa; bbb; ccc; d; dd"
inline std::string canonicalizeStringList(std::string strlist, const std::string &delim)
{
// expand space after delimiter: ";X" => "; X"
boost::replace_all(strlist, delim, delim + " ");
// collapse spaces; this is needed in case we expand "; X" => "; X" above
// but also makes sense to do irregardless of the fact - canonicalizing strings.
const auto spaces = [](auto lhs, auto rhs) { return ::isspace(lhs) && ::isspace(rhs); };
auto it = std::unique(begin(strlist), end(strlist), spaces);
strlist.erase(it, end(strlist));
return strlist;
}
} // extractor
} // osrm
#endif // EXTRACTION_HELPER_FUNCTIONS_HPP