ecoinaddressvalidator.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
  2. #include "ecoinaddressvalidator.h"
  3. EcoinAddressValidator::EcoinAddressValidator(QObject *parent) :
  4. QValidator(parent)
  5. {
  6. }
  7. QValidator::State EcoinAddressValidator::validate(QString &input, int &pos) const
  8. {
  9. // Correction
  10. for(int idx=0; idx<input.size();)
  11. {
  12. bool removeChar = false;
  13. QChar ch = input.at(idx);
  14. switch(ch.unicode())
  15. {
  16. case 0x200B: // ZERO WIDTH SPACE
  17. case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE
  18. removeChar = true;
  19. break;
  20. default:
  21. break;
  22. }
  23. // Remove whitespace
  24. if(ch.isSpace())
  25. removeChar = true;
  26. // To next character
  27. if(removeChar)
  28. input.remove(idx, 1);
  29. else
  30. ++idx;
  31. }
  32. // Validation
  33. QValidator::State state = QValidator::Acceptable;
  34. for(int idx=0; idx<input.size(); ++idx)
  35. {
  36. int ch = input.at(idx).unicode();
  37. if(((ch >= '0' && ch<='9') ||
  38. (ch >= 'a' && ch<='z') ||
  39. (ch >= 'A' && ch<='Z')) &&
  40. ch != 'l' && ch != 'I' && ch != '0' && ch != 'O')
  41. {
  42. // Alphanumeric and not a 'forbidden' character
  43. }
  44. else
  45. {
  46. state = QValidator::Invalid;
  47. }
  48. }
  49. // Empty address is "intermediate" input
  50. if(input.isEmpty())
  51. {
  52. state = QValidator::Intermediate;
  53. }
  54. return state;
  55. }