-#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() );
-}