diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-10-29 11:08:25 -0400 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-10-30 11:34:14 -0400 |
commit | 8f1c2b3bce579a0a7ae3ed38aacfc7feae33ccbf (patch) | |
tree | 75556f63c973d0d4e2680821ecf4fd050b6657bb /include | |
parent | 152545d33a74a9bd0060fe1b75b307d0636e69ea (diff) | |
download | qtlocation-mapboxgl-8f1c2b3bce579a0a7ae3ed38aacfc7feae33ccbf.tar.gz |
remove regex/boost regex usage
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/util/token.hpp | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/include/mbgl/util/token.hpp b/include/mbgl/util/token.hpp index 786654133a..0f045f434a 100644 --- a/include/mbgl/util/token.hpp +++ b/include/mbgl/util/token.hpp @@ -1,38 +1,36 @@ #ifndef MBGL_UTIL_TOKEN #define MBGL_UTIL_TOKEN -#ifdef __linux__ -#include <boost/regex.hpp> -namespace regex_impl = boost; -#else -#include <regex> -namespace regex_impl = std; -#endif - #include <map> +#include <string> +#include <algorithm> namespace mbgl { namespace util { -namespace detail { -const regex_impl::regex tokenRegex("\\{([\\w-]+)\\}"); -const regex_impl::sregex_token_iterator tokensEnd = regex_impl::sregex_token_iterator(); -} - +// Replaces {tokens} in a string by calling the lookup function. template <typename Lookup> std::string replaceTokens(const std::string &source, const Lookup &lookup) { std::string result; result.reserve(source.size()); - bool token = false; - for (auto token_it = regex_impl::sregex_token_iterator(source.begin(), source.end(), - detail::tokenRegex, {-1, 1}); - token_it != detail::tokensEnd; ++token_it, token = !token) { - if (!token_it->matched) { - continue; + auto pos = source.begin(); + const auto end = source.end(); + + while (pos != end) { + auto brace = std::find(pos, end, '{'); + result.append(pos, brace); + pos = brace; + if (pos != end) { + for (brace++; brace != end && std::isalnum(*brace); brace++); + if (brace != end && *brace == '}') { + result.append(lookup({ pos + 1, brace })); + pos = brace + 1; + } else { + result.append(pos, brace); + pos = brace; + } } - - result += token ? lookup(token_it->str()) : token_it->str(); } return result; |