forked from organicmaps/organicmaps
remove default name duplications on save
This commit is contained in:
parent
d4983dd818
commit
80c4ce875a
3 changed files with 21 additions and 14 deletions
|
@ -73,6 +73,7 @@ bool IsProtocolSpecified(string const & website)
|
|||
{
|
||||
return GetProtocolNameLength(website) > 0;
|
||||
}
|
||||
|
||||
osm::FakeNames MakeFakeSource(StringUtf8Multilang const & source,
|
||||
vector<int8_t> 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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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, ());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue