Gel2D - The free/open source game creation suite

gelString.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELSTRING_H__
00017 #define __GELSTRING_H__
00018 
00019 #include "gelNamespace.h"
00020 #include "gelCString.h"
00021 #include "gelChar.h"
00022 
00023 #include <cstring>
00024 
00025 namespace gel
00026 {
00028     class GelString
00029     {
00030         public:
00032             GelString();
00033 
00035             GelString( GelChar ch );
00036 
00038             GelString( const GelString &string );
00039 
00041 
00042             GelString( const char *str );
00043 
00045             ~GelString() { delete[] data; }
00046 
00048 
00049             void append( const GelString &str );
00050 
00052             void append( const char *str );
00053 
00055             void append( GelChar ch );
00056 
00058             void append( char ch );
00059 
00061 
00062             void prepend( const GelString &str );
00063 
00065             void prepend( const char *str );
00066 
00068             void prepend( GelChar ch );
00069 
00071             void prepend( char ch );
00072 
00074             void insert( const GelString &str, int pos );
00075 
00077             void insert( GelChar ch, int pos );
00078 
00080             void clear();
00081 
00083 
00084             void resize( int size );
00085 
00087 
00089             void remove( int pos, int num );
00090 
00092 
00093             void remove( const GelString &str );
00094 
00096 
00097             void remove( GelChar ch );
00098 
00100             void replace( GelChar before, GelChar after );
00101 
00103 
00104             void replace( const GelString &before, const GelString &after );
00105 
00107 
00108             void truncate( int pos );
00109 
00111 
00114             int findFirst( const GelString &str ) const;
00115 
00117 
00120             int findFirst( GelChar ch ) const;
00121 
00123 
00126             int findLast( const GelString &str ) const;
00127 
00129 
00132             int findLast( GelChar ch ) const;
00133 
00135 
00139             int findNext( const GelString &str, int pos  ) const;
00140 
00142 
00146             int findNext( GelChar ch, int pos ) const;
00147 
00149 
00151             int count( const GelString &str ) const;
00152 
00154 
00156             int count( GelChar ch ) const;
00157 
00159 
00163             int compare( const GelString &str ) const;
00164 
00166             void makeLower();
00167 
00169             void makeUpper();
00170 
00172 
00174             GelString subString( int start, int length ) const;
00175 
00177 
00178             GelCString toAscii() const;
00179 
00181             void fromAscii( const char *str );
00182 
00184 
00185             int getLength() const { return len; }
00186 
00188 
00189             GelChar *getData() { return data; }
00190 
00192 
00193             const GelChar *getData() const { return data; }
00194 
00196             GelString &operator=( GelChar ch );
00197 
00199             GelString &operator=( const GelString &s );
00200 
00202             GelString &operator=( const char *s );
00203 
00205 
00206             GelString &operator+=( const GelString &s ) { append(s); return *this; }
00207 
00209             GelString &operator+=( const char *s ) { append(s); return *this; }
00210 
00212             GelString &operator+=( GelChar c ) { append(c); return *this; }
00213 
00215             GelString &operator+=( char c ) { append(c); return *this;}
00216 
00218             GelString operator+( GelChar ch ) const
00219             { GelString str(*this); str += ch; return str; }
00220 
00222             GelString operator+( const GelString &s ) const
00223             { GelString str(*this); str += s; return str; }
00224 
00226             GelString operator+( const char *s ) const
00227             { GelString str(*this); str += s; return str; }
00228 
00230             GelChar &operator[]( int i ) { return data[i]; }
00231 
00233 
00234             const GelChar &operator[]( int i ) const { return data[i]; }
00235 
00236         private:
00238 
00240             void reallocate( int size );
00241 
00242         private:
00243             GelChar *data;
00244             int len;
00245             int alloc;
00246     };
00247 
00249 
00250     GelString operator+( GelChar ch, const GelString &s );
00251     //{ GelString str(ch); str += s; return str; }
00252 
00254 
00255     GelString operator+( const char *s1, const GelString &s2 );
00256     //{ GelString str(s1); str += s2; return str; }
00257 }
00258 
00259 #endif // __GELSTRING_H__