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/globalsdef.h"
00041 #include "base/fscapi.h"
00042 #include "base/util/ArrayElement.h"
00043 
00044 BEGIN_NAMESPACE
00045 
00046 class ArrayList;
00047 
00057 class StringBuffer: public ArrayElement {
00058     public:
00059         // Constant value for an invalid pos (returned by find and rfind)
00060         static const size_t npos;
00061 
00075         StringBuffer(const char* str = NULL, size_t len = npos);
00076 
00080         StringBuffer(const StringBuffer &sb);
00081         
00085         ~StringBuffer();
00086     
00090         StringBuffer& append(const char* );
00091 
00092         StringBuffer& append(unsigned long u, bool sign = true);
00093 
00097         StringBuffer& append(StringBuffer& s);
00098 
00102         StringBuffer& append(StringBuffer* str);
00103 
00107         StringBuffer& assign(const char* );
00108 
00110         StringBuffer& set(const char* other) { return assign(other);};
00111 
00118         StringBuffer& convert(const WCHAR* wc, const char *encoding = 0);
00119 
00125         StringBuffer& sprintf(const char* format, ...)
00126 #ifdef __GNUC__
00127             /* enables GCC checking of format <-> parameter mismatches */
00128             __attribute__ ((format (printf, 2, 3)))
00129 #endif
00130             ;
00131 
00137         StringBuffer& vsprintf(const char* format, PLATFORM_VA_LIST ap)
00138 #ifdef __GNUC__
00139             /* enables GCC checking of format <-> parameter mismatches */
00140             __attribute__ ((format (printf, 2, 0)))
00141 #endif
00142             ;
00143 
00144 
00148         StringBuffer& reset();
00149 
00153         const char*  getChars() const { return c_str(); };
00154 
00158         const char*  c_str() const { return s; };
00159 
00166         size_t find(const char *str, size_t pos = 0) const;
00167 
00173         size_t ifind(const char *str, size_t pos = 0) const;
00174 
00180         size_t rfind(const char *str, size_t pos = 0) const;
00181 
00188         size_t replace(const char *from, const char *to, size_t pos = 0);
00194         int replaceAll(const char *from, const char *to, size_t pos = 0);
00195 
00202         ArrayList &split (ArrayList &tokens,
00203                           const char *delimiters = " ") const;
00204 
00211         StringBuffer& join(ArrayList &tokens, const char *separator);
00212 
00219         StringBuffer substr(size_t pos, size_t len = npos) const;
00220 
00225         unsigned long length() const;
00226 
00230         void reserve(size_t len);
00231 
00235         StringBuffer& upperCase() ;
00236 
00240         StringBuffer& lowerCase() ;
00241 
00246         bool icmp(const char *sc) const ;
00247 
00251         bool empty() const;
00252 
00256         bool null() const;
00257 
00261         bool endsWith(char ch) const;
00262 
00266         bool endsWith(const char* str) const;
00267 
00271         ArrayElement* clone() ;
00272 
00276         StringBuffer& operator= (const char*  sc) ;
00277         StringBuffer& operator= (const StringBuffer& s) ;
00278         StringBuffer& operator+= (const char*  sc) ;
00279         StringBuffer& operator+= (const StringBuffer& s) ;
00280         bool operator== (const char*  sc) const ;
00281         bool operator== (const StringBuffer& sb) const ;
00282         bool operator!= (const char*  sc) const ;
00283         bool operator!= (const StringBuffer& s) const ;
00284 
00285         operator const char* () const { return s; } ;
00286 
00287     private:
00288         char*  s;
00289         size_t size;
00290 
00291         // Allocator
00292         void getmem(size_t len);
00293         // Deallocator
00294         void freemem();
00295 };
00296 
00297 StringBuffer operator+(const StringBuffer& x, const char *y);
00298 
00299 
00300 END_NAMESPACE
00301 
00303 #endif
00304 

Generated on Tue Jun 10 17:20:21 2008 for Funambol C++ Client Library by  doxygen 1.5.2