1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0011758: TCollection strings are not memory safe as reported by Purify

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
This commit is contained in:
vsr
2013-08-22 11:21:09 +04:00
committed by bugmaster
parent 80cd454f1d
commit 29cb310ae9
18 changed files with 744 additions and 2414 deletions

View File

@@ -840,21 +840,6 @@ is
-- (Just for HashCode for AsciiString)
---C++: inline
HASHCODE(myclass ; astring : AsciiString from TCollection; Upper : Integer)
returns Integer;
---Level: Internal
---Purpose: Hash function for AsciiString no case sensitive
---C++: inline
ISSIMILAR(myclass ; string1 : AsciiString from TCollection;
string2 : AsciiString from TCollection)
returns Boolean;
---Level: Internal
---Purpose: Returns True when the two strings are the same
-- (no case sensitive).
-- (Just for HashCode for AsciiString)
fields
mystring : PCharacter;
mylength : Integer;

856
src/TCollection/TCollection_AsciiString.cxx Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -111,15 +111,6 @@ inline Standard_Boolean TCollection_AsciiString::IsEqual(const TCollection_Ascii
return string1.IsEqual( string2 );
}
//------------------------------------------------------------------------
// HASHCODE
//------------------------------------------------------------------------
inline Standard_Integer TCollection_AsciiString::HASHCODE(const TCollection_AsciiString& astring,
const Standard_Integer Upper)
{
return ::HASHCODE( astring.ToCString() , astring.Length() , Upper );
}
// ----------------------------------------------------------------------------
// SubString
// ----------------------------------------------------------------------------

303
src/TCollection/TCollection_ExtendedString.cxx Executable file → Normal file
View File

