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/String.hpp

Go to the documentation of this file.
00001 #ifndef __J2K__String_HPP__
00002 #define __J2K__String_HPP__
00003 
00004 #include <j2k/Fred/Standard.hpp>
00005 #include <j2k/Fred/String/StrData.hpp>
00006 
00007 class JSubString;
00008 
00009 class JString {
00010 
00011 public:
00012 
00013 ////////////////////////////////////////////////////////////////////////////
00014 /// Constructor, Copy Constructor and Destructor                         ///
00015 ////////////////////////////////////////////////////////////////////////////
00016 /// Defined in:  StrBuild.cpp                                            ///
00017 ////////////////////////////////////////////////////////////////////////////
00018   JString();
00019   JString( const char* s );
00020   JString( const char* s, ULONG nBuffer );
00021 
00022   // Deprecated due to NULL problems
00023   //  JString( ULONG nBuffer );
00024 
00025   JString( const JString& src );
00026   JString( char ch );
00027   JString( char ch, ULONG nRepeat );
00028   JString( JStringData* sd );  // Verify this.
00029   virtual ~JString();
00030 
00031 ////////////////////////////////////////////////////////////////////////////
00032 /// Simple Attributes & Operations...                                    ///
00033 ////////////////////////////////////////////////////////////////////////////
00034 /// Defined in:  StrTools.cpp                                            ///
00035 ////////////////////////////////////////////////////////////////////////////
00036   BOOL OK()   const;      // Used by Test JString program
00037   BOOL isEmpty()  const;
00038   BOOL isFilled() const;
00039 
00040   void Clear();
00041   void Empty();         // free up the data
00042 
00043   void FillString( char ch );
00044   void FillBuffer( char ch );
00045 
00046   inline void  Display()   const;
00047 
00048   inline ULONG length();
00049   inline ULONG getLength();
00050 
00051   inline ULONG getAllocLength() const;
00052   inline ULONG getBufferSize()  const;
00053 
00054   inline int  getLockNb() const;
00055   inline BOOL isLock()  const;
00056   inline BOOL isUnlock() const;
00057 
00058 
00059 ////////////////////////////////////////////////////////////////////////////
00060 /// At X do this...                                                      ///
00061 ////////////////////////////////////////////////////////////////////////////
00062 /// Defined in:  JStringAt.cpp                                           ///
00063 ////////////////////////////////////////////////////////////////////////////
00064 
00065          JString at( ULONG startpos );
00066          JString at( ULONG startpos,  ULONG length   );
00067          JString at( const char* s,   ULONG startpos );
00068          JString at( const char* s,   ULONG startpos, ULONG length );
00069 
00070   // at() == at(  (ULONG) 0  )
00071 
00072   inline JString at();
00073   inline JString at( const char* s    );
00074   inline JString at( const JString& S );
00075   inline JString at( const JString& S, ULONG startpos );
00076   inline JString at( const JString& S, ULONG startpos, ULONG length );
00077 
00078   JString& setAt( ULONG nIndex, char ch );
00079 
00080   inline char charAt();
00081   inline char charAt( const char* s );
00082   inline char charAt( const JString& S );
00083 
00084   inline const JString& modifyAt( const JString& S );
00085   inline const JString& modifyAt( const JString& S, ULONG offset );
00086   inline const JString& modifyAt( const JString& S, ULONG offset, ULONG length );
00087 
00088   inline const JString& modifyAt( const char* s );
00089   inline const JString& modifyAt( const char* s, ULONG offset );
00090   inline const JString& modifyAt( const char* s, ULONG offset, ULONG length );
00091 
00092   inline char getAt(      ULONG nIndex ) const; 
00093   inline char operator[]( long   nIndex ) const;
00094 
00095   inline JString right( ULONG length );
00096   inline JString left(  ULONG length );
00097 
00098   inline JString mid( const char* s,    ULONG startpos, ULONG length );
00099   inline JString mid( const JString& S, ULONG startpos, ULONG length );
00100 
00101   inline JString after( const char* s );
00102   inline JString after( const char* s, ULONG startpos );
00103   inline JString after( const char* s, ULONG startpos, ULONG length );
00104   inline JString before( const char* s );
00105 
00106   // startpos of Search not String!
00107   // Design decision since it's more useful like that.
00108   // startpos of String can be obtained in few steps or with mid
00109   inline JString before( const char* s, ULONG startpos );
00110   inline JString beforeStr( const char* s, ULONG startpos );
00111   inline JString before( const char* s, ULONG startpos, ULONG length );
00112 
00113 
00114 
00115 /** ANDREA ***************************************************
00116 
00117   If I remember correctly 'Mid' is an l-value in QuickBasic.
00118   You can write statements like
00119   
00120                    mid(a$,2,3)="Hello!!!"
00121 
00122   both r-value and l-value.
00123 
00124   I implement ONLY the r-value version:
00125 
00126   A$ = "hello"
00127   print mid$(A$, 2, 3)
00128   
00129 *************************************************************/
00130   
00131   JString ltrim( char ch ) const;
00132   JString rtrim( char ch ) const;
00133   JString trim(  char ch ) const;
00134 
00135   JString trimCharset( const char* charset ) const;
00136   JString keepCharset( const char* charset ) const;
00137   
00138   
00139   inline JString operator()( ULONG startpos );
00140   inline JString operator()( ULONG startpos, ULONG length );
00141 
00142   inline JString operator()( const char* s    );
00143   inline JString operator()( const JString& S );
00144   inline JString operator()( const char* s,    ULONG startpos );
00145   inline JString operator()( const JString& S, ULONG startpos );
00146 
00147   inline JString operator()( const char* s,    ULONG startpos, ULONG length );
00148   inline JString operator()( const JString& S, ULONG startpos, ULONG length );
00149 
00150 ////////////////////////////////////////////////////////////////////////////
00151 /// Compare utilities...                                                 ///
00152 ////////////////////////////////////////////////////////////////////////////
00153 /// Defined in:  StrComp.cpp                                             ///
00154 ////////////////////////////////////////////////////////////////////////////
00155 
00156 /* Not Implemented Yet.
00157   int CompareNoCase( const char* s ) const;    // ignore case
00158   int Collate(       const char *s ) const;    // NLS aware
00159 */
00160 
00161   inline int compare( const JString& right ) const;
00162   inline int compare( const char*    right ) const;
00163          int compare( char           right ) const;
00164 
00165   // Left JString (THIS) is less than Right JString?
00166 
00167   inline BOOL operator<( const JString&  right ) const;
00168   inline BOOL operator<( const char*     right ) const;
00169   inline BOOL operator<( char            right ) const;
00170   
00171   inline BOOL operator>( const JString&  right ) const;
00172   inline BOOL operator>( const char*     right ) const;
00173   inline BOOL operator>( char            right ) const;
00174   
00175   inline BOOL operator<=( const JString& right ) const;
00176   inline BOOL operator<=( const char*    right ) const;
00177   inline BOOL operator<=( char           right ) const;
00178   
00179   inline BOOL operator>=( const JString& right ) const;
00180   inline BOOL operator>=( const char*    right ) const;
00181   inline BOOL operator>=( char           right ) const;
00182                                        
00183   inline BOOL operator==( const char*    right ) const;
00184   inline BOOL operator==( const JString& right ) const;
00185   inline BOOL operator==( char           right ) const;
00186 
00187   inline BOOL operator!=( const char*    right ) const;
00188   inline BOOL operator!=( const JString& right ) const;
00189   inline BOOL operator!=( char           right ) const;
00190 
00191 ////////////////////////////////////////////////////////////////////////////
00192 /// Parsing and Casting utilities...                                     ///
00193 ////////////////////////////////////////////////////////////////////////////
00194 /// Defined in:  StrMorph.cpp                                            ///
00195 ////////////////////////////////////////////////////////////////////////////
00196 
00197   inline operator char*()  const;
00198 
00199   // This makes more sense than (int*) operator !
00200   inline operator int()    const;
00201   inline operator long()   const;
00202   inline operator double() const;
00203 
00204   inline int    parseInt()     const;
00205   inline long   parseLong()    const;
00206   inline double parseDouble()  const;
00207          char*  parseString()  const;
00208 
00209   inline char*  toString() const;
00210   inline char*  getText()  const;
00211 
00212 ////////////////////////////////////////////////////////////////////////////
00213 /// Stream utilities...                                                  ///
00214 ////////////////////////////////////////////////////////////////////////////
00215   friend ostream& operator<<( ostream& os, const JString& s ) {
00216     return os << s.pData->data;
00217   }
00218 
00219 ////////////////////////////////////////////////////////////////////////////
00220 /// JString Assignment                                                   ///
00221 ////////////////////////////////////////////////////////////////////////////
00222 /// Defined in:  StrAdd.cpp                                              ///
00223 ////////////////////////////////////////////////////////////////////////////
00224   void  CopyBeforeWrite();
00225 
00226   // IT MUST RETURN CONST !
00227   // JString s = s1 = s2 = "Hello";  will work just fine, if it's const !
00228   const JString& operator=( const JString& s );
00229   const JString& operator=( const char* s );
00230   const JString& operator=( char  ch );
00231 
00232 ////////////////////////////////////////////////////////////////////////////
00233 /// JString Concatenation                                                ///
00234 ////////////////////////////////////////////////////////////////////////////
00235 /// Defined in:  StrAdd.cpp                                              ///
00236 ////////////////////////////////////////////////////////////////////////////
00237   void  Append( const char* s, ULONG Len );
00238   const JString& operator+=( const JString& s );
00239   const JString& operator+=( const char* s );
00240   const JString& operator+=( char  ch );
00241 
00242 ////////////////////////////////////////////////////////////////////////////
00243 /// JString Addition                                                     ///
00244 ////////////////////////////////////////////////////////////////////////////
00245 /// Defined in:  StrAdd.cpp                                              ///
00246 ////////////////////////////////////////////////////////////////////////////
00247 private:
00248   // Used for any private addition of JString
00249   // Private since it's usage is trivial...
00250   inline void  Add( const char* s1, const char* s2, ULONG Len1, ULONG Len2 );
00251          void  Add( const char* s1, const char* s2, ULONG Len1, ULONG Len2, ULONG LenExtra );
00252 
00253 public:
00254   friend JString operator+( const JString& s1, const JString& s2 );
00255 
00256   friend JString operator+( const JString& s1, const char*    s2 );
00257   friend JString operator+( const char*    s1, const JString& s2 );
00258 
00259   friend JString operator+( const JString& s,  char ch );
00260   friend JString operator+( char ch,  const JString& s );
00261 
00262 ////////////////////////////////////////////////////////////////////////////
00263 /// Upper/Lower/Reverse Conversion (QuickBasic Compatible)               ///
00264 ////////////////////////////////////////////////////////////////////////////
00265 /// Defined in:  StrTools.cpp                                            ///
00266 ////////////////////////////////////////////////////////////////////////////
00267   void MakeUpper();
00268   void MakeLower();
00269   void MakeReverse();
00270 
00271   // Might return JString object in the future...
00272   inline void UCase();  // QB format
00273   inline void LCase();
00274   inline void Reverse();
00275 
00276   char*    getLower();
00277   char*    getUpper();
00278   char*    getReverse();
00279 
00280   inline JString& setLower();
00281   inline JString& setUpper();
00282   inline JString& setReverse();
00283 
00284 ////////////////////////////////////////////////////////////////////////////
00285 /// Search/Find/ReverseFind function (QuickBasic Compatible)             ///
00286 ////////////////////////////////////////////////////////////////////////////
00287 /// Defined in:  StrFind.cpp                                             ///
00288 ////////////////////////////////////////////////////////////////////////////
00289 
00290    // searching (return starting index,
00291     // or -1 if not found)
00292    // look for a single character match
00293 
00294   long Find( char ch ) const;
00295   long ReverseFind( char ch ) const;
00296   
00297   inline long Find( const char* s ) const;
00298          long Find( const char* s, ULONG offset ) const;
00299 
00300   inline JString getFind( const char* s );
00301          JString getFind( const char* s, ULONG offset );
00302 
00303 
00304   inline long Find( const JString& S ) const;
00305   inline long Find( const JString& S, ULONG offset ) const;
00306 
00307 ////////////////////////////////////////////////////////////////////////////
00308 /// Every function str* from ANSI definition                             ///
00309 ////////////////////////////////////////////////////////////////////////////
00310 /// Defined in:  StrANSI.cpp                                             ///
00311 ////////////////////////////////////////////////////////////////////////////
00312   
00313   char*    getConcatenate( const char* src );
00314   JString& setConcatenate( const char* src );
00315   char*    getConcatenateWithLimits( const char* src, ULONG n );
00316   JString& setConcatenateWithLimits( const char* src, ULONG n );
00317 
00318   long     firstCharFound( const int c );
00319   long     lastCharFound( const int c );
00320 
00321   int      compare( const char* src );
00322   int      compareIgnoreCase( const char* src );
00323   int      compareUsingLocaleCollate( const char* src );
00324   int      compareWithLimits( const char* src, ULONG n );
00325   int      compareIgnoreCaseWithLimits( const char* src, ULONG n );
00326 
00327   char*    copy();
00328   JString  getCopy();
00329   char*    copyWithLimits( ULONG n );
00330   JString  getCopyWithLimits( ULONG n );
00331 
00332   ULONG   getNbCharNotFromCharSet( const char* charset );
00333 
00334   JString  getDate();  // MM/DD/YY format (not Y2K complient !)
00335   JString& setDate();  // MM/DD/YY format (not Y2K complient !)
00336   
00337   JString& setTime( ULONG maxSize, const char* format,
00338                     const struct tm* currTime );
00339   
00340   char*    duplicate();
00341   JString  duplicateString();
00342   JString  getError( int errnb );
00343   JString& setError( int errnb );
00344 
00345   JString  getTimeFormat( ULONG maxSize, const char* format, const struct tm* currTime );
00346   JString& setTimeFormat( ULONG maxSize, const char* format, const struct tm* currTime );
00347   JString  getTime();  // HH:MM:SS  (24h)
00348   JString& setTime();  // HH:MM:SS  (24h)
00349 
00350   char*    getFillWithChar( const int ch );
00351   JString& setFillWithChar( const int ch );
00352   char*    getFillWithChar( const int ch, ULONG n );
00353   JString& setFillWithChar( const int ch, ULONG n );
00354   
00355   // Return Where is the first charset in String
00356   long     locateCharSet( const char* charset );
00357   long     locateCharSet( const char* charset, ULONG startAt );
00358   
00359   // Return How much of charset in String
00360   ULONG   findCharset( const char* charset );
00361   ULONG   findCharset( const char* charset, ULONG startAt );
00362   
00363   // Return Where is the first String given in String
00364   long     findString( const char* s );
00365   long     findString( const char* s, ULONG startAt );
00366   
00367   double   toDouble();
00368   double   toDouble( ULONG startAt );
00369   
00370   long     toLong();
00371   long     toLong( ULONG base );
00372   long     toLong( ULONG startAt, ULONG base );
00373   
00374   ULONG    toULONG();
00375   ULONG    toULONG( ULONG base );
00376   ULONG    toULONG( ULONG startAt, ULONG base );
00377  
00378   char*    getTransform( const char* src, ULONG n );
00379   JString& setTransform( const char* src, ULONG n );
00380 
00381   char*    getTokens( const char* delims, ULONG startAt );
00382   JString  getStringTokens( const char* delims, ULONG startAt );
00383   char*    getMoreTokens( const char* delims );
00384   JString  getMoreStringTokens( const char* delims );
00385  
00386 /**************************************************************************
00387  *  NOT DEFINED YET !
00388  **************************************************************************/
00389 
00390  /*
00391 
00392 ////////////////////////////////////////////////////////////////////////////
00393 /// Trimming Space  (QuickBasic compatible)                              ///
00394 ////////////////////////////////////////////////////////////////////////////
00395   void TrimRight();  // lib g++ format
00396   void TrimLeft();
00397 
00398   // Might return JString object in the future...
00399   inline void LTrim();  // QB format
00400   inline void RTrim();
00401   inline void Trim();
00402 
00403 ////////////////////////////////////////////////////////////////////////////
00404 /// Span Include/Exclude function                                        ///
00405 ////////////////////////////////////////////////////////////////////////////
00406   JString SpanIncluding( const char* s ) const;
00407   JString SpanExcluding( const char* s ) const;
00408 
00409 ////////////////////////////////////////////////////////////////////////////
00410 /// Simple formatting function ( using  "sprintf"  Format )              ///
00411 ////////////////////////////////////////////////////////////////////////////
00412    // simple formatting
00413   void Format(  const char* sFormat, ... );
00414   void Format(  ULONG nFormatID, ... );
00415   void FormatV( const char* lpszFormat, va_list argList );
00416 
00417 */
00418 
00419 ////////////////////////////////////////////////////////////////////////////
00420 /// Unlock/Lock Buffer turn Ref counting on/off (MFC JString compatible) ///
00421 /// AND everything else related to Buffer and Allocation...              ///
00422 ////////////////////////////////////////////////////////////////////////////
00423 /// Defined in:  StrExtra.cpp  (NOT FULLY SUPPORTED YET)                 ///
00424 ////////////////////////////////////////////////////////////////////////////
00425   inline void AllocBuffer(      ULONG nLen );
00426   inline void AllocBeforeWrite( ULONG nLen );
00427 
00428   inline char* LockBuffer();
00429   inline void  UnlockBuffer();
00430 
00431   void  FreeExtra();
00432   char* GetBuffer( ULONG minBufferLength );
00433 
00434   inline void  ReleaseBuffer();
00435 
00436 /////////////////////////////////////////////////////////////////////////////
00437 /// Extra stuff for compatibility with the widely used Linux String class ///
00438 /////////////////////////////////////////////////////////////////////////////
00439 /// Defined in:  StrLinux.cpp  (NOT FULLY SUPPORTED YET)                  ///
00440 /////////////////////////////////////////////////////////////////////////////
00441 
00442 private:
00443          void Add( const char* s1 = NULL, ULONG Len1 = 0, \
00444                    const char* s2 = NULL, ULONG Len2 = 0, \
00445                    const char* s3 = NULL, ULONG Len3 = 0, \
00446                    const char* s4 = NULL, ULONG Len4 = 0, \
00447                    const char* s5 = NULL, ULONG Len5 = 0, \
00448                    const char* s6 = NULL, ULONG Len6 = 0, \
00449                    const char* s7 = NULL, ULONG Len7 = 0, \
00450                    const char* s8 = NULL, ULONG Len8 = 0, \
00451                    const char* s9 = NULL, ULONG Len9 = 0, \
00452                    ULONG LenExtra = 0 );
00453 
00454 public:
00455 
00456   const JString& Add( const JString& S1, const JString& S2, const JString& S3, \
00457                       const JString& S4, const JString& S5, const JString& S6, \
00458                       const JString& S7, const JString& S8 );
00459 
00460   const JString& Add( const JString& S1, const JString& S2, const JString& S3, \
00461                       const JString& S4, const JString& S5, const JString& S6, \
00462                       const JString& S7 );
00463 
00464   const JString& Add( const JString& S1, const JString& S2, const JString& S3, \
00465                       const JString& S4, const JString& S5, const JString& S6 );
00466 
00467   const JString& Add( const JString& S1, const JString& S2, const JString& S3, \
00468                       const JString& S4, const JString& S5 );
00469 
00470   const JString& Add( const JString& S1, const JString& S2, \
00471                       const JString& S3, const JString& S4 );
00472 
00473   const JString& Add( const JString& S1, const JString& S2, const JString& S3 );
00474 
00475 // With Find(), it's VERY EASY to implement the derivates!
00476 
00477   inline BOOL contains( const JString& S, ULONG offset ) const;
00478   inline BOOL contains( const char* s,    ULONG offset ) const;
00479   inline BOOL contains( char c,           ULONG offset ) const;
00480 
00481   inline BOOL contains( const JString& S ) const;
00482   inline BOOL contains( const char* s    ) const;  
00483   inline BOOL contains( char c           ) const; 
00484 
00485   inline const JString& append(  const JString& S );
00486   inline const JString& prepend( const JString& S );
00487 
00488   inline const JString& append(  const char* s );
00489   inline const JString& prepend( const char* s );
00490 
00491   inline const JString& append(  char c );
00492   inline const JString& prepend( char c );
00493 
00494 private:
00495   JStringData* pData;  // Pointer to the JStringData Rep
00496 
00497   friend JSubString;
00498 }; // End of JString Class
00499 
00500 #include <j2k/Fred/String/StrData.inl>
00501 #include <j2k/Fred/String/StrAdd.inl>
00502 #include <j2k/Fred/String/StrBuild.inl>
00503 #include <j2k/Fred/String/StrComp.inl>
00504 #include <j2k/Fred/String/StrFind.inl>
00505 #include <j2k/Fred/String/StrMorph.inl>
00506 #include <j2k/Fred/String/StrTools.inl>
00507 #include <j2k/Fred/String/StringAt.inl>
00508 #include <j2k/Fred/String/StrLinux.inl>
00509 
00510 // Real QB Style
00511 
00512 // Not EXTERN C due to class JString ADT
00513 
00514 inline JString Reverse( const JString& S ) {
00515   JString temp( S );
00516   temp.MakeReverse();
00517   return temp;
00518 }
00519 
00520 inline JString UCase( const JString& S ) {
00521   JString temp( S );
00522   temp.MakeUpper();
00523   return temp;
00524 }
00525 
00526 inline JString LCase( const JString& S ) {
00527   JString temp( S );  
00528   temp.MakeLower();
00529   return temp;
00530 }
00531 
00532 
00533 #endif
00534 
00535 

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