Roman Tsisyk 2022-01-09 18:24:42 +03:00 committed by Viktor Govako
parent e541af3268
commit e0c8ee4499
6 changed files with 619 additions and 8 deletions

View file

@ -112,8 +112,454 @@
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="maps.google.com"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:pathPrefix="/maps"/>
<!-- Generated from https://www.google.com/supported_domains //-->
<data android:host="maps.google.ad"/>
<data android:host="maps.google.ae"/>
<data android:host="maps.google.al"/>
<data android:host="maps.google.am"/>
<data android:host="maps.google.as"/>
<data android:host="maps.google.at"/>
<data android:host="maps.google.az"/>
<data android:host="maps.google.ba"/>
<data android:host="maps.google.be"/>
<data android:host="maps.google.bf"/>
<data android:host="maps.google.bg"/>
<data android:host="maps.google.bi"/>
<data android:host="maps.google.bj"/>
<data android:host="maps.google.bs"/>
<data android:host="maps.google.bt"/>
<data android:host="maps.google.by"/>
<data android:host="maps.google.ca"/>
<data android:host="maps.google.cat"/>
<data android:host="maps.google.cd"/>
<data android:host="maps.google.cf"/>
<data android:host="maps.google.cg"/>
<data android:host="maps.google.ch"/>
<data android:host="maps.google.ci"/>
<data android:host="maps.google.cl"/>
<data android:host="maps.google.cm"/>
<data android:host="maps.google.cn"/>
<data android:host="maps.google.co.ao"/>
<data android:host="maps.google.co.bw"/>
<data android:host="maps.google.co.ck"/>
<data android:host="maps.google.co.cr"/>
<data android:host="maps.google.co.id"/>
<data android:host="maps.google.co.il"/>
<data android:host="maps.google.co.in"/>
<data android:host="maps.google.co.jp"/>
<data android:host="maps.google.co.ke"/>
<data android:host="maps.google.co.kr"/>
<data android:host="maps.google.co.ls"/>
<data android:host="maps.google.co.ma"/>
<data android:host="maps.google.co.mz"/>
<data android:host="maps.google.co.nz"/>
<data android:host="maps.google.co.th"/>
<data android:host="maps.google.co.tz"/>
<data android:host="maps.google.co.ug"/>
<data android:host="maps.google.co.uk"/>
<data android:host="maps.google.co.uz"/>
<data android:host="maps.google.co.ve"/>
<data android:host="maps.google.co.vi"/>
<data android:host="maps.google.co.za"/>
<data android:host="maps.google.co.zm"/>
<data android:host="maps.google.co.zw"/>
<data android:host="maps.google.com.af"/>
<data android:host="maps.google.com.ag"/>
<data android:host="maps.google.com.ai"/>
<data android:host="maps.google.com.ar"/>
<data android:host="maps.google.com.au"/>
<data android:host="maps.google.com.bd"/>
<data android:host="maps.google.com.bh"/>
<data android:host="maps.google.com.bn"/>
<data android:host="maps.google.com.bo"/>
<data android:host="maps.google.com.br"/>
<data android:host="maps.google.com.bz"/>
<data android:host="maps.google.com.co"/>
<data android:host="maps.google.com.cu"/>
<data android:host="maps.google.com.cy"/>
<data android:host="maps.google.com.do"/>
<data android:host="maps.google.com.ec"/>
<data android:host="maps.google.com.eg"/>
<data android:host="maps.google.com.et"/>
<data android:host="maps.google.com.fj"/>
<data android:host="maps.google.com.gh"/>
<data android:host="maps.google.com.gi"/>
<data android:host="maps.google.com.gt"/>
<data android:host="maps.google.com.hk"/>
<data android:host="maps.google.com.jm"/>
<data android:host="maps.google.com.kh"/>
<data android:host="maps.google.com.kw"/>
<data android:host="maps.google.com.lb"/>
<data android:host="maps.google.com.ly"/>
<data android:host="maps.google.com.mm"/>
<data android:host="maps.google.com.mt"/>
<data android:host="maps.google.com.mx"/>
<data android:host="maps.google.com.my"/>
<data android:host="maps.google.com.na"/>
<data android:host="maps.google.com.ng"/>
<data android:host="maps.google.com.ni"/>
<data android:host="maps.google.com.np"/>
<data android:host="maps.google.com.om"/>
<data android:host="maps.google.com.pa"/>
<data android:host="maps.google.com.pe"/>
<data android:host="maps.google.com.pg"/>
<data android:host="maps.google.com.ph"/>
<data android:host="maps.google.com.pk"/>
<data android:host="maps.google.com.pr"/>
<data android:host="maps.google.com.py"/>
<data android:host="maps.google.com.qa"/>
<data android:host="maps.google.com.sa"/>
<data android:host="maps.google.com.sb"/>
<data android:host="maps.google.com.sg"/>
<data android:host="maps.google.com.sl"/>
<data android:host="maps.google.com.sv"/>
<data android:host="maps.google.com.tj"/>
<data android:host="maps.google.com.tr"/>
<data android:host="maps.google.com.tw"/>
<data android:host="maps.google.com.ua"/>
<data android:host="maps.google.com.uy"/>
<data android:host="maps.google.com.vc"/>
<data android:host="maps.google.com.vn"/>
<data android:host="maps.google.com"/>
<data android:host="maps.google.cv"/>
<data android:host="maps.google.cz"/>
<data android:host="maps.google.de"/>
<data android:host="maps.google.dj"/>
<data android:host="maps.google.dk"/>
<data android:host="maps.google.dm"/>
<data android:host="maps.google.dz"/>
<data android:host="maps.google.ee"/>
<data android:host="maps.google.es"/>
<data android:host="maps.google.fi"/>
<data android:host="maps.google.fm"/>
<data android:host="maps.google.fr"/>
<data android:host="maps.google.ga"/>
<data android:host="maps.google.ge"/>
<data android:host="maps.google.gg"/>
<data android:host="maps.google.gl"/>
<data android:host="maps.google.gm"/>
<data android:host="maps.google.gr"/>
<data android:host="maps.google.gy"/>
<data android:host="maps.google.hn"/>
<data android:host="maps.google.hr"/>
<data android:host="maps.google.ht"/>
<data android:host="maps.google.hu"/>
<data android:host="maps.google.ie"/>
<data android:host="maps.google.im"/>
<data android:host="maps.google.iq"/>
<data android:host="maps.google.is"/>
<data android:host="maps.google.it"/>
<data android:host="maps.google.je"/>
<data android:host="maps.google.jo"/>
<data android:host="maps.google.kg"/>
<data android:host="maps.google.ki"/>
<data android:host="maps.google.kz"/>
<data android:host="maps.google.la"/>
<data android:host="maps.google.li"/>
<data android:host="maps.google.lk"/>
<data android:host="maps.google.lt"/>
<data android:host="maps.google.lu"/>
<data android:host="maps.google.lv"/>
<data android:host="maps.google.md"/>
<data android:host="maps.google.me"/>
<data android:host="maps.google.mg"/>
<data android:host="maps.google.mk"/>
<data android:host="maps.google.ml"/>
<data android:host="maps.google.mn"/>
<data android:host="maps.google.ms"/>
<data android:host="maps.google.mu"/>
<data android:host="maps.google.mv"/>
<data android:host="maps.google.mw"/>
<data android:host="maps.google.ne"/>
<data android:host="maps.google.nl"/>
<data android:host="maps.google.no"/>
<data android:host="maps.google.nr"/>
<data android:host="maps.google.nu"/>
<data android:host="maps.google.pl"/>
<data android:host="maps.google.pn"/>
<data android:host="maps.google.ps"/>
<data android:host="maps.google.pt"/>
<data android:host="maps.google.ro"/>
<data android:host="maps.google.rs"/>
<data android:host="maps.google.ru"/>
<data android:host="maps.google.rw"/>
<data android:host="maps.google.sc"/>
<data android:host="maps.google.se"/>
<data android:host="maps.google.sh"/>
<data android:host="maps.google.si"/>
<data android:host="maps.google.sk"/>
<data android:host="maps.google.sm"/>
<data android:host="maps.google.sn"/>
<data android:host="maps.google.so"/>
<data android:host="maps.google.sr"/>
<data android:host="maps.google.st"/>
<data android:host="maps.google.td"/>
<data android:host="maps.google.tg"/>
<data android:host="maps.google.tl"/>
<data android:host="maps.google.tm"/>
<data android:host="maps.google.tn"/>
<data android:host="maps.google.to"/>
<data android:host="maps.google.tt"/>
<data android:host="maps.google.vg"/>
<data android:host="maps.google.vu"/>
<data android:host="maps.google.ws"/>
<data android:host="www.googlemaps.com"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:pathPrefix="/maps"/>
<!-- Generated from https://www.google.com/supported_domains //-->
<data android:host="www.google.ad"/>
<data android:host="www.google.ae"/>
<data android:host="www.google.al"/>
<data android:host="www.google.am"/>
<data android:host="www.google.as"/>
<data android:host="www.google.at"/>
<data android:host="www.google.az"/>
<data android:host="www.google.ba"/>
<data android:host="www.google.be"/>
<data android:host="www.google.bf"/>
<data android:host="www.google.bg"/>
<data android:host="www.google.bi"/>
<data android:host="www.google.bj"/>
<data android:host="www.google.bs"/>
<data android:host="www.google.bt"/>
<data android:host="www.google.by"/>
<data android:host="www.google.ca"/>
<data android:host="www.google.cat"/>
<data android:host="www.google.cd"/>
<data android:host="www.google.cf"/>
<data android:host="www.google.cg"/>
<data android:host="www.google.ch"/>
<data android:host="www.google.ci"/>
<data android:host="www.google.cl"/>
<data android:host="www.google.cm"/>
<data android:host="www.google.cn"/>
<data android:host="www.google.co.ao"/>
<data android:host="www.google.co.bw"/>
<data android:host="www.google.co.ck"/>
<data android:host="www.google.co.cr"/>
<data android:host="www.google.co.id"/>
<data android:host="www.google.co.il"/>
<data android:host="www.google.co.in"/>
<data android:host="www.google.co.jp"/>
<data android:host="www.google.co.ke"/>
<data android:host="www.google.co.kr"/>
<data android:host="www.google.co.ls"/>
<data android:host="www.google.co.ma"/>
<data android:host="www.google.co.mz"/>
<data android:host="www.google.co.nz"/>
<data android:host="www.google.co.th"/>
<data android:host="www.google.co.tz"/>
<data android:host="www.google.co.ug"/>
<data android:host="www.google.co.uk"/>
<data android:host="www.google.co.uz"/>
<data android:host="www.google.co.ve"/>
<data android:host="www.google.co.vi"/>
<data android:host="www.google.co.za"/>
<data android:host="www.google.co.zm"/>
<data android:host="www.google.co.zw"/>
<data android:host="www.google.com.af"/>
<data android:host="www.google.com.ag"/>
<data android:host="www.google.com.ai"/>
<data android:host="www.google.com.ar"/>
<data android:host="www.google.com.au"/>
<data android:host="www.google.com.bd"/>
<data android:host="www.google.com.bh"/>
<data android:host="www.google.com.bn"/>
<data android:host="www.google.com.bo"/>
<data android:host="www.google.com.br"/>
<data android:host="www.google.com.bz"/>
<data android:host="www.google.com.co"/>
<data android:host="www.google.com.cu"/>
<data android:host="www.google.com.cy"/>
<data android:host="www.google.com.do"/>
<data android:host="www.google.com.ec"/>
<data android:host="www.google.com.eg"/>
<data android:host="www.google.com.et"/>
<data android:host="www.google.com.fj"/>
<data android:host="www.google.com.gh"/>
<data android:host="www.google.com.gi"/>
<data android:host="www.google.com.gt"/>
<data android:host="www.google.com.hk"/>
<data android:host="www.google.com.jm"/>
<data android:host="www.google.com.kh"/>
<data android:host="www.google.com.kw"/>
<data android:host="www.google.com.lb"/>
<data android:host="www.google.com.ly"/>
<data android:host="www.google.com.mm"/>
<data android:host="www.google.com.mt"/>
<data android:host="www.google.com.mx"/>
<data android:host="www.google.com.my"/>
<data android:host="www.google.com.na"/>
<data android:host="www.google.com.ng"/>
<data android:host="www.google.com.ni"/>
<data android:host="www.google.com.np"/>
<data android:host="www.google.com.om"/>
<data android:host="www.google.com.pa"/>
<data android:host="www.google.com.pe"/>
<data android:host="www.google.com.pg"/>
<data android:host="www.google.com.ph"/>
<data android:host="www.google.com.pk"/>
<data android:host="www.google.com.pr"/>
<data android:host="www.google.com.py"/>
<data android:host="www.google.com.qa"/>
<data android:host="www.google.com.sa"/>
<data android:host="www.google.com.sb"/>
<data android:host="www.google.com.sg"/>
<data android:host="www.google.com.sl"/>
<data android:host="www.google.com.sv"/>
<data android:host="www.google.com.tj"/>
<data android:host="www.google.com.tr"/>
<data android:host="www.google.com.tw"/>
<data android:host="www.google.com.ua"/>
<data android:host="www.google.com.uy"/>
<data android:host="www.google.com.vc"/>
<data android:host="www.google.com.vn"/>
<data android:host="www.google.com"/>
<data android:host="www.google.cv"/>
<data android:host="www.google.cz"/>
<data android:host="www.google.de"/>
<data android:host="www.google.dj"/>
<data android:host="www.google.dk"/>
<data android:host="www.google.dm"/>
<data android:host="www.google.dz"/>
<data android:host="www.google.ee"/>
<data android:host="www.google.es"/>
<data android:host="www.google.fi"/>
<data android:host="www.google.fm"/>
<data android:host="www.google.fr"/>
<data android:host="www.google.ga"/>
<data android:host="www.google.ge"/>
<data android:host="www.google.gg"/>
<data android:host="www.google.gl"/>
<data android:host="www.google.gm"/>
<data android:host="www.google.gr"/>
<data android:host="www.google.gy"/>
<data android:host="www.google.hn"/>
<data android:host="www.google.hr"/>
<data android:host="www.google.ht"/>
<data android:host="www.google.hu"/>
<data android:host="www.google.ie"/>
<data android:host="www.google.im"/>
<data android:host="www.google.iq"/>
<data android:host="www.google.is"/>
<data android:host="www.google.it"/>
<data android:host="www.google.je"/>
<data android:host="www.google.jo"/>
<data android:host="www.google.kg"/>
<data android:host="www.google.ki"/>
<data android:host="www.google.kz"/>
<data android:host="www.google.la"/>
<data android:host="www.google.li"/>
<data android:host="www.google.lk"/>
<data android:host="www.google.lt"/>
<data android:host="www.google.lu"/>
<data android:host="www.google.lv"/>
<data android:host="www.google.md"/>
<data android:host="www.google.me"/>
<data android:host="www.google.mg"/>
<data android:host="www.google.mk"/>
<data android:host="www.google.ml"/>
<data android:host="www.google.mn"/>
<data android:host="www.google.ms"/>
<data android:host="www.google.mu"/>
<data android:host="www.google.mv"/>
<data android:host="www.google.mw"/>
<data android:host="www.google.ne"/>
<data android:host="www.google.nl"/>
<data android:host="www.google.no"/>
<data android:host="www.google.nr"/>
<data android:host="www.google.nu"/>
<data android:host="www.google.pl"/>
<data android:host="www.google.pn"/>
<data android:host="www.google.ps"/>
<data android:host="www.google.pt"/>
<data android:host="www.google.ro"/>
<data android:host="www.google.rs"/>
<data android:host="www.google.ru"/>
<data android:host="www.google.rw"/>
<data android:host="www.google.sc"/>
<data android:host="www.google.se"/>
<data android:host="www.google.sh"/>
<data android:host="www.google.si"/>
<data android:host="www.google.sk"/>
<data android:host="www.google.sm"/>
<data android:host="www.google.sn"/>
<data android:host="www.google.so"/>
<data android:host="www.google.sr"/>
<data android:host="www.google.st"/>
<data android:host="www.google.td"/>
<data android:host="www.google.tg"/>
<data android:host="www.google.tl"/>
<data android:host="www.google.tm"/>
<data android:host="www.google.tn"/>
<data android:host="www.google.to"/>
<data android:host="www.google.tt"/>
<data android:host="www.google.vg"/>
<data android:host="www.google.vu"/>
<data android:host="www.google.ws"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:host="2gis.ae"/>
<data android:host="2gis.az"/>
<data android:host="2gis.cl"/>
<data android:host="2gis.cl"/>
<data android:host="2gis.com.cy"/>
<data android:host="2gis.cz"/>
<data android:host="2gis.it"/>
<data android:host="2gis.kg"/>
<data android:host="2gis.kz"/>
<data android:host="2gis.ru"/>
<data android:host="2gis.ua"/>
<data android:host="2gis.uz"/>
<data android:host="m.2gis.ae"/>
<data android:host="m.2gis.az"/>
<data android:host="m.2gis.cl"/>
<data android:host="m.2gis.cl"/>
<data android:host="m.2gis.com.cy"/>
<data android:host="m.2gis.cz"/>
<data android:host="m.2gis.it"/>
<data android:host="m.2gis.kg"/>
<data android:host="m.2gis.kz"/>
<data android:host="m.2gis.ru"/>
<data android:host="m.2gis.ua"/>
<data android:host="m.2gis.uz"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"/>
<data android:scheme="https"/>
<!-- #map=$zoom/$lat/$lon -->
<data android:host="www.openstreetmap.org" android:path="/"/>
<data android:host="www.openstreetmap.org" android:pathPrefix="/search"/>
<data android:host="openstreetmap.org" android:path="/"/>
<data android:host="openstreetmap.org" android:pathPrefix="/search"/>
</intent-filter>
<intent-filter>

