00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
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