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 
00076         StringBuffer(const char* str = "", size_t len = npos);
00077 
00081         StringBuffer(const StringBuffer &sb);
00082         
00086         ~StringBuffer();
00087     
00091         StringBuffer& append(const char* );
00092 
00097         StringBuffer& append(const char* sNew, unsigned long len);
00098 
00102         StringBuffer& append(unsigned long u, bool sign = true);
00103 
00107         StringBuffer& append(StringBuffer& s);
00108 
00112         StringBuffer& append(StringBuffer* str);
00113 
00117         StringBuffer& assign(const char* );
00118 
00120         StringBuffer& set(const char* other) { return assign(other);};
00121 
00128         StringBuffer& convert(const WCHAR* wc, const char *encoding = 0);
00129 
00135         StringBuffer& sprintf(const char* format, ...)
00136 #ifdef __GNUC__
00137             /* enables GCC checking of format <-> parameter mismatches */
00138             __attribute__ ((format (printf, 2, 3)))
00139 #endif
00140             ;
00141 
00147         StringBuffer& vsprintf(const char* format, PLATFORM_VA_LIST ap)
00148 #ifdef __GNUC__
00149             /* enables GCC checking of format <-> parameter mismatches */
00150             __attribute__ ((format (printf, 2, 0)))
00151 #endif
00152             ;
00153 
00154 
00158         StringBuffer& reset();
00159 
00163         const char*  getChars() const { return c_str(); };
00164 
00168         const char*  c_str() const { return s; };
00169 
00176         size_t find(const char *str, size_t pos = 0) const;
00177 
00183         size_t ifind(const char *str, size_t pos = 0) const;
00184 
00190         size_t rfind(const char *str, size_t pos = 0) const;
00191 
00198         size_t replace(const char *from, const char *to, size_t pos = 0);
00204         int replaceAll(const char *from, const char *to, size_t pos = 0);
00205 
00212         ArrayList &split (ArrayList &tokens,
00213                           const char *delimiters = " ") const;
00214 
00221         StringBuffer& join(ArrayList &tokens, const char *separator);
00222 
00229         StringBuffer substr(size_t pos, size_t len = npos) const;
00230 
00235         unsigned long length() const;
00236 
00240         void reserve(size_t len);
00241 
00245         StringBuffer& upperCase() ;
00246 
00250         StringBuffer& lowerCase() ;
00251 
00256         bool icmp(const char *sc) const ;
00257 
00261         bool empty() const;
00262 
00266         bool null() const;
00267 
00271         bool endsWith(char ch) const;
00272 
00276         bool endsWith(const char* str) const;
00277         
00281         StringBuffer& trim();
00282 
00286         ArrayElement* clone() ;
00287 
00291         StringBuffer& operator= (const char*  sc) ;
00292         StringBuffer& operator= (const StringBuffer& s) ;
00293         StringBuffer& operator+= (const char*  sc) ;
00294         StringBuffer& operator+= (const StringBuffer& s) ;
00295         bool operator== (const char*  sc) const ;
00296         bool operator== (const StringBuffer& sb) const ;
00297         bool operator!= (const char*  sc) const ;
00298         bool operator!= (const StringBuffer& s) const ;
00299 
00304         char operator[]( int index ) const;
00305 
00306         operator const char* () const { return s; } ;
00307 
00308     private:
00309         char*  s;
00310         size_t size;
00311 
00312         // Allocator
00313         void getmem(size_t len);
00314         // Deallocator
00315         void freemem();
00316 };
00317 
00318 StringBuffer operator+(const StringBuffer& x, const char *y);
00319 
00320 
00321 END_NAMESPACE
00322 
00324 #endif
00325 

Generated on Wed Jan 14 17:15:36 2009 for Funambol C++ Client Library by  doxygen 1.5.2