View file

@ -92,7 +92,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity imp
Factory.createGeoIntentProcessor(),
Factory.createHttpGeoIntentProcessor(),
Factory.createMapsWithMeIntentProcessor(),
Factory.createGoogleMapsIntentProcessor(),
Factory.createHttpMapsIntentProcessor(),
Factory.createOldLeadUrlProcessor(),
Factory.createOldCoreLinkAdapterProcessor(),
Factory.createOpenCountryTaskProcessor(),

View file

@ -83,9 +83,9 @@ public class Factory
}
@NonNull
public static IntentProcessor createGoogleMapsIntentProcessor()
public static IntentProcessor createHttpMapsIntentProcessor()
{
return new GoogleMapsIntentProcessor();
return new HttpMapsIntentProcessor();
}
@NonNull
@ -250,20 +250,24 @@ public class Factory
}
}
private static class GoogleMapsIntentProcessor extends BaseOpenUrlProcessor
private static class HttpMapsIntentProcessor extends BaseOpenUrlProcessor
{
@Override
public boolean isSupported(@NonNull Intent intent)
{
final String scheme = intent.getScheme();
final Uri data = intent.getData();
return (data != null && "maps.google.com".equals(data.getHost()));
if (data == null || (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)))
return false;
final String host = data.getHost();
return host.contains("google") || host.contains("2gis") || host.contains("openstreetmap");
}
@NonNull
@Override
MapTask createMapTask(@NonNull String uri)
{
return new OpenUrlTask(uri);
return new OpenHttpMapsUrlTask(uri);
}
}
@ -537,6 +541,20 @@ public class Factory
}
}
public static class OpenHttpMapsUrlTask extends UrlTaskWithStatistics
{
OpenHttpMapsUrlTask(@NonNull String url)
{
super(url);
}
@Override
public boolean run(@NonNull MwmActivity target)
{
return MapFragment.nativeShowMapForUrl(getUrl());
}
}
public static class OpenUrlTask extends UrlTaskWithStatistics
{
private static final long serialVersionUID = -7257820771228127413L;

View file

@ -170,6 +170,60 @@ UNIT_TEST(ProcessURL_GoogleMaps)
TEST_ALMOST_EQUAL_ABS(info.m_lat, 1.356706, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 103.87591, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_zoom, 16.0, kEps, ());
info = GeoURLInfo("https://www.google.com/maps/place/Falafel+M.+Sahyoun/@33.8904447,35.5044618,16z");
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL_ABS(info.m_lat, 33.8904447, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 35.5044618, kEps, ());
// Sic: zoom is not parsed
//TEST_ALMOST_EQUAL_ABS(info.m_zoom, 16.0, kEps, ());
info = GeoURLInfo("https://www.google.com/maps?q=55.751809,37.6130029");
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL_ABS(info.m_lat, 55.751809, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 37.6130029, kEps, ());
}
UNIT_TEST(ProcessURL_2GIS)
{
GeoURLInfo info("https://2gis.ru/moscow/firm/4504127908589159/center/37.6186,55.7601/zoom/15.9764");
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL_ABS(info.m_lat, 55.7601, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 37.6186, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_zoom, 15.9764, kEps, ());
info = GeoURLInfo("https://2gis.ru/moscow/firm/4504127908589159/center/37,55/zoom/15");
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL_ABS(info.m_lat, 55.0, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 37.0, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_zoom, 15.0, kEps, ());
info = GeoURLInfo("https://2gis.ru/moscow/firm/4504127908589159?m=37.618632%2C55.760069%2F15.232");
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL_ABS(info.m_lat, 55.760069, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 37.618632, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_zoom, 15.232, kEps, ());
info = GeoURLInfo("https://2gis.ru/moscow/firm/4504127908589159?m=37.618632%2C55.760069%2F15");
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL_ABS(info.m_lat, 55.760069, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 37.618632, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_zoom, 15.0, kEps, ());
}
UNIT_TEST(ProcessURL_OpenStreetMap)
{
GeoURLInfo info("https://www.openstreetmap.org/#map=16/33.89041/35.50664");
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL_ABS(info.m_lat, 33.89041, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 35.50664, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_zoom, 16.0, kEps, ());
info = GeoURLInfo("https://www.openstreetmap.org/search?query=Falafel%20Sahyoun#map=16/33.89041/35.50664");
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL_ABS(info.m_lat, 33.89041, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 35.50664, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_zoom, 16.0, kEps, ());
}
UNIT_TEST(ProcessURL_CaseInsensitive)

