{"action":"created","comment":{"url":"https://api.github.com/repos/mapsme/omim/pulls/comments/47998725","id":47998725,"diff_hunk":"@@ -0,0 +1,214 @@\n+#include \"editor/xml_feature.hpp\"\n+\n+#include \"base/assert.hpp\"\n+#include \"base/string_utils.hpp\"\n+#include \"base/timer.hpp\"\n+\n+#include \"geometry/mercator.hpp\"\n+\n+#include \"std/set.hpp\"\n+#include \"std/unordered_set.hpp\"\n+\n+#include <boost/functional/hash.hpp>\n+\n+#include \"3party/pugixml/src/pugixml.hpp\"\n+\n+namespace\n+{\n+auto constexpr kLatLonTolerance = 7;\n+\n+pugi::xml_node FindTag(pugi::xml_document const & document, string const & key)\n+{\n+  return document.select_node((\"//tag[@k='\" + key + \"']\").data()).node();\n+}\n+\n+m2::PointD PointFromLatLon(pugi::xml_node const node)\n+{\n+  double lat, lon;\n+  if (!strings::to_double(node.attribute(\"lat\").value(), lat))\n+    MYTHROW(editor::XMLFeatureNoLatLonError,\n+            (\"Can't parse lat attribute: \" + string(node.attribute(\"lat\").value())));\n+ if (!strings::to_double(node.attribute(\"lon\").value(), lon))\n+   MYTHROW(editor::XMLFeatureNoLatLonError,\n+           (\"Can't parse lon attribute: \" + string(node.attribute(\"lon\").value())));\n+  return MercatorBounds::FromLatLon(lat, lon);\n+}\n+\n+void ValidateNode(pugi::xml_node const & node)\n+{\n+  if (!node)\n+    MYTHROW(editor::XMLFeatureNoNodeError, (\"Document has no node\"));\n+\n+  try\n+  {\n+    PointFromLatLon(node);\n+  }\n+  catch(editor::XMLFeatureError const &)\n+  {\n+    throw;\n+  }\n+\n+  if (!node.attribute(\"timestamp\"))\n+    MYTHROW(editor::XMLFeatureNoTimestampError, (\"Node has no timestamp attribute\"));\n+}\n+} // namespace\n+\n+namespace editor\n+{\n+char const * const XMLFeature::kLastModified = \"timestamp\";\n+char const * const XMLFeature::kHouseNumber = \"addr:housenumber\";\n+char const * const XMLFeature::kDefaultName = \"name\";\n+char const * const XMLFeature::kLocalName = \"name:\";\n+char const * const XMLFeature::kDefaultLang =\n+    StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::DEFAULT_CODE);;\n+\n+XMLFeature::XMLFeature()\n+{\n+  m_document.append_child(\"node\");\n+}\n+\n+XMLFeature::XMLFeature(string const & xml)\n+{\n+  m_document.load(xml.data());\n+  ValidateNode(GetRootNode());\n+}\n+\n+XMLFeature::XMLFeature(pugi::xml_document const & xml)\n+{\n+  m_document.reset(xml);\n+  ValidateNode(GetRootNode());\n+}\n+\n+XMLFeature::XMLFeature(pugi::xml_node const & xml)\n+{\n+  m_document.reset();\n+  m_document.append_copy(xml);\n+  ValidateNode(GetRootNode());\n+}\n+\n+void XMLFeature::Save(ostream & ost) const\n+{\n+  m_document.save(ost, \"  \", pugi::format_indent_attributes);\n+}\n+\n+m2::PointD XMLFeature::GetCenter() const\n+{\n+  return PointFromLatLon(GetRootNode());\n+}\n+\n+void XMLFeature::SetCenter(m2::PointD const & mercatorCenter)\n+{\n+  SetAttribute(\"lat\", strings::to_string_dac(MercatorBounds::YToLat(mercatorCenter.y),\n+                                             kLatLonTolerance));\n+  SetAttribute(\"lon\", strings::to_string_dac(MercatorBounds::XToLon(mercatorCenter.x),\n+                                             kLatLonTolerance));\n+}\n+\n+string XMLFeature::GetName(string const & lang) const\n+{\n+  auto const suffix = (lang == kDefaultLang || lang.empty()) ? \"\" : \":\" + lang;\n+  return GetTagValue(\"name\" + suffix);\n+}\n+\n+string XMLFeature::GetName(uint8_t const langCode) const\n+{\n+  return GetName(StringUtf8Multilang::GetLangByCode(langCode));\n+}\n+\n+void XMLFeature::SetName(string const & name)\n+{\n+  SetName(kDefaultLang, name);\n+}\n+\n+void XMLFeature::SetName(string const & lang, string const & name)\n+{\n+  auto const suffix = (lang == kDefaultLang || lang.empty()) ? \"\" : \":\" + lang;\n+  SetTagValue(\"name\" + suffix, name);\n+}\n+\n+void XMLFeature::SetName(uint8_t const langCode, string const & name)\n+{\n+  SetName(StringUtf8Multilang::GetLangByCode(langCode), name);\n+}\n+\n+string XMLFeature::GetHouse() const\n+{\n+  return GetTagValue(kHouseNumber);\n+}\n+\n+void XMLFeature::SetHouse(string const & house)\n+{\n+  SetTagValue(kHouseNumber, house);\n+}\n+\n+time_t XMLFeature::GetModificationTime() const\n+{\n+  auto const node = GetRootNode();","path":"editor/xml_feature.cpp","position":146,"original_position":146,"commit_id":"2e7fae592c1120d33eea747fc81c10392a95b0ab","original_commit_id":"2e7fae592c1120d33eea747fc81c10392a95b0ab","user":{"login":"deathbaba","id":170263,"avatar_url":"https://avatars.githubusercontent.com/u/170263?v=3","gravatar_id":"","url":"https://api.github.com/users/deathbaba","html_url":"https://github.com/deathbaba","followers_url":"https://api.github.com/users/deathbaba/followers","following_url":"https://api.github.com/users/deathbaba/following{/other_user}","gists_url":"https://api.github.com/users/deathbaba/gists{/gist_id}","starred_url":"https://api.github.com/users/deathbaba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deathbaba/subscriptions","organizations_url":"https://api.github.com/users/deathbaba/orgs","repos_url":"https://api.github.com/users/deathbaba/repos","events_url":"https://api.github.com/users/deathbaba/events{/privacy}","received_events_url":"https://api.github.com/users/deathbaba/received_events","type":"User","site_admin":false},"body":"You don't need node var here.","created_at":"2015-12-18T06:48:14Z","updated_at":"2015-12-18T06:48:14Z","html_url":"https://github.com/mapsme/omim/pull/916#discussion_r47998725","pull_request_url":"https://api.github.com/repos/mapsme/omim/pulls/916","_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments/47998725"},"html":{"href":"https://github.com/mapsme/omim/pull/916#discussion_r47998725"},"pull_request":{"href":"https://api.github.com/repos/mapsme/omim/pulls/916"}}},"pull_request":{"url":"https://api.github.com/repos/mapsme/omim/pulls/916","id":53238413,"html_url":"https://github.com/mapsme/omim/pull/916","diff_url":"https://github.com/mapsme/omim/pull/916.diff","patch_url":"https://github.com/mapsme/omim/pull/916.patch","issue_url":"https://api.github.com/repos/mapsme/omim/issues/916","number":916,"state":"open","locked":false,"title":"Feature xml reloaded","user":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"body":"Previous was https://github.com/mapsme/omim/pull/762","created_at":"2015-12-10T10:13:49Z","updated_at":"2015-12-18T06:48:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8078182b0962f891e1060baf59cef978f31c2adb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mapsme/omim/pulls/916/commits","review_comments_url":"https://api.github.com/repos/mapsme/omim/pulls/916/comments","review_comment_url":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapsme/omim/issues/916/comments","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/2e7fae592c1120d33eea747fc81c10392a95b0ab","head":{"label":"mgsergio:feature-xml-reloaded","ref":"feature-xml-reloaded","sha":"2e7fae592c1120d33eea747fc81c10392a95b0ab","user":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"repo":{"id":43430406,"name":"omim","full_name":"mgsergio/omim","owner":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mgsergio/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":true,"url":"https://api.github.com/repos/mgsergio/omim","forks_url":"https://api.github.com/repos/mgsergio/omim/forks","keys_url":"https://api.github.com/repos/mgsergio/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mgsergio/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mgsergio/omim/teams","hooks_url":"https://api.github.com/repos/mgsergio/omim/hooks","issue_events_url":"https://api.github.com/repos/mgsergio/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mgsergio/omim/events","assignees_url":"https://api.github.com/repos/mgsergio/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mgsergio/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mgsergio/omim/tags","blobs_url":"https://api.github.com/repos/mgsergio/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mgsergio/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mgsergio/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mgsergio/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mgsergio/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mgsergio/omim/languages","stargazers_url":"https://api.github.com/repos/mgsergio/omim/stargazers","contributors_url":"https://api.github.com/repos/mgsergio/omim/contributors","subscribers_url":"https://api.github.com/repos/mgsergio/omim/subscribers","subscription_url":"https://api.github.com/repos/mgsergio/omim/subscription","commits_url":"https://api.github.com/repos/mgsergio/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mgsergio/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mgsergio/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mgsergio/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mgsergio/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mgsergio/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mgsergio/omim/merges","archive_url":"https://api.github.com/repos/mgsergio/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mgsergio/omim/downloads","issues_url":"https://api.github.com/repos/mgsergio/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mgsergio/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mgsergio/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mgsergio/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mgsergio/omim/labels{/name}","releases_url":"https://api.github.com/repos/mgsergio/omim/releases{/id}","created_at":"2015-09-30T11:59:31Z","updated_at":"2015-09-30T12:01:39Z","pushed_at":"2015-12-17T18:01:54Z","git_url":"git://github.com/mgsergio/omim.git","ssh_url":"git@github.com:mgsergio/omim.git","clone_url":"https://github.com/mgsergio/omim.git","svn_url":"https://github.com/mgsergio/omim","homepage":null,"size":1899059,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mapsme:osm-editor","ref":"osm-editor","sha":"27cce7f5bbd35e29c68db70ba55851de42bf37c1","user":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","created_at":"2015-09-20T02:57:13Z","updated_at":"2015-12-17T20:17:34Z","pushed_at":"2015-12-17T18:01:54Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":null,"size":1993308,"stargazers_count":1538,"watchers_count":1538,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":192,"mirror_url":null,"open_issues_count":82,"forks":192,"open_issues":82,"watchers":1538,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/916"},"html":{"href":"https://github.com/mapsme/omim/pull/916"},"issue":{"href":"https://api.github.com/repos/mapsme/omim/issues/916"},"comments":{"href":"https://api.github.com/repos/mapsme/omim/issues/916/comments"},"review_comments":{"href":"https://api.github.com/repos/mapsme/omim/pulls/916/comments"},"review_comment":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapsme/omim/pulls/916/commits"},"statuses":{"href":"https://api.github.com/repos/mapsme/omim/statuses/2e7fae592c1120d33eea747fc81c10392a95b0ab"}}}}