From fa67eda1d5d1b9502469160c995d01be24ca2350 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 14 Jan 2013 21:05:23 +0300 Subject: [PATCH] [api] Added parsing of mwm:// scheme (synonym to mapswithme://) --- coding/uri.hpp | 4 ++-- map/map_tests/mwm_url_tests.cpp | 8 ++++---- map/mwm_url.cpp | 3 ++- map/mwm_url.hpp | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/coding/uri.hpp b/coding/uri.hpp index 305d34b566..bc98660e95 100644 --- a/coding/uri.hpp +++ b/coding/uri.hpp @@ -16,8 +16,8 @@ public: explicit Uri(string const & uri) : m_url(uri) { Init(); } Uri(char const * uri, size_t size) : m_url(uri, uri + size) { Init(); } - string GetScheme() const { return m_scheme; } - string GetPath() const { return m_path; } + string const & GetScheme() const { return m_scheme; } + string const & GetPath() const { return m_path; } bool IsValid() const { return !m_scheme.empty(); } void ForEachKeyValue(CallbackT const & callback) const; diff --git a/map/map_tests/mwm_url_tests.cpp b/map/map_tests/mwm_url_tests.cpp index 980378eb2d..912659e13c 100644 --- a/map/map_tests/mwm_url_tests.cpp +++ b/map/map_tests/mwm_url_tests.cpp @@ -24,7 +24,7 @@ UNIT_TEST(MapApiInvalidUrl) { TEST(!ParsedMapApi(Uri("competitors://map?ll=12.3,34.54")).IsValid(), ()); TEST(!ParsedMapApi(Uri("mapswithme://ggg?ll=12.3,34.54")).IsValid(), ()); - TEST(!ParsedMapApi(Uri("mapswithme://")).IsValid(), ("No path")); + TEST(!ParsedMapApi(Uri("mwm://")).IsValid(), ("No path")); TEST(!ParsedMapApi(Uri("mapswithme://map?")).IsValid(), ("No parameters")); TEST(!ParsedMapApi(Uri("mapswithme://map?ll=23.55")).IsValid(), ("No longtitude")); TEST(!ParsedMapApi(Uri("mapswithme://map?ll=1,2,3")).IsValid(), ("Too many values for ll")); @@ -33,7 +33,7 @@ UNIT_TEST(MapApiInvalidUrl) UNIT_TEST(MapApiLatLonLimits) { TEST(!ParsedMapApi(Uri("mapswithme://map?ll=-91,10")).IsValid(), ("Invalid latitude")); - TEST(!ParsedMapApi(Uri("mapswithme://map?ll=523.55,10")).IsValid(), ("Invalid latitude")); + TEST(!ParsedMapApi(Uri("mwm://map?ll=523.55,10")).IsValid(), ("Invalid latitude")); TEST(!ParsedMapApi(Uri("mapswithme://map?ll=23.55,450")).IsValid(), ("Invalid longtitude")); TEST(!ParsedMapApi(Uri("mapswithme://map?ll=23.55,-450")).IsValid(), ("Invalid longtitude")); } @@ -56,7 +56,7 @@ UNIT_TEST(MapApiPointNameOverwritten) UNIT_TEST(MapApiMultiplePoints) { - ParsedMapApi api(Uri("mapswithme://map?ll=1.1,1.2&n=A&ll=2.1,2.2&ll=-3.1,-3.2&n=C")); + ParsedMapApi api(Uri("mwm://map?ll=1.1,1.2&n=A&ll=2.1,2.2&ll=-3.1,-3.2&n=C")); TEST(api.IsValid(), ()); TEST_EQUAL(api.GetPoints().size(), 3, ()); TEST_EQUAL(api.GetPoints()[0].m_lat, 1.1, ()); @@ -82,7 +82,7 @@ UNIT_TEST(MapApiInvalidPointLatLonButValidOtherParts) UNIT_TEST(MapApiPointURLEncoded) { - ParsedMapApi api(Uri("mapswithme://map?ll=1,2&n=%D0%9C%D0%B8%D0%BD%D1%81%D0%BA&u=http%3A%2F%2Fmap%3Fll%3D1%2C2%26n%3Dtest")); + ParsedMapApi api(Uri("mwm://map?ll=1,2&n=%D0%9C%D0%B8%D0%BD%D1%81%D0%BA&u=http%3A%2F%2Fmap%3Fll%3D1%2C2%26n%3Dtest")); TEST(api.IsValid(), ()); TEST_EQUAL(api.GetPoints().size(), 1, ()); TEST_EQUAL(api.GetPoints()[0].m_title, "\xd0\x9c\xd0\xb8\xd0\xbd\xd1\x81\xd0\xba", ()); diff --git a/map/mwm_url.cpp b/map/mwm_url.cpp index 9e4fa04bf7..c020ac2dbd 100644 --- a/map/mwm_url.cpp +++ b/map/mwm_url.cpp @@ -36,7 +36,8 @@ bool ParsedMapApi::IsValid() const bool ParsedMapApi::Parse(Uri const & uri) { - if (uri.GetScheme() != "mapswithme" || uri.GetPath() != "map") + string const & scheme = uri.GetScheme(); + if ((scheme != "mapswithme" && scheme != "mwm") || uri.GetPath() != "map") return false; uri.ForEachKeyValue(bind(&ParsedMapApi::AddKeyValue, this, _1, _2)); diff --git a/map/mwm_url.hpp b/map/mwm_url.hpp index 317dfc5311..b73617c902 100644 --- a/map/mwm_url.hpp +++ b/map/mwm_url.hpp @@ -14,7 +14,7 @@ struct ApiPoint string m_url; }; -/// Handles mapswithme://map?params - everything related to displaying info on a map +/// Handles [mapswithme|mwm]://map?params - everything related to displaying info on a map class ParsedMapApi { public: