From: sbh Date: Mon, 13 Apr 2015 15:37:38 +0000 (+0300) Subject: Variable validation without regexp X-Git-Tag: V_1.1.0~37 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d5e6330e9901d4bb7c1abbf5e5a78f4e8b30004;p=modules%2Fshaper.git Variable validation without regexp --- diff --git a/src/ParametersPlugin/ParametersPlugin_Validators.cpp b/src/ParametersPlugin/ParametersPlugin_Validators.cpp index dc7eb066c..788e16398 100644 --- a/src/ParametersPlugin/ParametersPlugin_Validators.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Validators.cpp @@ -13,7 +13,6 @@ ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator() { - myPyVariableRegex = std::regex("[_a-zA-Z][a-zA-Z0-9_]*"); } ParametersPlugin_VariableValidator::~ParametersPlugin_VariableValidator() @@ -24,10 +23,24 @@ bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribut const std::list& theArguments) const { AttributeStringPtr aStrAttr = std::dynamic_pointer_cast(theAttribute); - bool result = std::regex_match(aStrAttr->value(), myPyVariableRegex); + bool result = isVariable(aStrAttr->value()); return result; } +bool ParametersPlugin_VariableValidator::isVariable(const std::string& theString) const +{ + std::string::const_iterator it = theString.begin(); + if (!(isalpha(*it) || (*it) == '_') || it == theString.end()) + return false; + it++; + for ( ; it != theString.end(); ++it ) { + if(!(isalnum(*it) || (*it) == '_')) { + return false; + } + } + return true; +} + ParametersPlugin_ExpressionValidator::ParametersPlugin_ExpressionValidator() { diff --git a/src/ParametersPlugin/ParametersPlugin_Validators.h b/src/ParametersPlugin/ParametersPlugin_Validators.h index 3a4db55c8..be8f285b5 100644 --- a/src/ParametersPlugin/ParametersPlugin_Validators.h +++ b/src/ParametersPlugin/ParametersPlugin_Validators.h @@ -13,7 +13,6 @@ #include -#include #include class ParametersPlugin_VariableValidator : public ModelAPI_AttributeValidator @@ -28,8 +27,9 @@ class ParametersPlugin_VariableValidator : public ModelAPI_AttributeValidator PARAMETERSPLUGIN_EXPORT virtual bool isValid(const AttributePtr& theAttribute, const std::list& theArguments) const; - private: - std::regex myPyVariableRegex; + protected: + PARAMETERSPLUGIN_EXPORT bool isVariable(const std::string& theString) const; + }; class ParametersPlugin_ExpressionValidator: public ModelAPI_AttributeValidator