static
| 543 | |
| 544 | // static |
| 545 | bool EditableMapObject::ValidatePhoneList(string const & phone) |
| 546 | { |
| 547 | // BNF: |
| 548 | // <digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
| 549 | // <available_char> ::= ' ' | '+' | '-' | '(' | ')' |
| 550 | // <delimeter> ::= ',' | ';' |
| 551 | // <phone> ::= (<digit> | <available_chars>)+ |
| 552 | // <phone_list> ::= '' | <phone> | <phone> <delimeter> <phone_list> |
| 553 | |
| 554 | if (phone.empty()) |
| 555 | return true; |
| 556 | |
| 557 | if (strings::CountChar(phone) > kMaximumOsmChars) |
| 558 | return false; |
| 559 | |
| 560 | auto constexpr kMaxNumberLen = 15; |
| 561 | auto constexpr kMinNumberLen = 5; |
| 562 | |
| 563 | if (phone.size() < kMinNumberLen) |
| 564 | return false; |
| 565 | |
| 566 | auto curr = phone.begin(); |
| 567 | auto last = phone.begin(); |
| 568 | |
| 569 | do |
| 570 | { |
| 571 | last = find_if(curr, phone.end(), [](string::value_type const & ch) { return ch == ',' || ch == ';'; }); |
| 572 | |
| 573 | auto digitsCount = 0; |
| 574 | string const symbols = "+-() "; |
| 575 | for (; curr != last; ++curr) |
| 576 | { |
| 577 | if (!isdigit(*curr) && find(symbols.begin(), symbols.end(), *curr) == symbols.end()) |
| 578 | return false; |
| 579 | |
| 580 | if (isdigit(*curr)) |
| 581 | ++digitsCount; |
| 582 | } |
| 583 | |
| 584 | if (digitsCount < kMinNumberLen || digitsCount > kMaxNumberLen) |
| 585 | return false; |
| 586 | |
| 587 | curr = last; |
| 588 | } |
| 589 | while (last != phone.end() && ++curr != phone.end()); |
| 590 | |
| 591 | return true; |
| 592 | } |
| 593 | |
| 594 | // static |
| 595 | bool EditableMapObject::ValidateEmail(string const & email) |