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:
authorvng <viktor.govako@gmail.com>2013-01-29 17:43:16 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:49:27 +0300
commit60abc31cdfcc6ffaa016fec7700077d8c472598c (patch)
tree2040691e64b2735e03171ff091cce862dcc18a32 /map/bookmark.cpp
parent219a9f8d565064f312c03bb2aa338b0064cc9f55 (diff)
- Fix error processing logic when loading bookmarks (do not create BookmarkCategory when xml parse error).
- Add test for special xml names.
Diffstat (limited to 'map/bookmark.cpp')
-rw-r--r--map/bookmark.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/map/bookmark.cpp b/map/bookmark.cpp
index cc6d253e44..2d22202692 100644
--- a/map/bookmark.cpp
+++ b/map/bookmark.cpp
@@ -13,6 +13,7 @@
#include "../std/fstream.hpp"
#include "../std/algorithm.hpp"
+#include "../std/auto_ptr.hpp"
void BookmarkCategory::AddBookmarkImpl(Bookmark const & bm, double scale)
@@ -268,29 +269,36 @@ namespace bookmark_impl
};
}
-void BookmarkCategory::LoadFromKML(ReaderPtr<Reader> const & reader)
+bool BookmarkCategory::LoadFromKML(ReaderPtr<Reader> const & reader)
{
ReaderSource<ReaderPtr<Reader> > src(reader);
bookmark_impl::KMLParser parser(*this);
- if (!ParseXML(src, parser, true))
+ if (ParseXML(src, parser, true))
+ return true;
+ else
+ {
LOG(LERROR, ("XML read error. Probably, incorrect file encoding."));
+ return false;
+ }
}
BookmarkCategory * BookmarkCategory::CreateFromKMLFile(string const & file)
{
- BookmarkCategory * cat = new BookmarkCategory("");
+ auto_ptr<BookmarkCategory> cat(new BookmarkCategory(""));
try
{
- cat->LoadFromKML(new FileReader(file));
- cat->m_file = file;
+ if (cat->LoadFromKML(new FileReader(file)))
+ cat->m_file = file;
+ else
+ cat.reset();
}
catch (std::exception const & e)
{
LOG(LWARNING, ("Error while loading bookmarks from", file, e.what()));
- delete cat;
- cat = 0;
+ cat.reset();
}
- return cat;
+
+ return cat.release();
}
namespace