View file

@ -174,7 +174,83 @@ private:
regex m_regexp;
int m_latPriority;
int m_lonPriority;
};
}; // class LatLongParser
bool MatchLatLonZoom(const string & s, const regex & re, size_t lati, size_t loni, size_t zoomi, url::GeoURLInfo & info)
{
std::smatch m;
if (!std::regex_search(s, m, re) || m.size() != 4)
return false;
double lat;
double lon;
double zoom;
VERIFY(strings::to_double(m[lati].str(), lat), ());
VERIFY(strings::to_double(m[loni].str(), lon), ());
VERIFY(strings::to_double(m[zoomi].str(), zoom), ());
if (!info.SetLat(lat) || !info.SetLon(lon))
return false;
info.SetZoom(zoom);
return true;
}
class DoubleGISParser
{
public:
DoubleGISParser()
: m_pathRe("/(\\d+\\.?\\d*),(\\d+\\.?\\d*)/zoom/(\\d+\\.?\\d*)"),
m_paramRe("(\\d+\\.?\\d*),(\\d+\\.?\\d*)/(\\d+\\.?\\d*)")
{
}
bool Parse(url::Url const & url, url::GeoURLInfo & info)
{
// Try m=$lon,$lat/$zoom first
for (auto const & param : url.Params())
{
if (param.m_name == "m")
{
if (MatchLatLonZoom(param.m_value, m_paramRe, 2, 1, 3, info))
return true;
break;
}
}
// Parse /$lon,$lat/zoom/$zoom from path next
if (MatchLatLonZoom(url.GetPath(), m_pathRe, 2, 1, 3, info))
return true;
return false;
}
private:
regex m_pathRe;
regex m_paramRe;
}; // Class DoubleGISParser
class OpenStreetMapParser
{
public:
OpenStreetMapParser()
: m_regex("#map=(\\d+\\.?\\d*)/(\\d+\\.\\d+)/(\\d+\\.\\d+)")
{
}
bool Parse(url::Url const & url, url::GeoURLInfo & info)
{
if (MatchLatLonZoom(url.GetPath(), m_regex, 2, 3, 1, info))
return true;
// Check if "#map=" fragment is attached to the last param in Url
if (!url.Params().empty() && MatchLatLonZoom(url.Params().back().m_value, m_regex, 2, 3, 1, info))
return true;
return false;
}
private:
regex m_regex;
}; // Class OpenStreetMapParser
} // namespace
namespace url
@ -376,6 +452,22 @@ GeoURLInfo::GeoURLInfo(string const & s)
if (!url.IsValid())
return;
if (url.GetScheme() == "https" || url.GetScheme() == "http")
{
if (url.GetWebDomain().find("2gis") != string::npos)
{
DoubleGISParser parser;
if (parser.Parse(url, *this))
return;
}
else if (url.GetWebDomain().find("openstreetmap.org") != string::npos)
{
OpenStreetMapParser parser;
if (parser.Parse(url, *this))
return;
}
}
LatLonParser parser(url, *this);
parser(url::Param(string(), url.GetPath()));
url.ForEachParam(ref(parser));

View file

@ -37,6 +37,7 @@ public:
std::string GetWebPath() const;
bool IsValid() const { return !m_scheme.empty(); }
void ForEachParam(Callback const & callback) const;
const std::vector<Param> & Params() const { return m_params; }
private:
bool Parse(std::string const & url);