Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

skString.h

00001 /*
00002   Copyright 1996-2003
00003   Simon Whiteside
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019   * $Id: skString_8h-source.html,v 1.14 2003/05/27 17:41:56 simkin_cvs Exp $
00020   */
00021 
00022 
00023 #ifndef skSTRING_H
00024 #define skSTRING_H
00025 
00026 #include "skGeneral.h"
00027 
00028 #ifdef STREAMS_ENABLED
00029 #include <iostream.h>
00030 #endif
00031 #include <string.h>
00032 
00033 #ifdef UNICODE_STRINGS
00034 typedef wchar_t Char;
00035 #define skSTR(x) L ## x
00036 #else
00037 typedef char Char;
00038 #define skSTR(x) x
00039 #endif
00040 
00041 class P_String;
00042 
00047 class CLASSEXPORT skString 
00048 #ifdef __SYMBIAN32__
00049 : public CBase
00050 #endif
00051 {
00052  public:
00056   inline skString();
00060   inline skString(const skString&);
00061 #ifndef __SYMBIAN32__
00062 
00066   inline skString(const Char *);
00073   inline skString(const Char * buffer, USize len);
00080   skString(const Char repeatChar, USize len);
00081 #endif
00082 
00085   virtual inline ~skString();
00089   inline skString& operator=(const skString&);
00095   IMPORT_C skString& operator=(Char c);
00100   IMPORT_C skString& operator=(const Char *);
00105   inline bool operator<(const skString&) const;
00110   inline bool operator==(const skString&) const;
00115   inline bool operator==(const Char *) const;
00116 #ifdef __SYMBIAN32__
00117 
00122   inline bool operator==(const TDesC&) const;
00123 #endif
00124 
00128   IMPORT_C bool operator!=(const skString&) const;
00133   IMPORT_C bool operator!=(const Char *) const;
00134 #ifndef __SYMBIAN32__
00135 
00140   inline operator const Char * () const;
00141 #endif
00142 #ifdef __SYMBIAN32__
00143 
00148   inline skString& operator=(const TDesC&);
00154   inline TPtrC ptr() const;
00155 #else
00156 
00161   inline const Char * ptr() const;
00162 #endif
00163 
00167   inline const Char * c_str() const;
00173   IMPORT_C bool equalsIgnoreCase(const skString&) const;
00177   inline USize hash() const;
00183   inline Char at(USize index) const;
00191   IMPORT_C skString substr(USize start,USize length) const;
00198   IMPORT_C skString substr(USize start) const;
00204   IMPORT_C skString operator+(const skString&) const ;
00210   IMPORT_C skString& operator+=(const skString&);
00215   inline USize length() const;
00220   IMPORT_C int indexOf(const skString& s) const;
00225   IMPORT_C int indexOf(Char c) const;
00230   IMPORT_C int indexOfLast(Char c) const;
00234   IMPORT_C int to() const;
00235 #ifdef USE_FLOATING_POINT
00236 
00239   IMPORT_C float toFloat() const;
00240 #endif
00241 
00245   static IMPORT_C skString literal(const Char *);
00250   static IMPORT_C skString from(int);
00255   static IMPORT_C skString from(USize);
00256 #ifdef USE_FLOATING_POINT
00257 
00261   static IMPORT_C skString from(float);
00262 #endif
00263 
00267   static IMPORT_C skString from(Char ch);
00272   static IMPORT_C skString fromBuffer(Char * buffer);
00277   static IMPORT_C skString copyFromBuffer(const Char * buffer,USize length);
00282   skString IMPORT_C ltrim() const;
00289   skString IMPORT_C removeInitialBlankLines() const;
00290 #ifndef __SYMBIAN32__
00291 
00296   static skString IMPORT_C readFromFile(const skString& filename);
00302   void IMPORT_C writeToFile(const skString& filename);
00303 #endif
00304 
00310   IMPORT_C skString replace(const skString& old_substr,const skString& new_substr) const;
00317   IMPORT_C skString replace(const Char * old_substr,const Char * new_substr) const;
00322   IMPORT_C static skString addStrings(const skString& s1,const skString & s2);
00327   IMPORT_C static skString addStrings(const skString & s1,const skString & s2,const skString & s3);
00332   IMPORT_C static skString addStrings(const skString & s1,const skString & s2,const skString & s3,const skString & s4);
00337   IMPORT_C static skString addStrings(const skString & s1,const skString & s2,const skString & s3,const skString & s4,const skString & s5);
00342   IMPORT_C static skString addStrings(const skString & s1,const skString & s2,const skString & s3,const skString & s4,const skString & s5,const skString & s6);
00347   IMPORT_C static skString addStrings(const skString & s1,const skString & s2,const skString & s3,const skString & s4,const skString & s5,const skString & s6,const skString & s7);
00352   IMPORT_C static skString addStrings(const skString & s1,const skString & s2,const skString & s3,const skString & s4,const skString & s5,const skString & s6,const skString & s7,const skString & s8);
00353 #ifdef __SYMBIAN32__
00354 
00361   IMPORT_C skString replace(const TDesC& old_substr,const TDesC& new_substr) const;
00367   IMPORT_C static skString addStrings(const TDesC& s1,const TDesC& s2);
00373   IMPORT_C static skString addStrings(const TDesC& s1,const TDesC& s2,const TDesC& s3);
00378   IMPORT_C static skString addStrings(const TDesC& s1,const TDesC& s2,const TDesC& s3,const TDesC& s4);
00384   IMPORT_C static skString addStrings(const TDesC& s1,const TDesC& s2,const TDesC& s3,const TDesC& s4,const TDesC& s5);
00390   IMPORT_C static skString addStrings(const TDesC& s1,const TDesC& s2,const TDesC& s3,const TDesC& s4,const TDesC& s5,const TDesC& s6);
00396   IMPORT_C static skString addStrings(const TDesC& s1,const TDesC& s2,const TDesC& s3,const TDesC& s4,const TDesC& s5,const TDesC& s6,const TDesC& s7);
00402   IMPORT_C static skString addStrings(const TDesC& s1,const TDesC& s2,const TDesC& s3,const TDesC& s4,const TDesC& s5,const TDesC& s6,const TDesC& s7,const TDesC& s8);
00403 #endif
00404 
00407   IMPORT_C void replaceInPlace(Char old_char,Char new_char);
00408 #ifdef __SYMBIAN32__
00409 
00414   inline operator TCleanupItem();
00419   static inline void Cleanup(TAny * s);
00420 #endif
00421  protected:
00425   skString(P_String *);
00430   IMPORT_C void assign(const Char *,int len=0);                         
00434   void deRef();
00438   P_String * pimp;
00439 #ifdef __SYMBIAN32__
00440   friend IMPORT_C skString operator+(const TDesC& s1,const skString& s2);
00441 #endif
00442   friend CLASSEXPORT IMPORT_C skString operator+(const Char * s1,const skString& s2);
00443 
00444 };
00445 /*
00446  * A hashKey function for HashTables
00447  */
00448 //---------------------------------------------------
00449 inline USize hashKey(const skString * s)
00450 //---------------------------------------------------
00451 {
00452   return s->hash();
00453 }
00454 /*
00455  * An operator to add strings
00456  */
00457 #ifdef __SYMBIAN32__
00458 EXPORT_C skString operator+(const TDesC& s1,const skString& s2);
00459 #endif
00460 CLASSEXPORT IMPORT_C skString operator+(const Char *& s1,const skString& s2);
00461 
00462 #ifdef STREAMS_ENABLED
00463 /*
00464  * A streaming operator to write a string to an output stream
00465  */
00466 CLASSEXPORT ostream& operator<<(ostream&,const skString&s);
00467 #endif
00468 /*
00469  * Some helper macros for declaring literal strings, and references to literal strings
00470  */
00471 #ifdef __SYMBIAN32__
00472 //#define skLITERAL(name) _LIT(s_##name,#name)
00473 #define skLITERAL(name) const TLitC16<sizeof(L## #name )/2> s_##name={sizeof(L## #name)/2-1,L## #name}
00474 //#define xskLITERAL(name) _LIT(s_##name,#name)
00475 #define xskLITERAL(name) extern const TLitC16<sizeof(L## #name )/2> s_##name
00476 //#define skNAMED_LITERAL(name,value) _LIT(s_##name,#value)
00477 #define skNAMED_LITERAL(name,value) const TLitC16<sizeof(value )/2> s_##name={sizeof(value)/2-1,value}
00478 //#define xskNAMED_LITERAL(name,value) _LIT(s_##name,#value)
00479 #define xskNAMED_LITERAL(name,value) extern const TLitC16<sizeof(value)/2> s_##name
00480 //#define skLITERAL_STRING(name,value) _LIT(s_##name,value)
00481 #define skLITERAL_STRING(name,value) const TLitC16<sizeof(L## #value )/2> s_##name={sizeof(L## #value)/2-1,L## #value}
00482 //#define xskLITERAL_STRING(name,value) _LIT(s_##name,value)
00483 #define xskLITERAL_STRING(name,value) extern const TLitC16<sizeof(L##value)/2> s_##name
00484 #else
00485 #define skLITERAL(name) const Char * s_##name=skSTR(#name)
00486 #define xskLITERAL(name) extern const Char * s_##name
00487 #define skNAMED_LITERAL(name,value) const Char * s_##name=value
00488 #define xskNAMED_LITERAL(name,value) extern const Char * s_##name
00489 #define skLITERAL_STRING(name,value) const Char * s_##name=skSTR(value)
00490 #define xskLITERAL_STRING(name,value) extern const Char * s_##name;
00491 #endif
00492 
00493 
00494 #include "skString.inl"
00495 
00496 #endif
00497 
00498 
00499 

Generated on Tue May 27 18:40:11 2003 for Simkin by doxygen1.3