diff options
author | Aleksey Belouosv <aleksey@maps.me> | 2018-08-08 19:39:13 +0300 |
---|---|---|
committer | Aleksey Belousov <beloal@users.noreply.github.com> | 2018-08-10 20:16:14 +0300 |
commit | cea09e06f06295ecd55ee75fe4842d20dd080648 (patch) | |
tree | 1d6d5a5ec67347cca2a3af9453ec536e57a92274 /map | |
parent | ecfe461def11596c0de59ef9d143cc8a99504181 (diff) |
[iOS] refactor deeplink parsing
Diffstat (limited to 'map')
-rw-r--r-- | map/mwm_url.cpp | 39 | ||||
-rw-r--r-- | map/mwm_url.hpp | 11 |
2 files changed, 47 insertions, 3 deletions
diff --git a/map/mwm_url.cpp b/map/mwm_url.cpp index 82f25f80a4..393cbd94aa 100644 --- a/map/mwm_url.cpp +++ b/map/mwm_url.cpp @@ -95,7 +95,13 @@ char const * kCenterLatLon = "cll"; char const * kLocale = "locale"; char const * kSearchOnMap = "map"; } // namespace search - + +namespace catalogue +{ +char const * kId = "id"; +char const * kName = "name"; +} + namespace { enum class ApiURLType @@ -104,7 +110,8 @@ enum class ApiURLType Map, Route, Search, - Lead + Lead, + Catalogue }; std::array<std::string, 3> const kAvailableSchemes = {{"mapswithme", "mwm", "mapsme"}}; @@ -123,6 +130,8 @@ ApiURLType URLType(Uri const & uri) return ApiURLType::Search; if (path == "lead") return ApiURLType::Lead; + if (path == "catalogue") + return ApiURLType::Catalogue; return ApiURLType::Incorrect; } @@ -258,6 +267,20 @@ ParsedMapApi::ParsingResult ParsedMapApi::Parse(Uri const & uri) description.Write(); return ParsingResult::Lead; } + case ApiURLType::Catalogue: + { + CatalogItem item; + auto const result = uri.ForEachKeyValue([&item, this](string const & key, string const & value) + { + return CatalogKeyValue(key, value, item); + }); + + if (!result) + return ParsingResult::Incorrect; + + m_catalogItem = item; + return ParsingResult::Catalogue; + } } CHECK_SWITCH(); } @@ -435,6 +458,18 @@ bool ParsedMapApi::LeadKeyValue(string const & key, string const & value, lead:: return true; } +bool ParsedMapApi::CatalogKeyValue(string const & key, string const & value, CatalogItem & item) const +{ + using namespace catalogue; + + if (key == kName) + item.m_name = value; + else if (key == kId) + item.m_id = value; + + return true; +} + void ParsedMapApi::Reset() { m_globalBackUrl.clear(); diff --git a/map/mwm_url.hpp b/map/mwm_url.hpp index a656988306..6718d715a0 100644 --- a/map/mwm_url.hpp +++ b/map/mwm_url.hpp @@ -37,6 +37,11 @@ struct SearchRequest bool m_isSearchOnMap = false; }; +struct CatalogItem +{ + string m_id; + string m_name; +}; namespace lead { @@ -55,7 +60,8 @@ public: Map, Route, Search, - Lead + Lead, + Catalogue }; ParsedMapApi() = default; @@ -76,16 +82,19 @@ public: vector<RoutePoint> const & GetRoutePoints() const { return m_routePoints; } string const & GetRoutingType() const { return m_routingType; } SearchRequest const & GetSearchRequest() const { return m_request; } + CatalogItem const & GetCatalogItem() const { return m_catalogItem; } private: ParsingResult Parse(Uri const & uri); bool AddKeyValue(string const & key, string const & value, vector<ApiPoint> & points); bool RouteKeyValue(string const & key, string const & value, vector<string> & pattern); bool SearchKeyValue(string const & key, string const & value, SearchRequest & request) const; bool LeadKeyValue(string const & key, string const & value, lead::CampaignDescription & description) const; + bool CatalogKeyValue(string const & key, string const & value, CatalogItem & item) const; BookmarkManager * m_bmManager = nullptr; vector<RoutePoint> m_routePoints; SearchRequest m_request; + CatalogItem m_catalogItem; string m_globalBackUrl; string m_appTitle; string m_routingType; |