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-22 15:54:25 +0300
committermgsergio <mgsergio@yandex.ru>2017-11-23 17:21:36 +0300
commit0e3a0465557f484e617e30142c76f82089c9d373 (patch)
treea77b0e0b4c7360e727f5e759d4760e856e9ac35b /indexer/editable_map_object.cpp
parent2dc84e195d60cae8fe54d86fec1967fdd178ebe8 (diff)
[editor] added possibility to save several phone numbers
Diffstat (limited to 'indexer/editable_map_object.cpp')
-rw-r--r--indexer/editable_map_object.cpp48
1 files changed, 34 insertions, 14 deletions
diff --git a/indexer/editable_map_object.cpp b/indexer/editable_map_object.cpp
index 30982a103b..a195d532a8 100644
--- a/indexer/editable_map_object.cpp
+++ b/indexer/editable_map_object.cpp
@@ -631,33 +631,53 @@ bool EditableMapObject::ValidatePostCode(string const & postCode)
}
// static
-bool EditableMapObject::ValidatePhone(string const & phone)
+bool EditableMapObject::ValidatePhoneList(string const & phone)
{
+ // BNF:
+ // <digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
+ // <available_chars> ::= ' ' | '+' | '-' | '(' | ')' | '' <available_chars>
+ // <delimeter> ::= ',' | ';'
+ // <phone> ::= <digit> | <available_chars> <phone>
+ // <phone_list> ::= '' | <phone> | <phone> <delimeter> <phone_list>
+
if (phone.empty())
return true;
- auto curr = begin(phone);
- auto const last = end(phone);
-
auto const kMaxNumberLen = 15;
auto const kMinNumberLen = 5;
- if (*curr == '+')
- ++curr;
+ if (phone.size() < kMinNumberLen)
+ return false;
+
+ auto curr = phone.begin();
+ auto last = phone.begin();
- auto digitsCount = 0;
- for (; curr != last; ++curr)
+ do
{
- auto const isCharValid = isdigit(*curr) || *curr == '(' ||
- *curr == ')' || *curr == ' ' || *curr == '-';
- if (!isCharValid)
+ last = find_if(curr, phone.end(), [](string::value_type const & ch)
+ {
+ return ch == ',' || ch == ';';
+ });
+
+ auto digitsCount = 0;
+ string const symbols = "+-() ";
+ for (; curr != last; ++curr)
+ {
+ if (!isdigit(*curr) && find(symbols.begin(), symbols.end(), *curr) == symbols.end())
+ return false;
+
+ if (isdigit(*curr))
+ ++digitsCount;
+ }
+
+ if (digitsCount < kMinNumberLen || digitsCount > kMaxNumberLen)
return false;
- if (isdigit(*curr))
- ++digitsCount;
+ curr = last;
}
+ while (last != phone.end() && ++curr != phone.end());
- return kMinNumberLen <= digitsCount && digitsCount <= kMaxNumberLen;
+ return true;
}
// static