diff --git a/src/BOPTest/BOPTest_BOPCommands.cxx b/src/BOPTest/BOPTest_BOPCommands.cxx index 54f81943f7..331669ba27 100755 --- a/src/BOPTest/BOPTest_BOPCommands.cxx +++ b/src/BOPTest/BOPTest_BOPCommands.cxx @@ -325,19 +325,11 @@ Standard_Integer bsection(Draw_Interpretor& di, const char* key2 = (n > 5) ? a[5] : NULL; const char* pcurveconf = NULL; -#ifdef WNT if (key1 && (!strcasecmp(key1,"-n2d") || !strcasecmp(key1,"-n2d1") || !strcasecmp(key1,"-n2d2"))) { -#else - if (key1 && (!strncasecmp(key1,"-n2d", 4) || !strncasecmp(key1,"-n2d1", 5) || !strncasecmp(key1,"-n2d2", 5))) { -#endif pcurveconf = key1; } else { -#ifdef WNT if (!strcasecmp(key1,"-na")) { -#else - if(!strncasecmp(key1,"-na", 3)) { -#endif bApp = Standard_False; } else { @@ -345,11 +337,7 @@ Standard_Integer bsection(Draw_Interpretor& di, } } if (key2) { -#ifdef WNT if(!strcasecmp(key2,"-na")) { -#else - if (!strncasecmp(key2,"-na", 3)) { -#endif bApp = Standard_False; } else { @@ -358,27 +346,15 @@ Standard_Integer bsection(Draw_Interpretor& di, } if(!isbadparameter && pcurveconf) { -#ifdef WNT if (!strcasecmp(pcurveconf, "-n2d1")) { -#else - if (!strncasecmp(pcurveconf, "-n2d1", 5)) { -#endif bPC1 = Standard_False; } else { -#ifdef WNT if (!strcasecmp(pcurveconf, "-n2d2")) { -#else - if (!strncasecmp(pcurveconf, "-n2d2", 5)) { -#endif bPC2 = Standard_False; } else { -#ifdef WNT if (!strcasecmp(pcurveconf, "-n2d")) { -#else - if (!strncasecmp(pcurveconf, "-n2d", 4)) { -#endif bPC1 = Standard_False; bPC2 = Standard_False; } diff --git a/src/BRepTest/BRepTest_TopologyCommands.cxx b/src/BRepTest/BRepTest_TopologyCommands.cxx index 322f9e2c9d..cef27f9ead 100755 --- a/src/BRepTest/BRepTest_TopologyCommands.cxx +++ b/src/BRepTest/BRepTest_TopologyCommands.cxx @@ -104,58 +104,35 @@ static Standard_Integer section(Draw_Interpretor& , Standard_Integer n, const ch BRepAlgo_Section Sec(s1, s2, Standard_False); TopoDS_Shape res; - if (n > 4) { -#ifdef WNT - if (!strcasecmp(a[4],"-2d") || !strcasecmp(a[4], "-no2d")) { -#else - if (!strncasecmp(a[4],"-2d", 3) || !strcasecmp(a[4], "-no2d")) { -#endif - if (!strcasecmp(a[4], "-2d")) { - Sec.ComputePCurveOn1(Standard_True); - Sec.ComputePCurveOn2(Standard_True); - } else - if (!strcasecmp(a[4], "-2d1")) - Sec.ComputePCurveOn1(Standard_True); - else - if (!strcasecmp(a[4], "-2d2")) - Sec.ComputePCurveOn2(Standard_True); - else - if (strcasecmp(a[4], "-no2d")) - return 1; - if(n > 5) - if (!strcasecmp(a[5], "-a")) - Sec.Approximation(TopOpeBRepTool_APPROX); - else - if (strcasecmp(a[5], "-p")) - return 1; - } else {// fin a[4],"-2d" - if (!strcasecmp(a[4], "-a") || !strcasecmp(a[4], "-p")) { - if (!strcasecmp(a[4], "-a")) - Sec.Approximation(TopOpeBRepTool_APPROX); - if(n > 5) { -#ifdef WNT - if (!strcasecmp(a[5],"-2d") || !strcasecmp(a[5], "-no2d")) { -#else - if (!strncasecmp(a[5],"-2d", 3) || !strcasecmp(a[5], "-no2d")) { -#endif - if (!strcasecmp(a[5], "-2d")) { - Sec.ComputePCurveOn1(Standard_True); - Sec.ComputePCurveOn2(Standard_True); - } else - if (!strcasecmp(a[5], "-2d1")) - Sec.ComputePCurveOn1(Standard_True); - else - if (!strcasecmp(a[5], "-2d2")) - Sec.ComputePCurveOn2(Standard_True); - else - if (strcasecmp(a[5], "-no2d")) - return 1; - } - } - } else // fin a[4],"-a" - return 1; + for (int i=4; i < n; i++) { + if (!strcasecmp(a[i], "-2d")) + { + Sec.ComputePCurveOn1(Standard_True); + Sec.ComputePCurveOn2(Standard_True); + } + else if (!strcasecmp(a[i], "-2d1")) + { + Sec.ComputePCurveOn1(Standard_True); + Sec.ComputePCurveOn2(Standard_False); + } + else if (!strcasecmp(a[i], "-2d2")) + { + Sec.ComputePCurveOn1(Standard_False); + Sec.ComputePCurveOn2(Standard_True); + } + else if (!strcasecmp(a[i], "-no2d")) + { + Sec.ComputePCurveOn1(Standard_False); + Sec.ComputePCurveOn2(Standard_False); + } + else if (!strcasecmp(a[i], "-a")) + Sec.Approximation(Standard_True); + else if (strcasecmp(a[i], "-p")) + { + cout << "Unknown option: " << a[i] << endl; + return 1; } - }// fin n > 4 + } res = Sec.Shape(); diff --git a/src/DDataStd/DDataStd_BasicCommands.cxx b/src/DDataStd/DDataStd_BasicCommands.cxx index a3b44cc2de..eb4ea8e525 100755 --- a/src/DDataStd/DDataStd_BasicCommands.cxx +++ b/src/DDataStd/DDataStd_BasicCommands.cxx @@ -99,13 +99,6 @@ #include #include -#include -#ifdef OptJr -#define ROUNDMEM(len) (((len)+3)&~0x3) -#else -#define ROUNDMEM(len) (len) -#endif - //======================================================================= //function : DDataStd_SetInteger //purpose : SetInteger (DF, entry, value) @@ -1128,7 +1121,7 @@ static Standard_Integer DDataStd_GetUTFtoFile (Draw_Interpretor& di, unsigned char prefix[4] = {0xEF,0xBB,0xBF, 0x00}; anOS.write( (char*)&prefix[0], 3); Standard_Integer n = aES.LengthOfCString(); - Standard_PCharacter aCstr = (Standard_PCharacter) Standard::Allocate(ROUNDMEM(n+1)); + Standard_PCharacter aCstr = (Standard_PCharacter) Standard::Allocate(n+1); n = aES.ToUTF8CString(aCstr); anOS.write( (char*)&aCstr[0], n); anOS.close(); diff --git a/src/Image/Image_AlienPixMap.cxx b/src/Image/Image_AlienPixMap.cxx index caef10b0ea..fd00cfb822 100644 --- a/src/Image/Image_AlienPixMap.cxx +++ b/src/Image/Image_AlienPixMap.cxx @@ -495,7 +495,7 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName) #else const Standard_Integer aLen = theFileName.Length(); if ((aLen >= 4) && (theFileName.Value (aLen - 3) == '.') - && TCollection_AsciiString::ISSIMILAR (theFileName.SubString (aLen - 2, aLen), "ppm")) + && strcasecmp( theFileName.ToCString() + aLen - 3, "ppm") == 0 ) { return savePPM (theFileName); } diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index 51a56147b9..cc85faf99e 100755 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -47,6 +47,11 @@ #include #include +#include + +#define QCOMPARE(val1, val2) \ + di << "Checking " #val1 " == " #val2 << \ + ((val1) == (val2) ? ": OK\n" : ": Error\n") static Standard_Integer OCC230 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) { @@ -174,10 +179,6 @@ private: }; #endif -#define QCOMPARE(val1, val2) \ - di << "Checking " #val1 " == " #val2 << \ - ((val1) == (val2) ? ": OK\n" : ": Error\n") - #ifdef HAVE_TBB static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/) { @@ -677,6 +678,472 @@ static Standard_Integer OCC24019 (Draw_Interpretor& di, Standard_Integer argc, c return 0; } +//======================================================================= +//function : OCC11758 +//purpose : +//======================================================================= +static Standard_Integer OCC11758 (Draw_Interpretor& di, Standard_Integer n, const char** argv) +{ + if (n != 1) return 1; + + const char* theStr = "0123456789"; + Standard_Integer i, j; + for ( i = 0; i < 5; ++i ) { + // TCollection_AsciiString(const Standard_CString astring) + TCollection_AsciiString a(theStr+i); + // IsEqual (const Standard_CString other)const + //assert( a == theStr+i ); + QCOMPARE ( a , theStr+i ); + + //TCollection_AsciiString(const Standard_CString astring,const Standard_Integer aLen ) + TCollection_AsciiString b(theStr+i, 3); + //assert( b.Length() == 3 ); + //assert( strncmp( b.ToCString(), theStr+i, 3 ) == 0 ); + //assert( strlen( b.ToCString() ) == 3 ); + QCOMPARE ( b.Length() , 3 ); + QCOMPARE ( strncmp( b.ToCString() , theStr+i, 3 ) , 0 ); + QCOMPARE ( b.Length() , 3 ); + + //TCollection_AsciiString(const Standard_Integer aValue) + TCollection_AsciiString c(i); + //assert( c.IsIntegerValue() ); + //assert( c.IntegerValue() == i ); + QCOMPARE ( c.IsIntegerValue() , Standard_True ); + QCOMPARE ( c.IntegerValue() , i ); + + //TCollection_AsciiString(const Standard_Real aValue) + TCollection_AsciiString d( 0.1*i ); + //assert( d.IsRealValue() ); + //assert( TCollection_AsciiString(3.3) == "3.3"); + QCOMPARE ( d.IsRealValue() , Standard_True ); + QCOMPARE ( TCollection_AsciiString(3.3) , "3.3" ); + + //TCollection_AsciiString(const TCollection_AsciiString& astring) + TCollection_AsciiString e(d); + //assert( e == d ); + //assert( e.Length() == d.Length() ); + //assert( strcmp( e.ToCString(), d.ToCString() ) == 0 ); + QCOMPARE ( e ,d ); + QCOMPARE ( e.Length() , d.Length() ); + QCOMPARE ( strcmp( e.ToCString(), d.ToCString() ) , 0 ); + + // TCollection_AsciiString(const TCollection_AsciiString& astring , + // const Standard_Character other ) + TCollection_AsciiString f(e,'\a'); + //assert( f.Length() == e.Length() + 1 ); + //assert( strncmp( f.ToCString(), e.ToCString(), e.Length() ) == 0 ); + //assert( f.Value( f.Length() ) == '\a'); + QCOMPARE ( f.Length() , e.Length() + 1 ); + QCOMPARE ( strncmp( f.ToCString(), e.ToCString(), e.Length() ) , 0 ); + QCOMPARE ( f.Value( f.Length() ) , '\a' ); + + // TCollection_AsciiString(const TCollection_AsciiString& astring , + // const Standard_CString other ) + TCollection_AsciiString g(f, theStr); + //assert( g.Length() == f.Length() + strlen( theStr )); + //assert( strncmp( g.ToCString(), f.ToCString(), f.Length() ) == 0 ); + //assert( g.Search( theStr ) == f.Length() + 1 ); + QCOMPARE ( g.Length() , f.Length() + (Standard_Integer)strlen( theStr ) ); + QCOMPARE ( strncmp( g.ToCString(), f.ToCString(), f.Length() ) , 0 ); + QCOMPARE ( g.Search( theStr ) , f.Length() + 1 ); + + // TCollection_AsciiString(const TCollection_AsciiString& astring , + // const TCollection_AsciiString& other ) + TCollection_AsciiString h(d,a); + //assert( h.Length() == d.Length() + a.Length() ); + //assert( strncmp( h.ToCString(), d.ToCString(), d.Length() ) == 0 ); + //assert( strncmp( h.ToCString() + d.Length(), a.ToCString(), a.Length() ) == 0 ); + QCOMPARE ( h.Length() , d.Length() + a.Length() ); + QCOMPARE ( strncmp( h.ToCString(), d.ToCString(), d.Length() ) , 0 ); + QCOMPARE ( strncmp( h.ToCString() + d.Length(), a.ToCString(), a.Length() ) , 0 ); + + // AssignCat(const Standard_CString other) + c.AssignCat( a.ToCString() ); + //assert( c.Length() == 1 + a.Length() ); + //assert( c.Search( a ) == 2 ); + QCOMPARE ( c.Length() , 1 + a.Length() ); + QCOMPARE ( c.Search( a ) , 2 ); + + // AssignCat(const TCollection_AsciiString& other) + Standard_Integer dl = d.Length(); + d.AssignCat( a ); + //assert( d.Length() == dl + a.Length() ); + //assert( d.Search( a ) == dl + 1 ); + QCOMPARE ( d.Length() , dl + a.Length() ); + QCOMPARE ( d.Search( a ) , dl + 1 ); + + // Capitalize() + TCollection_AsciiString capitalize("aBC"); + capitalize.Capitalize(); + //assert( capitalize == "Abc" ); + QCOMPARE ( capitalize , "Abc" ); + + // Copy(const Standard_CString fromwhere) + d = theStr+i; + //assert( d == theStr+i ); + QCOMPARE ( d , theStr+i ); + + // Copy(const TCollection_AsciiString& fromwhere) + d = h; + // IsEqual (const TCollection_AsciiString& other)const + //assert( d == h ); + QCOMPARE ( d , h ); + + // Insert(const Standard_Integer where, const Standard_CString what) + dl = d.Length(); + d.Insert( 2, theStr ); + //assert( d.Length() == dl + strlen( theStr )); + //assert( strncmp( d.ToCString() + 1, theStr, strlen( theStr )) == 0 ); + QCOMPARE ( d.Length() , dl + (Standard_Integer)strlen( theStr ) ); + QCOMPARE ( strncmp( d.ToCString() + 1, theStr, strlen( theStr )) , 0 ); + + //Insert(const Standard_Integer where,const Standard_Character what) + d = theStr; + d.Insert( i+1, 'i' ); + //assert( d.Length() == strlen( theStr ) + 1 ); + //assert( d.Value( i+1 ) == 'i'); + //assert( strcmp( d.ToCString() + i + 1, theStr+i ) == 0 ); + QCOMPARE ( d.Length() , (Standard_Integer)strlen( theStr ) + 1 ); + QCOMPARE ( d.Value( i+1 ) , 'i' ); + QCOMPARE ( strcmp( d.ToCString() + i + 1, theStr+i ) , 0 ); + + //Insert(const Standard_Integer where,const TCollection_AsciiString& what) + d = theStr; + d.Insert( i+1, TCollection_AsciiString( "i" )); + //assert( d.Length() == strlen( theStr ) + 1 ); + //assert( d.Value( i+1 ) == 'i'); + //assert( strcmp( d.ToCString() + i + 1, theStr+i ) == 0 ); + QCOMPARE ( d.Length() , (Standard_Integer)strlen( theStr ) + 1 ); + QCOMPARE ( d.Value( i+1 ) , 'i' ); + QCOMPARE ( strcmp( d.ToCString() + i + 1, theStr+i ) , 0 ); + + // IsDifferent (const Standard_CString other)const + //assert( d.IsDifferent( theStr )); + //assert( d.IsDifferent( "theStr" )); + //assert( d.IsDifferent( "" )); + //assert( !d.IsDifferent( d.ToCString() )); + QCOMPARE ( d.IsDifferent( theStr ) , Standard_True ); + QCOMPARE ( d.IsDifferent( "theStr" ) , Standard_True ); + QCOMPARE ( d.IsDifferent( "" ) , Standard_True ); + QCOMPARE ( !d.IsDifferent( d.ToCString() ) , Standard_True ); + + // IsDifferent (const TCollection_AsciiString& other)const + //assert( d.IsDifferent( TCollection_AsciiString() )); + //assert( d.IsDifferent( a )); + //assert( d.IsDifferent( h )); + //assert( !d.IsDifferent( d )); + QCOMPARE ( d.IsDifferent( TCollection_AsciiString() ) , Standard_True ); + QCOMPARE ( d.IsDifferent( a ) , Standard_True ); + QCOMPARE ( d.IsDifferent( h ) , Standard_True ); + QCOMPARE ( !d.IsDifferent( d ) , Standard_True ); + + // IsLess (const Standard_CString other)const + //assert( TCollection_AsciiString ("0"). IsLess("1")); + //assert( TCollection_AsciiString ("0"). IsLess("00")); + //assert( TCollection_AsciiString (""). IsLess("0")); + //assert( !TCollection_AsciiString("1"). IsLess("0")); + //assert( !TCollection_AsciiString("00").IsLess("0")); + //assert( !TCollection_AsciiString("0"). IsLess("")); + //assert( TCollection_AsciiString (theStr+i).IsLess(theStr+i+1)); + QCOMPARE ( TCollection_AsciiString ("0"). IsLess("1") , Standard_True ); + QCOMPARE ( TCollection_AsciiString ("0"). IsLess("00") , Standard_True ); + QCOMPARE ( TCollection_AsciiString (""). IsLess("0") , Standard_True ); + QCOMPARE ( !TCollection_AsciiString("1"). IsLess("0"), Standard_True ); + QCOMPARE ( !TCollection_AsciiString("00").IsLess("0") , Standard_True ); + QCOMPARE ( !TCollection_AsciiString("0"). IsLess("") , Standard_True ); + QCOMPARE ( TCollection_AsciiString (theStr+i).IsLess(theStr+i+1) , Standard_True ); + + // IsLess (const TCollection_AsciiString& other)const + //assert( TCollection_AsciiString ("0"). IsLess(TCollection_AsciiString("1" ))); + //assert( TCollection_AsciiString ("0"). IsLess(TCollection_AsciiString("00"))); + //assert( TCollection_AsciiString (""). IsLess(TCollection_AsciiString("0" ))); + //assert( !TCollection_AsciiString("1"). IsLess(TCollection_AsciiString("0" ))); + //assert( !TCollection_AsciiString("00").IsLess(TCollection_AsciiString("0" ))); + //assert( !TCollection_AsciiString("0"). IsLess(TCollection_AsciiString("" ))); + //assert( TCollection_AsciiString (theStr+i).IsLess(TCollection_AsciiString(theStr+i+1))); + QCOMPARE ( TCollection_AsciiString ("0"). IsLess(TCollection_AsciiString("1" )) , Standard_True ); + QCOMPARE ( TCollection_AsciiString ("0"). IsLess(TCollection_AsciiString("00")) , Standard_True ); + QCOMPARE ( TCollection_AsciiString (""). IsLess(TCollection_AsciiString("0" )) , Standard_True ); + QCOMPARE ( !TCollection_AsciiString("1"). IsLess(TCollection_AsciiString("0" )) , Standard_True ); + QCOMPARE ( !TCollection_AsciiString("00").IsLess(TCollection_AsciiString("0" )) , Standard_True ); + QCOMPARE ( !TCollection_AsciiString("0"). IsLess(TCollection_AsciiString("" )) , Standard_True ); + QCOMPARE ( TCollection_AsciiString (theStr+i).IsLess(TCollection_AsciiString(theStr+i+1)) , Standard_True ); + + // IsGreater (const Standard_CString other)const + //assert( !TCollection_AsciiString("0"). IsGreater("1")); + //assert( !TCollection_AsciiString("0"). IsGreater("00")); + //assert( !TCollection_AsciiString(""). IsGreater("0")); + //assert( TCollection_AsciiString ("1"). IsGreater("0")); + //assert( TCollection_AsciiString ("00").IsGreater("0")); + //assert( TCollection_AsciiString ("0"). IsGreater("")); + //assert( TCollection_AsciiString (theStr+i+1).IsGreater(theStr+i)); + QCOMPARE ( !TCollection_AsciiString("0"). IsGreater("1") , Standard_True ); + QCOMPARE ( !TCollection_AsciiString("0"). IsGreater("00") , Standard_True ); + QCOMPARE ( !TCollection_AsciiString(""). IsGreater("0") , Standard_True ); + QCOMPARE ( TCollection_AsciiString ("1"). IsGreater("0") , Standard_True ); + QCOMPARE ( TCollection_AsciiString ("00").IsGreater("0") , Standard_True ); + QCOMPARE ( TCollection_AsciiString ("0"). IsGreater("") , Standard_True ); + QCOMPARE ( TCollection_AsciiString (theStr+i+1).IsGreater(theStr+i) , Standard_True ); + + // IsGreater (const TCollection_AsciiString& other)const + //assert( !TCollection_AsciiString("0"). IsGreater(TCollection_AsciiString("1" ))); + //assert( !TCollection_AsciiString("0"). IsGreater(TCollection_AsciiString("00"))); + //assert( !TCollection_AsciiString(""). IsGreater(TCollection_AsciiString("0" ))); + //assert( TCollection_AsciiString ("1"). IsGreater(TCollection_AsciiString("0" ))); + //assert( TCollection_AsciiString ("00").IsGreater(TCollection_AsciiString("0" ))); + //assert( TCollection_AsciiString ("0"). IsGreater(TCollection_AsciiString("" ))); + //assert( TCollection_AsciiString (theStr+i+1).IsGreater(TCollection_AsciiString(theStr+i))); + QCOMPARE ( !TCollection_AsciiString("0"). IsGreater(TCollection_AsciiString("1" )) , Standard_True ); + QCOMPARE ( !TCollection_AsciiString("0"). IsGreater(TCollection_AsciiString("00")) , Standard_True ); + QCOMPARE ( !TCollection_AsciiString(""). IsGreater(TCollection_AsciiString("0" )) , Standard_True ); + QCOMPARE ( TCollection_AsciiString ("1"). IsGreater(TCollection_AsciiString("0" )) , Standard_True ); + QCOMPARE ( TCollection_AsciiString ("00").IsGreater(TCollection_AsciiString("0" )) , Standard_True ); + QCOMPARE ( TCollection_AsciiString ("0"). IsGreater(TCollection_AsciiString("" )) , Standard_True ); + QCOMPARE ( TCollection_AsciiString (theStr+i+1).IsGreater(TCollection_AsciiString(theStr+i)) , Standard_True ); + + // void Read(Standard_IStream& astream) + std::istringstream is( theStr ); + e.Read( is ); + //assert( e == theStr ); + QCOMPARE ( e , theStr ); + + // Standard_Integer SearchFromEnd (const Standard_CString what)const + //assert( e.SearchFromEnd( theStr + i ) == i + 1 ); + QCOMPARE ( e.SearchFromEnd( theStr + i ) , i + 1 ); + + // SetValue(const Standard_Integer where, const Standard_CString what) + e.SetValue( i+1, "what"); + //assert( e.Search( "what" ) == i+1 ); + //assert( e.Length() == strlen( theStr )); + QCOMPARE ( e.Search( "what" ) , i+1 ); + QCOMPARE ( e.Length() , (Standard_Integer)strlen( theStr ) ); + + // TCollection_AsciiString Split (const Standard_Integer where) + e = theStr; + d = e.Split( i+1 ); + //assert( d.Length() + e.Length() == strlen( theStr )); + QCOMPARE ( d.Length() + e.Length() , (Standard_Integer)strlen( theStr ) ); + + // TCollection_AsciiString SubString (const Standard_Integer FromIndex, + // const Standard_Integer ToIndex) const + e = theStr; + d = e.SubString( (unsigned int)i+1, (unsigned int)i+3 ); + //assert( d.Length() == 3 ); + //assert( d.Value(1) == theStr[ i ]); + QCOMPARE ( d.Length() , 3 ); + QCOMPARE ( d.Value(1) , theStr[ i ] ); + + // TCollection_AsciiString Token (const Standard_CString separators, + // const Standard_Integer whichone) const + e = " "; + for ( j = 0; j < i; ++j ) { + e += TCollection_AsciiString( theStr[j] ) + " "; + //assert( e.Token(" ", j+1 ) == TCollection_AsciiString( theStr+j, 1 )); + QCOMPARE ( e.Token(" ", j+1 ) , TCollection_AsciiString( theStr+j, 1 ) ); + } + } + for ( i = 0; i < 5; ++i ) + { + // TCollection_ExtendedString (const Standard_CString astring, + // const Standard_Boolean isMultiByte) + const TCollection_ExtendedString a( theStr+i ); + //assert( TCollection_AsciiString( a ) == theStr+i ); + QCOMPARE ( TCollection_AsciiString( a ) , theStr+i ); + + //TCollection_ExtendedString (const Standard_ExtString astring) + const TCollection_ExtendedString b( a.ToExtString() ); + //assert( a == b ); + QCOMPARE ( a , b ); + + // TCollection_ExtendedString (const Standard_Integer length, + // const Standard_ExtCharacter filler ) + const TCollection_ExtendedString c( i, 1 ); + //assert( c.Length() == i ); + QCOMPARE ( c.Length() , i ); + if ( c.Length() > 0 ) { + //assert( c.Value( i ) == 1 ); + QCOMPARE ( c.Value( i ) , 1 ); + } + + // TCollection_ExtendedString (const Standard_Integer aValue) + TCollection_ExtendedString d( i ); + const TCollection_AsciiString da( d ); + //assert( da.IsIntegerValue() ); + //assert( da.IntegerValue() == i ); + QCOMPARE ( da.IsIntegerValue() , Standard_True ); + QCOMPARE ( da.IntegerValue(), i ); + + // TCollection_ExtendedString (const Standard_Real aValue) + const TCollection_ExtendedString e( 0.1 * i ); + const TCollection_AsciiString ea( e ); + //assert( ea.IsRealValue() ); + //assert( Abs( ea.RealValue() - 0.1 * i ) < 1e-10 ); + QCOMPARE ( ea.IsRealValue() , Standard_True ); + QCOMPARE ( Abs( ea.RealValue() - 0.1 * i ) < 1e-10 , Standard_True ); + + // TCollection_ExtendedString (const TCollection_ExtendedString& astring) + const TCollection_ExtendedString f(e); + //assert( f.Length() == e.Length()); + //assert( f == e ); + QCOMPARE ( f.Length() , e.Length() ); + QCOMPARE ( f , e ); + + // TCollection_ExtendedString (const TCollection_AsciiString& astring) + const TCollection_ExtendedString g( ea ); + //assert( g.Length() == ea.Length() ); + //assert( TCollection_AsciiString( g ) == ea ); + QCOMPARE ( g.Length() , ea.Length() ); + QCOMPARE ( TCollection_AsciiString( g ) , ea ); + + // AssignCat (const TCollection_ExtendedString& other) + const TCollection_ExtendedString sep(","); + d.AssignCat( sep ); + d.AssignCat( g ); + //assert( d.Length() == 2 + g.Length() ); + //assert( d.Token( sep.ToExtString(), 1 ) == TCollection_ExtendedString( i )); + //assert( d.Token( sep.ToExtString(), 2 ) == g ); + QCOMPARE ( d.Length() , 2 + g.Length() ); + QCOMPARE ( d.Token( sep.ToExtString(), 1 ) , TCollection_ExtendedString( i ) ); + QCOMPARE ( d.Token( sep.ToExtString(), 2 ) , g ); + + // TCollection_ExtendedString Cat (const TCollection_ExtendedString& other) const + const TCollection_ExtendedString cat = a.Cat( sep ); + //assert( cat.Length() == a.Length() + sep.Length() ); + //assert( cat.Search( a ) == 1 ); + //assert( cat.Search( sep ) == a.Length() + 1 ); + QCOMPARE ( cat.Length() , a.Length() + sep.Length() ); + QCOMPARE ( cat.Search( a ) , 1 ); + QCOMPARE ( cat.Search( sep ) , a.Length() + 1 ); + + // Copy (const TCollection_ExtendedString& fromwhere) + d = cat; + //assert( d.Length() == cat.Length() ); + //assert( d == cat ); + QCOMPARE ( d.Length() , cat.Length() ); + QCOMPARE ( d , cat ); + + // IsEqual (const Standard_ExtString other) const + //assert( d.IsEqual( d.ToExtString() )); + QCOMPARE ( d.IsEqual( d.ToExtString() ) , Standard_True ); + + // IsDifferent (const Standard_ExtString other ) const + //assert( d.IsDifferent( a.ToExtString() )); + QCOMPARE ( d.IsDifferent( a.ToExtString() ) , Standard_True ); + + // IsDifferent (const TCollection_ExtendedString& other) const + //assert( d.IsDifferent( a )); + QCOMPARE ( d.IsDifferent( a ) , Standard_True ); + + // IsLess (const Standard_ExtString other) const + const TCollection_ExtendedString l0("0"), l1("1"), l00("00"), l, ls(theStr+i), ls1(theStr+i+1); + //assert( l0. IsLess( l1.ToExtString() )); + //assert( l0. IsLess( l00.ToExtString() )); + //assert( l. IsLess( l0.ToExtString() )); + //assert( ! l1. IsLess( l0.ToExtString() )); + //assert( ! l00.IsLess( l0.ToExtString() )); + //assert( ! l0. IsLess( l.ToExtString() )); + //assert( ls.IsLess( ls1.ToExtString() )); + QCOMPARE ( l0. IsLess( l1.ToExtString() ) , Standard_True ); + QCOMPARE ( l0. IsLess( l00.ToExtString() ) , Standard_True ); + QCOMPARE ( l. IsLess( l0.ToExtString() ) , Standard_True ); + QCOMPARE ( ! l1. IsLess( l0.ToExtString() ) , Standard_True ); + QCOMPARE ( ! l00.IsLess( l0.ToExtString() ) , Standard_True ); + QCOMPARE ( ! l0. IsLess( l.ToExtString() ) , Standard_True ); + QCOMPARE ( ls.IsLess( ls1.ToExtString() ) , Standard_True ); + + // IsLess (const TCollection_ExtendedString& other) const + //assert( l0. IsLess( l1 )); + //assert( l0. IsLess( l00 )); + //assert( l. IsLess( l0 )); + //assert( ! l1. IsLess( l0 )); + //assert( ! l00.IsLess( l0 )); + //assert( ! l0. IsLess( l )); + //assert( ls.IsLess( ls1 )); + QCOMPARE ( l0. IsLess( l1 ) , Standard_True ); + QCOMPARE ( l0. IsLess( l00 ) , Standard_True ); + QCOMPARE ( l. IsLess( l0 ) , Standard_True ); + QCOMPARE ( ! l1. IsLess( l0 ) , Standard_True ); + QCOMPARE ( ! l00.IsLess( l0 ) , Standard_True ); + QCOMPARE ( ! l0. IsLess( l ) , Standard_True ); + QCOMPARE ( ls.IsLess( ls1 ) , Standard_True ); + + // IsGreater (const Standard_ExtString other) const + //assert( ! l0.IsGreater( l1.ToExtString() )); + //assert( ! l0.IsGreater( l00.ToExtString() )); + //assert( ! l. IsGreater( l0.ToExtString() )); + //assert( l1. IsGreater( l0.ToExtString() )); + //assert( l00.IsGreater( l0.ToExtString() )); + //assert( l0. IsGreater( l.ToExtString() )); + //assert( ls1.IsGreater( ls.ToExtString() )); + QCOMPARE ( ! l0.IsGreater( l1.ToExtString() ) , Standard_True ); + QCOMPARE ( ! l0.IsGreater( l00.ToExtString() ) , Standard_True ); + QCOMPARE ( ! l. IsGreater( l0.ToExtString() ) , Standard_True ); + QCOMPARE ( l1. IsGreater( l0.ToExtString() ) , Standard_True ); + QCOMPARE ( l00.IsGreater( l0.ToExtString() ) , Standard_True ); + QCOMPARE ( l0. IsGreater( l.ToExtString() ) , Standard_True ); + QCOMPARE ( ls1.IsGreater( ls.ToExtString() ) ,Standard_True ); + + // IsGreater (const TCollection_ExtendedString& other) const + //assert( ! l0.IsGreater( l1)); + //assert( ! l0.IsGreater( l00)); + //assert( ! l. IsGreater( l0)); + //assert( l1. IsGreater( l0)); + //assert( l00.IsGreater( l0)); + //assert( l0. IsGreater( l)); + //assert( ls1.IsGreater( ls)); + QCOMPARE ( ! l0.IsGreater( l1) , Standard_True ); + QCOMPARE ( ! l0.IsGreater( l00) , Standard_True ); + QCOMPARE ( ! l. IsGreater( l0) , Standard_True ); + QCOMPARE ( l1. IsGreater( l0) , Standard_True ); + QCOMPARE ( l00.IsGreater( l0) , Standard_True ); + QCOMPARE ( l0. IsGreater( l) , Standard_True ); + QCOMPARE ( ls1.IsGreater( ls) , Standard_True ); + + // ========================== + //TCollection_HAsciiString:: + // ========================== + + // IsDifferent(const Handle(TCollection_HAsciiString)& S) + Handle(TCollection_HAsciiString) ha1 = new TCollection_HAsciiString( theStr+i ); + Handle(TCollection_HAsciiString) ha2 = new TCollection_HAsciiString( theStr+i+1 ); + //assert( ha1->IsDifferent( ha2 )); + //assert( !ha1->IsDifferent( ha1 )); + QCOMPARE ( ha1->IsDifferent( ha2 ) , Standard_True ); + QCOMPARE ( !ha1->IsDifferent( ha1 ) , Standard_True ); + + // IsSameString (const Handle(TCollection_HAsciiString)& S) + //assert( !ha1->IsSameString( ha2 )); + //assert( ha1->IsSameString( ha1 )); + QCOMPARE ( !ha1->IsSameString( ha2 ) , Standard_True ); + QCOMPARE ( ha1->IsSameString( ha1 ) , Standard_True ); + + // IsSameState (const Handle(TCollection_HAsciiString)& other) const + //assert( !ha1->IsSameState( ha2 )); + //assert( ha1->IsSameState( ha1 )); + QCOMPARE ( !ha1->IsSameState( ha2 ) , Standard_True ); + QCOMPARE ( ha1->IsSameState( ha1 ) , Standard_True ); + + // IsSameString (const Handle(TCollection_HAsciiString)& S , + // const Standard_Boolean CaseSensitive) const + //assert( !ha1->IsSameString( ha2, true )); + //assert( ha1->IsSameString( ha1, true )); + //assert( !ha1->IsSameString( ha2, false )); + //assert( ha1->IsSameString( ha1, false )); + QCOMPARE ( !ha1->IsSameString( ha2, Standard_True ) , Standard_True ); + QCOMPARE ( ha1->IsSameString( ha1, Standard_True ) , Standard_True ); + QCOMPARE ( !ha1->IsSameString( ha2, Standard_False ) , Standard_True ); + QCOMPARE ( ha1->IsSameString( ha1, Standard_False ) , Standard_True ); + + ha1->SetValue( 1, "AbC0000000"); + ha2->SetValue( 1, "aBc0000000"); + //assert( !ha1->IsSameString( ha2, true )); + //assert( ha1->IsSameString( ha2, false )); + QCOMPARE ( !ha1->IsSameString( ha2, Standard_True ) , Standard_True ); + QCOMPARE ( ha1->IsSameString( ha2, Standard_False ), Standard_True ); + } + return 0; +} + void QABugs::Commands_19(Draw_Interpretor& theCommands) { const char *group = "QABugs"; @@ -695,8 +1162,7 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) { theCommands.Add ("test_offset", "test_offset", __FILE__, test_offset, group); theCommands.Add("OCC23945", "OCC23945 surfname U V X Y Z [DUX DUY DUZ DVX DVY DVZ [D2UX D2UY D2UZ D2VX D2VY D2VZ D2UVX D2UVY D2UVZ]]", __FILE__, OCC23945,group); theCommands.Add ("OCC24019", "OCC24019 aShape", __FILE__, OCC24019, group); + theCommands.Add ("OCC11758", "OCC11758", __FILE__, OCC11758, group); return; } - - diff --git a/src/Standard/FILES b/src/Standard/FILES index 4738b3c5dd..140178f3e1 100755 --- a/src/Standard/FILES +++ b/src/Standard/FILES @@ -50,7 +50,6 @@ Standard_ShallowDump.cxx Standard_ShortReal.cxx Standard_ShortReal.hxx Standard_Stream.hxx -Standard_String.hxx Standard_Time.cxx Standard_Time.hxx Standard_Transient.hxx diff --git a/src/Standard/Standard_CString.cxx b/src/Standard/Standard_CString.cxx index 8ee527d9e3..fcd5c2ec35 100755 --- a/src/Standard/Standard_CString.cxx +++ b/src/Standard/Standard_CString.cxx @@ -25,31 +25,10 @@ #define _Standard_CString_SourceFile -#define OptJr 1 -#ifdef HAVE_CONFIG_H -# include -#endif - #include #include #include #include - -#if OptJr -# if defined(WORDS_BIGENDIAN) -static const Standard_Integer static_MaskEndIntegerString[4] = { 0x00000000 , - 0xff000000 , - 0xffff0000 , - 0xffffff00 } ; -# else -static const Standard_Integer static_MaskEndIntegerString[4] = { 0x00000000 , - 0x000000ff , - 0x0000ffff , - 0x00ffffff } ; -# endif -#endif - -#include #include #include @@ -76,186 +55,32 @@ Standard_EXPORT void ShallowDump (const Standard_CString Value, Standard_OStream Standard_Integer HashCode (const Standard_CString Value, const Standard_Integer Upper ) { - Standard_Integer aLen ; - //#if OptJr - //STRINGLEN( Value , aLen ) ; - //#else - aLen = (Standard_Integer)strlen(Value); - //#endif - return HashCode ( HashCodes( Value , aLen ) , Upper ) ; + Standard_Integer aLen = (Standard_Integer)strlen(Value); + return HashCode (HashCodes (Value, aLen), Upper); } -#if OptJr -# if defined(WORDS_BIGENDIAN) - static Standard_Integer Standard_Mask_String_Left[4] = - { 0 , 0x00ffffff , 0x0000ffff , 0x000000ff } ; - static Standard_Integer Standard_Mask_String_Right[4] = - { 0 , 0xff000000 , 0xffff0000 , 0xffffff00 } ; -# else - static Standard_Integer Standard_Mask_String_Left[4] = - { 0 , 0xffffff00 , 0xffff0000 , 0xff000000 } ; - static Standard_Integer Standard_Mask_String_Right[4] = - { 0 , 0x000000ff , 0x0000ffff , 0x00ffffff } ; -# endif -#endif - //============================================================================ //==== HashCode of a CString //============================================================================ -Standard_Integer HashCodes (const Standard_CString Value , - const Standard_Integer Len ) +Standard_Integer HashCodes (const Standard_CString Value, + const Standard_Integer Len) { - Standard_Integer aHashCode = 0 ; - Standard_Integer i ; -#if !OptJr - char *charPtr = (char *)Value; - Standard_Integer pos = 0, - count, - *tmphash; - char tabchar[20]; -#endif + // compute DJB2 hash of a string + Standard_Integer hash = 0; + const Standard_Character *c = Value; + for (Standard_Integer i = 0; i < Len; i++, c++) + { + /* hash = hash * 33 ^ c */ + hash = ((hash << 5) + hash) ^ (*c); + } - if (Value != NULL) { - -#if !OptJr - i = 0 ; - while (i < Len) { - for (count = 0,pos = i;count < sizeof(Standard_Integer); count++) { - if (pos + count >= Len) tabchar[count] = '\0'; - else tabchar[count] = charPtr[pos + count]; - i++; - } - tmphash = (Standard_Integer *)tabchar; - aHashCode = aHashCode ^ *tmphash; - } - } - -#else - Standard_Integer *value = (Standard_Integer *)(ptrdiff_t(Value) & ~0x3) ; - Standard_Integer len = Len ; - - unsigned int aResidue = (unsigned int)(ptrdiff_t(Value) & 0x3); - if (aResidue) { - aHashCode = *value & Standard_Mask_String_Left[aResidue] ; - value += 1 ; - len -= (4 - aResidue); - } - - for ( i = 1 ; i <= len >> 2 ; i++ ) { - aHashCode = aHashCode ^ value[ i - 1 ] ; - } - aHashCode = aHashCode ^ ( value[ i - 1 ] & - Standard_Mask_String_Right[ len & 3 ] ) ; - - if ( len != Len ) { -# if defined(WORDS_BIGENDIAN) - aHashCode = aHashCode << 8*aResidue | - aHashCode >> 8*(4 - aResidue) ; -# else - aHashCode = aHashCode << 8*(4 - aResidue) | - aHashCode >> 8*aResidue ; -# endif - } - - } -#endif - - return aHashCode ; + return hash; } - -# if defined(WORDS_BIGENDIAN) - static Standard_Integer Standard_Mask_Upper_Lower[5] = - { 0 , 0xdf000000 , 0xdfdf0000 , 0xdfdfdf00 , 0xdfdfdfdf } ; -#else - static Standard_Integer Standard_Mask_Upper_Lower[5] = - { 0 , 0xdf , 0xdfdf , 0xdfdfdf , 0xdfdfdfdf } ; -#endif - -//============================================================================ -//==== HashCode of a CString with discard of bit 5 (UpperCase<-->LowerCase) -// Efficient for Types and MethodNames (without copy of characters) -// Valid if we have only alphanumeric characters and "_" (unicity) -// Valid if the Strings address is aligned for Integers -//============================================================================ -Standard_Integer HASHCODES (const Standard_CString Value , - const Standard_Integer Len ) -{ - Standard_Integer aHashCode = 0 ; - Standard_Integer i = 0 ; - - if (Value != NULL) { -#ifdef ALIGNMENT_BUG - for ( i = 1 ; i <= Len >> 2 ; i++ ) { - aHashCode = aHashCode ^ - ( ((Standard_Integer *) Value ) [ i - 1 ] & - Standard_Mask_Upper_Lower[4] ) ; - } - aHashCode = aHashCode ^ - ( ((Standard_Integer *) Value ) [ i - 1 ] & - Standard_Mask_Upper_Lower[ Len & 3 ] ) ; -#else - Standard_Integer itmp = 0 ; - for ( i = 0 ; i <= Len-4 ; i+=4 ) { - memcpy(&itmp,(const void *)&Value[i],4); - aHashCode=aHashCode^(itmp&Standard_Mask_Upper_Lower[4]); - } - if (Len&3) { - memcpy(&itmp,(const void *)&Value[i],Len&3); - aHashCode=aHashCode^(itmp&Standard_Mask_Upper_Lower[Len&3]); - } -#endif - - } - return aHashCode ; -} - -//============================================================================ -// IsEqual : Returns Standard_True if two CString have the same value -// Comparison is done with discard of bit 5 (UpperCase<-->LowerCase) -// Efficient for Types and MethodNames (without copy of characters) -// Valid if we have only alphanumeric characters and "_" (unicity) -// Valid if the Strings address are aligned for Integers - -//============================================================================ -Standard_Boolean ISSIMILAR(const Standard_CString One , - const Standard_Integer LenOne , - const Standard_CString Two ) -{ - Standard_Integer i ; - -#ifdef ALIGNMENT_BUG - for ( i = 1 ; i <= LenOne >> 2 ; i++ ) { - if ( (((Standard_Integer *) One ) [ i - 1 ] & - Standard_Mask_Upper_Lower[ 4 ] ) != - (((Standard_Integer *) Two ) [ i - 1 ] & - Standard_Mask_Upper_Lower[ 4 ] ) ) - return Standard_False ; - } - if ( (((Standard_Integer *) One ) [ i - 1 ] & - Standard_Mask_Upper_Lower[ LenOne & 3 ] ) != - (((Standard_Integer *) Two ) [ i - 1 ] & - Standard_Mask_Upper_Lower[ LenOne & 3 ] ) ) - return Standard_False ; -#else - Standard_Integer iOne, iTwo ; - for ( i = 0; i <= LenOne-4; i+=4 ) { - memcpy(&iOne,(const void *)&One[i],4); - memcpy(&iTwo,(const void *)&Two[i],4); - if ((iOne&Standard_Mask_Upper_Lower[4] ) != - (iTwo&Standard_Mask_Upper_Lower[4])) - return Standard_False; - } - if(LenOne&3) { - memcpy(&iOne,(const void *)&One[i],4); - memcpy(&iTwo,(const void *)&Two[i],4); - if ( (iOne&Standard_Mask_Upper_Lower[LenOne&3]) != - (iTwo&Standard_Mask_Upper_Lower[LenOne&3])) - return Standard_False; - } -#endif - return Standard_True ; -} +//====================================================================== +// Locale-independent equivalents of C functions dealing with conversion +// of string to real and vice-versa +//====================================================================== #ifdef __APPLE__ // There are a lot of *_l functions availalbe on Mac OS X - we use them diff --git a/src/Standard/Standard_CString.hxx b/src/Standard/Standard_CString.hxx index acd19bf920..9eca98f925 100644 --- a/src/Standard/Standard_CString.hxx +++ b/src/Standard/Standard_CString.hxx @@ -63,22 +63,6 @@ inline Standard_Integer HashCode (const Standard_CString, Standard_Integer& ); Standard_Integer HashCodes (const Standard_CString , const Standard_Integer ); -inline Standard_Boolean ISEQUAL(const Standard_CString One , - const Standard_Integer LenOne , - const Standard_CString Two, - const Standard_Integer LenTwo ); -__Standard_API Standard_Boolean ISSIMILAR(const Standard_CString One , - const Standard_Integer Len , - const Standard_CString Two ); -inline Standard_Integer HASHCODE (const Standard_CString, - const Standard_Integer, - const Standard_Integer); -inline Standard_Integer HASHCODE (const Standard_CString, - const Standard_Integer, - const Standard_Integer , - Standard_Integer& ); -__Standard_API Standard_Integer HASHCODES (const Standard_CString, - const Standard_Integer); //! Equivalents of functions from standard C library that use always C locale __Standard_API double Atof (const char* theStr); @@ -130,52 +114,4 @@ inline Standard_Integer HashCode (const Standard_CString Value, return HashCode( (Standard_Integer) HashCodes( Value , Len ) , Upper ) ; } -//============================================================================ -//==== HashCode of CString converted to uppercase. Returns the HashCode itself -//==== and the HashCode % Upper -//============================================================================ -inline Standard_Integer HASHCODE (const Standard_CString Value, - const Standard_Integer Len , - const Standard_Integer Upper , - Standard_Integer& aHashCode ) -{ - aHashCode = HASHCODES( Value , Len ); -// return (Abs( aHashCode ) % Upper ) + 1 ; - return HashCode( (Standard_Integer) aHashCode , Upper ) ; -} - -//============================================================================ -//==== HashCode of a CString converted to uppercase -//============================================================================ -inline Standard_Integer HASHCODE (const Standard_CString Value, - const Standard_Integer Len , - const Standard_Integer Upper) -{ -// return (Abs( HASHCODES( Value , Len ) ) % Upper ) + 1 ; - return HashCode( (Standard_Integer) HASHCODES( Value , Len ) , Upper ) ; -} - -//============================================================================ -// IsEqual : Returns Standard_True if two CString have the same value -// Comparison is done with discard of bit 5 (UpperCase<-->LowerCase) -// Efficient for Types and MethodNames (without copy of characters) -// Valid if we have only alphanumeric characters and "_" (unicity) -// Valid if the Strings address are aligned for Integers - -//============================================================================ -inline Standard_Boolean ISEQUAL(const Standard_CString One , - const Standard_Integer LenOne , - const Standard_CString Two, - const Standard_Integer LenTwo ) -{ - - if ( One == Two ) - return Standard_True ; - if ( LenOne != LenTwo ) - return Standard_False ; - - return ISSIMILAR( One , LenOne , Two ) ; - -} - #endif diff --git a/src/Standard/Standard_ExtString.cxx b/src/Standard/Standard_ExtString.cxx index aec1974613..83e4668b5e 100755 --- a/src/Standard/Standard_ExtString.cxx +++ b/src/Standard/Standard_ExtString.cxx @@ -20,11 +20,8 @@ # include #endif -#define OptJr 1 - #include #include -#include #ifndef _Standard_OStream_HeaderFile #include #endif @@ -48,78 +45,13 @@ const Handle_Standard_Type& Standard_ExtString_Type_() Standard_Integer HashCode (const Standard_ExtString Value, const Standard_Integer Upper) { - Standard_Integer aHashCode ; - Standard_Integer i = 0 ; - -#if OptJr - Standard_ExtString aValue ; - -// cout << "HashCode " << hex << Value << dec << endl ; - - if ((ptrdiff_t(Value) & 3 ) == 2) { - aHashCode = Value[ 0 ] ; -#if defined(WNT) || defined(DECOSF1) || defined(LININTEL) || defined(__FreeBSD__) - aHashCode = aHashCode << 16 ; -#endif - aValue = &Value[1] ; - } - else { - aHashCode = 0 ; - aValue = Value ; + // compute SDBM hash of an ext string + Standard_Integer hash = 0; + for (const Standard_ExtCharacter *c = Value; *c; c++) + { + /* hash = hash * 33 ^ c */ + hash = (*c) + (hash << 6) + (hash << 16) - hash; } - while ( ExtStringTestOfZero(((Standard_Integer *) aValue ) [ i ] ) ) { -// cout << i << " " << hex << aHashCode << " " << ((Standard_Integer *) aValue )[i] -// << dec << endl ; - aHashCode = aHashCode ^ ((Standard_Integer *) aValue ) [ i++ ] ; - } - while ( aValue[ i << 1 ] != 0 && aValue[( i << 1 ) + 1 ] != 0 ) { -// cout << i << " " << hex << aHashCode << " " << ((Standard_Integer *) aValue )[i] -// << dec << endl ; - aHashCode = aHashCode ^ ((Standard_Integer *) aValue ) [ i++ ] ; - } - if ( aValue[ i << 1 ] != 0 ) { -// cout << i << " " << hex << aHashCode << dec << endl ; - aHashCode = aHashCode ^ ((Standard_Integer *) aValue ) [ i ] ; - } - if ((ptrdiff_t(Value ) & 3) == 2) { -// cout << hex << aHashCode << dec << endl ; - aHashCode = (( aHashCode >> 16 ) & 0x0000ffff ) | - (( aHashCode << 16 ) & 0xffff0000 ) ; - } -// cout << i << " " << hex << aHashCode << dec << endl ; - -#else - char* charPtr = (char *)Value; - Standard_Integer pos = 0, - count, - *tmphash, - isend = 0; - char tabchar[20]; - - aHashCode = 0 ; - if (Value != NULL) { - while(charPtr[i] != 0 || charPtr[i + 1] != 0) { - - for (count = 0,pos = i; count < sizeof(Standard_Integer); count += 2) { - - if (charPtr[pos + count] == 0 && charPtr[pos + count + 1] == 0 || isend == 1) { - isend = 1; - tabchar[count] = '\0'; - tabchar[count + 1] = '\0'; - } - else { - tabchar[count] = charPtr[pos + count]; - tabchar[count + 1] = charPtr[pos + count + 1]; - } - i += 2; - } - tmphash = (Standard_Integer *)tabchar; - aHashCode = aHashCode ^ *tmphash; - } - } -#endif - - aHashCode = HashCode(aHashCode , Upper) ; - return aHashCode ; + return HashCode (hash, Upper); } diff --git a/src/Standard/Standard_String.hxx b/src/Standard/Standard_String.hxx deleted file mode 100755 index 377e473bc3..0000000000 --- a/src/Standard/Standard_String.hxx +++ /dev/null @@ -1,906 +0,0 @@ -// Copyright (c) 1998-1999 Matra Datavision -// Copyright (c) 1999-2012 OPEN CASCADE SAS -// -// The content of this file is subject to the Open CASCADE Technology Public -// License Version 6.5 (the "License"). You may not use the content of this file -// except in compliance with the License. Please obtain a copy of the License -// at http://www.opencascade.org and read it completely before using this file. -// -// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its -// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. -// -// The Original Code and all software distributed under the License is -// distributed on an "AS IS" basis, without warranty of any kind, and the -// Initial Developer hereby disclaims all such warranties, including without -// limitation, any warranties of merchantability, fitness for a particular -// purpose or non-infringement. Please see the License for the specific terms -// and conditions governing the rights and limitations under the License. - - -#ifndef _Standard_String_HeaderFile -# define _Standard_String_HeaderFile - -# ifndef _Standard_TypeDef_HeaderFile -# include -# endif - -#define INF(X,Y) (((X)<(Y))?(X):(Y)) - -# if OptJr - -#define STRLEN(s,i) {(i) = 0;while((s)[(i)++] != '\0');(i)--;} -#define EXTSTRLEN(s,i) {(i) = 0;while((s)[(i)++] != 0);(i)--;} -#define STRCPY(s1,s2,i) {for(LoopIndex=0; LoopIndex<(i); LoopIndex++)(s1)[LoopIndex] = (s2)[LoopIndex];} -#define STRCAT(s1,i,s2,j) {for(LoopIndex=0; LoopIndex<(j); LoopIndex++) (s1)[(i)+LoopIndex] = (s2)[LoopIndex];} - -//# ifdef __Standard_DLL -# ifdef _Standard_CString_SourceFile -__Standard_API const Standard_Integer *MaskEndIntegerString = static_MaskEndIntegerString ; -# else -__Standard_APIEXTERN const Standard_Integer *MaskEndIntegerString ; -# endif -//# else -//Standard_IMPORT const Standard_Integer *MaskEndIntegerString ; -//# endif - -// JR 16-jul-1998 -// Algorithme utilise pour le calcul des longueurs de strings -// Je suppose que les octets sont de l'ascii 7 bits. -// Si un des octets d'un mot est a zero et si on soustrait 0x01010101 a ce -// mot, l'octet a zero change de signe. -// Reciproquement si (( Word - 0x01010101 ) & 0x80808080 ) != 0 -// alors Word a un octet a zero. - -// Si on a des octets negatifs et si on applique le resultat ci-dessus a -// ( Word & 0x7f7f7f7f ), cela sera vrai sauf si un des octets vaut 0x80 -// auquel cas on trouvera un octet a zero a tort. - -// Conclusion : il suffit de controler la presence d'un octet a zero a partir -// du debut du mot ou l'on croira en avoir trouve un pour traiter -// correctement les octets qui valent 0x80. - -// La meme chose est vraie pour les extendedstrings. - -// D'autre part afin d'accelerer les traitements, on teste si les chaines -// sont alignees sur des mots de 32 bits ( AND de l'adresse avec 3 ) ou -// sont alignees sur des shorts de 16 bits ( AND de l'adresse avec 1 ). - -inline Standard_Boolean CStringTestOfZero(const Standard_Integer aString ) -{ - return ( ((( aString & 0x7f7f7f7f ) - \ - 0x01010101 ) & 0x80808080 ) == 0 ) ; -} - -inline Standard_Boolean HalfCStringTestOfZero(const Standard_ExtCharacter anExtCharacter ) -{ - return ( ((( anExtCharacter & 0x7f7f ) - 0x0101 ) & 0x8080 ) == 0 ) ; -} - -inline Standard_Boolean ExtStringTestOfZero(const Standard_Integer anExtString ) -{ - return ( ((( anExtString & 0x7fff7fff ) - \ - 0x00010001 ) & 0x80008000 ) == 0 ) ; -} - -#define STRINGLEN( aString , LoopIndex ) { \ - if ((ptrdiff_t(aString) & 1) == 0) { \ - LoopIndex = 0 ; \ - if ((ptrdiff_t(aString) & 3) == 0) { \ - while (CStringTestOfZero(((Standard_Integer *)aString)[LoopIndex++])); \ - LoopIndex = ( LoopIndex << 2 ) - 4 ; \ - } \ - else { \ - while (HalfCStringTestOfZero(((Standard_ExtCharacter *)aString)[LoopIndex++])); \ - LoopIndex = ( LoopIndex << 1 ) - 2 ; \ - } \ - while (aString[LoopIndex++] != '\0'); \ - LoopIndex -= 1 ; \ - } \ - else \ - STRLEN( aString , LoopIndex ) ; \ -} - -#define EXTSTRINGLEN( anExtString , LoopIndex ) { \ - if ((ptrdiff_t(anExtString) & 3) == 0) { \ - LoopIndex = 0 ; \ - while (ExtStringTestOfZero(((Standard_Integer *)anExtString)[LoopIndex++]));\ - LoopIndex = ( LoopIndex << 1 ) - 2 ; \ - if ( anExtString[ LoopIndex ] != 0 ) \ - LoopIndex += 1 ; \ - } \ - else \ - EXTSTRLEN( anExtString , LoopIndex ) ; \ -} - -// aStringOut is an AsciiString and is word aligned -// aStringIn is a CString and may be not word aligned -#define CSTRINGCOPY( aStringOut , aStringIn , aStringLen ) { \ - Standard_Integer LoopIndex = (Standard_Integer)(ptrdiff_t(aStringIn) & 3) ; \ - if ( ( LoopIndex & 1 ) == 0 ) { \ - if ( LoopIndex == 0 ) { \ - for (; LoopIndex <= ( aStringLen >> 2 ) ; LoopIndex++ ) { \ - ((Standard_Integer *) aStringOut )[ LoopIndex ] = \ - ((Standard_Integer *) aStringIn )[ LoopIndex ] ; \ - } \ - } \ - else { \ - for ( LoopIndex = 0 ; LoopIndex <= ( aStringLen >> 1) ; LoopIndex++ ) { \ - ((Standard_ExtCharacter *) aStringOut )[ LoopIndex ] = \ - ((Standard_ExtCharacter *) aStringIn )[ LoopIndex ] ; \ - } \ - } \ - } \ - else \ - STRCPY( aStringOut , aStringIn , aStringLen + 1 ) ; \ -} - -// aStringOut is an AsciiString and is word aligned -// aStringIn is an AsciiString and is word aligned -#define ASCIISTRINGCOPY( aStringOut , aStringIn , aStringLen ) { \ - Standard_Integer LoopIndex ; \ - LoopIndex = 0 ; \ - for(; LoopIndex <= ( aStringLen >> 2 ) ; LoopIndex++ ) { \ - ((Standard_Integer *) aStringOut )[ LoopIndex ] = \ - ((Standard_Integer *) aStringIn )[ LoopIndex ] ; \ - } \ -} - -#define STRINGCAT( aStringOut , aStringOutLen , aStringIn , aStringInLen ) { \ - Standard_Integer LoopIndex ; \ - if ((ptrdiff_t(&aStringOut[ aStringOutLen ]) & 1) == 0 && \ - (ptrdiff_t(aStringIn) & 1 ) == 0 ) { \ - LoopIndex = 0 ; \ - if ((ptrdiff_t(&aStringOut[ aStringOutLen ]) & 3 ) == 0 && \ - (ptrdiff_t(aStringIn) & 3 ) == 0 ) { \ - for (; LoopIndex <= ( aStringInLen >> 2 ) ; LoopIndex++ ) { \ - ((Standard_Integer *) aStringOut )[ ( aStringOutLen >> 2 ) + \ - LoopIndex ] = ((Standard_Integer *) aStringIn )[ LoopIndex ] ; \ - } \ - } \ - else { \ - for (; LoopIndex <= ( aStringInLen >> 1 ) ; LoopIndex++ ) { \ - ((Standard_ExtCharacter *) aStringOut )[ ( aStringOutLen >> 1 ) + \ - LoopIndex ] = ((Standard_ExtCharacter *) aStringIn )[ LoopIndex ] ; \ - } \ - } \ - } \ - else \ - STRCPY( &aStringOut[ aStringOutLen ] , aStringIn , aStringInLen + 1 ) ; \ -} - -// aString is an AsciiString and is word aligned -// anOtherString is aCString and may be not word aligned -// aStringLen is the length of aString and anOtherString -#define CSTRINGEQUAL( aString , anOtherString , aStringLen , KEqual ) { \ - KEqual = Standard_True ; \ - Standard_Integer LoopIndex = Standard_Integer(ptrdiff_t(anOtherString) & 3); \ - if ( ( LoopIndex & 1 ) == 0 ) { \ - if ( LoopIndex == 0 ) { \ - for (; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \ - if (((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - if ( KEqual == Standard_True && \ - (((Standard_Integer *) aString )[ LoopIndex ] & \ - MaskEndIntegerString[ aStringLen & 3 ]) != \ - (((Standard_Integer *) anOtherString )[ LoopIndex ] & \ - MaskEndIntegerString[ aStringLen & 3 ] ) ) \ - KEqual = Standard_False ; \ - } \ - else { \ - for ( LoopIndex = 0 ; LoopIndex < (( aStringLen + 1) >> 1) ; LoopIndex++ ) { \ - if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \ - ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - } \ - } \ - else { \ - for ( LoopIndex = 0 ; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - } \ -} - -// aString is an AsciiString and is word aligned -// anOtherString is aCString and may be not word aligned -// aStringLen is the length of aString. -// The length of anOtherString is unknown -#define LCSTRINGEQUAL( aString , aStringLen , anOtherString , KEqual ) { \ - KEqual = Standard_True ; \ - Standard_Integer LoopIndex = Standard_Integer(ptrdiff_t(anOtherString) & 3); \ - if ( ( LoopIndex & 1 ) == 0 ) { \ - if ( LoopIndex == 0 ) { \ - for (; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \ - if (((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex << 2) ; \ - } \ - else { \ - for ( LoopIndex = 0 ; LoopIndex < (( aStringLen + 1) >> 1) ; LoopIndex++ ) { \ - if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \ - ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex << 1) ; \ - } \ - if ( KEqual ) { \ - for (; LoopIndex <= aStringLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - } \ - } \ - else { \ - for ( LoopIndex = 0 ; LoopIndex <= aStringLen ; LoopIndex++ ) { \ - if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - } \ -} - -// aString is an AsciiString and is word aligned -// anOtherString is an AsciiString and is word aligned -#define ASCIISTRINGEQUAL( aString , anOtherString , aStringLen , KEqual ) { \ - Standard_Integer LoopIndex ; \ - KEqual = Standard_True ; \ - LoopIndex = 0 ; \ - for(; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - if ( KEqual == Standard_True && \ - (((Standard_Integer *) aString )[ LoopIndex ] & \ - MaskEndIntegerString[ aStringLen & 3 ]) != \ - (((Standard_Integer *) anOtherString )[ LoopIndex ] & \ - MaskEndIntegerString[ aStringLen & 3 ] ) ) \ - KEqual = Standard_False ; \ -} - -// aString is an AsciiString and is word aligned -// anOtherString is aCString and may be not word aligned -#define CSTRINGLESS( aString , aStringLen , anOtherString , \ - anOtherStringLen , MinLen , KLess ) { \ - Standard_Integer LoopIndex ; \ - KLess = Standard_True ; \ - LoopIndex = ptrdiff_t(anOtherString) & 3 ; \ - if ( ( LoopIndex & 1 ) == 0 && MinLen > 3 ) { \ - if ( LoopIndex == 0 ) { \ - for (; LoopIndex < ( MinLen >> 2 ) ; LoopIndex++ ) { \ - if (((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 2 ; \ - } \ - else { \ - for ( LoopIndex = 0 ; LoopIndex < ( MinLen >> 1 ) ; LoopIndex++ ) { \ - if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \ - ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - } \ - else \ - LoopIndex = 0 ; \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \ - KLess = Standard_False ; \ - } \ - else if ( aStringLen >= anOtherStringLen ) \ - KLess = Standard_False ; \ -} - -// aString is an AsciiString and is word aligned -// anOtherString is aCString and may be not word aligned -// aStringLen is the length of aString -// The length of anOtherString is unknown -#define LCSTRINGLESS( aString , aStringLen , anOtherString , KLess ) { \ - KLess = Standard_True ; \ - Standard_Integer LoopIndex = Standard_Integer(ptrdiff_t(anOtherString) & 3); \ - if ( ( LoopIndex & 1 ) == 0 && aStringLen > 3 ) { \ - if ( LoopIndex == 0 ) { \ - for (; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \ - if (((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 2 ; \ - } \ - else { \ - for ( LoopIndex = 0 ; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \ - if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \ - ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - } \ - else \ - LoopIndex = 0 ; \ - for (; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != aStringLen ) { \ - if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \ - KLess = Standard_False ; \ - } \ - else if ( anOtherString[ LoopIndex ] == '\0' ) \ - KLess = Standard_False ; \ -} - -// aString is an AsciiString and is word aligned -// anOtherString is an AsciiString and is word aligned -#define ASCIISTRINGLESS( aString , aStringLen , anOtherString , \ - anOtherStringLen , MinLen , KLess ) { \ - Standard_Integer LoopIndex ; \ - KLess = Standard_True ; \ - LoopIndex = 0 ; \ - if ( MinLen > 3 ) { \ - for(; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 2 ; \ - } \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \ - KLess = Standard_False ; \ - } \ - else if ( aStringLen >= anOtherStringLen ) \ - KLess = Standard_False ; \ -} - -// aString is an AsciiString and is word aligned -// anOtherString is aCString and may be not word aligned -#define CSTRINGGREATER( aString , aStringLen , anOtherString , \ - anOtherStringLen , MinLen , KGreater ) { \ - KGreater = Standard_True ; \ - Standard_Integer LoopIndex = Standard_Integer(ptrdiff_t(anOtherString) & 3); \ - if ( ( LoopIndex & 1 ) == 0 && MinLen > 3 ) { \ - if ( LoopIndex == 0 ) { \ - for (; LoopIndex < ( MinLen >> 2 ) ; LoopIndex++ ) { \ - if (((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 2 ; \ - } \ - else { \ - for ( LoopIndex = 0 ; LoopIndex < ( MinLen >> 1 ) ; LoopIndex++ ) { \ - if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \ - ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - } \ - else \ - LoopIndex = 0 ; \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \ - KGreater = Standard_False ; \ - } \ - else if ( aStringLen <= anOtherStringLen ) \ - KGreater = Standard_False ; \ -} - -// aString is an AsciiString and is word aligned -// anOtherString is aCString and may be not word aligned -// aStringLen is the length of aString -// The length of anOtherString is unknown -#define LCSTRINGGREATER( aString , aStringLen , anOtherString , KGreater ) { \ - Standard_Integer LoopIndex ; \ - KGreater = Standard_True ; \ - LoopIndex = (Standard_Integer)(ptrdiff_t(anOtherString) & 3) ; \ - if ( ( LoopIndex & 1 ) == 0 && aStringLen > 3 ) { \ - if ( LoopIndex == 0 ) { \ - for (; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \ - if (((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 2 ; \ - } \ - else { \ - for ( LoopIndex = 0 ; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \ - if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \ - ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - } \ - else \ - LoopIndex = 0 ; \ - for (; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != aStringLen ) { \ - if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \ - KGreater = Standard_False ; \ - } \ - else \ - KGreater = Standard_False ; \ -} - -// aString is an AsciiString and is word aligned -// anOtherString is an AsciiString and is word aligned -#define ASCIISTRINGGREATER( aString , aStringLen , anOtherString , \ - anOtherStringLen , MinLen , KGreater ) { \ - Standard_Integer LoopIndex ; \ - KGreater = Standard_True ; \ - LoopIndex = 0 ; \ - if ( MinLen > 3 ) { \ - for(; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 2 ; \ - } \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \ - KGreater = Standard_False ; \ - } \ - else if ( aStringLen <= anOtherStringLen ) \ - KGreater = Standard_False ; \ -} - -// anExtStringOut is an ExtendedString and is word aligned -// anExtStringIn is an ExtString and may be not word aligned -#define EXTSTRINGCOPY( anExtStringOut , anExtStringIn , anExtStringLen ) { \ - Standard_Integer LoopIndex ; \ - LoopIndex = (Standard_Integer)(ptrdiff_t(anExtStringIn) & 3) ; \ - if ( LoopIndex == 0 ) { \ - for (; LoopIndex <= ( anExtStringLen >> 1 ) ; LoopIndex++ ) { \ - ((Standard_Integer *) anExtStringOut )[ LoopIndex ] = \ - ((Standard_Integer *) anExtStringIn )[ LoopIndex ] ; \ - } \ - } \ - else \ - STRCPY( anExtStringOut , anExtStringIn , anExtStringLen + 1 ) ; \ -} - -// anExtStringOut is an ExtendedString and is word aligned -// anExtStringIn is an ExtendedString and is word aligned -// We copy the ending zero and possibly the ExtCharacter folowing -#define EXTENDEDSTRINGCOPY( anExtStringOut , anExtStringIn , anExtStringLen ) {\ - Standard_Integer LoopIndex ; \ - for (LoopIndex = 0 ; LoopIndex <= ( anExtStringLen >> 1 ) ; LoopIndex++ ) { \ - ((Standard_Integer *) anExtStringOut )[ LoopIndex ] = \ - ((Standard_Integer *) anExtStringIn )[ LoopIndex ] ; \ - } \ -} - -// anExtStringOut is an ExtendedString and is word aligned -// anExtStringIn is an ExtendedString and is word aligned -// We copy the ending zero and possibly the ExtCharacter folowing -#define EXTENDEDSTRINGCAT( anExtStringOut , anExtStringOutLen , anExtStringIn , anExtStringInLen ) {\ - Standard_Integer LoopIndex ; \ - if ( ( anExtStringOutLen & 1 ) == 0 ) { \ - for (LoopIndex = 0 ; LoopIndex <= ( anExtStringInLen >> 1 ) ; LoopIndex++ ) { \ - ((Standard_Integer *) anExtStringOut )[ ( anExtStringOutLen >> 1 ) + LoopIndex ] = \ - ((Standard_Integer *) anExtStringIn )[ LoopIndex ] ; \ - } \ - } \ - else { \ - STRCAT( anExtStringOut , anExtStringOutLen , anExtStringIn , anExtStringInLen + 1 ) ; \ - } \ -} - -// aString is an ExtendedString and is word aligned -// anOtherString is an ExtString and may be not word aligned -// We compare the last two ExtCharacters or the last ExtCharacter and the -// ending zero if it's word aligned -// aStringLen is the length of aString and anOtherString -#define EXTSTRINGEQUAL( aString , anOtherString , aStringLen , KEqual ) { \ - Standard_Integer LoopIndex ; \ - KEqual = Standard_True ; \ - LoopIndex = 0 ; \ - if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \ - for(; LoopIndex < (( aStringLen + 1) >> 1 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - } \ - else { \ - for(; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - } \ -} - -// aString is an ExtendedString and is word aligned -// anOtherString is an ExtString and may be not word aligned -// We compare the last two ExtCharacters or the last ExtCharacter and the -// ending zero if it's word aligned -// aStringLen is the length of aString. -// The length of anOtherString is unknown -#define LEXTSTRINGEQUAL( aString , aStringLen , anOtherString , KEqual ) { \ - Standard_Integer LoopIndex ; \ - KEqual = Standard_True ; \ - LoopIndex = 0 ; \ - if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \ - for(; LoopIndex < (( aStringLen + 1) >> 1 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - if ( KEqual && aString [ aStringLen ] != anOtherString [ aStringLen ] ) \ - KEqual = Standard_False ; \ - } \ - else { \ - for(; LoopIndex <= aStringLen ; LoopIndex++ ) { \ - if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ - } \ -} - -// aString is an ExtendedString and is word aligned -// anOtherString is an ExtendedString and is word aligned -// We compare the last two ExtCharacters or the last ExtCharacter and the -// ending zero -#define EXTENDEDSTRINGEQUAL( aString , anOtherString , aStringLen , KEqual ) { \ - Standard_Integer LoopIndex ; \ - KEqual = Standard_True ; \ - LoopIndex = 0 ; \ - for(; LoopIndex < (( aStringLen + 1) >> 1 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - KEqual = Standard_False ; \ - break ; \ - } \ - } \ -} - -// aString is an ExtendedString and is word aligned -// anOtherString is an ExtendedString and may be not word aligned -#define EXTSTRINGLESS( aString , aStringLen , anOtherString , \ - anOtherStringLen , MinLen , KLess ) { \ - Standard_Integer LoopIndex ; \ - KLess = Standard_True ; \ - LoopIndex = 0 ; \ - if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \ - if ( MinLen > 1 ) { \ - for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \ - KLess = Standard_False ; \ - } \ - else if ( aStringLen >= anOtherStringLen ) \ - KLess = Standard_False ; \ - } \ - else { \ - if ( MinLen > 1 ) { \ - for(; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = LoopIndex - 1 ; \ - } \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \ - KLess = Standard_False ; \ - } \ - else if ( aStringLen >= anOtherStringLen ) \ - KLess = Standard_False ; \ - } \ -} - -// aString is an ExtendedString and is word aligned -// anOtherString is an ExtendedString and may be not word aligned -// aStringLen is the length of aString -// The length of anOtherString is unknown -#define LEXTSTRINGLESS( aString , aStringLen , anOtherString , KLess ) { \ - Standard_Integer LoopIndex ; \ - KLess = Standard_True ; \ - LoopIndex = 0 ; \ - if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \ - if ( aStringLen > 1 ) { \ - for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - for (; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != aStringLen ) { \ - if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \ - KLess = Standard_False ; \ - } \ - else if ( anOtherString[ LoopIndex ] == 0 ) \ - KLess = Standard_False ; \ - } \ - else { \ - if ( aStringLen > 1 ) { \ - for(; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = LoopIndex - 1 ; \ - } \ - for (; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != aStringLen ) { \ - if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \ - KLess = Standard_False ; \ - } \ - else if ( anOtherString[ LoopIndex ] == 0 ) \ - KLess = Standard_False ; \ - } \ -} - -// aString is an ExtendedString and is word aligned -// anOtherString is an ExtendedString and is word aligned -#define EXTENDEDSTRINGLESS( aString , aStringLen , anOtherString , \ - anOtherStringLen , MinLen , KLess ) { \ - Standard_Integer LoopIndex ; \ - KLess = Standard_True ; \ - LoopIndex = 0 ; \ - if ( MinLen > 1 ) { \ - for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \ - KLess = Standard_False ; \ - } \ - else if ( aStringLen >= anOtherStringLen ) \ - KLess = Standard_False ; \ -} - -// aString is an ExtendedString and is word aligned -// anOtherString is an ExtendedString and may be not word aligned -#define EXTSTRINGGREATER( aString , aStringLen , anOtherString , \ - anOtherStringLen , MinLen , KGreater ) { \ - Standard_Integer LoopIndex ; \ - KGreater = Standard_True ; \ - LoopIndex = 0 ; \ - if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \ - if ( MinLen > 1 ) { \ - for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \ - KGreater = Standard_False ; \ - } \ - else if ( aStringLen <= anOtherStringLen ) \ - KGreater = Standard_False ; \ - } \ - else { \ - if ( MinLen > 1 ) { \ - for(; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = LoopIndex - 1 ; \ - } \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \ - KGreater = Standard_False ; \ - } \ - else if ( aStringLen <= anOtherStringLen ) \ - KGreater = Standard_False ; \ - } \ -} - -// aString is an ExtendedString and is word aligned -// anOtherString is an ExtendedString and may be not word aligned -// aStringLen is the length of aString -// The length of anOtherString is unknown -#define LEXTSTRINGGREATER( aString , aStringLen , anOtherString , KGreater ) { \ - Standard_Integer LoopIndex ; \ - KGreater = Standard_True ; \ - LoopIndex = 0 ; \ - if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \ - if ( aStringLen > 1 ) { \ - for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - for (; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != aStringLen ) { \ - if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \ - KGreater = Standard_False ; \ - } \ - else \ - KGreater = Standard_False ; \ - } \ - else { \ - if ( aStringLen > 1 ) { \ - for(; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = LoopIndex - 1 ; \ - } \ - for (; LoopIndex < aStringLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != aStringLen ) { \ - if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \ - KGreater = Standard_False ; \ - } \ - else \ - KGreater = Standard_False ; \ - } \ -} - -// aString is an ExtendedString and is word aligned -// anOtherString is an ExtendedString and is word aligned -#define EXTENDEDSTRINGGREATER( aString , aStringLen , anOtherString , \ - anOtherStringLen , MinLen , KGreater ) { \ - Standard_Integer LoopIndex ; \ - KGreater = Standard_True ; \ - LoopIndex = 0 ; \ - if ( MinLen > 1 ) { \ - for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \ - if ( ((Standard_Integer *) aString )[ LoopIndex ] != \ - ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \ - LoopIndex++ ; \ - break ; \ - } \ - } \ - LoopIndex = ( LoopIndex - 1 ) << 1 ; \ - } \ - for (; LoopIndex < MinLen ; LoopIndex++ ) { \ - if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \ - break ; \ - } \ - if ( LoopIndex != MinLen ) { \ - if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \ - KGreater = Standard_False ; \ - } \ - else if ( aStringLen <= anOtherStringLen ) \ - KGreater = Standard_False ; \ -} - -# else - -#define STRLEN(s,i) {(i) = 0;while((s)[(i)++] != '\0');(i)--;} -#define EXTSTRLEN(s,i) {(i) = 0;while((s)[(i)++] != 0);(i)--;} -#define STRCPY(s1,s2,i) {for(int j=0; j<(i); j++)(s1)[j] = (s2)[j];} -#define STRCAT(s1,i,s2,j) {for(int k=0; k<(j); k++) (s1)[(i)+k] = (s2)[k];} - -# endif - -#endif diff --git a/src/TCollection/TCollection_AsciiString.cdl b/src/TCollection/TCollection_AsciiString.cdl index 3cb29a65df..2fda1d80e7 100755 --- a/src/TCollection/TCollection_AsciiString.cdl +++ b/src/TCollection/TCollection_AsciiString.cdl @@ -840,21 +840,6 @@ is -- (Just for HashCode for AsciiString) ---C++: inline - HASHCODE(myclass ; astring : AsciiString from TCollection; Upper : Integer) - returns Integer; - ---Level: Internal - ---Purpose: Hash function for AsciiString no case sensitive - ---C++: inline - - ISSIMILAR(myclass ; string1 : AsciiString from TCollection; - string2 : AsciiString from TCollection) - returns Boolean; - ---Level: Internal - ---Purpose: Returns True when the two strings are the same - -- (no case sensitive). - -- (Just for HashCode for AsciiString) - - fields mystring : PCharacter; mylength : Integer; diff --git a/src/TCollection/TCollection_AsciiString.cxx b/src/TCollection/TCollection_AsciiString.cxx old mode 100755 new mode 100644 index 63d42253e5..69f60f5e34 --- a/src/TCollection/TCollection_AsciiString.cxx +++ b/src/TCollection/TCollection_AsciiString.cxx @@ -18,21 +18,7 @@ -#define OptJr 1 -// OCC6794: if OptJr is ON, we need to ensure that memory allocations are done by 4 bytes words, -// in order to avoid writing into unallocated memory at the string end when it is copied -// by CSTRINGCOPY or ASCIISTRINGCOPY macros -// (though, due to OCC memory manager roundings of allocated memory, the problem appears -// only when MMGT_OPT is 0 and string size is greater than MMGT_THRESHOLD) -#ifdef OptJr -#define ROUNDMEM(len) (((len)+3)&~0x3) -#else -#define ROUNDMEM(len) (len) -#endif - -//#if defined(WNT) || defined(LIN) -#include -//#endif +#include #include #include @@ -41,13 +27,12 @@ #include #include #include -#include #include // ###### PLACER LE TYPE NON DEFINI strtol (portabilite) ###### #ifdef WNT -# include +# include #else extern "C" { long strtol(const char*, char**, int); @@ -64,6 +49,11 @@ static inline Standard_PCharacter Reallocate (Standard_Address aAddr, { return (Standard_PCharacter)Standard::Reallocate (aAddr, aLength); } +static inline void Free (Standard_PCharacter aAddr) +{ + Standard_Address aPtr = aAddr; + Standard::Free (aPtr); +} // ---------------------------------------------------------------------------- // Create an empty AsciiString @@ -84,18 +74,10 @@ TCollection_AsciiString::TCollection_AsciiString(const Standard_CString astring) : mystring(0) { if (astring) { -#if OptJr - STRINGLEN( astring , mylength ) ; -#else - STRLEN(astring,mylength); -#endif - mystring = Allocate(ROUNDMEM(mylength+1)); -#if OptJr - CSTRINGCOPY( mystring , astring , mylength ) ; -#else - STRCPY(mystring,astring,mylength); + mylength = Standard_Integer( strlen(astring) ); + mystring = Allocate(mylength+1); + strncpy(mystring,astring,mylength); mystring[mylength] = '\0'; -#endif } else { Standard_NullObject::Raise("TCollection_AsciiString : parameter 'astring'"); @@ -111,8 +93,8 @@ TCollection_AsciiString::TCollection_AsciiString(const Standard_CString astring, { if (astring) { mylength = aLen ; - mystring = Allocate(ROUNDMEM(mylength+1)); - CSTRINGCOPY( mystring , astring , mylength ) ; + mystring = Allocate(mylength+1); + strncpy( mystring , astring , mylength ); mystring [ mylength ] = '\0' ; } else { @@ -157,22 +139,11 @@ TCollection_AsciiString::TCollection_AsciiString(const Standard_Integer length, TCollection_AsciiString::TCollection_AsciiString(const Standard_Integer aValue) : mystring(0) { - - union { int bid ; // ?? to ensure alignment of t[] by double-word?? - char t [13]; } CHN ; - Sprintf(&CHN.t[0],"%d",aValue); -#if OptJr - STRINGLEN( CHN.t , mylength ) ; -#else - STRLEN(CHN.t,mylength); -#endif - mystring = Allocate(ROUNDMEM(mylength+1)); -#if OptJr - ASCIISTRINGCOPY( mystring , CHN.t , mylength ) ; -#else - STRCPY(mystring,CHN.t,mylength); + char t [13]; + mylength = Sprintf( t,"%d",aValue); + mystring = Allocate(mylength+1); + strncpy( mystring , t , mylength ); mystring[mylength] = '\0'; -#endif } // ---------------------------------------------------------------------------- @@ -181,22 +152,11 @@ TCollection_AsciiString::TCollection_AsciiString(const Standard_Integer aValue) TCollection_AsciiString::TCollection_AsciiString(const Standard_Real aValue) : mystring(0) { - - union { int bid ; - char t [50]; } CHN ; - Sprintf(&CHN.t[0],"%g",aValue); -#if OptJr - STRINGLEN( CHN.t , mylength ) ; -#else - STRLEN(CHN.t,mylength); -#endif - mystring = Allocate(ROUNDMEM(mylength+1)); -#if OptJr - ASCIISTRINGCOPY( mystring , CHN.t , mylength ) ; -#else - STRCPY(mystring,CHN.t,mylength); + char t [50]; + mylength = Sprintf( t,"%g",aValue); + mystring = Allocate(mylength+1); + strncpy( mystring , t , mylength ); mystring[mylength] = '\0'; -#endif } // ---------------------------------------------------------------------------- @@ -205,18 +165,10 @@ TCollection_AsciiString::TCollection_AsciiString(const Standard_Real aValue) TCollection_AsciiString::TCollection_AsciiString(const TCollection_AsciiString& astring) : mystring(0) { - mylength = astring.mylength; - mystring = Allocate(ROUNDMEM(mylength+1)); - if ( astring.mystring ) { -#if OptJr - ASCIISTRINGCOPY( mystring , astring.mystring , mylength ) ; - } - else -#else - STRCPY(mystring,astring.mystring,mylength); - } -#endif + mystring = Allocate(mylength+1); + if ( mylength ) + strncpy(mystring,astring.mystring,mylength); mystring[mylength] = '\0'; } @@ -228,11 +180,10 @@ TCollection_AsciiString::TCollection_AsciiString( const Standard_Character other ) : mystring(0) { - mylength = astring.mylength + 1 ; - mystring = Allocate(ROUNDMEM(mylength+1)); - if ( astring.mystring ) { - ASCIISTRINGCOPY( mystring , astring.mystring , astring.mylength ) ; + mystring = Allocate(mylength+1); + if ( astring.mylength ) { + strncpy( mystring , astring.mystring , astring.mylength ) ; } mystring[mylength-1] = other ; mystring[mylength] = '\0' ; @@ -246,15 +197,16 @@ TCollection_AsciiString::TCollection_AsciiString( const Standard_CString other ) : mystring(0) { - Standard_Integer otherlength; - - STRINGLEN( other , otherlength ); + Standard_Integer otherlength = Standard_Integer( other ? strlen( other ) : 0 ); mylength = astring.mylength + otherlength ; - mystring = Allocate(ROUNDMEM(mylength+1)); - if ( astring.mystring ) { - ASCIISTRINGCOPY( mystring , astring.mystring , astring.mylength ) ; + mystring = Allocate(mylength+1); + if ( astring.mylength ) { + strncpy( mystring , astring.mystring , astring.mylength ) ; } - STRINGCAT( mystring , astring.mylength , other , otherlength ) ; + if ( otherlength ) { + strncpy( mystring + astring.mylength, other, otherlength ); + } + mystring[ mylength ] = '\0'; } // ---------------------------------------------------------------------------- @@ -265,18 +217,15 @@ TCollection_AsciiString::TCollection_AsciiString( const TCollection_AsciiString& other ) : mystring(0) { - mylength = astring.mylength + other.mylength ; - mystring = Allocate(ROUNDMEM(mylength+1)); - if ( astring.mystring ) { - ASCIISTRINGCOPY( mystring , astring.mystring , astring.mylength ) ; + mystring = Allocate(mylength+1); + if ( astring.mylength ) { + strncpy( mystring , astring.mystring , astring.mylength ) ; } - if ( other.mystring ) { - STRINGCAT( mystring , astring.mylength , other.mystring , other.mylength ) ; + if ( other.mylength ) { + strncpy( mystring + astring.mylength, other.mystring , other.mylength ) ; } - if ( mylength == 0 ) - mystring[0] = '\0' ; - + mystring[mylength] = '\0' ; } //--------------------------------------------------------------------------- @@ -329,13 +278,7 @@ void TCollection_AsciiString::AssignCat(const Standard_Real other) void TCollection_AsciiString::AssignCat(const Standard_Character other) { if (other != '\0') { - if (mystring) { - mystring = Reallocate((void*&)mystring, - mylength+2); - } - else { - mystring = Allocate(mylength+2); - } + mystring = Reallocate (mystring, mylength + 2); mystring[mylength] = other ; mylength += 1; mystring[mylength] = '\0'; @@ -348,35 +291,12 @@ void TCollection_AsciiString::AssignCat(const Standard_Character other) void TCollection_AsciiString::AssignCat(const Standard_CString other) { if (other) { - if (other[0] != '\0') { - Standard_Integer otherlength; -#if OptJr - STRINGLEN( other , otherlength ) ; -#else - STRLEN(other,otherlength); -#endif + Standard_Integer otherlength = Standard_Integer( strlen( other )); + if ( otherlength ) { Standard_Integer newlength = mylength+otherlength; - if (mystring) { - mystring = Reallocate((void*&)mystring, - ROUNDMEM(newlength+1)); -#if OptJr - STRINGCAT( mystring , mylength , other , otherlength ) ; -#else - STRCAT(mystring,mylength,other,otherlength); -#endif - } - else { - mystring = Allocate(ROUNDMEM(newlength+1)); -#if OptJr - CSTRINGCOPY( mystring , other , newlength ) ; -#else - STRCPY(mystring,other,newlength); -#endif - } + mystring = Reallocate (mystring, newlength + 1); + strncpy( mystring + mylength, other, otherlength+1 ); mylength = newlength; -#if !OptJr - mystring[mylength] = '\0'; -#endif } } else { @@ -390,31 +310,11 @@ void TCollection_AsciiString::AssignCat(const Standard_CString other) void TCollection_AsciiString::AssignCat(const TCollection_AsciiString& other) { - Standard_Integer otherlength = other.mylength; - if (otherlength) { - Standard_CString sother = other.mystring; - Standard_Integer newlength = mylength+otherlength; - if (mystring) { - mystring = Reallocate((void*&)mystring, - ROUNDMEM(newlength+1)); -#if OptJr - STRINGCAT( mystring , mylength , sother , otherlength ) ; -#else - STRCAT(mystring,mylength,sother,otherlength); -#endif - } - else { - mystring =Allocate(ROUNDMEM(newlength+1)); -#if OptJr - ASCIISTRINGCOPY( mystring , sother , newlength ) ; -#else - STRCPY(mystring,sother,newlength); -#endif - } + if (other.mylength) { + Standard_Integer newlength = mylength+other.mylength; + mystring = Reallocate (mystring, newlength + 1); + strncpy( mystring + mylength, other.mystring, other.mylength+1 ); mylength = newlength; -#if !OptJr - mystring[mylength] = '\0'; -#endif } } @@ -423,10 +323,9 @@ void TCollection_AsciiString::AssignCat(const TCollection_AsciiString& other) // ---------------------------------------------------------------------------- void TCollection_AsciiString::Capitalize() { - for (int i=0; i < mylength; i++) { - if ( i==0 ) mystring[i] = ::UpperCase(mystring[i]); - else mystring[i] = ::LowerCase(mystring[i]); - } + if ( mylength ) mystring[0] = ::UpperCase(mystring[0]); + for (int i = 1; i < mylength; i++ ) + mystring[i] = ::LowerCase(mystring[i]); } // --------------------------------------------------------------------------- @@ -468,10 +367,13 @@ void TCollection_AsciiString::ChangeAll(const Standard_Character aChar, // ---------------------------------------------------------------------------- void TCollection_AsciiString::Clear() { - if (mystring) Standard::Free((void*&)mystring); - mylength = 0; - mystring = Allocate(mylength+1); - mystring[mylength] = '\0'; + if ( mylength > 0 ) + { + Free (mystring); + mylength = 0; + mystring = Allocate(mylength+1); + mystring[mylength] = '\0'; + } } // ---------------------------------------------------------------------------- @@ -479,37 +381,14 @@ void TCollection_AsciiString::Clear() // ---------------------------------------------------------------------------- void TCollection_AsciiString::Copy(const Standard_CString fromwhere) { - if (fromwhere) { - Standard_Integer newlength; -#if OptJr - STRINGLEN( fromwhere , newlength ) ; -#else - STRLEN(fromwhere,newlength); -#endif - if (mystring) { - - mystring = Reallocate((void*&)mystring, - ROUNDMEM(newlength+1)); - - } - else { - mystring = Allocate( ROUNDMEM(newlength + 1) ); - } -#if OptJr - CSTRINGCOPY( mystring , fromwhere , newlength ) ; - mylength = newlength; -#else - STRCPY(mystring, fromwhere,newlength); - mystring[newlength] = '\0'; - mylength = newlength; -#endif + mylength = Standard_Integer( strlen( fromwhere )); + mystring = Reallocate (mystring, mylength + 1); + strncpy( mystring, fromwhere, mylength+1 ); } else { - if (mystring) { - mylength = 0; - mystring[mylength] = '\0'; - } + mylength = 0; + mystring[mylength] = '\0'; } } @@ -518,34 +397,15 @@ void TCollection_AsciiString::Copy(const Standard_CString fromwhere) // ---------------------------------------------------------------------------- void TCollection_AsciiString::Copy(const TCollection_AsciiString& fromwhere) { - if (fromwhere.mystring) { - Standard_Integer newlength = fromwhere.mylength; - if (mystring) { - - mystring = Reallocate((void*&)mystring, - ROUNDMEM(newlength+1)); - - } - else { - mystring =Allocate(ROUNDMEM(newlength+1)); - } -#if OptJr - ASCIISTRINGCOPY( mystring , fromwhere.mystring , newlength ) ; - mylength = newlength; -#else - STRCPY(mystring, fromwhere.mystring,newlength); - mylength = newlength; - mystring[mylength] = '\0'; -#endif + mylength = fromwhere.mylength; + mystring = Reallocate (mystring, mylength + 1); + strncpy( mystring, fromwhere.mystring, mylength+1 ); } else { - if (mystring) { - mylength = 0; - mystring[mylength] = '\0'; - } + mylength = 0; + mystring[mylength] = '\0'; } - } // ---------------------------------------------------------------------------- @@ -553,7 +413,8 @@ void TCollection_AsciiString::Copy(const TCollection_AsciiString& fromwhere) // ---------------------------------------------------------------------------- void TCollection_AsciiString::Destroy() { - if (mystring) Standard::Free((void*&)mystring); + if (mystring) + Free (mystring); mystring = 0L; } @@ -607,18 +468,10 @@ void TCollection_AsciiString::Insert(const Standard_Integer where, { if (where > mylength + 1 ) Standard_OutOfRange::Raise ("TCollection_AsciiString::Insert : Parameter where is too big"); - if (where < 0) Standard_OutOfRange::Raise - ("TCollection_AsciiString::Insert : Parameter where is negative"); + if (where < 1) Standard_OutOfRange::Raise + ("TCollection_AsciiString::Insert : Parameter where is too small"); - if (mystring) { -// Standard_Integer length = *(int*)((long)mystring-8); -// if((mylength+1) >> 4 > length-1 >> 4) - mystring = Reallocate((void*&)mystring, - mylength+2); - } - else { - mystring = Allocate(mylength+2); - } + mystring = Reallocate (mystring, mylength + 2); if (where != mylength +1) { for (int i=mylength-1; i >= where-1; i--) mystring[i+1] = mystring[i]; @@ -634,25 +487,12 @@ void TCollection_AsciiString::Insert(const Standard_Integer where, void TCollection_AsciiString::Insert(const Standard_Integer where, const Standard_CString what) { - if (where <= mylength + 1) { + if (where <= mylength + 1 && where > 0) { if(what) { - Standard_Integer whatlength; -#if OptJr - STRINGLEN( what , whatlength ); -#else - STRLEN(what,whatlength); -#endif + Standard_Integer whatlength = Standard_Integer( strlen( what ) ); Standard_Integer newlength = mylength + whatlength; - if (mystring) { -// Standard_Integer length = *(int*)((long)mystring-8); -// if(newlength >> 4 > length-1 >> 4) - mystring = Reallocate((void*&)mystring, - newlength+1); - } - else { - mystring =Allocate(newlength+1); - } + mystring = Reallocate (mystring, newlength + 1); if (where != mylength +1) { for (int i=mylength-1; i >= where-1; i--) mystring[i+whatlength] = mystring[i]; @@ -666,7 +506,7 @@ void TCollection_AsciiString::Insert(const Standard_Integer where, } else { Standard_OutOfRange::Raise("TCollection_AsciiString::Insert : " - "Parameter where is too big"); + "Parameter where is invalid"); } } @@ -682,15 +522,8 @@ void TCollection_AsciiString::Insert(const Standard_Integer where, if(whatlength) { Standard_Integer newlength = mylength + whatlength; - if (mystring) { -// Standard_Integer length = *(int*)((long)mystring-8); -// if(newlength >> 4 > length-1 >> 4) - mystring = Reallocate((void*&)mystring, - newlength+1); - } - else { - mystring =Allocate(newlength+1); - } + mystring = Reallocate (mystring, newlength + 1); + if (where != mylength +1) { for (int i=mylength-1; i >= where-1; i--) mystring[i+whatlength] = mystring[i]; @@ -734,32 +567,8 @@ void TCollection_AsciiString::InsertBefore(const Standard_Integer Index, Standard_Boolean TCollection_AsciiString::IsEqual (const Standard_CString other)const { - int otherlength; - if (other) { -#if OptJr -// STRINGLEN( other , otherlength ); -#else - STRLEN(other,otherlength); - if(mylength != otherlength) return Standard_False; -#endif -#if OptJr - Standard_Boolean KEqual ; -// CSTRINGEQUAL( mystring , other , mylength , KEqual ) ; - if ( mystring ) { - LCSTRINGEQUAL( mystring , mylength , other , KEqual ) ; - return KEqual ; - } - - STRINGLEN( other , otherlength ); - if ( mylength != otherlength ) - return Standard_False ; - return Standard_True; -#else - for (int i = 0 ; i < mylength ; i++) - if (mystring[i] != other[i]) return Standard_False; - return Standard_True; -#endif + return ( strncmp( other, mystring, mylength+1 ) == 0 ); } Standard_NullObject::Raise("TCollection_AsciiString::Operator == " "Parameter 'other'"); @@ -772,18 +581,8 @@ Standard_Boolean TCollection_AsciiString::IsEqual Standard_Boolean TCollection_AsciiString::IsEqual (const TCollection_AsciiString& other)const { - if (mylength != other.mylength) return Standard_False; -#if OptJr - Standard_Boolean KEqual ; - ASCIISTRINGEQUAL( mystring , other.mystring , mylength , KEqual ) ; - return KEqual ; -#else - Standard_CString sother = other.mystring; - for (int i = 0 ; i < mylength ; i++) - if (mystring[i] != sother[i]) return Standard_False; - return Standard_True; -#endif + return ( strncmp( other.mystring, mystring, mylength ) == 0 ); } // ---------------------------------------------------------------------------- @@ -800,37 +599,12 @@ Standard_Boolean TCollection_AsciiString::IsEmpty() const Standard_Boolean TCollection_AsciiString::IsDifferent (const Standard_CString other)const { - if (other) { -#if OptJr -// STRINGLEN( other , otherlength ); -#else - STRLEN(other,otherlength); - if(mylength != otherlength) return Standard_True; -#endif -#if OptJr - Standard_Boolean KEqual ; -// CSTRINGEQUAL( mystring , other , mylength , KEqual ) ; - if ( mystring ) { - LCSTRINGEQUAL( mystring , mylength , other , KEqual ) ; - return !KEqual ; - } -// STRINGLEN( other , otherlength ); - return Standard_True; - -#else - int otherlength; - - for (int i = 0 ; i < mylength ; i++) - if (mystring[i] != other[i]) return Standard_True; - return Standard_False; - if ( mylength != otherlength ) - return Standard_False ; - return Standard_True; -#endif - } - Standard_NullObject::Raise("TCollection_AsciiString::Operator != " + if (other) { + return ( strncmp( other, mystring, mylength+1 ) != 0 ); + } + Standard_NullObject::Raise("TCollection_AsciiString::Operator != " "Parameter 'other'"); - return Standard_False; + return Standard_False; } // ---------------------------------------------------------------------------- @@ -841,16 +615,7 @@ Standard_Boolean TCollection_AsciiString::IsDifferent { if (mylength != other.mylength) return Standard_True; -#if OptJr - Standard_Boolean KEqual ; - ASCIISTRINGEQUAL( mystring , other.mystring , mylength , KEqual ) ; - return !KEqual ; -#else - Standard_CString sother = other.mystring; - for (int i = 0 ; i < mylength ; i++) - if (mystring[i] != sother[i]) return Standard_True; - return Standard_False; -#endif + return ( strncmp( other.mystring, mystring, mylength ) != 0 ); } // ---------------------------------------------------------------------------- @@ -860,28 +625,7 @@ Standard_Boolean TCollection_AsciiString::IsLess (const Standard_CString other)const { if (other) { -#if OptJr - - Standard_Boolean KLess ; - -// STRINGLEN( other , otherlength ); -// CSTRINGLESS( mystring , mylength , other , otherlength , -// INF( mylength , otherlength ) , KLess ) ; - LCSTRINGLESS( mystring , mylength , other , KLess ) ; - return KLess ; -#else - Standard_Integer otherlength; - Standard_Integer i = 0, j = 0; - STRLEN(other,otherlength); - while ( i < mylength && j < otherlength) { - if (mystring[i] < other[j]) return Standard_True; - if (mystring[i] > other[j]) return Standard_False; - i++ ; - j++; - } - if (i == mylength && j < otherlength) return Standard_True; - return Standard_False; -#endif + return ( strncmp( mystring, other, mylength+1 ) < 0 ); } Standard_NullObject::Raise("TCollection_AsciiString::Operator < " "Parameter 'other'"); @@ -894,26 +638,7 @@ Standard_Boolean TCollection_AsciiString::IsLess Standard_Boolean TCollection_AsciiString::IsLess (const TCollection_AsciiString& other)const { -#if OptJr - - Standard_Boolean KLess ; - ASCIISTRINGLESS( mystring , mylength , other.mystring , other.mylength , - INF( mylength , other.mylength ) , KLess ) ; - return KLess ; - -#else - Standard_Integer i = 0, j = 0; - Standard_Integer otherlength = other.mylength; - Standard_CString sother = other.mystring; - while ( i < mylength && j < otherlength) { - if (mystring[i] < sother[j]) return Standard_True; - if (mystring[i] > sother[j]) return Standard_False; - i++ ; - j++; - } - if (i == mylength && j < otherlength) return Standard_True; - return Standard_False; -#endif + return ( strncmp( mystring, other.mystring, mylength+1 ) < 0 ); } // ---------------------------------------------------------------------------- @@ -923,28 +648,7 @@ Standard_Boolean TCollection_AsciiString::IsGreater (const Standard_CString other)const { if (other) { -#if OptJr - - Standard_Boolean KGreater ; - -// STRINGLEN( other , otherlength ); -// CSTRINGGREATER( mystring , mylength , other , otherlength , -// INF( mylength , otherlength ) , KGreater ) ; - LCSTRINGGREATER( mystring , mylength , other , KGreater ) ; - return KGreater ; -#else - Standard_Integer otherlength; - Standard_Integer i = 0, j = 0; - STRLEN(other,otherlength); - while (i < mylength && j <= otherlength) { - if (mystring[i] < other[j]) return Standard_False; - if (mystring[i] > other[j]) return Standard_True; - i++ ; - j++; - } - if (j == otherlength && i < mylength) return Standard_True; - return Standard_False; -#endif + return ( strncmp( mystring, other, mylength+1 ) > 0 ); } Standard_NullObject::Raise("TCollection_AsciiString::Operator > " "Parameter 'other'"); @@ -957,26 +661,7 @@ Standard_Boolean TCollection_AsciiString::IsGreater Standard_Boolean TCollection_AsciiString::IsGreater (const TCollection_AsciiString& other)const { -#if OptJr - - Standard_Boolean KGreater ; - - ASCIISTRINGGREATER( mystring , mylength , other.mystring , other.mylength, - INF( mylength , other.mylength ) , KGreater ) ; - return KGreater ; -#else - Standard_Integer i = 0, j = 0; - Standard_Integer otherlength = other.mylength; - Standard_CString sother = other.mystring; - while (i < mylength && j <= otherlength) { - if (mystring[i] < sother[j]) return Standard_False; - if (mystring[i] > sother[j]) return Standard_True; - i++ ; - j++; - } - if (j == otherlength && i < mylength) return Standard_True; - return Standard_False; -#endif + return ( strncmp( mystring, other.mystring, mylength+1 ) > 0 ); } // ---------------------------------------------------------------------------- @@ -985,13 +670,11 @@ Standard_Boolean TCollection_AsciiString::IsGreater Standard_Integer TCollection_AsciiString::IntegerValue()const { char *ptr; - Standard_Integer value = 0; - if(mystring) { - value = (int)strtol(mystring,&ptr,10); - if (ptr != mystring) return value; - } + Standard_Integer value = (Standard_Integer)strtol(mystring,&ptr,10); + if (ptr != mystring) return value; + Standard_NumericError::Raise("TCollection_AsciiString::IntegerValue"); - return value; + return 0; } // ---------------------------------------------------------------------------- @@ -1000,18 +683,13 @@ Standard_Integer TCollection_AsciiString::IntegerValue()const Standard_Boolean TCollection_AsciiString::IsIntegerValue()const { char *ptr; - if(mystring) { -//#ifdef DEB -// Standard_Integer value = (int)strtol(mystring,&ptr,10); -//#else - strtol(mystring,&ptr,10); -//#endif - if (ptr != mystring) { - for (int i=0; i < mylength; i++) { - if (mystring[i] == '.') return Standard_False; - } - return Standard_True; + strtol(mystring,&ptr,10); + + if (ptr != mystring) { + for (int i=int(ptr-mystring); i < mylength; i++) { + if (mystring[i] == '.') return Standard_False; // what about 'e','x',etc ??? } + return Standard_True; } return Standard_False; } @@ -1022,12 +700,8 @@ Standard_Boolean TCollection_AsciiString::IsIntegerValue()const Standard_Boolean TCollection_AsciiString::IsRealValue()const { char *ptr; - if(mystring) { - Strtod(mystring,&ptr); - if (ptr != mystring) return Standard_True; - else return Standard_False; - } - return Standard_False; + Strtod(mystring,&ptr); + return (ptr != mystring); } // ---------------------------------------------------------------------------- @@ -1059,15 +733,7 @@ void TCollection_AsciiString::LeftJustify(const Standard_Integer Width, const Standard_Character Filler) { if (Width > mylength) { - if (mystring) { -// Standard_Integer length = *(int*)((long)mystring-8); -// if(Width >> 4 > length-1 >> 4) - mystring = Reallocate((void*&)mystring, - Width+1); - } - else { - mystring = Allocate(Width+1); - } + mystring = Reallocate (mystring, Width + 1); for (int i = mylength; i < Width ; i++) mystring[i] = Filler; mylength = Width; mystring[mylength] = '\0'; @@ -1155,11 +821,9 @@ void TCollection_AsciiString::Prepend(const TCollection_AsciiString& what) Standard_Real TCollection_AsciiString::RealValue()const { char *ptr; - Standard_Real value = 0; - if(mystring) { - value = Strtod(mystring,&ptr); - if (ptr != mystring) return value; - } + Standard_Real value = Strtod(mystring,&ptr); + if (ptr != mystring) return value; + Standard_NumericError::Raise("TCollection_AsciiString::RealValue"); return value; } @@ -1169,35 +833,18 @@ Standard_Real TCollection_AsciiString::RealValue()const //-------------------------------------------------------------------------- void TCollection_AsciiString::Read(Standard_IStream& astream) { + // get characters from astream + const Standard_Integer bufSize = 8190; + Standard_Character buffer[bufSize]; + std::streamsize oldWidth = astream.width (bufSize); + astream >> buffer; + astream.width( oldWidth ); - int newlength; - - union { int bid ; - Standard_Character buffer[8190]; } CHN ; - astream >> CHN.buffer; // Get characters from astream - -#if OptJr - STRINGLEN( CHN.buffer , newlength ); -#else - STRLEN(CHN.buffer,newlength); -#endif - if (mystring) { -// Standard_Integer length = *(int*)((long)mystring-8); -// if(newlength >> 4 > length-1 >> 4) - mystring = Reallocate((void*&)mystring, - ROUNDMEM(newlength+1)); - } - else { - mystring =Allocate(ROUNDMEM(newlength+1)); - } -#if OptJr - ASCIISTRINGCOPY( mystring , CHN.buffer , newlength ) ; - mylength = newlength; -#else - STRCPY(mystring,CHN.buffer,newlength); - mylength = newlength; - mystring[mylength] = '\0'; -#endif + // put to string + mylength = Standard_Integer( strlen( buffer )); + mystring = Reallocate (mystring, mylength + 1); + strncpy(mystring,buffer,mylength); + mystring[mylength] = '\0'; } @@ -1304,15 +951,8 @@ void TCollection_AsciiString::RightJustify(const Standard_Integer Width, Standard_Integer i ; Standard_Integer k ; if (Width > mylength) { - if (mystring) { -// Standard_Integer length = *(int*)((long)mystring-8); -// if(Width >> 4 > length-1 >> 4) - mystring = Reallocate((void*&)mystring, - Width+1); - } - else { - mystring =Allocate(Width+1); - } + mystring = Reallocate (mystring, Width + 1); + for ( i = mylength-1, k = Width-1 ; i >= 0 ; i--, k--) mystring[k] = mystring[i]; for(; k >= 0 ; k--) mystring[k] = Filler; @@ -1330,12 +970,7 @@ void TCollection_AsciiString::RightJustify(const Standard_Integer Width, Standard_Integer TCollection_AsciiString::Search (const Standard_CString what)const { - Standard_Integer size; -#if OptJr - STRINGLEN( what , size ); -#else - STRLEN(what,size); -#endif + Standard_Integer size = Standard_Integer( what ? strlen( what ) : 0 ); if (size) { int k,j; int i = 0; @@ -1380,12 +1015,7 @@ Standard_Integer TCollection_AsciiString::Search Standard_Integer TCollection_AsciiString::SearchFromEnd (const Standard_CString what)const { - int size; -#if OptJr - STRINGLEN( what , size ); -#else - STRLEN(what,size); -#endif + Standard_Integer size = Standard_Integer( what ? strlen( what ) : 0 ); if (size) { int k,j; int i = mylength-1; @@ -1447,23 +1077,10 @@ void TCollection_AsciiString::SetValue(const Standard_Integer where, const Standard_CString what) { if (where > 0 && where <= mylength+1) { - Standard_Integer size; -#if OptJr - STRINGLEN( what , size ); -#else - STRLEN(what,size); -#endif + Standard_Integer size = Standard_Integer( what ? strlen( what ) : 0 ); size += (where - 1); - if (size >= mylength){ - if (mystring) { -// Standard_Integer length = *(int*)((long)mystring-8); -// if(size >> 4 > length-1 >> 4) - mystring = Reallocate((void*&)mystring, - size+1); - } - else { - mystring =Allocate(size+1); - } + if (size >= mylength) { + mystring = Reallocate (mystring, size + 1); mylength = size; } for (int i = where-1; i < size; i++) @@ -1486,16 +1103,8 @@ void TCollection_AsciiString::SetValue(const Standard_Integer where, Standard_Integer size = what.mylength; Standard_CString swhat = what.mystring; size += (where - 1); - if (size >= mylength){ - if (mystring) { -// Standard_Integer length = *(int*)((long)mystring-8); -// if(size >> 4 > length-1 >> 4) - mystring = Reallocate((void*&)mystring, - size+1); - } - else { - mystring =Allocate(size+1); - } + if (size >= mylength) { + mystring = Reallocate (mystring, size + 1); mylength = size; } for (int i = where-1; i < size; i++) @@ -1531,11 +1140,7 @@ TCollection_AsciiString TCollection_AsciiString::Split (const Standard_Integer where) { if (where >= 0 && where <= mylength) { -#if OptJr TCollection_AsciiString res( &mystring[where] , mylength - where ); -#else - TCollection_AsciiString res(&mystring[where]); -#endif Trunc(where); return res; } @@ -1556,50 +1161,13 @@ void TCollection_AsciiString::SubString(const Standard_Integer FromIndex, if (ToIndex > mylength || FromIndex <= 0 || FromIndex > ToIndex ) Standard_OutOfRange::Raise(); Standard_Integer newlength = ToIndex-FromIndex+1; - res.mystring =Allocate(ROUNDMEM(newlength+1)); - -#if OptJr - CSTRINGCOPY( res.mystring , &(mystring [ FromIndex - 1 ]) , newlength ); -#else - memcpy(res.mystring, &(mystring[FromIndex-1]),newlength); -#endif + res.mystring =Reallocate (res.mystring, newlength + 1); + strncpy( res.mystring, mystring + FromIndex - 1, newlength ); res.mystring[newlength] = '\0'; res.mylength = newlength; return ; } -#if !OptJr -// ---------------------------------------------------------------------------- -// SubString -// ---------------------------------------------------------------------------- -TCollection_AsciiString TCollection_AsciiString::SubString - (const Standard_Integer FromIndex, - const Standard_Integer ToIndex) const -{ - - if (ToIndex > mylength || FromIndex <= 0 || FromIndex > ToIndex ) - Standard_OutOfRange::Raise(); - -#if OptJr - return TCollection_AsciiString( &mystring [ FromIndex - 1 ] , - ToIndex - FromIndex + 1 ) ; - -#else - TCollection_AsciiString res; - Standard_Integer newlength = ToIndex-FromIndex+1; - res.mystring = Allocate(ROUNDMEM(newlength+1)); -#if OptJr - CSTRINGCOPY( res.mystring , &(mystring [ FromIndex - 1 ]) , newlength ); -#else - memcpy(res.mystring, &(mystring[FromIndex-1]),newlength); -#endif - res.mystring[newlength] = '\0'; - res.mylength = newlength; - return res; -#endif -} -#endif - // ---------------------------------------------------------------------------- // Token // Private @@ -1608,81 +1176,7 @@ void TCollection_AsciiString::Token(const Standard_CString separators, const Standard_Integer whichone, TCollection_AsciiString& res)const { - -#if OptJr res = Token( separators , whichone ) ; - -#else - if (!separators) - Standard_NullObject::Raise("TCollection_AsciiString::Token : " - "parameter 'separators'"); - - int i,j,k,l; - Standard_CString buftmp =Allocate(mylength+1); - Standard_Character aSep; - - Standard_Boolean isSepFound = Standard_False, otherSepFound; - - j = 0; - - for (i = 0; i < whichone && j < mylength; i++) { - isSepFound = Standard_False; - k = 0; - buftmp[0] = 0; - - // Avant de commencer il faut virer les saloperies devant - // - otherSepFound = Standard_True; - while (j < mylength && otherSepFound) { - l = 0; - otherSepFound = Standard_False; - aSep = separators[l]; - while(aSep != 0) { - if (aSep == mystring[j]) { - aSep = 0; - otherSepFound = Standard_True; - } - else { - aSep = separators[l++]; - } - } - if (otherSepFound) j++; - } - - while (!isSepFound && k < mylength && j 0 && where <= mylength) { - if(mystring) return mystring[where-1]; - else return '\0'; + return mystring[where-1]; } Standard_OutOfRange::Raise("TCollection_AsciiString::Value : parameter where"); return '\0'; } - - -//------------------------------------------------------------------------ -// ISSIMILAR -//------------------------------------------------------------------------ -Standard_Boolean TCollection_AsciiString::ISSIMILAR - (const TCollection_AsciiString& string1, - const TCollection_AsciiString& string2) -{ - if ( string1.Length() != string2.Length() ) - return Standard_False ; - return ::ISSIMILAR (string1.ToCString() , - string1.Length() , - string2.ToCString() ); -} diff --git a/src/TCollection/TCollection_AsciiString.lxx b/src/TCollection/TCollection_AsciiString.lxx index 69ee968bf2..515930ebdb 100755 --- a/src/TCollection/TCollection_AsciiString.lxx +++ b/src/TCollection/TCollection_AsciiString.lxx @@ -111,15 +111,6 @@ inline Standard_Boolean TCollection_AsciiString::IsEqual(const TCollection_Ascii return string1.IsEqual( string2 ); } -//------------------------------------------------------------------------ -// HASHCODE -//------------------------------------------------------------------------ -inline Standard_Integer TCollection_AsciiString::HASHCODE(const TCollection_AsciiString& astring, - const Standard_Integer Upper) -{ - return ::HASHCODE( astring.ToCString() , astring.Length() , Upper ); -} - // ---------------------------------------------------------------------------- // SubString // ---------------------------------------------------------------------------- diff --git a/src/TCollection/TCollection_ExtendedString.cxx b/src/TCollection/TCollection_ExtendedString.cxx old mode 100755 new mode 100644 index 62235535d7..772b1bc4be --- a/src/TCollection/TCollection_ExtendedString.cxx +++ b/src/TCollection/TCollection_ExtendedString.cxx @@ -17,18 +17,6 @@ // and conditions governing the rights and limitations under the License. -#define OptJr 1 - -// OCC6794: if OptJr is ON, we need to ensure that memory allocations are done by 4 bytes words, -// in order to avoid writing into unallocated memory at the string end when it is copied -// by CSTRINGCOPY or ASCIISTRINGCOPY macros -// (though, due to OCC memory manager roundings of allocated memory, the problem appears -// only when MMGT_OPT is 0 and string size is greater than MMGT_THRESHOLD) -#ifdef OptJr -#define ROUNDMEM(len) (((len)+3)&~0x3) -#else -#define ROUNDMEM(len) (len) -#endif //#if defined(WNT) || defined(LIN) #include //#endif @@ -39,7 +27,6 @@ #include #include #include -#include #include static @@ -47,7 +34,7 @@ static static Standard_PExtCharacter Reallocate(Standard_Address aAddr, - const Standard_Size aLength); + const Standard_Size aLength); Standard_EXPORT short NULL_EXTSTRING[1] = {0}; @@ -117,13 +104,13 @@ inline Standard_Integer nbSymbols(const Standard_CString aStr) { if((aStr[i] & 0x80) == 0x00) //1byte => 1 symb - Lat1 {aLen++; i++;} else if((aStr[i] & 0xE0) == 0xC0 && - (aStr[i+1] && - (aStr[i+1] & 0xC0) == 0x80)) {//2 bytes => 1 symb + (aStr[i+1] && + (aStr[i+1] & 0xC0) == 0x80)) {//2 bytes => 1 symb aLen++; i += 2; } else if((aStr[i] & 0xF0) == 0xE0 && - ((aStr[i+1] && (aStr[i+1] & 0xC0) == 0x80)) && - (aStr[i+2] && (aStr[i+2] & 0xC0) == 0x80)) { + ((aStr[i+1] && (aStr[i+1] & 0xC0) == 0x80)) && + (aStr[i+2] && (aStr[i+2] & 0xC0) == 0x80)) { aLen++; i += 3; } else @@ -148,27 +135,23 @@ TCollection_ExtendedString::TCollection_ExtendedString() //---------------------------------------------------------------------------- TCollection_ExtendedString::TCollection_ExtendedString (const Standard_CString astring, - const Standard_Boolean isMultiByte) + const Standard_Boolean isMultiByte) { if (astring) { if(!isMultiByte) { -#if OptJr - STRINGLEN( astring , mylength ) ; -#else - STRLEN(astring,mylength); -#endif + mylength = strlen( astring ); mystring = Allocate((mylength+1)*2); for (int i = 0 ; i < mylength ; i++) - mystring[i] = ToExtCharacter(astring[i]); + mystring[i] = ToExtCharacter(astring[i]); mystring[mylength] = '\0'; } else { mylength = nbSymbols(astring); - mystring = Allocate(ROUNDMEM((mylength+1)*2)); + mystring = Allocate( (mylength+1)*2 ); if(!ConvertToUnicode (astring)) { #ifdef DEB - cout <<"UTF8 decoding failure..." < 0) STRCPY (res.mystring, mystring, mylength); - STRCPY (&res.mystring[mylength], sother, otherlength); - res.mystring[newlength] = '\0'; -#endif - } - else if (mylength > 0) { -// TCollection_ExtendedString res; -// res.mystring = (Standard_ExtString)Standard::Allocate((mylength+1)*2); -#if OptJr - EXTENDEDSTRINGCOPY( res.mystring , mystring , mylength ); -#else - STRCPY (res.mystring, mystring,mylength); - res.mystring[res.mylength] = '\0'; -#endif - } + TCollection_ExtendedString res( mylength + other.mylength, 0 ); + if ( mylength > 0 ) + memcpy( res.mystring, mystring, mylength*2 ); + if ( other.mylength > 0 ) + memcpy( res.mystring + mylength, other.mystring, other.mylength*2 ); return res; } @@ -436,20 +347,16 @@ void TCollection_ExtendedString::Copy (const TCollection_ExtendedString& fromwhe { if (fromwhere.mystring) { - Standard_Integer newlength = fromwhere.mylength; + const Standard_Integer newlength = fromwhere.mylength; + const Standard_Integer size = (newlength + 1) * 2; if (mystring) { - mystring = Reallocate((void*&)mystring, ROUNDMEM(( newlength + 1)*2 )); + mystring = Reallocate((void*&)mystring, size ); } else { - mystring = Allocate(ROUNDMEM((newlength+1)*2)); + mystring = Allocate( size ); } mylength = newlength; -#if OptJr - EXTENDEDSTRINGCOPY( mystring , fromwhere.mystring , newlength ); -#else - STRCPY(mystring, fromwhere.mystring,newlength); - mystring[mylength] = '\0'; -#endif + memcpy( mystring, fromwhere.mystring, size ); } else { if (mystring) { @@ -533,26 +440,14 @@ void TCollection_ExtendedString::Insert(const Standard_Integer where, } } -#if OptJr // ---------------------------------------------------------------------------- // IsEqual // ---------------------------------------------------------------------------- Standard_Boolean TCollection_ExtendedString::IsEqual (const Standard_ExtString other) const { -// Standard_Integer otherlength ; - -// EXTSTRINGLEN( other , otherlength ) -// if ( mylength != otherlength ) return Standard_False; - Standard_Boolean KEqual ; - LEXTSTRINGEQUAL( mystring , mylength , other , KEqual ) ; - return KEqual ; + return ( memcmp( mystring, other, (mylength+1)*2 ) == 0 ); } -#else -Standard_Boolean TCollection_ExtendedString::NoIsEqual - (const Standard_ExtString other) const -{return Standard_False ;} -#endif // ---------------------------------------------------------------------------- // IsEqual @@ -560,39 +455,17 @@ Standard_Boolean TCollection_ExtendedString::NoIsEqual Standard_Boolean TCollection_ExtendedString::IsEqual (const TCollection_ExtendedString& other) const { - if (mylength != other.mylength) return Standard_False; - Standard_ExtString sother = other.mystring; -#if OptJr - Standard_Boolean KEqual ; - EXTENDEDSTRINGEQUAL( mystring , sother , mylength , KEqual ) ; - return KEqual ; -#else - for (int i = 0 ; i < mylength ; i++) - if (mystring[i] != sother[i]) return Standard_False; - return Standard_True; -#endif + return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) == 0 ); } -#if OptJr // ---------------------------------------------------------------------------- // IsDifferent // ---------------------------------------------------------------------------- Standard_Boolean TCollection_ExtendedString::IsDifferent (const Standard_ExtString other ) const { -// Standard_Integer otherlength ; - -// EXTSTRINGLEN( other , otherlength ) -// if ( mylength != otherlength ) return Standard_True; - Standard_Boolean KEqual ; - LEXTSTRINGEQUAL( mystring , mylength , other , KEqual ) ; - return !KEqual ; + return ( memcmp( mystring, other, (mylength+1)*2 ) != 0 ); } -#else -Standard_Boolean TCollection_ExtendedString::NoIsDifferent - (const Standard_ExtString other ) const -{return Standard_False ;} -#endif // ---------------------------------------------------------------------------- // IsDifferent @@ -600,40 +473,17 @@ Standard_Boolean TCollection_ExtendedString::NoIsDifferent Standard_Boolean TCollection_ExtendedString::IsDifferent (const TCollection_ExtendedString& other) const { - if (mylength != other.mylength) return Standard_True; - Standard_ExtString sother = other.mystring; -#if OptJr - Standard_Boolean KEqual ; - EXTENDEDSTRINGEQUAL( mystring , sother , mylength , KEqual ) ; - return !KEqual ; -#else - for (int i = 0 ; i < mylength ; i++) - if (mystring[i] != sother[i]) return Standard_True; - return Standard_False; -#endif + return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) != 0 ); } -#if OptJr // ---------------------------------------------------------------------------- // IsLess // ---------------------------------------------------------------------------- Standard_Boolean TCollection_ExtendedString::IsLess (const Standard_ExtString other) const { -// Standard_Integer otherlength ; - -// EXTSTRINGLEN( other , otherlength ) - Standard_Boolean KLess ; -// EXTSTRINGLESS( mystring , mylength , other , otherlength , -// INF( mylength , otherlength ) , KLess ) ; - LEXTSTRINGLESS( mystring , mylength , other , KLess ) ; - return KLess ; + return ( memcmp( mystring, other, (mylength+1)*2 ) < 0 ); } -#else -Standard_Boolean TCollection_ExtendedString::NoIsLess - (const Standard_ExtString other) const -{return Standard_False ;} -#endif // ---------------------------------------------------------------------------- // IsLess @@ -641,48 +491,17 @@ Standard_Boolean TCollection_ExtendedString::NoIsLess Standard_Boolean TCollection_ExtendedString::IsLess (const TCollection_ExtendedString& other) const { - - Standard_Integer otherlength = other.mylength; - Standard_ExtString sother = other.mystring; -#if OptJr - Standard_Boolean KLess ; - EXTENDEDSTRINGLESS( mystring , mylength , sother , otherlength , - INF( mylength , otherlength ) , KLess ) ; - return KLess ; -#else - Standard_Integer i = 0, j = 0; - while ( i < mylength && j < otherlength) { - if (mystring[i] < sother[j]) return Standard_True; - if (mystring[i] > sother[j]) return Standard_False; - i++ ; - j++; - } - if (i == mylength && j < otherlength) return Standard_True; - return Standard_False; -#endif + return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) < 0 ); } -#if OptJr // ---------------------------------------------------------------------------- // IsGreater // ---------------------------------------------------------------------------- Standard_Boolean TCollection_ExtendedString::IsGreater (const Standard_ExtString other) const { -// Standard_Integer otherlength ; - -// EXTSTRINGLEN( other , otherlength ) - Standard_Boolean KGreater ; -// EXTSTRINGGREATER( mystring , mylength , other , otherlength , -// INF( mylength , otherlength ) , KGreater ) ; - LEXTSTRINGGREATER( mystring , mylength , other , KGreater ) ; - return KGreater ; + return ( memcmp( mystring, other, (mylength+1)*2 ) > 0 ); } -#else -Standard_Boolean TCollection_ExtendedString::NoIsGreater - (const Standard_ExtString other) const -{return Standard_False ;} -#endif // ---------------------------------------------------------------------------- // IsGreater @@ -690,24 +509,7 @@ Standard_Boolean TCollection_ExtendedString::NoIsGreater Standard_Boolean TCollection_ExtendedString::IsGreater (const TCollection_ExtendedString& other) const { - Standard_Integer otherlength = other.mylength; - Standard_ExtString sother = other.mystring; -#if OptJr - Standard_Boolean KGreater ; - EXTENDEDSTRINGGREATER( mystring , mylength , sother , otherlength , - INF( mylength , otherlength ) , KGreater ) ; - return KGreater ; -#else - Standard_Integer i = 0, j = 0; - while (i < mylength && j <= otherlength) { - if (mystring[i] < sother[j]) return Standard_False; - if (mystring[i] > sother[j]) return Standard_True; - i++ ; - j++; - } - if (j == otherlength && i < mylength) return Standard_True; - return Standard_False; -#endif + return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) > 0 ); } // ---------------------------------------------------------------------------- @@ -898,7 +700,7 @@ TCollection_ExtendedString TCollection_ExtendedString::Token (const Standard_ExtString separators, const Standard_Integer whichone) const { - TCollection_ExtendedString res(""); + TCollection_ExtendedString res; if (!separators) Standard_NullObject::Raise("TCollection_ExtendedString::Token : " "parameter 'separators'"); @@ -960,12 +762,9 @@ TCollection_ExtendedString TCollection_ExtendedString::Token Standard::Free((void*&)buftmp); } else { + Standard::Free((void*&)res.mystring); res.mystring = buftmp; -#if OptJr - EXTSTRINGLEN( buftmp , res.mylength ) ; -#else - EXTSTRLEN(buftmp,res.mylength); -#endif + for ( res.mylength=0; buftmp[res.mylength]; ++res.mylength ); } return res; } @@ -1020,13 +819,13 @@ Standard_Boolean TCollection_ExtendedString::ConvertToUnicode if((aStr[i] & 0x80) == 0x00) //1byte => 1 symb - Lat1 {*p++ = ToExtCharacter(aStr[i]); i++;} else if((aStr[i] & 0xE0) == 0xC0 && - (aStr[i+1] && - (aStr[i+1] & 0xC0) == 0x80)) {//2 bytes => 1 symb + (aStr[i+1] && + (aStr[i+1] & 0xC0) == 0x80)) {//2 bytes => 1 symb *p++ = ConvertToUnicode2B((unsigned char*)&aStr[i]); i += 2; } else if((aStr[i] & 0xF0) == 0xE0 && - ((aStr[i+1] && (aStr[i+1] & 0xC0) == 0x80)) && - (aStr[i+2] && (aStr[i+2] & 0xC0) == 0x80)) { + ((aStr[i+1] && (aStr[i+1] & 0xC0) == 0x80)) && + (aStr[i+2] && (aStr[i+2] & 0xC0) == 0x80)) { *p++ = ConvertToUnicode3B((unsigned char*)&aStr[i]); i += 3; } else { //unsupported case ==> not UTF8 @@ -1118,7 +917,7 @@ Standard_PExtCharacter Allocate(const Standard_Size aLength) //purpose : //======================================================================= Standard_PExtCharacter Reallocate(Standard_Address aAddr, - const Standard_Size aLength) + const Standard_Size aLength) { Standard_PExtCharacter pChar; // diff --git a/src/TCollection/TCollection_HAsciiString.cxx b/src/TCollection/TCollection_HAsciiString.cxx index 9506eb4bc8..1b56519db0 100755 --- a/src/TCollection/TCollection_HAsciiString.cxx +++ b/src/TCollection/TCollection_HAsciiString.cxx @@ -18,11 +18,8 @@ -#define OptJr 1 - #include #include -#include // ---------------------------------------------------------------------------- // Create @@ -294,20 +291,9 @@ Standard_Boolean TCollection_HAsciiString::IsAscii() const Standard_Boolean TCollection_HAsciiString::IsDifferent (const Handle(TCollection_HAsciiString)& S) const { - if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsDifferent"); -#if OptJr - if ( myString.Length() == S->Length() ) { - Standard_Boolean KEqual ; - ASCIISTRINGEQUAL( myString.ToCString() , S->ToCString() , - myString.mylength , KEqual ) ; - return !KEqual ; - } - else - return Standard_True ; -#else - return ( strcmp(myString.ToCString(), S->ToCString()) ); -#endif + if(S->Length() != myString.Length() ) return Standard_True; + return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) != 0 ); } // ---------------------------------------------------------------------------- @@ -316,20 +302,11 @@ Standard_Boolean TCollection_HAsciiString::IsDifferent Standard_Boolean TCollection_HAsciiString::IsSameString (const Handle(TCollection_HAsciiString)& S) const { - if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsSameString"); -#if OptJr - if ( myString.Length() == S->Length() ) { - Standard_Boolean KEqual ; - ASCIISTRINGEQUAL( myString.ToCString() , S->ToCString() , - myString.mylength , KEqual ) ; - return KEqual ; - } + if ( myString.Length() == S->Length() ) + return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) == 0 ); else return Standard_False ; -#else - return ( !strcmp(myString.ToCString(), S->ToCString()) ); -#endif } // ---------------------------------------------------------------------------- @@ -339,21 +316,12 @@ Standard_Boolean TCollection_HAsciiString::IsSameString (const Handle(TCollection_HAsciiString)& S , const Standard_Boolean CaseSensitive) const { -// Handle(TCollection_HAsciiString) H1,H2; -// H1 = UpperCase(This); -// H2 = UpperCase(S); -// return ( H1 == H2)); - if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsSameString"); - Standard_Integer size1 = Length(); + const Standard_Integer size1 = Length(); if ( size1 != S->Length() ) return Standard_False; -#if OptJr if ( CaseSensitive ) { - Standard_Boolean KEqual ; - ASCIISTRINGEQUAL( myString.ToCString() , S->String().ToCString() , - size1 , KEqual ) ; - return KEqual ; + return ( strncmp( myString.ToCString(), S->ToCString(), size1 ) == 0 ); } else { for ( Standard_Integer i = 1 ; i <= size1; i++) { @@ -362,22 +330,6 @@ Standard_Boolean TCollection_HAsciiString::IsSameString } return Standard_True ; } - -#else -// Example of bad sequence of test : CaseSensitive does not change in the loop - Standard_Character C1,C2; - for( Standard_Integer i = 1 ; i <= size1; i++) { - if(CaseSensitive){ - if (Value(i) != S->Value(i)) return Standard_False; - } - else { - C1 = Value(i); - C2 = S->Value(i); - if(toupper(C1) != toupper(C2)) return Standard_False; - } - } - return Standard_True; -#endif } //------------------------------------------------------------------------ @@ -648,19 +600,10 @@ void TCollection_HAsciiString::ShallowDump(Standard_OStream& S) const // ---------------------------------------------------------------------------- Standard_Boolean TCollection_HAsciiString::IsSameState (const Handle(TCollection_HAsciiString)& other) const - { - -#if OptJr - if ( myString.Length() == other->Length() ) { - Standard_Boolean KEqual ; - ASCIISTRINGEQUAL( myString.ToCString() , other->ToCString() , - myString.mylength , KEqual ) ; - return KEqual ; - } +{ + if ( myString.Length() == other->Length() ) + return ( strncmp( myString.mystring, other->ToCString(), myString.Length() ) == 0 ); else return Standard_False ; -#else - return ( !strcmp(myString.mystring , other->ToCString() )); -#endif - } +} diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index d505780c70..90638695b0 100755 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -796,16 +796,16 @@ static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, cons Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB; if (argc > 2) { - TCollection_AsciiString aBuffTypeStr (argv[2]); - if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb"))) + const char* aBuffTypeStr = argv[2]; + if ( strcasecmp( aBuffTypeStr, "rgb" ) == 0 ) // 4 is to compare '\0' as well { aBufferType = Graphic3d_BT_RGB; } - else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba"))) + else if ( strcasecmp( aBuffTypeStr, "rgba" ) == 0 ) { aBufferType = Graphic3d_BT_RGBA; } - else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth"))) + else if ( strcasecmp( aBuffTypeStr, "depth" ) == 0 ) { aBufferType = Graphic3d_BT_Depth; } diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 6b9030e17a..250ced8955 100755 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -1079,7 +1079,7 @@ static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const ch // Create list to iterate and remove views from the map of views NCollection_List aViewList; - if (TCollection_AsciiString::ISSIMILAR (anInputString, TCollection_AsciiString("ALL"))) + if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 ) { for (NCollection_DoubleMap::Iterator anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) @@ -1123,7 +1123,7 @@ static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const } TCollection_AsciiString aNameString(theArgVec[1]); - if (TCollection_AsciiString::ISSIMILAR (aNameString, TCollection_AsciiString("NONE"))) + if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 ) { TCollection_AsciiString aTitle("3D View - "); aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView()); @@ -1174,16 +1174,14 @@ static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const if (theArgsNb > 2) { theDi << theArgVec[0] << ": Wrong number of command arguments\n" - << "Usage: " << theArgVec[0]; + << "Usage: " << theArgVec[0] << " name"; return 1; } if (ViewerTest_myContexts.Size() < 1) return 0; - TCollection_AsciiString aNameString(theArgsNb==2?theArgVec[1]:""); Standard_Boolean isTreeView = - TCollection_AsciiString::ISSIMILAR (aNameString, TCollection_AsciiString("long"))? - Standard_False:Standard_True; + (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); if (isTreeView) theDi << theArgVec[0] <<":\n"; @@ -3905,39 +3903,39 @@ static int VReadPixel (Draw_Interpretor& theDI, Standard_Boolean toShowHls = Standard_False; for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) { - TCollection_AsciiString aParam (theArgVec[anIter]); - if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgb"))) + const char* aParam = theArgVec[anIter]; + if ( strcasecmp( aParam, "rgb" ) == 0 ) { aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; aBufferType = Graphic3d_BT_RGB; } - else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls"))) + else if ( strcasecmp( aParam, "hls" ) == 0 ) { aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; aBufferType = Graphic3d_BT_RGB; toShowHls = Standard_True; } - else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf"))) + else if ( strcasecmp( aParam, "rgbf" ) == 0 ) { aFormat = Image_PixMap::ImgRGBF; aBufferType = Graphic3d_BT_RGB; } - else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba"))) + else if ( strcasecmp( aParam, "rgba" ) == 0 ) { aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; aBufferType = Graphic3d_BT_RGBA; } - else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf"))) + else if ( strcasecmp( aParam, "rgbaf" ) == 0 ) { aFormat = Image_PixMap::ImgRGBAF; aBufferType = Graphic3d_BT_RGBA; } - else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth"))) + else if ( strcasecmp( aParam, "depth" ) == 0 ) { aFormat = Image_PixMap::ImgGrayF; aBufferType = Graphic3d_BT_Depth; } - else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name"))) + else if ( strcasecmp( aParam, "name" ) == 0 ) { toShowName = Standard_True; } diff --git a/tests/bugs/fclasses/bug11758 b/tests/bugs/fclasses/bug11758 new file mode 100755 index 0000000000..b3e34e5891 --- /dev/null +++ b/tests/bugs/fclasses/bug11758 @@ -0,0 +1,10 @@ +puts "=======" +puts "OCC11758" +puts "=======" +puts "" +########################################################################### TCollection strings are not memory safe as reported by Purify +########################################################################### + +pload QAcommands + +OCC11758