From 597ea27b021f7d7b1e60fc580ad3041d67275487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 16 Nov 2016 19:32:56 +0100 Subject: [PATCH] [core] replace usage with plain string code to reduce binary size --- src/mbgl/util/mapbox.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index 9cf250f7a36..89f6a55167b 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -5,7 +5,6 @@ #include #include #include -#include namespace { @@ -192,14 +191,22 @@ std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_ } result += "." + extension; - + // get the query and remove access_token, if more parameters exist, add them to the final result if (queryIdx != url.length()) { - const auto query = url.substr(queryIdx + 1); - std::regex re ("&?access_token=([^&]*)"); - std::string replace = std::regex_replace(query, re, ""); - std::string subQuery = (replace.find("&") == 0) ? replace.substr(1, replace.length()) : replace; - if (subQuery.length() > 0) result += "?" + subQuery; + auto idx = queryIdx; + bool hasQuery = false; + while (idx != std::string::npos) { + idx++; // skip & or ? + auto ampersandIdx = url.find("&", idx); + if (url.substr(idx, 13) != "access_token=") { + result += hasQuery ? "&" : "?"; + result += url.substr(idx, ampersandIdx != std::string::npos ? ampersandIdx - idx + : std::string::npos); + hasQuery = true; + } + idx = ampersandIdx; + } } return result;