|
Xbase Class Library 2.0.0
|
00001 /* 00002 00003 Xbase project source code 00004 00005 This file contains the Class definition for a xbString object. 00006 00007 Copyright (C) 1997 StarTech, Gary A. Kunkel 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library 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 GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 Contact: 00024 00025 Mail: 00026 00027 Technology Associates, Inc. 00028 XBase Project 00029 1455 Deming Way #11 00030 Sparks, NV 89434 00031 USA 00032 00033 Email: 00034 00035 xbase@techass.com 00036 00037 See our website at: 00038 00039 xdb.sourceforge.net 00040 00041 00042 V 1.9.2 9/14/99 - Misc user supplied updates 00043 */ 00044 00045 #ifndef __XBSTRING_H__ 00046 #define __XBSTRING_H__ 00047 00048 #ifdef __GNUG__ 00049 #pragma interface 00050 #endif 00051 00052 #ifdef __WIN32__ 00053 #include <xbase/xbconfigw32.h> 00054 #else 00055 #include <xbase/xbconfig.h> 00056 #endif 00057 00058 #include <stdlib.h> 00059 #include <iostream> 00060 using namespace std; 00061 00065 00066 00069 class XBDLLEXPORT xbString { 00070 public: 00071 enum {npos = -1}; 00072 00073 xbString(); 00074 xbString(size_t size); 00075 xbString(char c); 00076 xbString(const char *s); 00077 xbString(const char *s, size_t maxlen); 00078 xbString(const xbString &s); 00079 00080 ~xbString(); 00081 00082 xbString &operator=(const xbString &s); 00083 xbString &operator=(const char *s); 00084 xbString &operator=(char c); 00085 00086 bool isNull() const; 00087 bool isEmpty() const; 00088 size_t len() const; 00089 size_t length() const; 00090 00091 void resize(size_t size); 00092 xbString copy() const; 00093 00094 xbString &sprintf(const char *format, ...); 00095 void setNum(long num); 00096 00097 xbString& assign(const xbString& str, size_t pos = 0, int n = npos); 00098 xbString& assign(char* str, int n); 00099 char operator[](int n) { return data[n]; } 00100 char getCharacter( int n ) const { return data[n]; } 00101 operator const char *() const; 00102 xbString &operator+=(const char *s); 00103 xbString &operator+=(char c); 00104 xbString &operator-=(const char *s); 00105 void putAt(size_t pos, char c); 00106 00107 const char *getData() const; 00108 const char *c_str() const; 00109 void toLowerCase(); 00110 int pos(char c); 00111 int pos(const char* s); 00112 void trim(); 00113 bool compare(char s); 00114 bool compare(const char *s); 00115 00116 bool operator == ( const xbString& ) const; 00117 bool operator != ( const xbString& ) const; 00118 bool operator < ( const xbString& ) const; 00119 bool operator > ( const xbString& ) const; 00120 bool operator <= ( const xbString& ) const; 00121 bool operator >= ( const xbString& ) const; 00122 00123 friend ostream& operator << ( ostream&, const xbString& ); 00124 00125 xbString &remove(size_t pos = 0, int n = npos); 00126 xbString mid(size_t pos = 0, int n = npos) const; 00127 00128 protected: 00129 void ctor(const char *s); 00130 void ctor(const char *s, size_t maxlen); 00131 00132 char *data; 00133 size_t size; 00134 static const char * NullString; 00135 }; 00136 00137 bool operator==(const xbString &s1, const char *s2); 00138 bool operator!=(const xbString &s1, const char *s2); 00139 bool operator==(const xbString &s1, char s2); 00140 bool operator!=(const xbString &s1, char s2); 00141 00142 xbString operator+(const xbString &s1, const xbString &s2); 00143 xbString operator+(const xbString &s1, const char *s2); 00144 xbString operator+(const char *s1, const xbString &s2); 00145 xbString operator+(const xbString &s1, char c2); 00146 xbString operator+(char c1, const xbString &s2); 00147 xbString operator-(const xbString &s1, const xbString &s2); 00148 00149 #endif 00150
1.7.3