Do not parse whole string in "geo" url and Validate it.

This commit is contained in:
vng 2013-05-17 21:50:21 +03:00 committed by Alex Zolotarev
parent 7733e37c20
commit 54fffdfb1b
2 changed files with 26 additions and 10 deletions

View file

@ -8,9 +8,14 @@
namespace url_scheme
{
bool Info::IsValid() const
{
return (MercatorBounds::ValidLat(m_lat) && MercatorBounds::ValidLon(m_lon));
}
void Info::Reset()
{
m_lat = m_lon = EmptyValue();
m_lat = m_lon = -1000.0;
m_zoom = scales::GetUpperScale();
}
@ -91,6 +96,14 @@ namespace url_scheme
if (!CheckKeyword(token))
{
ToDouble(token, m_info.m_zoom);
// validate zoom bounds
if (m_info.m_zoom < 0.0)
m_info.m_zoom = 0.0;
int const upperScale = scales::GetUpperScale();
if (m_info.m_zoom > upperScale)
m_info.m_zoom = upperScale;
m_mode = FINISH;
}
break;
@ -99,10 +112,19 @@ namespace url_scheme
break;
}
}
bool IsEnd() const { return m_mode == FINISH; }
};
void ParseGeoURL(string const & s, Info & info)
{
strings::Tokenize(s, ":/?&=,", DoGeoParse(info));
DoGeoParse parser(info);
strings::SimpleTokenizer iter(s, ":/?&=,");
while (iter && !parser.IsEnd())
{
parser(*iter);
++iter;
}
}
}

View file

@ -11,13 +11,7 @@ namespace url_scheme
{
double m_lat, m_lon, m_zoom;
static double EmptyValue() { return -1000.0; }
bool IsValid() const
{
return (m_lat != EmptyValue() && m_lon != EmptyValue());
}
bool IsValid() const;
void Reset();
Info()
@ -26,7 +20,7 @@ namespace url_scheme
}
m2::RectD GetViewport() const;
// @return lat and lon in Mercator projection
/// @return lat and lon in Mercator projection
m2::PointD GetMercatorPoint() const;
};