X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FExchangePlugin%2FExchangePlugin_Validators.cpp;h=e0579464007a69089e5e9578d58dfcb40bb747bb;hb=e32f95642855a63da2727cb324ce2a75632a712f;hp=16df0a1fe6b5946f4940f14cf3cad44b350882dd;hpb=f565325d5c15b590237ae70c1ac6e57b448579ad;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/ExchangePlugin_Validators.cpp b/src/ExchangePlugin/ExchangePlugin_Validators.cpp index 16df0a1fe..e05794640 100644 --- a/src/ExchangePlugin/ExchangePlugin_Validators.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Validators.cpp @@ -1,8 +1,8 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -// File: SketchPlugin_Validators.cpp -// Created: 01 Aug 2014 -// Author: Vitaly SMETANNIKOV +// File: ExchangePlugin_Validators.cpp +// Created: Aug 01, 2014 +// Author: Sergey BELASH #include @@ -38,19 +38,26 @@ bool ExchangePlugin_FormatValidator::parseFormats(const std::list& } bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const + const std::list& theArguments, + std::string& theError) const { - if (!theAttribute->isInitialized()) + if (!theAttribute->isInitialized()) { + theError = "Is not initialized."; return false; + } const AttributeStringPtr aStrAttr = std::dynamic_pointer_cast(theAttribute); - if (!aStrAttr) + if (!aStrAttr) { + theError = "Is not a string attribute."; return false; + } std::string aFileName = aStrAttr->value(); - if (aFileName.empty()) + if (aFileName.empty()) { + theError = "File name is empty."; return false; + } std::list aFormats; ExchangePlugin_FormatValidator::parseFormats(theArguments, aFormats); @@ -59,10 +66,13 @@ bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute, std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper); // Is file name ends with the format for (; itFormats != aFormats.end(); ++itFormats) { - size_t aFormatBeginPos = aFileNameLen - (*itFormats).length(); - if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) { - return true; + if (aFileNameLen > (*itFormats).length()) { + size_t aFormatBeginPos = aFileNameLen - (*itFormats).length(); + if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) { + return true; + } } } + theError = "File name does not end with any available format."; return false; }