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 #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