@@ -17,18 +17,6 @@
// and conditions governing the rights and limitations under the License.
#define OptJr 1
// OCC6794: if OptJr is ON, we need to ensure that memory allocations are done by 4 bytes words,
// in order to avoid writing into unallocated memory at the string end when it is copied
// by CSTRINGCOPY or ASCIISTRINGCOPY macros
// (though, due to OCC memory manager roundings of allocated memory, the problem appears
// only when MMGT_OPT is 0 and string size is greater than MMGT_THRESHOLD)
#ifdef OptJr
#define ROUNDMEM(len) (((len)+3)&~0x3)
#else
#define ROUNDMEM(len) (len)
#endif
//#if defined(WNT) || defined(LIN)
#include <stdio.h>
//#endif
@@ -39,7 +27,6 @@
#include <Standard_NullObject.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_ctype.hxx>
#include <Standard_String.hxx>
#include <TCollection_AsciiString.hxx>
static
@@ -47,7 +34,7 @@ static
static
Standard_PExtCharacter Reallocate(Standard_Address aAddr,
const Standard_Size aLength);
const Standard_Size aLength);
Standard_EXPORT short NULL_EXTSTRING[1] = {0};
@@ -117,13 +104,13 @@ inline Standard_Integer nbSymbols(const Standard_CString aStr) {
if((aStr[i] & 0x80) == 0x00) //1byte => 1 symb - Lat1
{aLen++; i++;}
else if((aStr[i] & 0xE0) == 0xC0 &&
(aStr[i+1] &&
(aStr[i+1] & 0xC0) == 0x80)) {//2 bytes => 1 symb
(aStr[i+1] &&
(aStr[i+1] & 0xC0) == 0x80)) {//2 bytes => 1 symb
aLen++;
i += 2;
} else if((aStr[i] & 0xF0) == 0xE0 &&
((aStr[i+1] && (aStr[i+1] & 0xC0) == 0x80)) &&
(aStr[i+2] && (aStr[i+2] & 0xC0) == 0x80)) {
((aStr[i+1] && (aStr[i+1] & 0xC0) == 0x80)) &&
(aStr[i+2] && (aStr[i+2] & 0xC0) == 0x80)) {
aLen++;
i += 3;
} else
@@ -148,27 +135,23 @@ TCollection_ExtendedString::TCollection_ExtendedString()
//----------------------------------------------------------------------------
TCollection_ExtendedString::TCollection_ExtendedString
(const Standard_CString astring,
const Standard_Boolean isMultiByte)
const Standard_Boolean isMultiByte)
{
if (astring) {
if(!isMultiByte) {
#if OptJr
STRINGLEN( astring , mylength ) ;
#else
STRLEN(astring,mylength);
#endif
mylength = strlen( astring );
mystring = Allocate((mylength+1)*2);
for (int i = 0 ; i < mylength ; i++)
mystring[i] = ToExtCharacter(astring[i]);
mystring[i] = ToExtCharacter(astring[i]);
mystring[mylength] = '\0';
}
else {
mylength = nbSymbols(astring);
mystring = Allocate(ROUNDMEM((mylength+1)*2));
mystring = Allocate( (mylength+1)*2 );
if(!ConvertToUnicode (astring))
{
#ifdef DEB
cout <<"UTF8 decoding failure..." <<endl;
cout <<"UTF8 decoding failure..." <<endl;
#endif
}
}
@@ -187,18 +170,11 @@ TCollection_ExtendedString::TCollection_ExtendedString
{
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 ");
@@ -244,7 +220,7 @@ TCollection_ExtendedString::TCollection_ExtendedString
(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';
@@ -259,11 +235,7 @@ TCollection_ExtendedString::TCollection_ExtendedString
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';
@@ -278,11 +250,7 @@ TCollection_ExtendedString::TCollection_ExtendedString
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';
@@ -294,16 +262,11 @@ TCollection_ExtendedString::TCollection_ExtendedString
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
}
//---------------------------------------------------------------------------
@@ -314,15 +277,9 @@ TCollection_ExtendedString::TCollection_ExtendedString
{
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
}
// ----------------------------------------------------------------------------
@@ -334,32 +291,16 @@ void TCollection_ExtendedString::AssignCat
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
}
}
@@ -369,41 +310,11 @@ void TCollection_ExtendedString::AssignCat
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;
}
@@ -436,20 +347,16 @@ void TCollection_ExtendedString::Copy (const TCollection_ExtendedString& fromwhe
{
if (fromwhere.mystring) {
Standard_Integer newlength = fromwhere.mylength;
const Standard_Integer newlength = fromwhere.mylength;
const Standard_Integer size = (newlength + 1) * 2;
if (mystring) {
mystring = Reallocate((void*&)mystring, ROUNDMEM(( newlength + 1)*2 ));
mystring = Reallocate((void*&)mystring, size );
}
else {
mystring = Allocate(ROUNDMEM((newlength+1)*2));
mystring = Allocate( size );
}
mylength = newlength;
#if OptJr
EXTENDEDSTRINGCOPY( mystring , fromwhere.mystring , newlength );
#else
STRCPY(mystring, fromwhere.mystring,newlength);
mystring[mylength] = '\0';
#endif
memcpy( mystring, fromwhere.mystring, size );
}
else {
if (mystring) {
@@ -533,26 +440,14 @@ void TCollection_ExtendedString::Insert(const Standard_Integer where,
}
}
#if OptJr
// ----------------------------------------------------------------------------
// IsEqual
// ----------------------------------------------------------------------------
Standard_Boolean TCollection_ExtendedString::IsEqual
(const Standard_ExtString other) const
{
// Standard_Integer otherlength ;
// EXTSTRINGLEN( other , otherlength )
// if ( mylength != otherlength ) return Standard_False;
Standard_Boolean KEqual ;
LEXTSTRINGEQUAL( mystring , mylength , other , KEqual ) ;
return KEqual ;
return ( memcmp( mystring, other, (mylength+1)*2 ) == 0 );
}
#else
Standard_Boolean TCollection_ExtendedString::NoIsEqual
(const Standard_ExtString other) const
{return Standard_False ;}
#endif
// ----------------------------------------------------------------------------
// IsEqual
@@ -560,39 +455,17 @@ Standard_Boolean TCollection_ExtendedString::NoIsEqual
Standard_Boolean TCollection_ExtendedString::IsEqual
(const TCollection_ExtendedString& other) const
{
if (mylength != other.mylength) return Standard_False;
Standard_ExtString sother = other.mystring;
#if OptJr
Standard_Boolean KEqual ;
EXTENDEDSTRINGEQUAL( mystring , sother , mylength , KEqual ) ;
return KEqual ;
#else
for (int i = 0 ; i < mylength ; i++)
if (mystring[i] != sother[i]) return Standard_False;
return Standard_True;
#endif
return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) == 0 );
}
#if OptJr
// ----------------------------------------------------------------------------
// IsDifferent
// ----------------------------------------------------------------------------
Standard_Boolean TCollection_ExtendedString::IsDifferent
(const Standard_ExtString other ) const
{
// Standard_Integer otherlength ;
// EXTSTRINGLEN( other , otherlength )
// if ( mylength != otherlength ) return Standard_True;
Standard_Boolean KEqual ;
LEXTSTRINGEQUAL( mystring , mylength , other , KEqual ) ;
return !KEqual ;
return ( memcmp( mystring, other, (mylength+1)*2 ) != 0 );
}
#else
Standard_Boolean TCollection_ExtendedString::NoIsDifferent
(const Standard_ExtString other ) const
{return Standard_False ;}
#endif
// ----------------------------------------------------------------------------
// IsDifferent
@@ -600,40 +473,17 @@ Standard_Boolean TCollection_ExtendedString::NoIsDifferent
Standard_Boolean TCollection_ExtendedString::IsDifferent
(const TCollection_ExtendedString& other) const
{
if (mylength != other.mylength) return Standard_True;
Standard_ExtString sother = other.mystring;
#if OptJr
Standard_Boolean KEqual ;
EXTENDEDSTRINGEQUAL( mystring , sother , mylength , KEqual ) ;
return !KEqual ;
#else
for (int i = 0 ; i < mylength ; i++)
if (mystring[i] != sother[i]) return Standard_True;
return Standard_False;
#endif
return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) != 0 );
}
#if OptJr
// ----------------------------------------------------------------------------
// IsLess
// ----------------------------------------------------------------------------
Standard_Boolean TCollection_ExtendedString::IsLess
(const Standard_ExtString other) const
{
// Standard_Integer otherlength ;
// EXTSTRINGLEN( other , otherlength )
Standard_Boolean KLess ;
// EXTSTRINGLESS( mystring , mylength , other , otherlength ,
// INF( mylength , otherlength ) , KLess ) ;
LEXTSTRINGLESS( mystring , mylength , other , KLess ) ;
return KLess ;
return ( memcmp( mystring, other, (mylength+1)*2 ) < 0 );
}
#else
Standard_Boolean TCollection_ExtendedString::NoIsLess
(const Standard_ExtString other) const
{return Standard_False ;}
#endif
// ----------------------------------------------------------------------------
// IsLess
@@ -641,48 +491,17 @@ Standard_Boolean TCollection_ExtendedString::NoIsLess
Standard_Boolean TCollection_ExtendedString::IsLess
(const TCollection_ExtendedString& other) const
{
Standard_Integer otherlength = other.mylength;
Standard_ExtString sother = other.mystring;
#if OptJr
Standard_Boolean KLess ;
EXTENDEDSTRINGLESS( mystring , mylength , sother , otherlength ,
INF( mylength , otherlength ) , KLess ) ;
return KLess ;
#else
Standard_Integer i = 0, j = 0;
while ( i < mylength && j < otherlength) {
if (mystring[i] < sother[j]) return Standard_True;
if (mystring[i] > sother[j]) return Standard_False;
i++ ;
j++;
}
if (i == mylength && j < otherlength) return Standard_True;
return Standard_False;
#endif
return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) < 0 );
}
#if OptJr
// ----------------------------------------------------------------------------
// IsGreater
// ----------------------------------------------------------------------------
Standard_Boolean TCollection_ExtendedString::IsGreater
(const Standard_ExtString other) const
{
// Standard_Integer otherlength ;
// EXTSTRINGLEN( other , otherlength )
Standard_Boolean KGreater ;
// EXTSTRINGGREATER( mystring , mylength , other , otherlength ,
// INF( mylength , otherlength ) , KGreater ) ;
LEXTSTRINGGREATER( mystring , mylength , other , KGreater ) ;
return KGreater ;
return ( memcmp( mystring, other, (mylength+1)*2 ) > 0 );
}
#else
Standard_Boolean TCollection_ExtendedString::NoIsGreater
(const Standard_ExtString other) const
{return Standard_False ;}
#endif
// ----------------------------------------------------------------------------
// IsGreater
@@ -690,24 +509,7 @@ Standard_Boolean TCollection_ExtendedString::NoIsGreater
Standard_Boolean TCollection_ExtendedString::IsGreater
(const TCollection_ExtendedString& other) const
{
Standard_Integer otherlength = other.mylength;
Standard_ExtString sother = other.mystring;
#if OptJr
Standard_Boolean KGreater ;
EXTENDEDSTRINGGREATER( mystring , mylength , sother , otherlength ,
INF( mylength , otherlength ) , KGreater ) ;
return KGreater ;
#else
Standard_Integer i = 0, j = 0;
while (i < mylength && j <= otherlength) {
if (mystring[i] < sother[j]) return Standard_False;
if (mystring[i] > sother[j]) return Standard_True;
i++ ;
j++;
}
if (j == otherlength && i < mylength) return Standard_True;
return Standard_False;
#endif
return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) > 0 );
}
// ----------------------------------------------------------------------------
@@ -898,7 +700,7 @@ TCollection_ExtendedString TCollection_ExtendedString::Token
(const Standard_ExtString separators,
const Standard_Integer whichone) const
{
TCollection_ExtendedString res("");
TCollection_ExtendedString res;
if (!separators)
Standard_NullObject::Raise("TCollection_ExtendedString::Token : "
"parameter 'separators'");
@@ -960,12 +762,9 @@ TCollection_ExtendedString TCollection_ExtendedString::Token
Standard::Free((void*&)buftmp);
}
else {
Standard::Free((void*&)res.mystring);
res.mystring = buftmp;
#if OptJr
EXTSTRINGLEN( buftmp , res.mylength ) ;
#else
EXTSTRLEN(buftmp,res.mylength);
#endif
for ( res.mylength=0; buftmp[res.mylength]; ++res.mylength );
}
return res;
}
@@ -1020,13 +819,13 @@ Standard_Boolean TCollection_ExtendedString::ConvertToUnicode
if((aStr[i] & 0x80) == 0x00) //1byte => 1 symb - Lat1
{*p++ = ToExtCharacter(aStr[i]); i++;}
else if((aStr[i] & 0xE0) == 0xC0 &&
(aStr[i+1] &&
(aStr[i+1] & 0xC0) == 0x80)) {//2 bytes => 1 symb
(aStr[i+1] &&
(aStr[i+1] & 0xC0) == 0x80)) {//2 bytes => 1 symb
*p++ = ConvertToUnicode2B((unsigned char*)&aStr[i]);
i += 2;
} else if((aStr[i] & 0xF0) == 0xE0 &&
((aStr[i+1] && (aStr[i+1] & 0xC0) == 0x80)) &&
(aStr[i+2] && (aStr[i+2] & 0xC0) == 0x80)) {
((aStr[i+1] && (aStr[i+1] & 0xC0) == 0x80)) &&
(aStr[i+2] && (aStr[i+2] & 0xC0) == 0x80)) {
*p++ = ConvertToUnicode3B((unsigned char*)&aStr[i]);
i += 3;
} else { //unsupported case ==> not UTF8
@@ -1118,7 +917,7 @@ Standard_PExtCharacter Allocate(const Standard_Size aLength)
//purpose :
//=======================================================================
Standard_PExtCharacter Reallocate(Standard_Address aAddr,
const Standard_Size aLength)
const Standard_Size aLength)
{
Standard_PExtCharacter pChar;
//

View File

@@ -18,11 +18,8 @@
#define OptJr 1
#include <TCollection_HAsciiString.ixx>
#include <TCollection_HExtendedString.hxx>
#include <Standard_String.hxx>
// ----------------------------------------------------------------------------
// Create
@@ -294,20 +291,9 @@ Standard_Boolean TCollection_HAsciiString::IsAscii() const
Standard_Boolean TCollection_HAsciiString::IsDifferent
(const Handle(TCollection_HAsciiString)& S) const
{
if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsDifferent");
#if OptJr
if ( myString.Length() == S->Length() ) {
Standard_Boolean KEqual ;
ASCIISTRINGEQUAL( myString.ToCString() , S->ToCString() ,
myString.mylength , KEqual ) ;
return !KEqual ;
}
else
return Standard_True ;
#else
return ( strcmp(myString.ToCString(), S->ToCString()) );
#endif
if(S->Length() != myString.Length() ) return Standard_True;
return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) != 0 );
}
// ----------------------------------------------------------------------------
@@ -316,20 +302,11 @@ Standard_Boolean TCollection_HAsciiString::IsDifferent
Standard_Boolean TCollection_HAsciiString::IsSameString
(const Handle(TCollection_HAsciiString)& S) const
{
if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsSameString");
#if OptJr
if ( myString.Length() == S->Length() ) {
Standard_Boolean KEqual ;
ASCIISTRINGEQUAL( myString.ToCString() , S->ToCString() ,
myString.mylength , KEqual ) ;
return KEqual ;
}
if ( myString.Length() == S->Length() )
return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) == 0 );
else
return Standard_False ;
#else
return ( !strcmp(myString.ToCString(), S->ToCString()) );
#endif
}
// ----------------------------------------------------------------------------
@@ -339,21 +316,12 @@ Standard_Boolean TCollection_HAsciiString::IsSameString
(const Handle(TCollection_HAsciiString)& S ,
const Standard_Boolean CaseSensitive) const
{
// Handle(TCollection_HAsciiString) H1,H2;
// H1 = UpperCase(This);
// H2 = UpperCase(S);
// return ( H1 == H2));
if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsSameString");
Standard_Integer size1 = Length();
const Standard_Integer size1 = Length();
if ( size1 != S->Length() ) return Standard_False;
#if OptJr
if ( CaseSensitive ) {
Standard_Boolean KEqual ;
ASCIISTRINGEQUAL( myString.ToCString() , S->String().ToCString() ,
size1 , KEqual ) ;
return KEqual ;
return ( strncmp( myString.ToCString(), S->ToCString(), size1 ) == 0 );
}
else {
for ( Standard_Integer i = 1 ; i <= size1; i++) {
@@ -362,22 +330,6 @@ Standard_Boolean TCollection_HAsciiString::IsSameString
}
return Standard_True ;
}
#else
// Example of bad sequence of test : CaseSensitive does not change in the loop
Standard_Character C1,C2;
for( Standard_Integer i = 1 ; i <= size1; i++) {
if(CaseSensitive){
if (Value(i) != S->Value(i)) return Standard_False;
}
else {
C1 = Value(i);
C2 = S->Value(i);
if(toupper(C1) != toupper(C2)) return Standard_False;
}
}
return Standard_True;
#endif
}
//------------------------------------------------------------------------
@@ -648,19 +600,10 @@ void TCollection_HAsciiString::ShallowDump(Standard_OStream& S) const
// ----------------------------------------------------------------------------
Standard_Boolean TCollection_HAsciiString::IsSameState
(const Handle(TCollection_HAsciiString)& other) const
{
#if OptJr
if ( myString.Length() == other->Length() ) {
Standard_Boolean KEqual ;
ASCIISTRINGEQUAL( myString.ToCString() , other->ToCString() ,
myString.mylength , KEqual ) ;
return KEqual ;
}
{
if ( myString.Length() == other->Length() )
return ( strncmp( myString.mystring, other->ToCString(), myString.Length() ) == 0 );
else
return Standard_False ;
#else
return ( !strcmp(myString.mystring , other->ToCString() ));
#endif
}
}