Merge pull request #4143 from milchakov/names_optimization_and_fix

[drape][indexer] names optimization and fix
This commit is contained in:
ygorshenin 2016-08-30 15:47:27 +03:00 committed by GitHub
commit 530f7c2703
4 changed files with 50 additions and 7 deletions

View file

@ -214,14 +214,14 @@ void CaptionDescription::FormatCaptions(FeatureType const & f,
{
if (!auxCaptionExists && !m_auxText.empty() && type != feature::GEOM_LINE)
{
f.GetReadableName(m_mainText);
if (m_mainText == m_auxText)
m_auxText.clear();
m_mainText.swap(m_auxText);
m_auxText.clear();
}
if (mainTextType == drule::text_type_housenumber)
{
m_mainText = move(m_houseNumber);
m_mainText.swap(m_houseNumber);
m_houseNumber.clear();
}
else if (mainTextType == drule::text_type_name)
{

View file

@ -37,6 +37,12 @@ void GetMwmLangName(FeatureID const & id, StringUtf8Multilang const & src, strin
void GetNames(FeatureID const & id, StringUtf8Multilang const & src, string & primary,
string & secondary)
{
primary.clear();
secondary.clear();
if (src.IsEmpty())
return;
vector<int8_t> primaryCodes = {StringUtf8Multilang::kDefaultCode};
vector<int8_t> secondaryCodes = {StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm()),
StringUtf8Multilang::kInternationalCode,
@ -45,9 +51,6 @@ void GetNames(FeatureID const & id, StringUtf8Multilang const & src, string & pr
auto primaryIndex = primaryCodes.size();
auto secondaryIndex = secondaryCodes.size();
primary.clear();
secondary.clear();
auto const findAndSet = [](vector<int8_t> const & langs, int8_t const code, string const & name,
size_t & bestIndex, string & outName)
{

View file

@ -0,0 +1,39 @@
#include "testing/testing.hpp"
#include "indexer/features_vector.hpp"
#include "indexer/index.hpp"
#include "indexer/mwm_set.hpp"
#include "platform/local_country_file.hpp"
using namespace platform;
namespace
{
UNIT_TEST(GetFeatureNames)
{
LocalCountryFile localFile = LocalCountryFile::MakeForTesting("minsk-pass");
Index index;
auto result = index.RegisterMap(localFile);
TEST_EQUAL(result.second, MwmSet::RegResult::Success, ());
auto const & id = result.first;
MwmSet::MwmHandle handle = index.GetMwmHandleById(id);
TEST(handle.IsAlive(), ());
auto const * value = handle.GetValue<MwmValue>();
FeaturesVector fv(value->m_cont, value->GetHeader(), value->m_table.get());
string primary, secondary, readable;
fv.ForEach([&](FeatureType & ft, uint32_t /* index */)
{
ft.GetPreferredNames(primary, secondary);
if (!secondary.empty())
{
ft.GetReadableName(readable);
TEST_EQUAL(secondary, readable, ());
}
});
}
} // namespace

View file

@ -28,6 +28,7 @@ SOURCES += \
drules_selector_parser_test.cpp \
editable_map_object_test.cpp \
feature_metadata_test.cpp \
feature_names_test.cpp \
feature_xml_test.cpp \
features_offsets_table_test.cpp \
features_vector_test.cpp \