| 852 | } |
| 853 | |
| 854 | bool Database::CheckNameFilter(const std::string& name, bool surname) |
| 855 | { |
| 856 | // the minimum 4 is enforced by the client too |
| 857 | if (name.empty() || name.size() < 4) { |
| 858 | return false; |
| 859 | } |
| 860 | |
| 861 | // Given name length is enforced by the client too |
| 862 | if (!surname && name.size() > 15) { |
| 863 | return false; |
| 864 | } |
| 865 | |
| 866 | for (size_t i = 0; i < name.size(); i++) { |
| 867 | if (!isalpha(name[i])) { |
| 868 | return false; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | char c = '\0'; |
| 873 | uint8 num_c = 0; |
| 874 | for (size_t x = 0; x < name.size(); ++x) { |
| 875 | if (name[x] == c) { |
| 876 | num_c++; |
| 877 | } else { |
| 878 | num_c = 1; |
| 879 | c = name[x]; |
| 880 | } |
| 881 | |
| 882 | if (num_c > 2) { |
| 883 | return false; |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | const auto& l = NameFilterRepository::All(*this); |
| 888 | |
| 889 | if (l.empty()) { |
| 890 | return true; |
| 891 | } |
| 892 | |
| 893 | for (const auto& e : l) { |
| 894 | if (Strings::Contains(Strings::ToLower(name), Strings::ToLower(e.name))) { |
| 895 | return false; |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | return true; |
| 900 | } |
| 901 | |
| 902 | bool Database::AddToNameFilter(const std::string& name) |
| 903 | { |
no test coverage detected