Hello,
I've just came across WRegExpValidator::validate and tried to
check against some user input. But surprisingly, the "input" parameter
of validate must be a non-const WString, making things like this
impossible:

if (this->validatorMail->validate (this->txtJabber->text ()) ==  
WValidator::Valid) {
   // ...
}

So, I opened up the source and header file of WRegExpValidator and simply
added "const" (It works fine) - I haven't found a reason for needing a
non-const WString. So, I think that the devers simply overlooked this one.

$ git diff
diff --git a/src/Wt/WRegExpValidator b/src/Wt/WRegExpValidator
index a1656e8..39c1dc2 100644
--- a/src/Wt/WRegExpValidator
+++ b/src/Wt/WRegExpValidator
@@ -101,7 +101,7 @@ public:
     * The input is considered valid only when it is blank for a  
non-mandatory
     * field, or matches the regular expression.
     */
-  virtual State validate(WT_USTRING& input) const;
+  virtual State validate(const WT_USTRING& input) const;

    virtual void createExtConfig(std::ostream& config) const;

diff --git a/src/Wt/WRegExpValidator.C b/src/Wt/WRegExpValidator.C
index 0559e93..c9f3e0c 100644
--- a/src/Wt/WRegExpValidator.C
+++ b/src/Wt/WRegExpValidator.C
@@ -85,7 +85,7 @@ WString WRegExpValidator::invalidNoMatchText() const
      return WString::tr("Wt.WRegExpValidator.Invalid");
  }

-WValidator::State WRegExpValidator::validate(WT_USTRING& input) const
+WValidator::State WRegExpValidator::validate(const WT_USTRING& input)  
const
  {
    if (isMandatory()) {
      if (input.empty())

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to