Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Deprecated/old_18mar_diff/Str14dec/StrLinux.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__JString_Linux_CPP__
00002 #define __J2K__JString_Linux_CPP__
00003 
00004 // Extra stuff for compatibility with the widely used Linux String class
00005 
00006 #include <j2k/Fred/String/String.hpp>
00007 
00008 void JString::Add( const char* s1, ULONG Len1, \
00009                    const char* s2, ULONG Len2, \
00010                    const char* s3, ULONG Len3, \
00011                    const char* s4, ULONG Len4, \
00012                    const char* s5, ULONG Len5, \
00013                    const char* s6, ULONG Len6, \
00014                    const char* s7, ULONG Len7, \
00015                    const char* s8, ULONG Len8, \
00016                    const char* s9, ULONG Len9, \
00017                    ULONG LenExtra )
00018 {
00019   // -- Modify THIS JString Object.
00020 
00021   // Take care of NULL JString parameters, if any.
00022   if ( s1 == NULL  ||  *s1 == '\0' ) { Len1 = 0; }
00023   if ( s2 == NULL  ||  *s2 == '\0' ) { Len2 = 0; }
00024   if ( s3 == NULL  ||  *s3 == '\0' ) { Len3 = 0; }
00025   if ( s4 == NULL  ||  *s4 == '\0' ) { Len4 = 0; }
00026   if ( s5 == NULL  ||  *s5 == '\0' ) { Len5 = 0; }
00027   if ( s6 == NULL  ||  *s6 == '\0' ) { Len6 = 0; }
00028   if ( s7 == NULL  ||  *s7 == '\0' ) { Len7 = 0; }
00029   if ( s8 == NULL  ||  *s8 == '\0' ) { Len8 = 0; }
00030   if ( s9 == NULL  ||  *s9 == '\0' ) { Len9 = 0; }
00031 
00032   ULONG newLen = Len1 + Len2 + Len3 + Len4 + Len5 + Len6 + Len7 + Len8 + Len9;
00033 
00034   // Don't delete now, since memcpy will occur
00035   // in the case we delete ourself before copy !
00036   JStringData* sd = pData;
00037 
00038   if ( newLen > 0 ) {
00039 
00040   pData = new JStringData( newLen + LenExtra );
00041 
00042   ULONG pos = 0;
00043 
00044   if ( Len1 > 0 ) {  memcpy( pData->data + pos, s1, Len1 );  pos += Len1;  }
00045   if ( Len2 > 0 ) {  memcpy( pData->data + pos, s2, Len2 );  pos += Len2;  }
00046   if ( Len3 > 0 ) {  memcpy( pData->data + pos, s3, Len3 );  pos += Len3;  }
00047   if ( Len4 > 0 ) {  memcpy( pData->data + pos, s4, Len4 );  pos += Len4;  }
00048   if ( Len5 > 0 ) {  memcpy( pData->data + pos, s5, Len5 );  pos += Len5;  }
00049   if ( Len6 > 0 ) {  memcpy( pData->data + pos, s6, Len6 );  pos += Len6;  }
00050   if ( Len7 > 0 ) {  memcpy( pData->data + pos, s7, Len7 );  pos += Len7;  }
00051   if ( Len8 > 0 ) {  memcpy( pData->data + pos, s8, Len8 );  pos += Len8;  }
00052   if ( Len9 > 0 ) {  memcpy( pData->data + pos, s9, Len9 );  pos += Len9;  }
00053 
00054   pData->length = newLen;
00055   pData->data[ newLen ] = '\0';
00056 
00057    /*
00058      This Null ending is needed since the last string
00059      might not be ended by '\0' or in case the copy
00060      doesn't go up to Zero. To be checked!
00061 
00062      i.e. If we pass a 'char c' as &c instead of a char* s = { c, 0 }
00063    */   
00064 
00065   } else { // strNull
00066     pData = strNull;
00067   }
00068 
00069   sd->Dec(); // Now you can suicide, we don't care.
00070 }
00071 
00072 const JString& JString::Add( const JString& S1, const JString& S2, const JString& S3, \
00073                              const JString& S4, const JString& S5, const JString& S6, \
00074                              const JString& S7, const JString& S8 ) 
00075 {
00076     Add(    pData->data,      pData->length, S1.pData->data,   S1.pData->length, \
00077          S2.pData->data,   S2.pData->length, \
00078          S3.pData->data,   S3.pData->length, S4.pData->data,   S4.pData->length, \
00079          S5.pData->data,   S5.pData->length, S6.pData->data,   S6.pData->length, \
00080          S7.pData->data,   S7.pData->length, S8.pData->data,   S8.pData->length, 0 );
00081 
00082   return *this;
00083 }
00084 
00085 
00086 const JString& JString::Add( const JString& S1, const JString& S2, const JString& S3, \
00087                              const JString& S4, const JString& S5, const JString& S6, \
00088                              const JString& S7 )
00089 {
00090     Add(    pData->data,      pData->length, S1.pData->data,   S1.pData->length, \
00091          S2.pData->data,   S2.pData->length, \
00092          S3.pData->data,   S3.pData->length, S4.pData->data,   S4.pData->length, \
00093          S5.pData->data,   S5.pData->length, S6.pData->data,   S6.pData->length, \
00094          S7.pData->data,   S7.pData->length );
00095   
00096   return *this;
00097 }
00098 
00099 const JString& JString::Add( const JString& S1, const JString& S2, const JString& S3, \
00100                              const JString& S4, const JString& S5, const JString& S6 )
00101 {
00102     Add(    pData->data,      pData->length, S1.pData->data,   S1.pData->length, \
00103          S2.pData->data,   S2.pData->length, \
00104          S3.pData->data,   S3.pData->length, S4.pData->data,   S4.pData->length, \
00105          S5.pData->data,   S5.pData->length, S6.pData->data,   S6.pData->length );
00106   
00107   return *this;
00108 }
00109 
00110 const JString& JString::Add( const JString& S1, const JString& S2, const JString& S3,
00111                              const JString& S4, const JString& S5 )
00112 {
00113     Add(    pData->data,      pData->length, S1.pData->data,   S1.pData->length, \
00114          S2.pData->data,   S2.pData->length, \
00115          S3.pData->data,   S3.pData->length, S4.pData->data,   S4.pData->length, \
00116          S5.pData->data,   S5.pData->length );
00117 
00118   return *this;
00119 }
00120 
00121 const JString& JString::Add( const JString& S1, const JString& S2,
00122                              const JString& S3, const JString& S4 )                   
00123 {
00124     Add(    pData->data,      pData->length, S1.pData->data,   S1.pData->length, \
00125          S2.pData->data,   S2.pData->length, \
00126          S3.pData->data,   S3.pData->length, S4.pData->data,   S4.pData->length );
00127            
00128   return *this;
00129 }
00130 
00131 const JString& JString::Add( const JString& S1, const JString& S2, const JString& S3 )
00132 {
00133     Add(    pData->data,      pData->length, S1.pData->data,   S1.pData->length, \
00134          S2.pData->data,   S2.pData->length, \
00135          S3.pData->data,   S3.pData->length );
00136   
00137   return *this;
00138 }
00139 
00140 // With Find(), it's VERY EASY to implement the derivates!
00141 
00142 inline BOOL JString::contains( const JString& S, ULONG offset ) const
00143 {
00144   return( Find( S, offset ) >= 0 );
00145 }
00146 
00147 inline BOOL JString::contains( const char* s, ULONG offset ) const
00148 {
00149   return( Find( s, offset ) >= 0 );
00150 }
00151 
00152 inline BOOL JString::contains( char c, ULONG offset ) const
00153 {
00154   return( Find( c, offset ) >= 0 );
00155 }
00156 
00157 inline BOOL JString::contains( const JString& S ) const
00158 {
00159   return( Find( S, 0 ) >= 0 );
00160 }
00161   
00162 inline BOOL JString::contains( const char* s ) const   
00163 {        
00164   return( Find( s, 0 ) >= 0 );
00165 } 
00166     
00167 inline BOOL JString::contains( char c ) const          
00168 {
00169   return( Find( c, 0 ) >= 0 );
00170 }
00171 
00172 // Append BEFORE (at the head)
00173 // JString s("world").prepend("hello") == "helloworld"
00174 
00175 inline const JString& JString::append( const JString& S )
00176 {
00177   Add( pData->data, S.pData->data, pData->length, S.pData->length );
00178   return *this;
00179 }
00180 
00181 inline const JString& JString::prepend( const JString& S )
00182 {
00183   Add( S.pData->data, pData->data, S.pData->length, pData->length );
00184   return *this;
00185 }
00186 
00187 inline const JString& JString::append( const char* s )
00188 {
00189   if ( s != NULL && *s != '\0' ) {
00190     Add( pData->data, s, pData->length, strlen( s ) );
00191   }
00192   return *this;
00193 }   
00194 
00195 inline const JString& JString::prepend( const char* s )
00196 {
00197   if ( s != NULL && *s != '\0' ) {
00198     Add( s, pData->data, strlen( s ), pData->length );
00199   }
00200   return *this;
00201 }
00202 
00203 // WARNING:
00204 // This works because Add() suppose 
00205 // that the string is not NULL terminated!
00206 inline const JString& JString::append( char c )   
00207 {
00208   if ( c != '\0' ) {
00209     Add( pData->data, &c, pData->length, 1 );
00210   }
00211   return *this;
00212 }
00213   
00214 inline const JString& JString::prepend( char c )
00215 {
00216   if ( c != '\0' ) {
00217     Add( &c, pData->data, 1, pData->length );
00218   }
00219   return *this;
00220 }
00221 
00222 #endif

Generated on Sun Oct 14 18:46:29 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001