diff --git a/indexer/editable_map_object.cpp b/indexer/editable_map_object.cpp index 3f982ab72f..0f03d30793 100644 --- a/indexer/editable_map_object.cpp +++ b/indexer/editable_map_object.cpp @@ -73,6 +73,7 @@ bool IsProtocolSpecified(string const & website) { return GetProtocolNameLength(website) > 0; } + osm::FakeNames MakeFakeSource(StringUtf8Multilang const & source, vector const & mwmLanguages, StringUtf8Multilang & fakeSource) { @@ -335,7 +336,10 @@ void EditableMapObject::SetName(string name, int8_t langCode) mwmInfo->GetRegionData().GetLanguages(mwmLanguages); if (CanUseAsDefaultName(langCode, mwmLanguages)) + { m_name.AddString(StringUtf8Multilang::kDefaultCode, name); + return; + } } } @@ -523,19 +527,22 @@ void EditableMapObject::SetOpeningHours(string const & openingHours) void EditableMapObject::SetPointType() { m_geomType = feature::EGeomType::GEOM_POINT; } - -void EditableMapObject::RemoveBlankNames() +void EditableMapObject::RemoveBlankAndDuplicationsForDefault() { - StringUtf8Multilang nameWithoutBlanks; - m_name.ForEach([&nameWithoutBlanks](int8_t langCode, string const & name) + StringUtf8Multilang editedName; + string defaultName; + m_name.GetString(StringUtf8Multilang::kDefaultCode, defaultName); + + m_name.ForEach([&defaultName, &editedName](int8_t langCode, string const & name) { - if (!name.empty()) - nameWithoutBlanks.AddString(langCode, name); + auto const duplicate = langCode != StringUtf8Multilang::kDefaultCode && defaultName == name; + if (!name.empty() && !duplicate) + editedName.AddString(langCode, name); return true; }); - m_name = nameWithoutBlanks; + m_name = editedName; } void EditableMapObject::RemoveNeedlessNames() @@ -543,7 +550,7 @@ void EditableMapObject::RemoveNeedlessNames() if (!IsNamesAdvancedModeEnabled()) RemoveFakeNames(m_fakeNames, m_name); - RemoveBlankNames(); + RemoveBlankAndDuplicationsForDefault(); } // static diff --git a/indexer/editable_map_object.hpp b/indexer/editable_map_object.hpp index fdf9570a24..b27caf08ad 100644 --- a/indexer/editable_map_object.hpp +++ b/indexer/editable_map_object.hpp @@ -151,8 +151,8 @@ public: /// Enables advanced mode with direct access to default name and disables any recalculations. void EnableNamesAdvancedMode() { m_namesAdvancedMode = true; } bool IsNamesAdvancedModeEnabled() const { return m_namesAdvancedMode; } - /// Remove blank names for advanced mode. - void RemoveBlankNames(); + /// Remove blank names and default name duplications. + void RemoveBlankAndDuplicationsForDefault(); /// Calls RemoveBlankNames or RemoveFakeNames depending on mode. void RemoveNeedlessNames(); diff --git a/indexer/indexer_tests/editable_map_object_test.cpp b/indexer/indexer_tests/editable_map_object_test.cpp index 044cc8d6ab..ac340c844b 100644 --- a/indexer/indexer_tests/editable_map_object_test.cpp +++ b/indexer/indexer_tests/editable_map_object_test.cpp @@ -558,7 +558,7 @@ UNIT_TEST(EditableMapObject_RemoveBlankNames) EditableMapObject emo; emo.SetName(name); - emo.RemoveBlankNames(); + emo.RemoveBlankAndDuplicationsForDefault(); TEST_EQUAL(getCountOfNames(emo.GetName()), 4, ()); @@ -570,7 +570,7 @@ UNIT_TEST(EditableMapObject_RemoveBlankNames) name.AddString(GetLangCode("de"), ""); emo.SetName(name); - emo.RemoveBlankNames(); + emo.RemoveBlankAndDuplicationsForDefault(); TEST_EQUAL(getCountOfNames(emo.GetName()), 2, ()); @@ -582,7 +582,7 @@ UNIT_TEST(EditableMapObject_RemoveBlankNames) name.AddString(GetLangCode("de"), ""); emo.SetName(name); - emo.RemoveBlankNames(); + emo.RemoveBlankAndDuplicationsForDefault(); TEST_EQUAL(getCountOfNames(emo.GetName()), 1, ()); @@ -594,7 +594,7 @@ UNIT_TEST(EditableMapObject_RemoveBlankNames) name.AddString(GetLangCode("de"), "De name"); emo.SetName(name); - emo.RemoveBlankNames(); + emo.RemoveBlankAndDuplicationsForDefault(); TEST_EQUAL(getCountOfNames(emo.GetName()), 1, ()); }