Skip to content

Commit

Permalink
[downloader] Fix behavior for absent description
Browse files Browse the repository at this point in the history
  • Loading branch information
igrechuhin committed Apr 20, 2016
1 parent 81edaa1 commit c294c3c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
13 changes: 9 additions & 4 deletions storage/country_name_getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ void CountryNameGetter::SetLocaleForTesting(string const & jsonBuffer, string co
m_getCurLang = platform::ForTestingGetTextByIdFactory(jsonBuffer, locale);
}

string CountryNameGetter::operator()(TCountryId const & countryId) const
string CountryNameGetter::Get(string const & key) const
{
ASSERT(!countryId.empty(), ());
ASSERT(!key.empty(), ());

if (m_getCurLang == nullptr)
return countryId;
return string();

string name = (*m_getCurLang)(countryId);
return (*m_getCurLang)(key);
}

string CountryNameGetter::operator()(TCountryId const & countryId) const
{
string const name = Get(countryId);
if (name.empty())
return countryId;

Expand Down
5 changes: 5 additions & 0 deletions storage/country_name_getter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class CountryNameGetter
/// \note See countries/languages.txt for the full list of available locales.
void SetLocale(string const & locale);

/// \brief Gets localized string for key. If not found returns empty string.
/// @param key is a string for lookup.
/// \note Unlike operator (), does not return key if localized string is not found.
string Get(string const & key) const;

string operator()(TCountryId const & countryId) const;

// for testing
Expand Down
2 changes: 1 addition & 1 deletion storage/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs)
nodeAttrs.m_status = statusAndErr.status;
nodeAttrs.m_error = statusAndErr.error;
nodeAttrs.m_nodeLocalName = m_countryNameGetter(countryId);
nodeAttrs.m_nodeLocalDescription = m_countryNameGetter(countryId + LOCALIZATION_DESCRIPTION_SUFFIX);
nodeAttrs.m_nodeLocalDescription = m_countryNameGetter.Get(countryId + LOCALIZATION_DESCRIPTION_SUFFIX);

// Progress.
if (nodeAttrs.m_status == NodeStatus::OnDisk)
Expand Down

0 comments on commit c294c3c

Please sign in to comment.