Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

String.h

Go to the documentation of this file.
00001 /*
00002  * String.h
00003  *
00004  * Smalltalk like class library for C++
00005  * Abstract textual string. Header.
00006  *
00007  * Copyright (c) 2003,2004 Milan Cermak
00008  */
00009 /*
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 #ifndef __STRING_H
00025 #define __STRING_H
00026 
00027 #include <stlib/SequenceableCollection.h>
00028 #include <stdarg.h>
00029 
00030 namespace Core {
00031 
00032 class Array;
00033 class ByteArray;
00034 class Character;
00035 class Number;
00036 class StringImpl;
00037 class Stream;
00038 class Visitor;
00039 
00047 class String : public SequenceableCollection
00048 {
00049   protected:
00050     StringImpl *implementor;
00051 
00052   public:
00056     String(long size = 0);
00057 
00061     String(const char *str);
00062 
00063     String(const ByteArray *byteArray);
00064 
00065     virtual ~String(void);
00066 
00073     static String* format(const String* format, ...);
00074 
00079     static String* format(const char* format, ...);
00080 
00081     /* Copying protocol */
00082     String(const String &origin);
00083 
00084     /* Class-accessing protocol */
00085     virtual String *className(void) const;
00086 
00087     /* Class-instance creation protocol */
00088     static String *with(Character *object);
00089     static String *with(Character *obj1, Character *obj2);
00090     static String *with(Character *obj1, Character *obj2, Character *obj3);
00091     static String *with(Character *obj1, Character *obj2, Character *obj3, Character *obj4);
00092 
00093     static String *withAll(Collection *coll);
00094 
00095     /* Accessing protocol */
00096     virtual Object *at(int index) const;
00097     virtual void put(int index, Object *obj);
00098     virtual void put(int index, char obj);
00099     virtual long size(void) const;
00100     virtual long indexOf(Object *obj) const
00101       { return SequenceableCollection::indexOf(obj); }
00102     virtual long indexOf(const char obj) const;
00103     virtual long lastIndexOf(Object *obj) const
00104       { return SequenceableCollection::lastIndexOf(obj); }
00105     virtual long lastIndexOf(const char obj) const;
00106     virtual long nextIndexOf(Object *element, long startIndex, long stopIndex) const
00107       { return SequenceableCollection::nextIndexOf(element, startIndex, stopIndex); }
00108     virtual long nextIndexOf(const char element, long startIndex, long stopIndex) const;
00109     virtual long prevIndexOf(Object *element, long startIndex, long stopIndex) const
00110       { return SequenceableCollection::prevIndexOf(element, startIndex, stopIndex); }
00111     virtual long prevIndexOf(const char element, long startIndex, long stopIndex) const;
00112 
00113     /* Adding protocol */
00114     virtual void add(Object *obj);
00115     virtual void changeSize(long newSize);
00116 
00117     /* Comparing protocol */
00118     virtual long hash(void) const;
00119     virtual bool isEqual(const Object *object) const;
00120     virtual bool isEqual(const Object &object) const
00121       { return SequenceableCollection::isEqual(object); }
00122     virtual bool isEqual(const char *string) const;
00123 
00138     virtual bool match(String *string);
00139     virtual bool match(const char *string);
00140     virtual bool match(String *string, bool ignoreCase);
00141     virtual bool match(const char *string, bool ignoreCase);
00142     virtual bool matchesPattern(String *string, bool ignoreCase);
00143 
00144     /* Converting protocol */
00148     virtual char *asCString(void) const;
00149     virtual operator char*(void) const;
00150 
00152     virtual Array *asArrayOfSubstrings(void);
00153 
00157     virtual Array *asArrayOfSubstringsSeparatedBy(Character *ch);
00158     virtual Array *asArrayOfSubstringsSeparatedBy(const char ch);
00159     virtual ByteArray *asByteArray(void) const;
00160     virtual ByteArray *asByteArrayEncoding(String *encoding) const;
00161     virtual ByteArray *asByteArrayEncoding(const char *encoding) const;
00162     virtual String *asLowercase(void);
00163     virtual Number *asNumber(void);
00164     virtual Number *asNumberRadix(int radix);
00165     virtual String *asUppercase(void);
00166     virtual String *asUppercaseFirst(void);
00167     virtual String *asString(void);
00168 
00169     /* Copying protocol */
00170     virtual Object *copy(void);
00171     virtual Object *copy(long from, long to)
00172       { return SequenceableCollection::copy(from, to); }
00173 
00174     virtual Object *copyEmpty(long size);
00175     virtual SequenceableCollection &operator+(SequenceableCollection &collection);
00176     virtual String &operator+(const char *string);
00177     virtual String *concatenateWith(String *string);
00178     virtual String *concatenateWith(const char *string);
00179 
00180     /* Printing protocol */
00181     virtual void printOn(Stream *stream) const;
00182 
00183     /* Testing protocol */
00184     virtual bool includes(Object *object)
00185       { return SequenceableCollection::includes(object); }
00186     virtual bool includes(const char element);
00187     virtual bool includesSubcollection(SequenceableCollection *coll) const
00188       { return SequenceableCollection::includesSubcollection(coll); }
00189     virtual bool includesSubcollection(const char *coll) const
00190       { return SequenceableCollection::includesSubcollection(new String(coll)); }
00191     virtual bool isString(void) const;
00192     virtual bool isByteString(void) const;
00193     virtual bool isTwoByteString(void) const;
00194     virtual bool isCharacterArray(void) const;
00195 
00197     virtual bool isDigitString(void);
00198 
00199     virtual bool startsWith(SequenceableCollection *coll) const
00200       { return SequenceableCollection::startsWith(coll); }
00201     virtual bool startsWith(const char *str) const;
00202     virtual bool endsWith(SequenceableCollection *coll) const
00203       { return SequenceableCollection::endsWith(coll); }
00204     virtual bool endsWith(const char *str) const;
00205 
00206     /* Utilities protocol */
00207     virtual String *trimBlanks(void);
00208     virtual String *demangleMethodName(void);
00209 
00210     /* Visiting protocol */
00211     virtual void visitBy(Visitor *visitor);
00212 
00213   protected:
00214     /* Private protocol */
00215     static String *formatArgumentsIntoString(const char *format, va_list args);
00216     virtual void changeWideToFit(int width);
00217 };
00218 
00219 };
00220 
00221 #endif /* __STRING_H */

Generated on Mon Nov 27 09:47:55 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2