Canonicalizes Spaces in Semicolon Stringlists, fixes #3086
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user