forked from organicmaps/organicmaps
[api] Added parsing of mwm:// scheme (synonym to mapswithme://)
This commit is contained in:
parent
56ec19061b
commit
fa67eda1d5
4 changed files with 9 additions and 8 deletions
|
@ -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;
|
||||
|
|
|
@ -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", ());
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue