diff --git a/coding/coding_tests/url_tests.cpp b/coding/coding_tests/url_tests.cpp index c820f89798..0d573fdede 100644 --- a/coding/coding_tests/url_tests.cpp +++ b/coding/coding_tests/url_tests.cpp @@ -12,39 +12,39 @@ namespace { double const kEps = 1e-10; -class TestUri +class TestUrl { public: - explicit TestUri(string const & uri) : m_uri(uri) {} + explicit TestUrl(string const & url) : m_url(url) {} - TestUri & Scheme(string const & scheme) { m_scheme = scheme; return *this; } - TestUri & Path(string const & path) { m_path = path; return *this; } - TestUri & KV(string const & key, string const & value) + TestUrl & Scheme(string const & scheme) { m_scheme = scheme; return *this; } + TestUrl & Path(string const & path) { m_path = path; return *this; } + TestUrl & KV(string const & key, string const & value) { m_keyValuePairs.push(make_pair(key, value)); return *this; } - ~TestUri() + ~TestUrl() { - url::Uri uri(m_uri); - TEST_EQUAL(uri.GetScheme(), m_scheme, ()); - TEST_EQUAL(uri.GetPath(), m_path, ()); - TEST(!m_scheme.empty() || !uri.IsValid(), ("Scheme is empty if and only if uri is invalid!")); - uri.ForEachParam(bind(&TestUri::AddTestValue, this, placeholders::_1)); + url::Url url(m_url); + TEST_EQUAL(url.GetScheme(), m_scheme, ()); + TEST_EQUAL(url.GetPath(), m_path, ()); + TEST(!m_scheme.empty() || !url.IsValid(), ("Scheme is empty if and only if url is invalid!")); + url.ForEachParam(bind(&TestUrl::AddTestValue, this, placeholders::_1)); } private: bool AddTestValue(url::Param const & param) { - TEST(!m_keyValuePairs.empty(), ("Failed for uri = ", m_uri, "Passed KV = ", param)); + TEST(!m_keyValuePairs.empty(), ("Failed for url = ", m_url, "Passed KV = ", param)); TEST_EQUAL(m_keyValuePairs.front().first, param.m_name, ()); TEST_EQUAL(m_keyValuePairs.front().second, param.m_value, ()); m_keyValuePairs.pop(); return true; } - string m_uri; + string m_url; string m_scheme; string m_path; queue> m_keyValuePairs; @@ -173,50 +173,50 @@ UNIT_TEST(ProcessURL_GoogleMaps) TEST_ALMOST_EQUAL_ABS(info.m_zoom, 16.0, kEps, ()); } -UNIT_TEST(UriValidScheme) +UNIT_TEST(UrlValidScheme) { - Uri uri("mapswithme://map?ll=10.3,12.3223&n=Hello%20World"); - TEST_EQUAL(uri.GetScheme(), "mapswithme", ()); + Url url("mapswithme://map?ll=10.3,12.3223&n=Hello%20World"); + TEST_EQUAL(url.GetScheme(), "mapswithme", ()); } -UNIT_TEST(UriInvalidSchemeNoColon) +UNIT_TEST(UrlInvalidSchemeNoColon) { - TEST_EQUAL(Uri("mapswithme:").GetScheme(), "mapswithme", ()); + TEST_EQUAL(Url("mapswithme:").GetScheme(), "mapswithme", ()); } -UNIT_TEST(UriTestValidScheme2) +UNIT_TEST(UrlTestValidScheme2) { - TestUri("mapswithme://map?ll=10.3,12.3223&n=Hello%20World") + TestUrl("mapswithme://map?ll=10.3,12.3223&n=Hello%20World") .Scheme("mapswithme") .Path("map") .KV("ll", "10.3,12.3223") .KV("n", "Hello World"); } -UNIT_TEST(UriComprehensive) +UNIT_TEST(UrlComprehensive) { - TestUri(""); - TestUri("scheme:").Scheme("scheme"); - TestUri("scheme:/").Scheme("scheme"); - TestUri("scheme://").Scheme("scheme"); - TestUri("sometext"); - TestUri(":noscheme"); - TestUri("://noscheme?"); - TestUri("mwm://?").Scheme("mwm"); - TestUri("http://path/to/something").Scheme("http").Path("path/to/something"); - TestUri("http://path?").Scheme("http").Path("path"); - TestUri("maps://path?&&key=&").Scheme("maps").Path("path").KV("key", ""); - TestUri("mapswithme://map?ll=1.2,3.4&z=15").Scheme("mapswithme").Path("map") + TestUrl(""); + TestUrl("scheme:").Scheme("scheme"); + TestUrl("scheme:/").Scheme("scheme"); + TestUrl("scheme://").Scheme("scheme"); + TestUrl("sometext"); + TestUrl(":noscheme"); + TestUrl("://noscheme?"); + TestUrl("mwm://?").Scheme("mwm"); + TestUrl("http://path/to/something").Scheme("http").Path("path/to/something"); + TestUrl("http://path?").Scheme("http").Path("path"); + TestUrl("maps://path?&&key=&").Scheme("maps").Path("path").KV("key", ""); + TestUrl("mapswithme://map?ll=1.2,3.4&z=15").Scheme("mapswithme").Path("map") .KV("ll", "1.2,3.4").KV("z", "15"); - TestUri("nopathnovalues://?key1&key2=val2").Scheme("nopathnovalues").Path("") + TestUrl("nopathnovalues://?key1&key2=val2").Scheme("nopathnovalues").Path("") .KV("key1", "").KV("key2", "val2"); - TestUri("s://?key1&key2").Scheme("s").Path("").KV("key1", "").KV("key2", ""); - TestUri("g://p?key1=val1&key2=").Scheme("g").Path("p").KV("key1", "val1").KV("key2", ""); - TestUri("g://p?=val1&key2=").Scheme("g").Path("p").KV("", "val1").KV("key2", ""); - TestUri("g://?k&key2").Scheme("g").KV("k", "").KV("key2", ""); - TestUri("m:?%26Amp%26%3D%26Amp%26&name=%31%20%30").Scheme("m") + TestUrl("s://?key1&key2").Scheme("s").Path("").KV("key1", "").KV("key2", ""); + TestUrl("g://p?key1=val1&key2=").Scheme("g").Path("p").KV("key1", "val1").KV("key2", ""); + TestUrl("g://p?=val1&key2=").Scheme("g").Path("p").KV("", "val1").KV("key2", ""); + TestUrl("g://?k&key2").Scheme("g").KV("k", "").KV("key2", ""); + TestUrl("m:?%26Amp%26%3D%26Amp%26&name=%31%20%30").Scheme("m") .KV("&Amp&=&Amp&", "").KV("name", "1 0"); - TestUri("s://?key1=value1&key1=value2&key1=value3&key2&key2&key3=value1&key3&key3=value2") + TestUrl("s://?key1=value1&key1=value2&key1=value3&key2&key2&key3=value1&key3&key3=value2") .Scheme("s") .KV("key1", "value1").KV("key1", "value2").KV("key1", "value3") .KV("key2", "").KV("key2", "") diff --git a/coding/url.cpp b/coding/url.cpp index ca1693218d..9f3e09c767 100644 --- a/coding/url.cpp +++ b/coding/url.cpp @@ -153,33 +153,33 @@ std::string DebugPrint(Param const & param) return "UrlParam [" + param.m_name + "=" + param.m_value + "]"; } -Uri::Uri(std::string const & uri) +Url::Url(std::string const & url) { - if (!Parse(uri)) + if (!Parse(url)) { ASSERT(m_scheme.empty() && m_path.empty() && !IsValid(), ()); } } -bool Uri::Parse(std::string const & uri) +bool Url::Parse(std::string const & url) { // Get url scheme. - size_t pathStart = uri.find(':'); + size_t pathStart = url.find(':'); if (pathStart == string::npos || pathStart == 0) return false; - m_scheme.assign(uri, 0, pathStart); + m_scheme.assign(url, 0, pathStart); // Skip slashes. - while (++pathStart < uri.size() && uri[pathStart] == '/') + while (++pathStart < url.size() && url[pathStart] == '/') { } // Find query starting point for (key, value) parsing. - size_t queryStart = uri.find('?', pathStart); + size_t queryStart = url.find('?', pathStart); size_t pathLength; if (queryStart == string::npos) { - queryStart = uri.size(); + queryStart = url.size(); pathLength = queryStart - pathStart; } else @@ -189,30 +189,30 @@ bool Uri::Parse(std::string const & uri) } // Get path (url without query). - m_path.assign(uri, pathStart, pathLength); + m_path.assign(url, pathStart, pathLength); // Parse query for keys and values. - for (size_t start = queryStart; start < uri.size();) + for (size_t start = queryStart; start < url.size();) { - size_t end = uri.find('&', start); + size_t end = url.find('&', start); if (end == string::npos) - end = uri.size(); + end = url.size(); // Skip empty keys. if (end != start) { - size_t const eq = uri.find('=', start); + size_t const eq = url.find('=', start); string key; string value; if (eq != string::npos && eq < end) { - key = UrlDecode(uri.substr(start, eq - start)); - value = UrlDecode(uri.substr(eq + 1, end - eq - 1)); + key = UrlDecode(url.substr(start, eq - start)); + value = UrlDecode(url.substr(eq + 1, end - eq - 1)); } else { - key = UrlDecode(uri.substr(start, end - start)); + key = UrlDecode(url.substr(start, end - start)); } m_params.emplace_back(key, value); @@ -224,7 +224,7 @@ bool Uri::Parse(std::string const & uri) return true; } -bool Uri::ForEachParam(Callback const & callback) const +bool Url::ForEachParam(Callback const & callback) const { // todo(@m) Looks strange but old code worked this way. if (m_params.empty()) @@ -325,16 +325,16 @@ string UrlDecode(string const & encodedUrl) GeoURLInfo::GeoURLInfo(string const & s) { - Uri uri(s); - if (!uri.IsValid()) + Url url(s); + if (!url.IsValid()) { Reset(); return; } LatLonParser parser(*this); - parser(url::Param(string(), uri.GetPath())); - uri.ForEachParam(ref(parser)); + parser(url::Param(string(), url.GetPath())); + url.ForEachParam(ref(parser)); if (!parser.IsValid()) { diff --git a/coding/url.hpp b/coding/url.hpp index 289a00f858..13c0d29ece 100644 --- a/coding/url.hpp +++ b/coding/url.hpp @@ -22,13 +22,13 @@ std::string DebugPrint(Param const & param); using Params = std::vector; -// Uri in format: 'scheme://path?key1=value1&key2&key3=&key4=value4' -class Uri +// Url in format: 'scheme://path?key1=value1&key2&key3=&key4=value4' +class Url { public: using Callback = std::function; - explicit Uri(std::string const & uri); + explicit Url(std::string const & url); std::string const & GetScheme() const { return m_scheme; } std::string const & GetPath() const { return m_path; } @@ -36,7 +36,7 @@ public: bool ForEachParam(Callback const & callback) const; private: - bool Parse(std::string const & uri); + bool Parse(std::string const & url); std::string m_scheme; std::string m_path; diff --git a/map/framework.cpp b/map/framework.cpp index 659751a57e..c2dd098023 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2209,7 +2209,7 @@ url_scheme::ParsedMapApi::ParsingResult Framework::ParseAndSetApiURL(string cons editSession.SetIsVisible(UserMark::Type::API, true); } - return m_parsedMapApi.SetUriAndParse(url); + return m_parsedMapApi.SetUrlAndParse(url); } Framework::ParsedRoutingData Framework::GetParsedRoutingData() const diff --git a/map/map_tests/mwm_url_tests.cpp b/map/map_tests/mwm_url_tests.cpp index b324192f1f..a452cc8c4c 100644 --- a/map/map_tests/mwm_url_tests.cpp +++ b/map/map_tests/mwm_url_tests.cpp @@ -38,13 +38,13 @@ UserMark::Type const type = UserMark::Type::API; class ApiTest { public: - explicit ApiTest(string const & uriString) + explicit ApiTest(string const & urlString) : m_fm(kFrameworkParams) { m_m = &m_fm.GetBookmarkManager(); m_api.SetBookmarkManager(m_m); - auto const res = m_api.SetUriAndParse(uriString); + auto const res = m_api.SetUrlAndParse(urlString); if (res != ParsedMapApi::ParsingResult::Incorrect) { if (!m_api.GetViewportRect(m_viewportRect)) @@ -109,11 +109,11 @@ private: BookmarkManager * m_m; }; -bool IsValid(Framework & fm, string const & uriString) +bool IsValid(Framework & fm, string const & urlString) { ParsedMapApi api; api.SetBookmarkManager(&fm.GetBookmarkManager()); - api.SetUriAndParse(uriString); + api.SetUrlAndParse(urlString); fm.GetBookmarkManager().GetEditSession().ClearGroup(UserMark::Type::API); return api.IsValid(); @@ -122,10 +122,10 @@ bool IsValid(Framework & fm, string const & uriString) UNIT_TEST(MapApiSmoke) { - string uriString = "mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name"; - TEST(url::Uri(uriString).IsValid(), ()); + string urlString = "mapswithme://map?ll=38.970559,-9.419289&ignoreThisParam=Yes&z=17&n=Point%20Name"; + TEST(url::Url(urlString).IsValid(), ()); - ApiTest test(uriString); + ApiTest test(urlString); TEST(test.IsValid(), ()); TEST_EQUAL(test.GetPointCount(), 1, ()); @@ -137,11 +137,11 @@ UNIT_TEST(MapApiSmoke) UNIT_TEST(RouteApiSmoke) { - string const uriString = + string const urlString = "mapswithme://route?sll=1,1&saddr=name0&dll=2,2&daddr=name1&type=vehicle"; - TEST(url::Uri(uriString).IsValid(), ()); + TEST(url::Url(urlString).IsValid(), ()); - ApiTest test(uriString); + ApiTest test(urlString); TEST(test.IsValid(), ()); TEST(test.TestRoutePoint(0, 1, 1, "name0"), ()); TEST(test.TestRoutePoint(1, 2, 2, "name1"), ()); @@ -150,10 +150,10 @@ UNIT_TEST(RouteApiSmoke) UNIT_TEST(CatalogueApiSmoke) { - string const uriString = "mapsme://catalogue?id=440f02e5-ff38-45ed-95c0-44587c9a5fc7&name=CatalogGroupName"; - TEST(url::Uri(uriString).IsValid(), ()); + string const urlString = "mapsme://catalogue?id=440f02e5-ff38-45ed-95c0-44587c9a5fc7&name=CatalogGroupName"; + TEST(url::Url(urlString).IsValid(), ()); - ApiTest test(uriString); + ApiTest test(urlString); TEST(test.IsValid(), ()); auto const & catalogItem = test.GetCatalog(); @@ -176,10 +176,10 @@ UNIT_TEST(CatalogueApiInvalidUrl) UNIT_TEST(SearchApiSmoke) { - string const uriString = "mapsme://search?query=fff&cll=1,1&locale=ru&map"; - TEST(url::Uri(uriString).IsValid(), ()); + string const urlString = "mapsme://search?query=fff&cll=1,1&locale=ru&map"; + TEST(url::Url(urlString).IsValid(), ()); - ApiTest test(uriString); + ApiTest test(urlString); TEST(test.IsValid(), ()); auto const & request = test.GetSearchRequest(); @@ -208,9 +208,9 @@ UNIT_TEST(LeadApiSmoke) UNUSED_VALUE(base::DeleteFileX(path)); }); - string const uriString = "mapsme://lead?utm_source=a&utm_medium=b&utm_campaign=c&utm_content=d&utm_term=e"; - TEST(url::Uri(uriString).IsValid(), ()); - ApiTest test(uriString); + string const urlString = "mapsme://lead?utm_source=a&utm_medium=b&utm_campaign=c&utm_content=d&utm_term=e"; + TEST(url::Url(urlString).IsValid(), ()); + ApiTest test(urlString); TEST(test.IsValid(), ()); auto checkEqual = [](string const & key, string const & value) diff --git a/map/mwm_url.cpp b/map/mwm_url.cpp index 89503eea3a..8a9c0ae273 100644 --- a/map/mwm_url.cpp +++ b/map/mwm_url.cpp @@ -127,7 +127,7 @@ enum class ApiURLType std::array const kAvailableSchemes = {{"mapswithme", "mwm", "mapsme"}}; -ApiURLType URLType(url::Uri const & uri) +ApiURLType URLType(url::Url const & uri) { if (std::find(kAvailableSchemes.begin(), kAvailableSchemes.end(), uri.GetScheme()) == kAvailableSchemes.end()) return ApiURLType::Incorrect; @@ -181,7 +181,7 @@ void ParsedMapApi::SetBookmarkManager(BookmarkManager * manager) m_bmManager = manager; } -ParsedMapApi::ParsingResult ParsedMapApi::SetUriAndParse(string const & url) +ParsedMapApi::ParsingResult ParsedMapApi::SetUrlAndParse(string const & url) { Reset(); @@ -191,12 +191,12 @@ ParsedMapApi::ParsingResult ParsedMapApi::SetUriAndParse(string const & url) return ParsingResult::Incorrect; } - ParsingResult const res = Parse(url::Uri(url)); + ParsingResult const res = Parse(url::Url(url)); m_isValid = res != ParsingResult::Incorrect; return res; } -ParsedMapApi::ParsingResult ParsedMapApi::Parse(url::Uri const & uri) +ParsedMapApi::ParsingResult ParsedMapApi::Parse(url::Url const & uri) { switch (URLType(uri)) { diff --git a/map/mwm_url.hpp b/map/mwm_url.hpp index 530b8516c0..e801941041 100644 --- a/map/mwm_url.hpp +++ b/map/mwm_url.hpp @@ -11,7 +11,7 @@ class BookmarkManager; namespace url { -class Uri; +class Url; } namespace url_scheme @@ -83,7 +83,7 @@ public: void SetBookmarkManager(BookmarkManager * manager); - ParsingResult SetUriAndParse(std::string const & url); + ParsingResult SetUrlAndParse(std::string const & url); bool IsValid() const { return m_isValid; } std::string const & GetGlobalBackUrl() const { return m_globalBackUrl; } std::string const & GetAppTitle() const { return m_appTitle; } @@ -101,7 +101,7 @@ public: CatalogPath const & GetCatalogPath() const { return m_catalogPath; } Subscription const & GetSubscription() const { return m_subscription; } private: - ParsingResult Parse(url::Uri const & uri); + ParsingResult Parse(url::Url const & url); bool AddKeyValue(std::string const & key, std::string const & value, std::vector & points); bool RouteKeyValue(std::string const & key, std::string const & value, std::vector & pattern); bool SearchKeyValue(std::string const & key, std::string const & value, SearchRequest & request) const;