src/include/common/base/util/StringBuffer.h

00001 /*
00002  * Copyright (C) 2003-2007 Funambol, Inc
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 2 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00016  * 02111-1307  USA
00017  */
00018 
00019 #ifndef INCL_BASE_STRING_BUFFER
00020 #define INCL_BASE_STRING_BUFFER
00021 
00023 #include "base/util/ArrayElement.h"
00024 
00025 #include <stdarg.h>
00026 
00027 class ArrayList;
00028 
00032 class StringBuffer: public ArrayElement {
00033     public:
00034         // Constant value for an invalid pos (returned by find and rfind)
00035         static const size_t npos;
00036 
00037         StringBuffer(const char*  str = NULL, size_t len = npos);
00038 
00039         StringBuffer(const StringBuffer &sb);
00040 
00041         StringBuffer(const void* str, size_t len);
00042 
00043         ~StringBuffer();
00044 
00045         StringBuffer& append(const char* );
00046 
00047         StringBuffer& append(unsigned long u, BOOL sign = TRUE);
00048 
00049         StringBuffer& append(StringBuffer& s);
00050 
00051         StringBuffer& append(StringBuffer* str);
00052 
00053         StringBuffer& set(const char* );
00054 
00060         StringBuffer& sprintf(const char* format, ...)
00061 #ifdef __GNUC__
00062             /* enables GCC checking of format <-> parameter mismatches */
00063             __attribute__ ((format (printf, 2, 3)))
00064 #endif
00065             ;
00066 
00072         StringBuffer& vsprintf(const char* format, va_list ap)
00073 #ifdef __GNUC__
00074             /* enables GCC checking of format <-> parameter mismatches */
00075             __attribute__ ((format (printf, 2, 0)))
00076 #endif
00077             ;
00078 
00079 
00083         StringBuffer& reset();
00084 
00088         const char*  getChars() const;
00089         inline const char*  c_str() const { return s; };
00090 
00097         size_t find(const char *str, size_t pos = 0) const;
00098 
00104         size_t ifind(const char *str, size_t pos = 0) const;
00105 
00111         size_t rfind(const char *str, size_t pos = 0) const;
00112 
00119         size_t replace(const char *from, const char *to, size_t pos = 0);
00125         int replaceAll(const char *from, const char *to, size_t pos = 0);
00126 
00133         ArrayList &split (ArrayList &tokens,
00134                           const char *delimiters = " ") const;
00135 
00142         StringBuffer& join(ArrayList &tokens, const char *separator);
00143 
00150         StringBuffer substr(size_t pos, size_t len = npos) const;
00151 
00156         unsigned long length() const;
00157 
00161         void reserve(size_t len);
00162 
00166         StringBuffer& upperCase() ;
00167 
00171         StringBuffer& lowerCase() ;
00172 
00177         bool icmp(const char *sc) const ;
00178 
00182         bool empty() const;
00183 
00187         bool null() const;
00188 
00192         ArrayElement* clone() ;
00193 
00197         StringBuffer& operator= (const char*  sc) ;
00198         StringBuffer& operator= (const StringBuffer& s) ;
00199         StringBuffer& operator+= (const char*  sc) ;
00200         StringBuffer& operator+= (const StringBuffer& s) ;
00201         bool operator== (const char*  sc) const ;
00202         bool operator== (const StringBuffer& sb) const ;
00203         bool operator!= (const char*  sc) const ;
00204         bool operator!= (const StringBuffer& s) const ;
00205 
00206         operator const char* () const { return s; } ;
00207 
00208     private:
00209         char*  s;
00210         size_t size;
00211 
00212         // Allocator
00213         void getmem(size_t len);
00214         // Deallocator
00215         void freemem();
00216 };
00217 
00218 StringBuffer operator+(const StringBuffer& x, const char *y);
00219 
00221 #endif
00222 

Generated on Fri Nov 9 12:21:24 2007 for Funambol Outlook Plug-in Library by  doxygen 1.5.2