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.h,v 1.26 2003/03/18 19:36:13 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 
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 {
00049  public:
00053   skString();
00057   skString(const Char *);
00061   skString(const skString&);
00067   skString(const Char * buffer, USize len);
00073   skString(const Char repeatChar, USize len);
00077   virtual ~skString();
00081   skString& operator=(const skString&);
00085   skString& operator=(const Char *);
00090   bool operator<(const skString&) const;
00095   bool operator==(const skString&) const;
00100   bool operator==(const Char *) const;
00105   bool operator!=(const skString&) const;
00110   bool operator!=(const Char *) const;
00115   operator const Char * () const;
00120   bool equalsIgnoreCase(const skString&) const;
00124   USize hash() const;
00130   Char at(USize index) const;
00137   skString substr(USize start,USize length) const;
00143   skString substr(USize start) const;
00148   skString operator+(const skString&) const ;
00153   skString& operator+=(const skString&);
00158   USize length() const;
00163   int indexOf(const skString& s) const;
00168   int indexOf(Char c) const;
00173   int indexOfLast(Char c) const;
00177   int to() const;
00181   float toFloat() const;
00185   static skString literal(const Char *);
00189   static skString from(int);
00193   static skString from(USize);
00197   static skString from(float);
00201   static skString from(Char ch);
00205   static skString fromBuffer(Char * buffer);
00209   skString ltrim() const;
00215   skString removeInitialBlankLines() const;
00220   static skString readFromFile(const skString& filename);
00225   void writeToFile(const skString& filename);
00231   skString replace(const skString& old_substr,const skString& new_substr) const;
00232  protected:
00236   skString(P_String *);
00240   skString(const Char * s,int);
00244   void assign(const Char *,int len=0);                          
00248   void deRef();
00252   P_String * pimp;
00253 };
00254 /*
00255  * A hashKey function for HashTables
00256  */
00257 inline USize hashKey(const skString * s)
00258 {
00259     return s->hash();
00260 }
00261 /*
00262  * An operator to add strings
00263  */
00264 CLASSEXPORT skString operator+(const Char * s1,const skString& s2);
00265 
00266 #ifdef STREAMS_ENABLED
00267 /*
00268  * A streaming operator to write a string to an output stream
00269  */
00270 CLASSEXPORT ostream& operator<<(ostream&,const skString&s);
00271 #endif
00272 /*
00273  * Some helper macros for declaring literal strings, and references to literal strings
00274  */
00275 #define skLITERAL(s) skString s_##s=skString::literal(skSTR(#s))
00276 #define xskLITERAL(s) extern skString s_##s
00277 //#define skSTR(s) skString(s)
00278 
00279 inline float ATOF(const Char * c){
00280 #ifdef UNICODE_STRINGS
00281   return (float) wcstod(c,0);
00282 #else
00283   return (float) atof(c);
00284 #endif
00285 }
00286 inline int ATOI(const Char * c){
00287 #ifdef UNICODE_STRINGS
00288   return _wtoi(c);
00289 #else
00290   return atoi(c);
00291 #endif
00292 }
00293 
00294 #include "skString.inl"
00295 
00296 #endif
00297 
00298 
00299 

Generated on Tue Mar 18 19:46:18 2003 for Simkin by doxygen1.3-rc1