Xbase64 Class Library 3.1.2
xbstring.h
Go to the documentation of this file.
00001 /*  xbstring.h
00002 
00003     Xbase64 project source code
00004 
00005     This file contains the Class definition for a xbString object.
00006 
00007     Copyright (C) 1997,2003  Gary A Kunkel
00008     
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with this program; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023 
00024     Contact:
00025     
00026      Email:
00027     
00028       xdb-devel@lists.sourceforge.net
00029       xdb-users@lists.sourceforge.net
00030       
00031       
00032      Regular Mail:
00033      
00034        XBase Support
00035        149C South Main St
00036        Keller Texas, 76248     
00037        USA
00038 
00039 */
00040 
00041 #ifndef __XBSTRING_H__
00042 #define __XBSTRING_H__
00043 
00044 #ifdef __GNU LesserG__
00045 #pragma interface
00046 #endif
00047 
00048 #ifdef __WIN32__
00049 #include <xbase64/xbwincfg.h>
00050 #else
00051 #include <xbase64/xbconfig.h>
00052 #endif
00053 
00054 #include <stdlib.h>
00055 #include <iostream>
00056 
00060 
00061 
00063 class XBDLLEXPORT xbString {
00064 public:
00065   enum {npos = -1};
00066 
00067   xbString();
00068   xbString(size_t size);
00069   xbString(char c);
00070   xbString(const char *s);
00071   xbString(const char *s, size_t maxlen);
00072   xbString(const xbString &s);
00073   virtual ~xbString();
00074 
00075   operator const char *() const;
00076   char operator[](int n) { return data[n]; }
00077 
00078   xbString &operator=(const xbString &s);
00079   xbString &operator=(const char *s);
00080   xbString &operator=(char c);
00081   xbString &operator+=(const char *s);
00082   xbString &operator+=(char c);
00083   xbString &operator-=(const char *s);
00084 
00085   xbBool operator == ( const xbString& ) const;
00086   xbBool operator != ( const xbString& ) const;
00087   xbBool operator < ( const xbString& ) const;
00088   xbBool operator > ( const xbString& ) const;
00089   xbBool operator <= ( const xbString& ) const;
00090   xbBool operator >= ( const xbString& ) const;
00091 
00092   friend XBDLLEXPORT std::ostream& operator << ( std::ostream&,
00093                                              const xbString& );
00094   void     addBackSlash( char c );
00095   xbString &assign(const xbString& str, size_t pos = 0, int n = npos);
00096   xbString &assign(char* str, int n);
00097   xbString copy() const;
00098   const char *c_str() const;
00099   int      countChar( char c ) const;
00100   int      cvtHexChar( char & out );
00101   int      cvtHexString( xbString & out );
00102   char     getCharacter( int n ) const { return data[n]; }
00103   const char *getData() const;
00104   xbBool   hasAlphaChars() const;
00105   xbBool   isEmpty() const;
00106   xbBool   isNull() const;
00107   size_t   len() const;
00108   size_t   length() const;
00109   xbString mid(size_t pos = 0, int n = npos) const;
00110   void     lTrunc( size_t cnt );
00111   int      pos(char c);
00112   int      pos(const char* s);
00113   void     putAt(size_t pos, char c);
00114   xbString &remove(size_t pos = 0, int n = npos);
00115   void     resize(size_t size);  
00116   void     setNum(long num);
00117   void     setNum(char * fmt, double num);
00118   xbString &sprintf(const char *format, ...);
00119   void     swapChars( char from, char to );
00120   void     toLowerCase();
00121   void     toUpperCase();
00122   void     trim();
00123   void     zapChar( char c );
00124   void     zapLeadingChar( char c );
00125   int      setFromDelimitedInput(const char *,char, int, int );
00126 
00127 protected:
00128   void ctor(const char *s);
00129   void ctor(const char *s, size_t maxlen);
00130   char *data;
00131   size_t size;
00132   static const char * NullString;
00133 };
00134 
00135 XBDLLEXPORT xbString operator-(const xbString &s1, const xbString &s2);
00136 XBDLLEXPORT xbString operator+(const xbString &s1, const xbString &s2);
00137 XBDLLEXPORT xbString operator+(const xbString &s1, const char *s2);
00138 XBDLLEXPORT xbString operator+(const char *s1, const xbString &s2);
00139 XBDLLEXPORT xbString operator+(const xbString &s1, char c2);
00140 XBDLLEXPORT xbString operator+(char c1, const xbString &s2);
00141 XBDLLEXPORT xbBool operator==(const xbString &s1, const char *s2);
00142 XBDLLEXPORT xbBool operator!=(const xbString &s1, const char *s2);
00143 
00144 #endif
00145