summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-07-19 16:03:28 +0200
committerMinh Nguyễn <mxn@1ec5.org>2016-07-19 12:23:02 -0700
commitc261d0b2a8ca2b1311e55eeae628d9a169ae31c5 (patch)
treed9b202d1fddd6db6718c6ec246c74e5313e03aba /src
parentd640c2215f7dc47f4d55d2c0c1da867849761e2a (diff)
downloadqtlocation-mapboxgl-c261d0b2a8ca2b1311e55eeae628d9a169ae31c5.tar.gz
[core] use more const, auto and refs
Cherry-picked from 40ea4247d81eccc1d48af56fe1da95438bbdefcc.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/util/mapbox.cpp69
1 files changed, 32 insertions, 37 deletions
diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp
index 28dedaf25c..b60c04a3ed 100644
--- a/src/mbgl/util/mapbox.cpp
+++ b/src/mbgl/util/mapbox.cpp
@@ -19,13 +19,13 @@ bool isMapboxURL(const std::string& url) {
std::vector<std::string> getMapboxURLPathname(const std::string& url) {
std::vector<std::string> pathname;
- std::size_t startIndex = protocol.length();
- std::size_t end = url.find_first_of("?#");
+ auto startIndex = protocol.length();
+ auto end = url.find_first_of("?#");
if (end == std::string::npos) {
end = url.length();
}
while (startIndex < end) {
- std::size_t endIndex = url.find("/", startIndex);
+ auto endIndex = url.find("/", startIndex);
if (endIndex == std::string::npos) {
endIndex = end;
}
@@ -52,16 +52,15 @@ std::string normalizeStyleURL(const std::string& url, const std::string& accessT
return url;
}
- std::vector<std::string> pathname = getMapboxURLPathname(url);
-
+ const auto pathname = getMapboxURLPathname(url);
if (pathname.size() < 3) {
Log::Error(Event::ParseStyle, "Invalid style URL");
return url;
}
- std::string user = pathname[1];
- std::string id = pathname[2];
- bool isDraft = pathname.size() > 3;
+ const auto& user = pathname[1];
+ const auto& id = pathname[2];
+ const bool isDraft = pathname.size() > 3;
return baseURL + "styles/v1/" + user + "/" + id + (isDraft ? "/draft" : "") + "?access_token=" + accessToken;
}
@@ -70,36 +69,33 @@ std::string normalizeSpriteURL(const std::string& url, const std::string& access
return url;
}
- std::vector<std::string> pathname = getMapboxURLPathname(url);
-
+ const auto pathname = getMapboxURLPathname(url);
if (pathname.size() < 3) {
Log::Error(Event::ParseStyle, "Invalid sprite URL");
return url;
}
- std::string user = pathname[1];
- bool isDraft = pathname.size() > 3;
+ const auto& user = pathname[1];
+ const bool isDraft = pathname.size() > 3;
+
+ const auto& name = isDraft ? pathname[3] : pathname[2];
+ const size_t index = name.find_first_of("@.");
+ if (index == std::string::npos) {
+ Log::Error(Event::ParseStyle, "Invalid sprite URL");
+ return url;
+ }
+ const auto& extension = name.substr(index);
- std::string id, extension;
if (isDraft) {
- size_t index = pathname[3].find_first_of("@.");
- if (index == std::string::npos) {
- Log::Error(Event::ParseStyle, "Invalid sprite URL");
- return url;
- }
- id = pathname[2];
- extension = pathname[3].substr(index);
+ const auto& id = pathname[2];
+ return baseURL + "styles/v1/" + user + "/" + id + "/draft/sprite" + extension +
+ "?access_token=" + accessToken;
+
} else {
- size_t index = pathname[2].find_first_of("@.");
- if (index == std::string::npos) {
- Log::Error(Event::ParseStyle, "Invalid sprite URL");
- return url;
- }
- id = pathname[2].substr(0, index);
- extension = pathname[2].substr(index);
+ const auto& id = pathname[2].substr(0, index);
+ return baseURL + "styles/v1/" + user + "/" + id + "/sprite" + extension + "?access_token=" +
+ accessToken;
}
-
- return baseURL + "styles/v1/" + user + "/" + id + "/" + (isDraft ? "draft/" : "") + "sprite" + extension + "?access_token=" + accessToken;
}
std::string normalizeGlyphsURL(const std::string& url, const std::string& accessToken) {
@@ -107,16 +103,15 @@ std::string normalizeGlyphsURL(const std::string& url, const std::string& access
return url;
}
- std::vector<std::string> pathname = getMapboxURLPathname(url);
-
+ const auto pathname = getMapboxURLPathname(url);
if (pathname.size() < 4) {
Log::Error(Event::ParseStyle, "Invalid glyph URL");
return url;
}
- std::string user = pathname[1];
- std::string fontstack = pathname[2];
- std::string range = pathname[3];
+ const auto& user = pathname[1];
+ const auto& fontstack = pathname[2];
+ const auto& range = pathname[3];
return baseURL + "fonts/v1/" + user + "/" + fontstack + "/" + range + "?access_token=" + accessToken;
}
@@ -137,7 +132,7 @@ std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_
tilesetStartIdx += sizeof("/v4/") - 1;
- auto tilesetEndIdx = url.find("/", tilesetStartIdx);
+ const auto tilesetEndIdx = url.find("/", tilesetStartIdx);
if (tilesetEndIdx == std::string::npos) {
return url;
}
@@ -154,12 +149,12 @@ std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_
basenameIdx += 1;
}
- auto extensionIdx = url.find(".", basenameIdx);
+ const auto extensionIdx = url.find(".", basenameIdx);
if (extensionIdx == std::string::npos || extensionIdx == queryIdx - 1) {
return url;
}
- auto tileset = url.substr(tilesetStartIdx, tilesetEndIdx - tilesetStartIdx);
+ const auto tileset = url.substr(tilesetStartIdx, tilesetEndIdx - tilesetStartIdx);
auto extension = url.substr(extensionIdx + 1, queryIdx - extensionIdx - 1);
#if !defined(__ANDROID__) && !defined(__APPLE__) && !defined(QT_IMAGE_DECODERS)