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:
authorArsentiy Milchakov <milcars@mapswithme.com>2017-11-24 16:51:21 +0300
committerIlya Zverev <ilya@zverev.info>2017-11-27 18:03:53 +0300
commit76cbee1c328cc10a1719bbac9fd2b6114f84bcae (patch)
tree44ae081086b59bf96fc6fba58b3c78584d67c2fc /indexer/editable_map_object.cpp
parent54eeceaa2e1b476a1c8c79d289112404db4a27bc (diff)
[editor] validate name method is added
Diffstat (limited to 'indexer/editable_map_object.cpp')
-rw-r--r--indexer/editable_map_object.cpp42
1 files changed, 38 insertions, 4 deletions
diff --git a/indexer/editable_map_object.cpp b/indexer/editable_map_object.cpp
index 6d3dac6999..02067c4e32 100644
--- a/indexer/editable_map_object.cpp
+++ b/indexer/editable_map_object.cpp
@@ -7,10 +7,13 @@
#include "base/macros.hpp"
#include "base/string_utils.hpp"
-#include "std/cctype.hpp"
-#include "std/cmath.hpp"
-#include "std/regex.hpp"
-#include "std/sstream.hpp"
+#include <codecvt>
+#include <cctype>
+#include <cmath>
+#include <regex>
+#include <sstream>
+
+using namespace std;
namespace
{
@@ -756,4 +759,35 @@ bool EditableMapObject::ValidateLevel(string const & level)
return strings::to_double(level, result) && result > kMinBuildingLevel &&
result <= kMaximumLevelsEditableByUsers;
}
+
+// static
+bool EditableMapObject::ValidateName(string const & name)
+{
+ if (name.empty())
+ return true;
+
+ if (strings::IsASCIIString(name))
+ return regex_match(name, regex(R"(^[ A-Za-z0-9.,?!@()\-:;"'`]+$)"));
+
+ std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
+
+ std::u32string const u32name = converter.from_bytes(name);
+
+ std::u32string const excludedSymbols = U"$%^~§><{}[]*=_#№±\n\t\r\v\f|√•π÷׶∆°";
+
+ for (auto const ch : u32name)
+ {
+ // Exclude arrows, mathematical symbols, borders, geometric shapes.
+ if (ch >= U'\U00002190' && ch <= U'\U00002BFF')
+ return false;
+ // Exclude format controls, musical symbols, emoticons, ornamental and pictographs,
+ // ancient and exotic alphabets.
+ if (ch >= U'\U0000FFF0' && ch <= U'\U0001F9FF')
+ return false;
+
+ if (find(excludedSymbols.cbegin(), excludedSymbols.cend(), ch) != excludedSymbols.cend())
+ return false;
+ }
+ return true;
+}
} // namespace osm