summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-01-08 12:14:39 +0100
committerKonstantin Käfer <mail@kkaefer.com>2016-01-08 12:14:39 +0100
commitbc309d84d77a5719a332f2dffdf24006d8610f97 (patch)
tree44cc87134e9eb59c3a259482cfdca50c84b287d6
parentb6fca670896e6351a03916fd9fb646e1970d3ebe (diff)
downloadqtlocation-mapboxgl-bc309d84d77a5719a332f2dffdf24006d8610f97.tar.gz
[core] unify URL prefix detection (asset:// and mapbox://)
-rw-r--r--platform/default/online_file_source.cpp12
-rw-r--r--src/mbgl/map/map_context.cpp4
-rw-r--r--src/mbgl/util/mapbox.cpp2
-rw-r--r--src/mbgl/util/mapbox.hpp2
-rw-r--r--src/mbgl/util/url.cpp8
-rw-r--r--src/mbgl/util/url.hpp2
6 files changed, 18 insertions, 12 deletions
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp
index 871bd36d43..c482d6d96f 100644
--- a/platform/default/online_file_source.cpp
+++ b/platform/default/online_file_source.cpp
@@ -14,21 +14,13 @@
#include <mbgl/util/async_task.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/timer.hpp>
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
-#pragma GCC diagnostic ignored "-Wunknown-pragmas"
-#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
-#include <boost/algorithm/string.hpp>
-#pragma GCC diagnostic pop
+#include <mbgl/util/url.hpp>
#include <algorithm>
#include <cassert>
#include <set>
#include <unordered_map>
-namespace algo = boost::algorithm;
-
namespace mbgl {
class RequestBase;
@@ -299,7 +291,7 @@ void OnlineFileSource::Impl::startRealRequest(OnlineFileRequestImpl& request) {
reschedule(request);
};
- if (algo::starts_with(request.resource.url, "asset://")) {
+ if (util::isAssetURL(request.resource.url)) {
request.realRequest =
assetContext->createRequest(request.resource.url, callback, assetRoot);
} else {
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index f2c17824c3..be6d32d2a0 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -21,6 +21,7 @@
#include <mbgl/util/texture_pool.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/string.hpp>
+#include <mbgl/util/mapbox.hpp>
#include <algorithm>
@@ -114,7 +115,8 @@ void MapContext::setStyleURL(const std::string& url) {
styleRequest = nullptr;
if (res.error) {
- if (res.error->reason == Response::Error::Reason::NotFound && styleURL.find("mapbox://") == 0) {
+ if (res.error->reason == Response::Error::Reason::NotFound &&
+ util::mapbox::isMapboxURL(styleURL)) {
Log::Error(Event::Setup, "style %s could not be found or is an incompatible legacy map or style", styleURL.c_str());
} else {
Log::Error(Event::Setup, "loading style failed: %s", res.error->message.c_str());
diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp
index 0798607467..7bcfa7322c 100644
--- a/src/mbgl/util/mapbox.cpp
+++ b/src/mbgl/util/mapbox.cpp
@@ -13,7 +13,7 @@ const std::string protocol = "mapbox://";
const std::string baseURL = "https://api.mapbox.com/";
bool isMapboxURL(const std::string& url) {
- return url.compare(0, protocol.length(), protocol) == 0;
+ return std::equal(protocol.begin(), protocol.end(), url.begin());
}
std::vector<std::string> getMapboxURLPathname(const std::string& url) {
diff --git a/src/mbgl/util/mapbox.hpp b/src/mbgl/util/mapbox.hpp
index 29ee454894..64f34d72a7 100644
--- a/src/mbgl/util/mapbox.hpp
+++ b/src/mbgl/util/mapbox.hpp
@@ -8,6 +8,8 @@ namespace mbgl {
namespace util {
namespace mapbox {
+bool isMapboxURL(const std::string& url);
+
std::string normalizeSourceURL(const std::string& url, const std::string& accessToken);
std::string normalizeStyleURL(const std::string& url, const std::string& accessToken);
std::string normalizeSpriteURL(const std::string& url, const std::string& accessToken);
diff --git a/src/mbgl/util/url.cpp b/src/mbgl/util/url.cpp
index bf6fc70ff5..07a226414c 100644
--- a/src/mbgl/util/url.cpp
+++ b/src/mbgl/util/url.cpp
@@ -47,5 +47,13 @@ std::string percentDecode(const std::string& input) {
return decoded;
}
+namespace {
+const std::string assetProtocol = "asset://";
+}
+
+bool isAssetURL(const std::string& url) {
+ return std::equal(assetProtocol.begin(), assetProtocol.end(), url.begin());
+}
+
} // namespace util
} // namespace mbgl
diff --git a/src/mbgl/util/url.hpp b/src/mbgl/util/url.hpp
index 6257a171c0..583e04c302 100644
--- a/src/mbgl/util/url.hpp
+++ b/src/mbgl/util/url.hpp
@@ -9,6 +9,8 @@ namespace util {
std::string percentEncode(const std::string&);
std::string percentDecode(const std::string&);
+bool isAssetURL(const std::string&);
+
} // namespace util
} // namespace mbgl