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
00064
00065
00068 class XBDLLEXPORT xbString {
00069 public:
00070 enum {npos = -1};
00071
00072 xbString();
00073 xbString(size_t size);
00074 xbString(char c);
00075 xbString(const char *s);
00076 xbString(const char *s, size_t maxlen);
00077 xbString(const xbString &s);
00078
00079 virtual ~xbString();
00080
00081 xbString &operator=(const xbString &s);
00082 xbString &operator=(const char *s);
00083 xbString &operator=(char c);
00084
00085 bool isNull() const;
00086 bool isEmpty() const;
00087 size_t len() const;
00088 size_t length() const;
00089
00090 void resize(size_t size);
00091 xbString copy() const;
00092
00093 xbString &sprintf(const char *format, ...);
00094 void setNum(long num);
00095
00096 xbString& assign(const xbString& str, size_t pos = 0, int n = npos);
00097 xbString& assign(char* str, int n);
00098 char operator[](int n) { return data[n]; }
00099 char getCharacter( int n ) const { return data[n]; }
00100 operator const char *() const;
00101 xbString &operator+=(const char *s);
00102 xbString &operator+=(char c);
00103 xbString &operator-=(const char *s);
00104 void putAt(size_t pos, char c);
00105
00106 const char *getData() const;
00107 const char *c_str() const;
00108 void toLowerCase();
00109 int pos(char c);
00110 int pos(const char* s);
00111 void trim();
00112 bool compare(char s);
00113 bool compare(const char *s);
00114
00115 bool operator == ( const xbString& ) const;
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
00122 friend XBDLLEXPORT std::ostream& operator << ( std::ostream&,
00123 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 XBDLLEXPORT xbString operator-(const xbString &s1, const xbString &s2);
00138 XBDLLEXPORT xbString operator+(const xbString &s1, const xbString &s2);
00139 XBDLLEXPORT xbString operator+(const xbString &s1, const char *s2);
00140 XBDLLEXPORT xbString operator+(const char *s1, const xbString &s2);
00141 XBDLLEXPORT xbString operator+(const xbString &s1, char c2);
00142 XBDLLEXPORT xbString operator+(char c1, const xbString &s2);
00143 XBDLLEXPORT bool operator==(const xbString &s1, const char *s2);
00144 XBDLLEXPORT bool operator!=(const xbString &s1, const char *s2);
00145
00146 #endif
00147