From ad7130a3ada97609b6b63508b30e715a7dc61f0d Mon Sep 17 00:00:00 2001 From: asl Date: Wed, 25 Nov 2009 12:38:34 +0000 Subject: [PATCH] correct conversion into int and real --- src/Notebook/SALOME_EvalVariant.cxx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Notebook/SALOME_EvalVariant.cxx b/src/Notebook/SALOME_EvalVariant.cxx index 403458c0c..d0a218c76 100755 --- a/src/Notebook/SALOME_EvalVariant.cxx +++ b/src/Notebook/SALOME_EvalVariant.cxx @@ -354,10 +354,10 @@ bool SALOME_EvalVariant::toBool() const //======================================================================= int SALOME_EvalVariant::toInt(bool *ok) const { - *ok=false; - // + if( ok ) + *ok = true; + SALOME_EvalVariantType aType=type(); - // if (aType == SALOME_EvalVariant_Boolean ) { return (int)DataValueBoolean(); } @@ -372,10 +372,10 @@ int SALOME_EvalVariant::toInt(bool *ok) const } else if (aType == SALOME_EvalVariant_String) { int iRet; - // - const SALOME_String& aStr=DataValueString(); - const char *pStr=aStr.c_str(); - iRet=atoi(pStr); + const SALOME_String& aStr = DataValueString(); + bool res = sscanf( aStr.c_str(), "%i", &iRet ) == 1; + if( ok ) + *ok = res; return iRet; } return 0; @@ -398,7 +398,8 @@ uint SALOME_EvalVariant::toUInt(bool *ok) const //======================================================================= double SALOME_EvalVariant::toDouble(bool *ok) const { - *ok=false; + if( ok ) + *ok = true; // SALOME_EvalVariantType aType=type(); // @@ -417,9 +418,10 @@ double SALOME_EvalVariant::toDouble(bool *ok) const else if (aType == SALOME_EvalVariant_String) { double dRet; // - const SALOME_String& aStr=DataValueString(); - const char *pStr=aStr.c_str(); - dRet=atof(pStr); + const SALOME_String& aStr = DataValueString(); + bool res = sscanf( aStr.c_str(), "%lf", &dRet ) == 1; + if( ok ) + *ok = res; return dRet; } return 0.; -- 2.39.2