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

00001 /*
00002  * Funambol is a mobile platform developed by Funambol, Inc. 
00003  * Copyright (C) 2003 - 2007 Funambol, Inc.
00004  * 
00005  * This program is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Affero General Public License version 3 as published by
00007  * the Free Software Foundation with the addition of the following permission 
00008  * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
00009  * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
00010  * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  * 
00017  * You should have received a copy of the GNU Affero General Public License 
00018  * along with this program; if not, see http://www.gnu.org/licenses or write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00020  * MA 02110-1301 USA.
00021  * 
00022  * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
00023  * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
00024  * 
00025  * The interactive user interfaces in modified source and object code versions
00026  * of this program must display Appropriate Legal Notices, as required under
00027  * Section 5 of the GNU Affero General Public License version 3.
00028  * 
00029  * In accordance with Section 7(b) of the GNU Affero General Public License
00030  * version 3, these Appropriate Legal Notices must retain the display of the
00031  * "Powered by Funambol" logo. If the display of the logo is not reasonably 
00032  * feasible for technical reasons, the Appropriate Legal Notices must display
00033  * the words "Powered by Funambol".
00034  */
00035 
00036 #ifndef INCL_BASE_STRING_BUFFER
00037 #define INCL_BASE_STRING_BUFFER
00038 
00040 #include "base/util/ArrayElement.h"
00041 
00042 #include <stdarg.h>
00043 
00044 class ArrayList;
00045 
00049 class StringBuffer: public ArrayElement {
00050     public:
00051         // Constant value for an invalid pos (returned by find and rfind)
00052         static const size_t npos;
00053 
00054         StringBuffer(const char*  str = NULL, size_t len = npos);
00055 
00056         StringBuffer(const StringBuffer &sb);
00057 
00058         StringBuffer(const void* str, size_t len);
00059 
00060         ~StringBuffer();
00061 
00062         StringBuffer& append(const char* );
00063 
00064         StringBuffer& append(unsigned long u, BOOL sign = TRUE);
00065 
00066         StringBuffer& append(StringBuffer& s);
00067 
00068         StringBuffer& append(StringBuffer* str);
00069 
00070         StringBuffer& set(const char* );
00071 
00077         StringBuffer& sprintf(const char* format, ...)
00078 #ifdef __GNUC__
00079             /* enables GCC checking of format <-> parameter mismatches */
00080             __attribute__ ((format (printf, 2, 3)))
00081 #endif
00082             ;
00083 
00089         StringBuffer& vsprintf(const char* format, va_list ap)
00090 #ifdef __GNUC__
00091             /* enables GCC checking of format <-> parameter mismatches */
00092             __attribute__ ((format (printf, 2, 0)))
00093 #endif
00094             ;
00095 
00096 
00100         StringBuffer& reset();
00101 
00105         const char*  getChars() const;
00106         inline const char*  c_str() const { return s; };
00107 
00114         size_t find(const char *str, size_t pos = 0) const;
00115 
00121         size_t ifind(const char *str, size_t pos = 0) const;
00122 
00128         size_t rfind(const char *str, size_t pos = 0) const;
00129 
00136         size_t replace(const char *from, const char *to, size_t pos = 0);
00142         int replaceAll(const char *from, const char *to, size_t pos = 0);
00143 
00150         ArrayList &split (ArrayList &tokens,
00151                           const char *delimiters = " ") const;
00152 
00159         StringBuffer& join(ArrayList &tokens, const char *separator);
00160 
00167         StringBuffer substr(size_t pos, size_t len = npos) const;
00168 
00173         unsigned long length() const;
00174 
00178         void reserve(size_t len);
00179 
00183         StringBuffer& upperCase() ;
00184 
00188         StringBuffer& lowerCase() ;
00189 
00194         bool icmp(const char *sc) const ;
00195 
00199         bool empty() const;
00200 
00204         bool null() const;
00205 
00209         ArrayElement* clone() ;
00210 
00214         StringBuffer& operator= (const char*  sc) ;
00215         StringBuffer& operator= (const StringBuffer& s) ;
00216         StringBuffer& operator+= (const char*  sc) ;
00217         StringBuffer& operator+= (const StringBuffer& s) ;
00218         bool operator== (const char*  sc) const ;
00219         bool operator== (const StringBuffer& sb) const ;
00220         bool operator!= (const char*  sc) const ;
00221         bool operator!= (const StringBuffer& s) const ;
00222 
00223         operator const char* () const { return s; } ;
00224 
00225     private:
00226         char*  s;
00227         size_t size;
00228 
00229         // Allocator
00230         void getmem(size_t len);
00231         // Deallocator
00232         void freemem();
00233 };
00234 
00235 StringBuffer operator+(const StringBuffer& x, const char *y);
00236 
00238 #endif
00239 

Generated on Thu Mar 6 14:25:04 2008 for Funambol C++ Client Library by  doxygen 1.5.2