1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0031226: Foundation Classes - TCollection_AsciiString::IsRealValue() returns true if a string contains a non-real value

- Added comment to the method
- Added Boolean argument indicating the need for a strict
- Extended OCC11758 command in QABugs_19.cxx to verify IsRealValue()
- Updated existing places of IsRealValue() usage in ViewerTest to use new flag
This commit is contained in:
mkrylova 2020-12-14 15:18:43 +03:00 committed by bugmaster
parent 5fd0b80027
commit d45edf248c
8 changed files with 76 additions and 65 deletions

View File

@ -753,7 +753,9 @@ static Standard_Integer OCC11758 (Draw_Interpretor& di, Standard_Integer n, cons
TCollection_AsciiString d( 0.1*i );
//assert( d.IsRealValue() );
//assert( TCollection_AsciiString(3.3) == "3.3");
QCOMPARE ( d.IsRealValue() , Standard_True );
QCOMPARE ( d.IsRealValue (Standard_True) , Standard_True );
QCOMPARE (TCollection_AsciiString("3.3!").IsRealValue (Standard_True), Standard_False);
QCOMPARE (TCollection_AsciiString("3.3!").IsRealValue (Standard_False), Standard_True);
QCOMPARE ( TCollection_AsciiString(3.3) , "3.3" );
//TCollection_AsciiString(const TCollection_AsciiString& astring)

View File

@ -763,11 +763,18 @@ Standard_Boolean TCollection_AsciiString::IsIntegerValue()const
// ----------------------------------------------------------------------------
// IsRealValue
// ----------------------------------------------------------------------------
Standard_Boolean TCollection_AsciiString::IsRealValue()const
Standard_Boolean TCollection_AsciiString::IsRealValue (Standard_Boolean theToCheckFull)const
{
char *ptr;
Strtod(mystring,&ptr);
return (ptr != mystring);
if (theToCheckFull)
{
return (ptr[0] == '\0');
}
else
{
return (ptr != mystring);
}
}
// ----------------------------------------------------------------------------

View File

@ -444,9 +444,11 @@ Standard_Boolean operator > (const TCollection_AsciiString& other) const
//! Note: an integer value is considered to be a real value as well.
Standard_EXPORT Standard_Boolean IsIntegerValue() const;
//! Returns True if the AsciiString contains a real value.
//! Returns True if the AsciiString starts with some characters that can be interpreted as integer or real value.
//! @param theToCheckFull [in] when TRUE, checks if entire string defines a real value;
//! otherwise checks if string starts with a real value
//! Note: an integer value is considered to be a real value as well.
Standard_EXPORT Standard_Boolean IsRealValue() const;
Standard_EXPORT Standard_Boolean IsRealValue (Standard_Boolean theToCheckFull = Standard_False) const;
//! Returns True if the AsciiString contains only ASCII characters
//! between ' ' and '~'.

View File

@ -2258,7 +2258,7 @@ static Standard_Integer VAspects (Draw_Interpretor& theDI,
if (aCmdName == "vsetwidth")
{
if (aNames.IsEmpty()
|| !aNames.Last().IsRealValue())
|| !aNames.Last().IsRealValue (Standard_True))
{
Message::SendFail ("Error: not enough arguments!");
return 1;
@ -2321,7 +2321,7 @@ static Standard_Integer VAspects (Draw_Interpretor& theDI,
else if (aCmdName == "vsettransparency")
{
if (aNames.IsEmpty()
|| !aNames.Last().IsRealValue())
|| !aNames.Last().IsRealValue (Standard_True))
{
Message::SendFail ("Error: not enough arguments!");
return 1;
@ -2357,7 +2357,7 @@ static Standard_Integer VAspects (Draw_Interpretor& theDI,
else if (aCmdName == "vsetinteriorstyle")
{
if (aNames.IsEmpty()
|| !aNames.Last().IsRealValue())
|| !aNames.Last().IsRealValue (Standard_True))
{
Message::SendFail ("Error: not enough arguments!");
return 1;
@ -2398,7 +2398,7 @@ static Standard_Integer VAspects (Draw_Interpretor& theDI,
}
}
if (aNames.Size() == 6
&& aNames.Value (6).IsRealValue())
&& aNames.Value (6).IsRealValue (Standard_True))
{
aChangeSet->ToSetFaceBoundaryWidth = 1;
aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue();
@ -2560,7 +2560,7 @@ static Standard_Integer VAspects (Draw_Interpretor& theDI,
&& theArgVec[anArgIter + 1][0] != '-')
{
TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
if (aParam2.IsRealValue())
if (aParam2.IsRealValue (Standard_True))
{
aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
++anArgIter;
@ -4208,8 +4208,8 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
else if (anArgIter + 1 < theArgsNb)
{
TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
if (aValU.IsRealValue()
&& aValV.IsRealValue())
if (aValU.IsRealValue (Standard_True)
&& aValV.IsRealValue (Standard_True))
{
aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
++anArgIter;
@ -4243,8 +4243,8 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
else if (anArgIter + 1 < theArgsNb)
{
TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
if (aValU.IsRealValue()
&& aValV.IsRealValue())
if (aValU.IsRealValue (Standard_True)
&& aValV.IsRealValue (Standard_True))
{
aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
++anArgIter;
@ -4278,8 +4278,8 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
else if (anArgIter + 1 < theArgsNb)
{
TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
if (aValU.IsRealValue()
&& aValV.IsRealValue())
if (aValU.IsRealValue (Standard_True)
&& aValV.IsRealValue (Standard_True))
{
aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
++anArgIter;
@ -4976,8 +4976,8 @@ static int VDisplay2 (Draw_Interpretor& theDI,
TCollection_AsciiString aX (theArgVec[++anArgIter]);
TCollection_AsciiString aY (theArgVec[++anArgIter]);
TCollection_AsciiString aZ = "0";
if (!aX.IsRealValue()
|| !aY.IsRealValue())
if (!aX.IsRealValue (Standard_True)
|| !aY.IsRealValue (Standard_True))
{
Message::SendFail() << "Error: wrong syntax at " << aName << ".";
return 1;
@ -4985,7 +4985,7 @@ static int VDisplay2 (Draw_Interpretor& theDI,
if (anArgIter + 1 < theArgNb)
{
TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
if (aTemp.IsRealValue())
if (aTemp.IsRealValue (Standard_True))
{
aZ = aTemp;
++anArgIter;

View File

@ -288,7 +288,7 @@ namespace
{
TCollection_AsciiString anArg (theArgVec [anArgIt]);
if (anArg.Value (1) == '-'
&& !anArg.IsRealValue())
&& !anArg.IsRealValue (Standard_True))
{
aParseKey = anArg;
aParseKey.Remove (1);
@ -3742,7 +3742,7 @@ bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand
for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
{
aStrCommand = theArgsArray->Value (theArgIndex);
if (!aStrCommand.IsRealValue())
if (!aStrCommand.IsRealValue (Standard_True))
return false;
}
@ -3950,8 +3950,8 @@ namespace
TCollection_AsciiString anX (theArgVec[0]);
TCollection_AsciiString anY (theArgVec[1]);
if (!anX.IsRealValue()
|| !anY.IsRealValue())
if (!anX.IsRealValue (Standard_True)
|| !anY.IsRealValue (Standard_True))
{
return 0;
}
@ -3961,7 +3961,7 @@ namespace
if (theArgNb >= 3)
{
TCollection_AsciiString anZ (theArgVec[2]);
if (anZ.IsRealValue())
if (anZ.IsRealValue (Standard_True))
{
theVec.SetZ (anZ.RealValue());
return 3;
@ -4112,7 +4112,7 @@ static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
Standard_Integer aScaleArgIter = 0;
for (; aScaleArgIter < 4; ++aScaleArgIter)
{
if (!aScaleArgs[aScaleArgIter].IsRealValue())
if (!aScaleArgs[aScaleArgIter].IsRealValue (Standard_True))
{
break;
}
@ -4135,7 +4135,7 @@ static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
else if (anArgIter + 1 < theArgNb)
{
TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
if (aScaleArg.IsRealValue())
if (aScaleArg.IsRealValue (Standard_True))
{
aScale = aScaleArg.RealValue();
++anArgIter;
@ -4238,7 +4238,7 @@ static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
Standard_Integer aQuatArgIter = 0;
for (; aQuatArgIter < 4; ++aQuatArgIter)
{
if (!aQuatArgs[aQuatArgIter].IsRealValue())
if (!aQuatArgs[aQuatArgIter].IsRealValue (Standard_True))
{
break;
}
@ -6387,7 +6387,7 @@ static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
Standard_CString anArg = theArgs[anArgIter];
TCollection_AsciiString aFlag (anArg);
aFlag.LowerCase();
if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
if (aFlag.IsRealValue (Standard_True) || aFlag.Search ("-") != 1)
{
aCmdArgs++;
}

View File

@ -380,7 +380,7 @@ static int ParseDimensionParams (Standard_Integer theArgNum,
else if (aParam.IsEqual ("-arrowlength") || aParam.IsEqual ("-arlen"))
{
TCollection_AsciiString aValue (theArgVec[++anIt]);
if (!aValue.IsRealValue())
if (!aValue.IsRealValue (Standard_True))
{
Message::SendFail() << "Error: arrow lenght should be float degree value.";
return 1;
@ -390,7 +390,7 @@ static int ParseDimensionParams (Standard_Integer theArgNum,
else if (aParam.IsEqual ("-arrowangle") || aParam.IsEqual ("-arangle"))
{
TCollection_AsciiString aValue (theArgVec[++anIt]);
if (!aValue.IsRealValue())
if (!aValue.IsRealValue (Standard_True))
{
Message::SendFail ("Error: arrow angle should be float degree value.");
return 1;
@ -414,7 +414,7 @@ static int ParseDimensionParams (Standard_Integer theArgNum,
else if (aParam.IsEqual ("-extension"))
{
TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
if (!aLocalParam.IsRealValue())
if (!aLocalParam.IsRealValue (Standard_True))
{
Message::SendFail ("Error: extension size for dimension should be real value.");
return 1;
@ -449,7 +449,7 @@ static int ParseDimensionParams (Standard_Integer theArgNum,
else if (aParam.IsEqual ("-flyout"))
{
TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
if (!aLocalParam.IsRealValue())
if (!aLocalParam.IsRealValue (Standard_True))
{
Message::SendFail ("Error: flyout for dimension should be real value.");
return 1;
@ -460,7 +460,7 @@ static int ParseDimensionParams (Standard_Integer theArgNum,
else if (aParam.IsEqual ("-value"))
{
TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
if (!aLocalParam.IsRealValue())
if (!aLocalParam.IsRealValue (Standard_True))
{
Message::SendFail ("Error: dimension value for dimension should be real value");
return 1;
@ -1671,7 +1671,7 @@ static int VLengthParam (Draw_Interpretor&, Standard_Integer theArgNum, const ch
for (; anArgumentIt < theArgNum; ++anArgumentIt)
{
TCollection_AsciiString anArg (theArgVec[anArgumentIt]);
if (!anArg.IsRealValue())
if (!anArg.IsRealValue (Standard_True))
{
break;
}

View File

@ -3847,7 +3847,7 @@ static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char**
{
Standard_Real aFps = -1.0;
if (anArgIter + 1 < theArgNb
&& TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue())
&& TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue (Standard_True))
{
aFps = Draw::Atof (theArgVec[++anArgIter]);
}
@ -4449,8 +4449,8 @@ static int VColorScale (Draw_Interpretor& theDI,
const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
if (!aRangeMin.IsRealValue()
|| !aRangeMax.IsRealValue())
if (!aRangeMin.IsRealValue (Standard_True)
|| !aRangeMax.IsRealValue (Standard_True))
{
Message::SendFail ("Syntax error: the range values should be real");
return 1;
@ -4882,7 +4882,7 @@ static int VColorScale (Draw_Interpretor& theDI,
TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
if (!anArg1.IsRealValue())
if (!anArg1.IsRealValue (Standard_True))
{
Message::SendFail ("Syntax error: the value should be real");
return 1;
@ -4948,7 +4948,7 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
{
TCollection_AsciiString anArg (theArgs [anArgIt]);
if (anArg.Value (1) == '-' && !anArg.IsRealValue())
if (anArg.Value (1) == '-' && !anArg.IsRealValue (Standard_True))
{
aParseKey = anArg;
aParseKey.Remove (1);
@ -4999,7 +4999,7 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
// One string argument
if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
|| aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
&& anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
&& anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue (Standard_True))
{
continue;
}
@ -5016,14 +5016,14 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
// One real argument
if ( aKey.IsEqual ("arrowlength")
&& anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
&& anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue (Standard_True)))
{
continue;
}
// Two string arguments
if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
&& anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
&& anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue (Standard_True))
{
continue;
}
@ -6249,7 +6249,7 @@ static int VConvert (Draw_Interpretor& theDI,
for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
{
TCollection_AsciiString anArg (theArgVec[anArgIdx]);
if (!anArg.IsRealValue())
if (!anArg.IsRealValue (Standard_True))
{
break;
}
@ -7402,7 +7402,7 @@ static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const
}
}
else if (aTolColor < 0.0
&& anArg.IsRealValue())
&& anArg.IsRealValue (Standard_True))
{
isOldSyntax = Standard_True;
aTolColor = anArg.RealValue();
@ -7822,9 +7822,9 @@ namespace
static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
{
const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
if (!anXYZ[0].IsRealValue()
|| !anXYZ[1].IsRealValue()
|| !anXYZ[2].IsRealValue())
if (!anXYZ[0].IsRealValue (Standard_True)
|| !anXYZ[1].IsRealValue (Standard_True)
|| !anXYZ[2].IsRealValue (Standard_True))
{
return Standard_False;
}
@ -7837,10 +7837,10 @@ namespace
static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
{
const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
if (!anXYZW[0].IsRealValue()
|| !anXYZW[1].IsRealValue()
|| !anXYZW[2].IsRealValue()
|| !anXYZW[3].IsRealValue())
if (!anXYZW[0].IsRealValue (Standard_True)
|| !anXYZW[1].IsRealValue (Standard_True)
|| !anXYZW[2].IsRealValue (Standard_True)
|| !anXYZW[3].IsRealValue (Standard_True))
{
return Standard_False;
}
@ -7972,7 +7972,7 @@ static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, con
&& *theArgVec[anArgIter + 1] != '-')
{
const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
if (aValueArg.IsRealValue())
if (aValueArg.IsRealValue (Standard_True))
{
++anArgIter;
if (anArg == "-scale")
@ -8588,7 +8588,7 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
}
const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
if (!aScaleStr.IsRealValue())
if (!aScaleStr.IsRealValue (Standard_True))
{
Message::SendFail() << "Syntax error at " << aTrsfArg;
return 1;
@ -8654,7 +8654,7 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
}
const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
if (!aScaleStr.IsRealValue())
if (!aScaleStr.IsRealValue (Standard_True))
{
Message::SendFail() << "Syntax error at " << aViewArg;
return 1;
@ -9162,9 +9162,9 @@ static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb,
isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
(aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
(aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
anAngleOpt.IsRealValue());
aSScaleOpt.IsRealValue (Standard_True) && aTScaleOpt.IsRealValue (Standard_True) &&
aSTransOpt.IsRealValue (Standard_True) && aTTransOpt.IsRealValue (Standard_True) &&
anAngleOpt.IsRealValue (Standard_True));
}
}
}
@ -9625,7 +9625,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
{
TCollection_AsciiString aValStr (aChangeArgs[1]);
Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
if (aValStr.IsRealValue())
if (aValStr.IsRealValue (Standard_True))
{
Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
aMat.SetTransparency ((float )aValStr.RealValue());
@ -11790,7 +11790,7 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
TCollection_AsciiString aParam = theArgVec[anArgIter];
aParam.LowerCase();
if (aParam.IsRealValue())
if (aParam.IsRealValue (Standard_True))
{
const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
if (aWeight < 0.f || aWeight > 1.f)
@ -12011,7 +12011,7 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
}
const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
if (!aMaxRadStr.IsRealValue())
if (!aMaxRadStr.IsRealValue (Standard_True))
{
Message::SendFail() << "Syntax error at argument '" << anArg << "'";
return 1;
@ -12344,7 +12344,7 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
}
TCollection_AsciiString aParam (theArgVec[anArgIter]);
if (aParam.IsRealValue())
if (aParam.IsRealValue (Standard_True))
{
float aFocalDist = static_cast<float> (aParam.RealValue());
if (aFocalDist < 0)
@ -12369,7 +12369,7 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
}
TCollection_AsciiString aParam(theArgVec[anArgIter]);
if (aParam.IsRealValue())
if (aParam.IsRealValue (Standard_True))
{
float aApertureSize = static_cast<float> (aParam.RealValue());
if (aApertureSize < 0)
@ -12394,7 +12394,7 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
}
TCollection_AsciiString anExposure (theArgVec[anArgIter]);
if (anExposure.IsRealValue())
if (anExposure.IsRealValue (Standard_True))
{
aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
}
@ -12413,7 +12413,7 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
}
TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
if (aWhitePoint.IsRealValue())
if (aWhitePoint.IsRealValue (Standard_True))
{
aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
}

View File

@ -22,7 +22,7 @@ set up_y 0.398446
set up_z 0.825238
set at_x 146.11
set at_y -109.936
set at_z 60.2014"
set at_z 60.2014
vviewparams -scale ${scale} -proj ${proj_x} ${proj_y} ${proj_z} -up ${up_x} ${up_y} ${up_z} -at ${at_x} ${at_y} ${at_z}
checkview -screenshot -3d -path ${imagedir}/${test_image}.png