Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Zhdanovich <kzhdanovich@gmail.com>2013-01-08 13:00:58 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:48:31 +0300
commitc535a999955472944d7afdfa0f910d9cca588175 (patch)
tree096778121a6c9bbcd5e8d1cd0532e78b3787feea /map/bookmark.cpp
parent208a1580b0f956406165d33db047878ed448177e (diff)
Function that imports files to application(kml/kmz)
Diffstat (limited to 'map/bookmark.cpp')
-rw-r--r--map/bookmark.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/map/bookmark.cpp b/map/bookmark.cpp
index 2d8febae2c..b5feeb3c49 100644
--- a/map/bookmark.cpp
+++ b/map/bookmark.cpp
@@ -433,7 +433,7 @@ namespace
}
}
-string BookmarkCategory::GetValidFileName(string const & name)
+string BookmarkCategory::RemoveInvalidSymbols(string const & name)
{
// Remove not allowed symbols
strings::UniString uniName = strings::MakeUniString(name);
@@ -447,8 +447,14 @@ string BookmarkCategory::GetValidFileName(string const & name)
return (uniName.empty() ? "Bookmarks" : strings::ToUtf8(uniName));
}
-string BookmarkCategory::GenerateUniqueFileName(const string & path, string const & name)
+string BookmarkCategory::GenerateUniqueFileName(const string & path, string name)
{
+ string const kmlExt(".kml");
+ // check if file name already contains .kml extension
+ size_t const extPos = name.rfind(kmlExt);
+ if (extPos == name.size() - kmlExt.size())
+ name.resize(name.size() - kmlExt.size());
+
size_t counter = 1;
string suffix;
while (Platform::IsFileExistsByFullPath(path + name + suffix + ".kml"))
@@ -461,18 +467,21 @@ bool BookmarkCategory::SaveToKMLFile()
string oldFile;
// Get valid file name from category name
- string const name = GetValidFileName(m_name);
+ string const name = RemoveInvalidSymbols(m_name);
if (!m_file.empty())
{
size_t i2 = m_file.find_last_of('.');
- if (i2 == string::npos) i2 = m_file.size();
+ if (i2 == string::npos)
+ i2 = m_file.size();
size_t i1 = m_file.find_last_of("\\/");
- if (i1 == string::npos) i1 = 0;
- else ++i1;
+ if (i1 == string::npos)
+ i1 = 0;
+ else
+ ++i1;
// If m_file doesn't match name, assign new m_file for this category and save old file name.
- if (m_file.substr(i1, i2-i1).find(name) != 0)
+ if (m_file.substr(i1, i2 - i1).find(name) != 0)
{
oldFile = GenerateUniqueFileName(GetPlatform().WritableDir(), name);
m_file.swap(oldFile);