#ifndef MBGL_UTIL_TOKEN #define MBGL_UTIL_TOKEN #ifdef __linux__ #include namespace regex_impl = boost; #else #include namespace regex_impl = std; #endif #include namespace mbgl { namespace util { namespace detail { const regex_impl::regex tokenRegex("\\{([\\w-]+)\\}"); const regex_impl::sregex_token_iterator tokensEnd = regex_impl::sregex_token_iterator(); } template 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; } result += token ? lookup(token_it->str()) : token_it->str(); } return result; } template inline std::string replaceTokens(const std::string &source, const std::map &properties) { return replaceTokens(source, [&properties](const std::string &token) -> std::string { const auto it_prop = properties.find(token); return it_prop != properties.end() ? toString(it_prop->second) : ""; }); } } // end namespace util } // end namespace mbgl #endif