Fixed bookmarks naming

This commit is contained in:
r.kuznetsov 2018-05-29 12:12:34 +03:00 committed by yoksnod
parent c134c7fc75
commit 0b899b438d
7 changed files with 160 additions and 98 deletions

View file

@ -7,6 +7,7 @@ set(
serdes.hpp
serdes_binary.cpp
serdes_binary.hpp
type_utils.cpp
type_utils.hpp
types.hpp
visitors.hpp

View file

@ -126,42 +126,44 @@ char const * kTextKml =
std::vector<uint8_t> const kBinKml = {
0x03, 0x00, 0x00, 0x1E, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xE5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0xED, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01,
0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x8D, 0xB7, 0xF5, 0x71, 0xFC, 0x8C, 0xFC, 0xC0, 0x02, 0x00, 0x03, 0x01,
0x00, 0x03, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x05, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF3, 0xC2, 0xFB, 0xF9, 0x01, 0xE3, 0xB9, 0xBB, 0x8E, 0x01, 0xC3,
0xC5, 0xD2, 0xBB, 0x02, 0x00, 0x03, 0x01, 0x00, 0x04, 0x01, 0x00, 0x05, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8, 0xBC,
0xED, 0xA7, 0x03, 0x97, 0xB0, 0x9A, 0xA7, 0x02, 0xA4, 0xD6, 0xAE, 0xDB, 0x02, 0x00, 0x03, 0x01,
0x00, 0x06, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xCD, 0x97, 0xA7, 0x02, 0xFD, 0xC1, 0xAC, 0xDB, 0x02,
0x00, 0x03, 0x01, 0x00, 0x07, 0x01, 0x00, 0x08, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0x0E, 0x08, 0x1B, 0x1A, 0x41, 0x0C, 0x11, 0x25, 0x3F, 0x00, 0x02, 0x00,
0x01, 0x08, 0x03, 0x02, 0x06, 0x01, 0x03, 0x06, 0x40, 0x05, 0x07, 0x8D, 0x01, 0x06, 0x05, 0x02,
0x07, 0x07, 0x71, 0x09, 0x05, 0x05, 0x0A, 0x07, 0x12, 0x0B, 0x06, 0x5E, 0x0D, 0x06, 0xBA, 0x01,
0x0E, 0x05, 0x04, 0x0F, 0x05, 0x75, 0x11, 0x05, 0x0D, 0x12, 0x06, 0x09, 0x13, 0x07, 0x4E, 0x15,
0x06, 0x91, 0x01, 0x16, 0x06, 0x0B, 0x17, 0x06, 0x73, 0x19, 0x05, 0x06, 0x1A, 0x08, 0x1C, 0x1B,
0x07, 0x63, 0x1D, 0x06, 0xC0, 0x01, 0x1E, 0x05, 0x07, 0x1F, 0x06, 0x77, 0x21, 0x06, 0x0A, 0x22,
0x07, 0x08, 0x23, 0x07, 0x49, 0x25, 0x07, 0x90, 0x01, 0x27, 0x06, 0x72, 0x2A, 0x08, 0x14, 0x2B,
0x06, 0x62, 0x2D, 0x06, 0xBD, 0x01, 0x32, 0x06, 0x0C, 0x33, 0x06, 0x57, 0x35, 0x07, 0xA1, 0x01,
0x36, 0x06, 0x0F, 0x37, 0x07, 0x76, 0x3A, 0x08, 0x31, 0x3B, 0x06, 0x68, 0x3D, 0x06, 0xD1, 0x01,
0x3F, 0x06, 0x79, 0x41, 0x07, 0xB8, 0x01, 0x45, 0x07, 0x8F, 0x01, 0x47, 0x07, 0x74, 0x4A, 0x07,
0x13, 0x53, 0x07, 0x59, 0x5A, 0x07, 0x29, 0x5B, 0x07, 0x6D, 0x62, 0x08, 0x10, 0x63, 0x07, 0x4B,
0x65, 0x07, 0x96, 0x01, 0x6A, 0x08, 0x18, 0x75, 0x07, 0xB7, 0x01, 0x77, 0x07, 0x8A, 0x01, 0x7A,
0x08, 0x3F, 0x81, 0x01, 0x08, 0x0E, 0x9A, 0x01, 0x08, 0x25, 0xAA, 0x01, 0x08, 0x17, 0xBA, 0x01,
0x08, 0x3E, 0xE2, 0x01, 0x08, 0x11, 0xEA, 0x01, 0x08, 0x19, 0xFA, 0x01, 0x08, 0x41, 0xB0, 0x01,
0xD7, 0x64, 0xD6, 0x6E, 0x37, 0x46, 0x07, 0x3D, 0xA1, 0xA8, 0x65, 0x2F, 0x34, 0x01, 0x83, 0xBE,
0x2E, 0x87, 0x3C, 0x64, 0x71, 0x6E, 0xA3, 0xE7, 0xCC, 0xB7, 0x8E, 0x6D, 0xA7, 0xE2, 0xFD, 0x13,
0xBC, 0x9A, 0x51, 0x7D, 0xF2, 0xE9, 0x17, 0x8F, 0x33, 0x91, 0x28, 0xDB, 0xA1, 0x22, 0x5F, 0xB3,
0x14, 0x65, 0xE9, 0x57, 0x92, 0xAC, 0x33, 0xC5, 0xF8, 0x3E, 0x37, 0x35, 0x00, 0x88, 0x1C, 0x96,
0x62, 0x97, 0x17, 0x09, 0xA5, 0x3F, 0x42, 0x18, 0x98, 0xD5, 0x45, 0x96, 0x1D, 0x0A, 0x46, 0x2C,
0xB9, 0x94, 0xFE, 0x35, 0xF7, 0x00, 0x00, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x1A, 0xD0, 0xA2, 0xD9,
0x95, 0x6B, 0xDC, 0x69, 0xEA, 0x2D, 0x52, 0xB0, 0x43, 0xA8, 0x7C, 0xA9, 0x32, 0x0E, 0x01, 0x00,
0x09,
0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x05,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF3, 0xC2, 0xFB, 0xF9, 0x01, 0xE3, 0xB9, 0xBB, 0x8E,
0x01, 0xC3, 0xC5, 0xD2, 0xBB, 0x02, 0x00, 0x03, 0x01, 0x00, 0x05, 0x01, 0x00, 0x06, 0x01, 0x00,
0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xB8, 0xBC, 0xED, 0xA7, 0x03, 0x97, 0xB0, 0x9A, 0xA7, 0x02, 0xA4, 0xD6, 0xAE, 0xDB,
0x02, 0x00, 0x03, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, 0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xCD, 0x97, 0xA7,
0x02, 0xFD, 0xC1, 0xAC, 0xDB, 0x02, 0x00, 0x03, 0x01, 0x00, 0x0A, 0x01, 0x00, 0x0B, 0x01, 0x00,
0x0C, 0x00, 0x6F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0E, 0x08, 0x08, 0x1B,
0x1A, 0x1B, 0x41, 0x41, 0x0C, 0x11, 0x0C, 0x37, 0x3E, 0x00, 0x01, 0x00, 0x01, 0x06, 0x01, 0x03,
0x09, 0x03, 0x05, 0x05, 0x07, 0x07, 0x07, 0x41, 0x09, 0x06, 0x0A, 0x0B, 0x08, 0x8D, 0x01, 0x0D,
0x07, 0x10, 0x0F, 0x08, 0x71, 0x11, 0x05, 0x02, 0x13, 0x06, 0x04, 0x15, 0x06, 0x0B, 0x17, 0x07,
0x5E, 0x19, 0x05, 0x0D, 0x1B, 0x07, 0xBA, 0x01, 0x1D, 0x08, 0x1C, 0x1F, 0x06, 0x75, 0x21, 0x06,
0x06, 0x23, 0x06, 0x09, 0x27, 0x08, 0x4E, 0x29, 0x06, 0x12, 0x2B, 0x07, 0x91, 0x01, 0x2D, 0x08,
0x14, 0x2F, 0x07, 0x73, 0x33, 0x06, 0x05, 0x35, 0x07, 0x0C, 0x37, 0x08, 0x63, 0x3B, 0x07, 0xC0,
0x01, 0x3D, 0x08, 0x31, 0x3F, 0x07, 0x77, 0x43, 0x07, 0x08, 0x47, 0x08, 0x48, 0x4B, 0x08, 0x90,
0x01, 0x4D, 0x07, 0x13, 0x4F, 0x07, 0x72, 0x57, 0x07, 0x62, 0x5B, 0x07, 0xBD, 0x01, 0x5D, 0x07,
0x29, 0x67, 0x07, 0x57, 0x6B, 0x08, 0xA1, 0x01, 0x6D, 0x08, 0x18, 0x6F, 0x08, 0x76, 0x75, 0x07,
0x0F, 0x77, 0x07, 0x68, 0x7B, 0x07, 0xD1, 0x01, 0x7D, 0x08, 0x3F, 0x7F, 0x07, 0x79, 0x83, 0x01,
0x08, 0xB8, 0x01, 0x8B, 0x01, 0x08, 0x8F, 0x01, 0x8F, 0x01, 0x08, 0x74, 0x9D, 0x01, 0x08, 0x25,
0xA7, 0x01, 0x08, 0x59, 0xAD, 0x01, 0x08, 0x17, 0xB7, 0x01, 0x08, 0x6D, 0xBD, 0x01, 0x08, 0x3E,
0xC7, 0x01, 0x08, 0x4B, 0xCB, 0x01, 0x08, 0x96, 0x01, 0xEB, 0x01, 0x08, 0xB7, 0x01, 0xED, 0x01,
0x08, 0x19, 0xEF, 0x01, 0x08, 0x8A, 0x01, 0xFD, 0x01, 0x08, 0x40, 0x83, 0x02, 0x09, 0x0E, 0xA0,
0x02, 0xAF, 0x13, 0xE7, 0xEE, 0xAD, 0x1B, 0x51, 0x0F, 0x7D, 0x02, 0x8B, 0xBA, 0xDC, 0x17, 0x6C,
0x0C, 0xE8, 0x3F, 0xF4, 0x7A, 0x70, 0x54, 0x0E, 0x25, 0xE5, 0x6D, 0xFE, 0x26, 0xE1, 0xCF, 0xD5,
0xB1, 0x7A, 0xD1, 0x32, 0x1C, 0x8A, 0x5F, 0x54, 0xDA, 0xC4, 0x56, 0x9F, 0xFC, 0x54, 0x5C, 0x8A,
0x49, 0x94, 0x65, 0x55, 0x23, 0x49, 0x43, 0x2F, 0xE7, 0x51, 0xAE, 0x19, 0xFD, 0x9B, 0xCC, 0x95,
0xE7, 0x2C, 0xCB, 0xDF, 0xCF, 0x74, 0x1A, 0x01, 0x0C, 0x4D, 0x54, 0x52, 0x77, 0xB5, 0x8B, 0x51,
0xB3, 0x3C, 0x22, 0x31, 0x30, 0xD4, 0x5E, 0x8D, 0x41, 0x3D, 0x11, 0x88, 0x0D, 0xF3, 0x64, 0x9E,
0xFF, 0xD7, 0x70, 0x0F, 0x00, 0x80, 0x3D, 0x00, 0x00, 0x00, 0x80, 0x0E, 0xB0, 0x45, 0xA7, 0x9D,
0x65, 0x6B, 0x78, 0xC7, 0xC6, 0xBA, 0x2D, 0x46, 0x83, 0x76, 0x08, 0xAC, 0x14, 0x4B, 0x56, 0xA2,
0x09, 0x01, 0x00, 0x0D,
};
// This function can be used to generate textual representation of vector<uint8_t> like you see above.
@ -305,6 +307,7 @@ char const * kGeneratedKml =
" <mwm:serverId>AAAA-BBBB-CCCC-DDDD</mwm:serverId>\n"
" <mwm:name>\n"
" <mwm:lang code=\"ru\">Тестовая категория</mwm:lang>\n"
" <mwm:lang code=\"default\">Test category</mwm:lang>\n"
" </mwm:name>\n"
" <mwm:annotation>\n"
" <mwm:lang code=\"en\">Test annotation</mwm:lang>\n"
@ -312,6 +315,7 @@ char const * kGeneratedKml =
" </mwm:annotation>\n"
" <mwm:description>\n"
" <mwm:lang code=\"ru\">Тестовое описание</mwm:lang>\n"
" <mwm:lang code=\"default\">Test description</mwm:lang>\n"
" </mwm:description>\n"
" <mwm:imageUrl>https://localhost/123.png</mwm:imageUrl>\n"
" <mwm:author id=\"12345\">Maps.Me</mwm:author>\n"
@ -339,7 +343,7 @@ char const * kGeneratedKml =
" </mwm:properties>\n"
" </ExtendedData>\n"
" <Placemark>\n"
" <name>Test bookmark</name>\n"
" <name>Мое любимое место</name>\n"
" <description>Test bookmark description</description>\n"
" <TimeStamp><when>1970-01-01T00:13:20Z</when></TimeStamp>\n"
" <styleUrl>#placemark-blue</styleUrl>\n"
@ -347,9 +351,11 @@ char const * kGeneratedKml =
" <ExtendedData xmlns:mwm=\"https://maps.me\">\n"
" <mwm:name>\n"
" <mwm:lang code=\"ru\">Тестовая метка</mwm:lang>\n"
" <mwm:lang code=\"default\">Test bookmark</mwm:lang>\n"
" </mwm:name>\n"
" <mwm:description>\n"
" <mwm:lang code=\"ru\">Тестовое описание метки</mwm:lang>\n"
" <mwm:lang code=\"default\">Test bookmark description</mwm:lang>\n"
" </mwm:description>\n"
" <mwm:featureTypes>\n"
" <mwm:value>historic-castle</mwm:value>\n"
@ -377,9 +383,11 @@ char const * kGeneratedKml =
" <ExtendedData xmlns:mwm=\"https://maps.me\">\n"
" <mwm:name>\n"
" <mwm:lang code=\"ru\">Тестовый трек</mwm:lang>\n"
" <mwm:lang code=\"default\">Test track</mwm:lang>\n"
" </mwm:name>\n"
" <mwm:description>\n"
" <mwm:lang code=\"ru\">Тестовое описание трека</mwm:lang>\n"
" <mwm:lang code=\"default\">Test track description</mwm:lang>\n"
" </mwm:description>\n"
" <mwm:localId>0</mwm:localId>\n"
" <mwm:additionalStyle>\n"

View file

@ -188,15 +188,9 @@ std::string TimestampToString(Timestamp const & timestamp)
void SaveLocalizableString(KmlWriter::WriterWrapper & writer, LocalizableString const & str,
std::string const & tagName, std::string const & offsetStr)
{
if ((tagName == "name" || tagName == "description") && str.size() == 1 && str.begin()->first == kDefaultLang)
return;
writer << offsetStr << "<mwm:" << tagName << ">\n";
for (auto const & s : str)
{
if (s.first == kDefaultLang && (tagName == "name" || tagName == "description"))
continue;
writer << offsetStr << kIndent2 << "<mwm:lang code=\""
<< StringUtf8Multilang::GetLangByCode(s.first) << "\">";
SaveStringWithCDATA(writer, s.second);
@ -343,7 +337,7 @@ void SaveCategoryData(KmlWriter::WriterWrapper & writer, CategoryData const & ca
void SaveBookmarkExtendedData(KmlWriter::WriterWrapper & writer, BookmarkData const & bookmarkData)
{
if (bookmarkData.m_name.size() < 2 && bookmarkData.m_description.size() < 2 &&
if (bookmarkData.m_name.empty() && bookmarkData.m_description.empty() &&
bookmarkData.m_customName.empty() && bookmarkData.m_viewportScale == 0 &&
bookmarkData.m_icon == BookmarkIcon::None && bookmarkData.m_featureTypes.empty() &&
bookmarkData.m_boundTracks.empty())
@ -389,7 +383,8 @@ void SaveBookmarkData(KmlWriter::WriterWrapper & writer, BookmarkData const & bo
{
writer << kIndent2 << "<Placemark>\n";
writer << kIndent4 << "<name>";
SaveStringWithCDATA(writer, GetLocalizableString(bookmarkData.m_name, kDefaultLang));
std::string const defaultLang = StringUtf8Multilang::GetLangByCode(kDefaultLangCode);
SaveStringWithCDATA(writer, GetPreferredBookmarkName(bookmarkData, defaultLang, defaultLang));
writer << "</name>\n";
if (!bookmarkData.m_description.empty())
@ -714,6 +709,14 @@ void KmlParser::Pop(std::string const & tag)
data.m_featureTypes = std::move(m_featureTypes);
data.m_customName = std::move(m_customName);
data.m_boundTracks = std::move(m_boundTracks);
// Here we set custom name from 'name' field for KML-files exported from 3rd-party services.
if (data.m_name.size() == 1 && data.m_name.begin()->first == kDefaultLangCode &&
data.m_customName.empty() && data.m_featureTypes.empty())
{
data.m_customName = data.m_name;
}
m_data.m_bookmarksData.push_back(std::move(data));
}
else if (GEOMETRY_TYPE_LINE == m_geometryType)
@ -859,7 +862,9 @@ void KmlParser::CharData(std::string value)
{
if (currTag == "name")
{
m_name[kDefaultLang] = value;
// Use this name only if we have not read name from extended data yet.
if (m_name.find(kDefaultLang) == m_name.end())
m_name[kDefaultLang] = value;
}
else if (currTag == kStyleUrl)
{

83
kml/type_utils.cpp Normal file
View file

@ -0,0 +1,83 @@
#include "kml/type_utils.hpp"
#include "kml/types.hpp"
#include "indexer/categories_holder.hpp"
#include "indexer/classificator.hpp"
#include "indexer/feature_utils.hpp"
#include "coding/multilang_utf8_string.hpp"
namespace kml
{
bool IsEqual(std::vector<m2::PointD> const & v1, std::vector<m2::PointD> const & v2)
{
if (v1.size() != v2.size())
return false;
double constexpr kEps = 1e-5;
for (size_t i = 0; i < v1.size(); ++i)
{
if (!v1[i].EqualDxDy(v2[i], kEps))
return false;
}
return true;
}
std::string GetPreferredBookmarkStr(LocalizableString const & name, std::string const & languageNorm)
{
if (name.size() == 1)
return name.begin()->second;
StringUtf8Multilang nameMultilang;
for (auto const & pair : name)
nameMultilang.AddString(pair.first, pair.second);
auto const deviceLang = StringUtf8Multilang::GetLangIndex(languageNorm);
std::string preferredName;
if (feature::GetPreferredName(nameMultilang, deviceLang, preferredName))
return preferredName;
return {};
}
std::string GetPreferredBookmarkStr(LocalizableString const & name, feature::RegionData const & regionData,
std::string const & languageNorm)
{
if (name.size() == 1)
return name.begin()->second;
StringUtf8Multilang nameMultilang;
for (auto const & pair : name)
nameMultilang.AddString(pair.first, pair.second);
auto const deviceLang = StringUtf8Multilang::GetLangIndex(languageNorm);
std::string preferredName;
feature::GetReadableName(regionData, nameMultilang, deviceLang, false /* allowTranslit */, preferredName);
return preferredName;
}
std::string GetLocalizedBookmarkType(std::vector<uint32_t> const & types, std::string const & languageOrig)
{
if (types.empty())
return {};
auto const & c = classif();
auto const type = c.GetTypeForIndex(types.front());
CategoriesHolder const & categories = GetDefaultCategories();
return categories.GetReadableFeatureType(type, categories.MapLocaleToInteger(languageOrig));
}
std::string GetPreferredBookmarkName(BookmarkData const & bmData, std::string const & languageNorm,
std::string const & languageOrig)
{
std::string name = GetPreferredBookmarkStr(bmData.m_customName, languageNorm);
if (name.empty())
name = GetPreferredBookmarkStr(bmData.m_name, languageNorm);
if (name.empty())
name = GetLocalizedBookmarkType(bmData.m_featureTypes, languageOrig);
return name;
}
} // namespace kml

View file

@ -1,5 +1,7 @@
#pragma once
#include "indexer/feature.hpp"
#include "geometry/point2d.hpp"
#include <cstdint>
@ -8,6 +10,7 @@
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
@ -48,22 +51,6 @@ inline Timestamp FromSecondsSinceEpoch(uint64_t seconds)
return Timestamp(std::chrono::seconds(seconds));
}
inline bool IsEqual(std::vector<m2::PointD> const & v1,
std::vector<m2::PointD> const & v2)
{
if (v1.size() != v2.size())
return false;
double constexpr kEps = 1e-5;
for (size_t i = 0; i < v1.size(); ++i)
{
if (!v1[i].EqualDxDy(v2[i], kEps))
return false;
}
return true;
}
inline bool IsEqual(Timestamp const & ts1, Timestamp const & ts2)
{
return ToSecondsSinceEpoch(ts1) == ToSecondsSinceEpoch(ts2);
@ -88,6 +75,16 @@ inline void SetDefaultStr(LocalizableString & localizableStr, std::string const
localizableStr[kDefaultLangCode] = str;
}
extern bool IsEqual(std::vector<m2::PointD> const & v1, std::vector<m2::PointD> const & v2);
struct BookmarkData;
std::string GetPreferredBookmarkName(BookmarkData const & bmData, std::string const & languageNorm,
std::string const & languageOrig);
std::string GetPreferredBookmarkStr(LocalizableString const & name, std::string const & languageNorm);
std::string GetPreferredBookmarkStr(LocalizableString const & name, feature::RegionData const & regionData,
std::string const & languageNorm);
std::string GetLocalizedBookmarkType(std::vector<uint32_t> const & types, std::string const & languageOrig);
#define DECLARE_COLLECTABLE(IndexType, ...) \
IndexType m_collectionIndex; \
template <typename Collector> \

View file

@ -3,7 +3,6 @@
#include "kml/serdes.hpp"
#include "kml/serdes_binary.hpp"
#include "indexer/categories_holder.hpp"
#include "indexer/classificator.hpp"
#include "indexer/feature_utils.hpp"
@ -436,57 +435,22 @@ void SaveFeatureTypes(feature::TypesHolder const & types, kml::BookmarkData & bm
std::string GetPreferredBookmarkStr(kml::LocalizableString const & name)
{
if (name.size() == 1)
return name.begin()->second;
StringUtf8Multilang nameMultilang;
for (auto const & pair : name)
nameMultilang.AddString(pair.first, pair.second);
auto const deviceLang = StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm());
std::string preferredName;
if (feature::GetPreferredName(nameMultilang, deviceLang, preferredName))
return preferredName;
return {};
return kml::GetPreferredBookmarkStr(name, languages::GetCurrentNorm());
}
std::string GetPreferredBookmarkStr(kml::LocalizableString const & name, feature::RegionData const & regionData)
{
if (name.size() == 1)
return name.begin()->second;
StringUtf8Multilang nameMultilang;
for (auto const & pair : name)
nameMultilang.AddString(pair.first, pair.second);
auto const deviceLang = StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm());
std::string preferredName;
feature::GetReadableName(regionData, nameMultilang, deviceLang, false /* allowTranslit */, preferredName);
return preferredName;
return kml::GetPreferredBookmarkStr(name, regionData, languages::GetCurrentNorm());
}
std::string GetLocalizedBookmarkType(std::vector<uint32_t> const & types)
{
if (types.empty())
return {};
auto const & c = classif();
auto const type = c.GetTypeForIndex(types.front());
CategoriesHolder const & categories = GetDefaultCategories();
return categories.GetReadableFeatureType(type, categories.MapLocaleToInteger(languages::GetCurrentOrig()));
return kml::GetLocalizedBookmarkType(types, languages::GetCurrentOrig());
}
std::string GetPreferredBookmarkName(kml::BookmarkData const & bmData)
{
std::string name = GetPreferredBookmarkStr(bmData.m_customName);
if (name.empty())
name = GetPreferredBookmarkStr(bmData.m_name);
if (name.empty())
name = GetLocalizedBookmarkType(bmData.m_featureTypes);
return name;
return kml::GetPreferredBookmarkName(bmData, languages::GetCurrentNorm(), languages::GetCurrentOrig());
}
bool FromCatalog(kml::FileData const & kmlData)

View file

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
4568C86420BD455700E2192B /* type_utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4568C86320BD455600E2192B /* type_utils.cpp */; };
45E4559520584ABA00D9F45E /* serdes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45E4558E20584AB900D9F45E /* serdes.cpp */; };
45E4559620584ABA00D9F45E /* serdes_binary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45E4559220584ABA00D9F45E /* serdes_binary.cpp */; };
45E4560120584DF200D9F45E /* serdes_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45E455FF20584DEF00D9F45E /* serdes_tests.cpp */; };
@ -40,6 +41,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
4568C86320BD455600E2192B /* type_utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = type_utils.cpp; sourceTree = "<group>"; };
45E4557D205849A600D9F45E /* libkml.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libkml.a; sourceTree = BUILT_PRODUCTS_DIR; };
45E45589205849DC00D9F45E /* common-release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "common-release.xcconfig"; path = "../common-release.xcconfig"; sourceTree = "<group>"; };
45E4558A205849DC00D9F45E /* common-debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "common-debug.xcconfig"; path = "../common-debug.xcconfig"; sourceTree = "<group>"; };
@ -130,6 +132,7 @@
45E4559320584ABA00D9F45E /* serdes_binary.hpp */,
45E4558E20584AB900D9F45E /* serdes.cpp */,
45E4559020584AB900D9F45E /* serdes.hpp */,
4568C86320BD455600E2192B /* type_utils.cpp */,
45E4558F20584AB900D9F45E /* type_utils.hpp */,
45E4559420584ABA00D9F45E /* types.hpp */,
45E4559120584ABA00D9F45E /* visitors.hpp */,
@ -258,6 +261,7 @@
buildActionMask = 2147483647;
files = (
45E4559620584ABA00D9F45E /* serdes_binary.cpp in Sources */,
4568C86420BD455700E2192B /* type_utils.cpp in Sources */,
45E4559520584ABA00D9F45E /* serdes.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;