Custom string handling code enabled by OptJr macro removed from implementation of strings in TCollection and elsewhere.
Functions from string.h are used instead of macros from Standard_String.hxx
File Standard_String.hxx and methods ISSIMILAR and HASHCODE of TCollection*String classes are removed (to be replaced by strcasecmp).
Functions HashCode for strings reimplemented using DJB2 algorithm for C strings and SDBM algorithm for extended strings.
Adding test cases and draw-command for issue CR11758
Fix misprint added with previous integration
Fix misprint in the test command.
Remove compilation warnings (Linux).
Avoid compiler warning "dereferencing type-punned pointer will break strict-aliasing rules" on Linux
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 {
}
}
if (key2) {
-#ifdef WNT
if(!strcasecmp(key2,"-na")) {
-#else
- if (!strncasecmp(key2,"-na", 3)) {
-#endif
bApp = Standard_False;
}
else {
}
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;
}
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();
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TColStd_ListIteratorOfListOfReal.hxx>
-#include <Standard_Macro.hxx>
-#ifdef OptJr
-#define ROUNDMEM(len) (((len)+3)&~0x3)
-#else
-#define ROUNDMEM(len) (len)
-#endif
-
//=======================================================================
//function : DDataStd_SetInteger
//purpose : SetInteger (DF, entry, value)
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();
#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);
}
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepAlgo_Cut.hxx>
+#include <TCollection_HAsciiString.hxx>
+
+#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)
{
};
#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*/)
{
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";
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;
}
-
-
Standard_ShortReal.cxx
Standard_ShortReal.hxx
Standard_Stream.hxx
-Standard_String.hxx
Standard_Time.cxx
Standard_Time.hxx
Standard_Transient.hxx
#define _Standard_CString_SourceFile
-#define OptJr 1
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
#include <Standard_CLocaleSentry.hxx>
#include <Standard_CString.hxx>
#include <Standard_Type.hxx>
#include <Standard_OStream.hxx>
-
-#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 <Standard_String.hxx>
#include <string.h>
#include <stdarg.h>
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 aHashCode = 0 ;
- Standard_Integer i ;
-#if !OptJr
- char *charPtr = (char *)Value;
- Standard_Integer pos = 0,
- count,
- *tmphash;
- char tabchar[20];
-#endif
-
- 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 ;
-}
-
-
-# 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 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
+ // 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);
+ }
- }
- return aHashCode ;
+ return hash;
}
-//============================================================================
-// 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
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);
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
# include <config.h>
#endif
-#define OptJr 1
-
#include <Standard_ExtString.hxx>
#include <Standard_Type.hxx>
-#include <Standard_String.hxx>
#ifndef _Standard_OStream_HeaderFile
#include <Standard_OStream.hxx>
#endif
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 ;
- }
-
- 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++ ] ;
+ // 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;
}
- 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);
}
+++ /dev/null
-// 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 <Standard_TypeDef.hxx>
-# 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
-- (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;
-#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 <stdio.h>
-//#endif
+#include <cstdio>
#include <TCollection_AsciiString.ixx>
#include <Standard.hxx>
#include <Standard_NegativeValue.hxx>
#include <Standard_NumericError.hxx>
#include <Standard_ctype.hxx>
-#include <Standard_String.hxx>
#include <TCollection_ExtendedString.hxx>
// ###### PLACER LE TYPE NON DEFINI strtol (portabilite) ######
#ifdef WNT
-# include <string.h>
+# include <cstring>
#else
extern "C" {
long strtol(const char*, char**, int);
{
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
: 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'");
{
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 {
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
}
// ----------------------------------------------------------------------------
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
}
// ----------------------------------------------------------------------------
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';
}
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' ;
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';
}
// ----------------------------------------------------------------------------
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' ;
}
//---------------------------------------------------------------------------
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';
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 {
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
}
}
// ----------------------------------------------------------------------------
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]);
}
// ---------------------------------------------------------------------------
// ----------------------------------------------------------------------------
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';
+ }
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
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';
}
}
// ----------------------------------------------------------------------------
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';
}
-
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void TCollection_AsciiString::Destroy()
{
- if (mystring) Standard::Free((void*&)mystring);
+ if (mystring)
+ Free (mystring);
mystring = 0L;
}
{
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];
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];
}
else {
Standard_OutOfRange::Raise("TCollection_AsciiString::Insert : "
- "Parameter where is too big");
+ "Parameter where is invalid");
}
}
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];
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'");
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 );
}
// ----------------------------------------------------------------------------
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;
}
// ----------------------------------------------------------------------------
{
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 );
}
// ----------------------------------------------------------------------------
(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'");
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 );
}
// ----------------------------------------------------------------------------
(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'");
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 );
}
// ----------------------------------------------------------------------------
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;
}
// ----------------------------------------------------------------------------
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;
}
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);
}
// ----------------------------------------------------------------------------
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';
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;
}
//--------------------------------------------------------------------------
void TCollection_AsciiString::Read(Standard_IStream& astream)
{
-
- 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
+ // get characters from astream
+ const Standard_Integer bufSize = 8190;
+ Standard_Character buffer[bufSize];
+ std::streamsize oldWidth = astream.width (bufSize);
+ astream >> buffer;
+ astream.width( oldWidth );
+
+ // put to string
+ mylength = Standard_Integer( strlen( buffer ));
+ mystring = Reallocate (mystring, mylength + 1);
+ strncpy(mystring,buffer,mylength);
+ mystring[mylength] = '\0';
}
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;
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;
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;
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++)
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++)
(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;
}
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
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<mylength ) {
- l = 0;
- aSep = separators[l];
-
- while (aSep != 0 && !isSepFound) {
- if (aSep == mystring[j]) {
- buftmp[k] = 0;
- isSepFound = Standard_True;
- }
- else {
- buftmp[k] = mystring[j];
- }
- l++;
- aSep = separators[l];
- }
- j++; k++;
- if(j==mylength) buftmp[k] = 0;
- }
- }
-
- if (i < whichone) {
- buftmp[0] = 0;
- Standard::Free((void*&)buftmp);
- }
- else {
- res.mystring = buftmp;
-#if OptJr
- STRINGLEN( buftmp , res.mylength );
-#else
- STRLEN(buftmp,res.mylength);
-#endif
- }
-#endif
- return ;
}
// ----------------------------------------------------------------------------
Standard_NullObject::Raise("TCollection_AsciiString::Token : "
"parameter 'separators'");
-#if OptJr
Standard_Integer theOne ;
Standard_Integer StringIndex = 0 ;
Standard_Integer SeparatorIndex ;
// cout << "'" << SubString( BeginIndex , EndIndex ).ToCString() << "'" << endl ;
return TCollection_AsciiString( &mystring [ BeginIndex - 1 ] ,
EndIndex - BeginIndex + 1 ) ;
-
-// Hereafter : Why write simple when we can write complicated ! ...
-#else
- TCollection_AsciiString res;
-
- 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<mylength ) {
- l = 0;
- aSep = separators[l];
-
- while (aSep != 0 && !isSepFound) {
- if (aSep == mystring[j]) {
- buftmp[k] = 0;
- isSepFound = Standard_True;
- }
- else {
- buftmp[k] = mystring[j];
- }
- l++;
- aSep = separators[l];
- }
- j++; k++;
- if(j==mylength) buftmp[k] = 0;
- }
- }
-
- if (i < whichone) {
- buftmp[0] = 0;
- Standard::Free((void*&)buftmp);
- }
- else {
- res.mystring = buftmp;
-#if OptJr
- STRINGLEN( buftmp , res.mylength );
-#else
- STRLEN(buftmp,res.mylength);
-#endif
- }
- return res;
-#endif
}
// ----------------------------------------------------------------------------
(const Standard_Integer where)const
{
if (where > 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() );
-}
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
// ----------------------------------------------------------------------------
// 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 <stdio.h>
//#endif
#include <Standard_NullObject.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_ctype.hxx>
-#include <Standard_String.hxx>
#include <TCollection_AsciiString.hxx>
static
static
Standard_PExtCharacter Reallocate(Standard_Address aAddr,
- const Standard_Size aLength);
+ const Standard_Size aLength);
Standard_EXPORT short NULL_EXTSTRING[1] = {0};
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
//----------------------------------------------------------------------------
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..." <<endl;
+ cout <<"UTF8 decoding failure..." <<endl;
#endif
}
}
{
if (astring) {
-#if OptJr
- EXTSTRINGLEN( astring , mylength ) ;
-#else
- EXTSTRLEN(astring,mylength);
-#endif
- mystring = Allocate(ROUNDMEM((mylength+1)*2));
-#if OptJr
- EXTSTRINGCOPY( mystring , astring , mylength );
-#else
- STRCPY(mystring,astring,mylength);
+ for ( mylength=0; astring[mylength]; ++mylength );
+ const Standard_Integer size = (mylength+1)*2;
+ mystring = Allocate(size);
+ memcpy( mystring, astring, size );
mystring[mylength] = '\0';
-#endif
}
else {
Standard_NullObject::Raise("TCollection_ExtendedString : null parameter ");
(const Standard_Integer length,
const Standard_ExtCharacter filler )
{
- mystring = Allocate((length+1)*2);
+ mystring = Allocate( (length+1)*2 );
mylength = length;
for (int i = 0 ; i < length ; i++) mystring[i] = filler;
mystring[length] = '\0';
union {int bid ;
char t [13];} CHN ;
Sprintf(&CHN.t[0],"%d",aValue);
-#if OptJr
- STRINGLEN( CHN.t , mylength ) ;
-#else
- STRLEN(CHN.t,mylength);
-#endif
+ mylength = strlen(CHN.t);
mystring = Allocate((mylength+1)*2);
for (int i = 0 ; i < mylength ; i++) mystring[i] = ToExtCharacter(CHN.t[i]);
mystring[mylength] = '\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
+ mylength = strlen( CHN.t );
mystring = Allocate((mylength+1)*2);
for (int i = 0 ; i < mylength ; i++) mystring[i] = ToExtCharacter(CHN.t[i]);
mystring[mylength] = '\0';
TCollection_ExtendedString::TCollection_ExtendedString
(const TCollection_ExtendedString& astring)
{
-
+ const Standard_Integer size = (astring.mylength+1)*2;
mylength = astring.mylength;
- mystring = Allocate(ROUNDMEM((mylength+1)*2));
- if (astring.mystring)
-#if OptJr
- EXTENDEDSTRINGCOPY( mystring , astring.mystring , mylength );
-#else
- STRCPY(mystring,astring.mystring,mylength);
+ mystring = Allocate(size);
+ memcpy( mystring, astring.mystring, size );
mystring[mylength] = '\0';
-#endif
}
//---------------------------------------------------------------------------
{
mylength = astring.Length();
mystring = Allocate((mylength+1)*2);
-#if OptJr
Standard_CString aCString = astring.ToCString() ;
for (Standard_Integer i = 0; i <= mylength ; i++)
mystring[i] = ToExtCharacter( aCString[i] );
-#else
- for (Standard_Integer i = 0; i < mylength ; i++)
- mystring[i] = ToExtCharacter(astring.Value(i+1));
- mystring[mylength] = '\0';
-#endif
}
// ----------------------------------------------------------------------------
Standard_Integer otherlength = other.mylength;
if (otherlength) {
Standard_ExtString sother = other.mystring;
- Standard_Integer newlength = mylength +otherlength;
+ Standard_Integer newlength = mylength + otherlength;
if (mystring) {
- mystring = Reallocate((void*&)mystring,
- ROUNDMEM((newlength+1)*2));
-#if OptJr
-// if ( ((long ) ( &mystring[ mylength ] ) & 3) == 0 ) {
- EXTENDEDSTRINGCAT( mystring , mylength , sother , otherlength ) ;
-// }
-// else
-// STRCAT( mystring , mylength , sother , otherlength + 1 ) ;
-#else
- STRCAT(mystring,mylength,sother,otherlength);
-#endif
+ mystring = Reallocate((void*&)mystring, (newlength+1)*2 );
+ memcpy( mystring + mylength, sother, (otherlength+1)*2 );
}
else {
- mystring = Allocate(ROUNDMEM((newlength+1)*2));
-#if OptJr
- EXTENDEDSTRINGCOPY( mystring , sother , newlength );
-#else
- STRCPY(mystring,sother,newlength);
-#endif
+ mystring = Allocate( (newlength+1)*2 );
+ memcpy( mystring, sother, (otherlength+1)*2 );
}
mylength = newlength;
-#if !OptJr
- mystring[mylength] = '\0';
-#endif
}
}
TCollection_ExtendedString TCollection_ExtendedString::Cat
(const TCollection_ExtendedString& other) const
{
- Standard_ExtString sother = other.mystring;
- const Standard_Integer otherlength = sother ? other.mylength : 0;
- const Standard_Integer newlength = mylength + otherlength;
-#ifdef OptJr
- // ensure rounding allocated memory to 4 bytes
- TCollection_ExtendedString res (newlength | 0x1, 0);
- res.mylength = newlength;
-#else
- TCollection_ExtendedString res (newlength, 0);
-#endif
-
- if (otherlength) {
-#if OptJr
- EXTENDEDSTRINGCOPY( res.mystring , mystring , mylength );
- // if ( ((long ) ( &res.mystring[ mylength ] ) & 3) == 0 ) {
- EXTENDEDSTRINGCAT( res.mystring , mylength , sother , otherlength ) ;
-// }
-// else
-// STRCAT( res.mystring , mylength , sother , otherlength + 1 ) ;
-#else
- if (mylength > 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;
}
{
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) {
}
}
-#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
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
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
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
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 );
}
// ----------------------------------------------------------------------------
(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'");
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;
}
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
//purpose :
//=======================================================================
Standard_PExtCharacter Reallocate(Standard_Address aAddr,
- const Standard_Size aLength)
+ const Standard_Size aLength)
{
Standard_PExtCharacter pChar;
//
-#define OptJr 1
-
#include <TCollection_HAsciiString.ixx>
#include <TCollection_HExtendedString.hxx>
-#include <Standard_String.hxx>
// ----------------------------------------------------------------------------
// Create
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 );
}
// ----------------------------------------------------------------------------
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
}
// ----------------------------------------------------------------------------
(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++) {
}
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
}
//------------------------------------------------------------------------
// ----------------------------------------------------------------------------
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
- }
+}
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;
}
// Create list to iterate and remove views from the map of views
NCollection_List<TCollection_AsciiString> aViewList;
- if (TCollection_AsciiString::ISSIMILAR (anInputString, TCollection_AsciiString("ALL")))
+ if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 )
{
for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
anIter.More(); anIter.Next())
}
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());
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";
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;
}
--- /dev/null
+puts "======="
+puts "OCC11758"
+puts "======="
+puts ""
+########################################################################### TCollection strings are not memory safe as reported by Purify
+###########################################################################
+
+pload QAcommands
+
+OCC11758