Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/ge0
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2020-02-17 13:50:29 +0300
committerTatiana Yan <tatiana.kondakova@gmail.com>2020-02-17 16:47:30 +0300
commit292febc91770b46e7d82300dc9b7d412f9d79504 (patch)
tree152994d7e7125381ff8f286932e422e8b905e8cb /ge0
parentd1ab27b508e6cb60f3f905dd660a08ad9dc852e2 (diff)
[ge0] Pack the Parser's return values into a struct.
Diffstat (limited to 'ge0')
-rw-r--r--ge0/ge0_tests/parser_tests.cpp45
-rw-r--r--ge0/parser.cpp29
-rw-r--r--ge0/parser.hpp15
3 files changed, 50 insertions, 39 deletions
diff --git a/ge0/ge0_tests/parser_tests.cpp b/ge0/ge0_tests/parser_tests.cpp
index d3c4ceff1c..a7fbf5e330 100644
--- a/ge0/ge0_tests/parser_tests.cpp
+++ b/ge0/ge0_tests/parser_tests.cpp
@@ -44,31 +44,25 @@ double GetLonEpsilon(size_t coordBytes)
void TestSuccess(char const * s, double lat, double lon, double zoom, char const * name)
{
Ge0Parser parser;
- double parsedLat;
- double parsedLon;
- string parsedName;
- double parsedZoomLevel;
- bool const result = parser.Parse(s, parsedLat, parsedLon, parsedName, parsedZoomLevel);
+ Ge0Parser::Result parseResult;
+ bool const success = parser.Parse(s, parseResult);
- TEST(result, (s, zoom, lat, lon, name));
+ TEST(success, (s, parseResult));
- TEST_EQUAL(parsedName, string(name), (s));
+ TEST_EQUAL(parseResult.m_name, string(name), (s));
double const latEps = GetLatEpsilon(9);
- double const lonEps = GetLonEpsilon(9);
- TEST_ALMOST_EQUAL_ABS(parsedLat, lat, latEps, (s, zoom, lat, lon, name));
- TEST_ALMOST_EQUAL_ABS(parsedLon, lon, lonEps, (s, zoom, lat, lon, name));
- TEST_ALMOST_EQUAL_ABS(parsedZoomLevel, zoom, kZoomEps, (s, zoom, lat, lon, name));
+ double const lonEps = GetLonEpsilon(9);
+ TEST_ALMOST_EQUAL_ABS(parseResult.m_lat, lat, latEps, (s, parseResult));
+ TEST_ALMOST_EQUAL_ABS(parseResult.m_lon, lon, lonEps, (s, parseResult));
+ TEST_ALMOST_EQUAL_ABS(parseResult.m_zoomLevel, zoom, kZoomEps, (s, parseResult));
}
void TestFailure(char const * s)
{
Ge0Parser parser;
- string name;
- double lat;
- double lon;
- double zoomLevel;
- bool const result = parser.Parse(s, lat, lon, name, zoomLevel);
- TEST(!result, (s));
+ Ge0Parser::Result parseResult;
+ bool const success = parser.Parse(s, parseResult);
+ TEST(!success, (s, parseResult));
}
bool ConvergenceTest(double lat, double lon, double latEps, double lonEps)
@@ -225,21 +219,18 @@ UNIT_TEST(NameDecoding)
"d0%bd%d0%b8%d1%8e%3F";
Ge0Parser parser;
- double parsedLat;
- double parsedLon;
- string parsedName;
- double parsedZoomLevel;
- bool const result = parser.Parse(url.c_str(), parsedLat, parsedLon, parsedName, parsedZoomLevel);
+ Ge0Parser::Result parseResult;
+ bool const success = parser.Parse(url.c_str(), parseResult);
- TEST(result, (url, zoom, lat, lon, name));
+ TEST(success, (url, parseResult));
// Name would be valid but is too long.
- TEST_NOT_EQUAL(parsedName, string(name), (url));
+ TEST_NOT_EQUAL(parseResult.m_name, string(name), (url));
double const latEps = GetLatEpsilon(9);
double const lonEps = GetLonEpsilon(9);
- TEST_ALMOST_EQUAL_ABS(parsedLat, lat, latEps, (url, zoom, lat, lon, name));
- TEST_ALMOST_EQUAL_ABS(parsedLon, lon, lonEps, (url, zoom, lat, lon, name));
- TEST_ALMOST_EQUAL_ABS(parsedZoomLevel, zoom, kZoomEps, (url, zoom, lat, lon, name));
+ TEST_ALMOST_EQUAL_ABS(parseResult.m_lat, lat, latEps, (url, parseResult));
+ TEST_ALMOST_EQUAL_ABS(parseResult.m_lon, lon, lonEps, (url, parseResult));
+ TEST_ALMOST_EQUAL_ABS(parseResult.m_zoomLevel, zoom, kZoomEps, (url, parseResult));
}
}
diff --git a/ge0/parser.cpp b/ge0/parser.cpp
index 53fbd0c04b..4507e76bcd 100644
--- a/ge0/parser.cpp
+++ b/ge0/parser.cpp
@@ -11,6 +11,7 @@
#include "base/string_utils.hpp"
#include <algorithm>
+#include <sstream>
using namespace std;
@@ -27,7 +28,7 @@ Ge0Parser::Ge0Parser()
}
}
-bool Ge0Parser::Parse(string const & url, double & outLat, double & outLon, std::string & outName, double & outZoomLevel)
+bool Ge0Parser::Parse(string const & url, Result & result)
{
// Original URL format:
//
@@ -43,14 +44,13 @@ bool Ge0Parser::Parse(string const & url, double & outLat, double & outLon, std:
for (string const & prefix : {"ge0://", "http://ge0.me/", "https://ge0.me/"})
{
if (strings::StartsWith(url, prefix))
- return ParseAfterPrefix(url, prefix.size(), outLat, outLon, outName, outZoomLevel);
+ return ParseAfterPrefix(url, prefix.size(), result);
}
return false;
}
-bool Ge0Parser::ParseAfterPrefix(string const & url, size_t from, double & outLat, double & outLon,
- std::string & outName, double & outZoomLevel)
+bool Ge0Parser::ParseAfterPrefix(string const & url, size_t from, Result & result)
{
size_t const kEncodedZoomAndCoordinatesLength = 10;
if (url.size() < from + kEncodedZoomAndCoordinatesLength)
@@ -66,20 +66,20 @@ bool Ge0Parser::ParseAfterPrefix(string const & url, size_t from, double & outLa
uint8_t const zoomI = DecodeBase64Char(url[posZoom]);
if (zoomI >= 64)
return false;
- outZoomLevel = DecodeZoom(zoomI);
+ result.m_zoomLevel = DecodeZoom(zoomI);
- if (!DecodeLatLon(url.substr(posLatLon, lengthLatLon), outLat, outLon))
+ if (!DecodeLatLon(url.substr(posLatLon, lengthLatLon), result.m_lat, result.m_lon))
return false;
- ASSERT(mercator::ValidLon(outLon), (outLon));
- ASSERT(mercator::ValidLat(outLat), (outLat));
+ ASSERT(mercator::ValidLat(result.m_lat), (result.m_lat));
+ ASSERT(mercator::ValidLon(result.m_lon), (result.m_lon));
if (url.size() >= posName)
{
CHECK_GREATER(posName, 0, ());
if (url[posName - 1] != '/')
return false;
- outName = DecodeName(url.substr(posName, min(url.size() - posName, kMaxNameLength)));
+ result.m_name = DecodeName(url.substr(posName, min(url.size() - posName, kMaxNameLength)));
}
return true;
@@ -179,4 +179,15 @@ bool Ge0Parser::IsHexChar(char const a)
{
return ((a >= '0' && a <= '9') || (a >= 'A' && a <= 'F') || (a >= 'a' && a <= 'f'));
}
+
+string DebugPrint(Ge0Parser::Result const & r)
+{
+ ostringstream oss;
+ oss << "ParseResult [";
+ oss << "zoom=" << r.m_zoomLevel << ", ";
+ oss << "lat=" << r.m_lat << ", ";
+ oss << "lon=" << r.m_lon << ", ";
+ oss << "name=" << r.m_name << "]";
+ return oss.str();
+}
} // namespace ge0
diff --git a/ge0/parser.hpp b/ge0/parser.hpp
index 6120323b87..6967ffc50d 100644
--- a/ge0/parser.hpp
+++ b/ge0/parser.hpp
@@ -9,13 +9,20 @@ namespace ge0
class Ge0Parser
{
public:
+ struct Result
+ {
+ double m_zoomLevel = 0.0;
+ double m_lat = 0.0;
+ double m_lon = 0.0;
+ std::string m_name;
+ };
+
Ge0Parser();
- bool Parse(std::string const & url, double & outLat, double & outLon, std::string & outName, double & outZoomLevel);
+ bool Parse(std::string const & url, Result & result);
protected:
- bool ParseAfterPrefix(std::string const & url, size_t from, double & outLat, double & outLon,
- std::string & outName, double & outZoomLevel);
+ bool ParseAfterPrefix(std::string const & url, size_t from, Result & result);
uint8_t DecodeBase64Char(char const c);
static double DecodeZoom(uint8_t const zoomByte);
@@ -31,4 +38,6 @@ protected:
private:
uint8_t m_base64ReverseCharTable[256];
};
+
+std::string DebugPrint(Ge0Parser::Result const & r);
} // namespace ge0