Guest User

Untitled

a guest
Dec 17th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. QValidator::State QNickValidator::validate(const QString &input) const
  2. {
  3. if (input.length() > 20)
  4. {
  5. return QValidator::Invalid;
  6. }
  7. if (input.length() == 0)
  8. return QValidator::Intermediate;
  9.  
  10. if (!isBegEndChar(input[0])) {
  11. return QValidator::Invalid;
  12. }
  13.  
  14. bool spaced = false;
  15. bool punct = false;
  16.  
  17. for (int i = 0; i < input.length(); i++) {
  18. if (input[i] == '\n' || input[i] == '%' || input[i] == '*' || input[i] == '<' || input[i] == ':' || input[i] == '(' || input[i] == ')'
  19. || input[i] == ';')
  20. return QValidator::Invalid;
  21. if (input[i].isPunct()) {
  22. if (punct == true) {
  23. //Error: two punctuations are not separated by a letter/number
  24. return QValidator::Invalid;
  25. }
  26. punct = true;
  27. spaced = false;
  28. } else if (input[i] == ' ') {
  29. if (spaced == true) {
  30. //Error: two spaces are following
  31. return QValidator::Invalid;
  32. }
  33. spaced = true;
  34. } else if (input[i].isLetterOrNumber()) {
  35. //we allow another punct & space
  36. punct = false;
  37. spaced = false;
  38. }
  39.  
  40. if (input[i].category() >= QChar::Other_Control && input[i].category() <= QChar::Other_NotAssigned) {
  41. return QValidator::Intermediate;
  42. }
  43. }
  44.  
  45. //let's check if there is at least a letter/number & no whitespace at the end
  46. if (input.length() == 1 && input[0].isPunct()) {
  47. return QValidator::Intermediate;
  48. }
  49. if (!isBegEndChar(input[input.length()-1])) {
  50. return QValidator::Intermediate;
  51. }
  52.  
  53. return QValidator::Acceptable;
  54. }
Add Comment
Please, Sign In to add comment