Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

rtstring.h

Go to the documentation of this file.
00001 /*
00002  * rtstring.h
00003  * 
00004  * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
00005  * and Martin Trautmann (martintrautmann@gmx.de) 
00006  * 
00007  * This file may be distributed and/or modified under the terms of the 
00008  * GNU General Public License version 2 as published by the Free Software 
00009  * Foundation. 
00010  * 
00011  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013  * 
00014  */
00015 
00023 #ifndef __LRT_STRING__
00024 #define __LRT_STRING__
00025 
00026 #include "rtcollect.h"
00027 #include "rtmath.h"
00028 
00029 namespace lrt {
00030 
00036 class String : public Vector<char>  
00037 {
00038 public:
00040         String();
00041 
00046         String(const char * cStr);
00047 
00051         String(const char chr, int length);
00052 //      String(const short * ucStr);
00053         
00061         String(int num, int radix = 10, int length = 0);
00062 
00068         explicit String(double num, int minLength = 13);
00069 
00071         String(const String& str);
00072 
00073 /*      String operator += (const char *); // impl. Konv. per Konstruktor */
00074         
00078         String &operator += (const char);
00079     
00083         String &operator += (const int);    // impl. Konv. per Konstruktor tut nicht
00084 
00088         String &operator += (const String&);
00089 
00092         String& operator= (const String&);
00093 
00096 //      const char& operator[](int index) const;
00097 
00100 //    char& operator[](int index);
00101 
00106         String trim() const;
00107         
00113         String substring(int start, int end = Math::MAX_INT) const;
00114 
00116         String lowerCase() const;
00117 
00119     String upperCase() const;
00120         
00121         // OBSOLETE. Now in Array<>. However, we still need it so that this method is selected,
00122         //           and not the next one (where a String would be constructed from (int)ch)
00129         inline int indexOf(char ch, int fromIndex = 0) const { return Array<char>::indexOf(ch, fromIndex); }
00136         int indexOf(const String &str, int fromIndex = 0) const;
00144         int lastIndexOf(char ch, int fromIndex = Math::MAX_INT) const;
00152         int lastIndexOf(const String &str, int fromIndex = Math::MAX_INT) const;
00153         
00156         inline bool operator == (const String&) const;
00159         inline bool operator != (const String&) const;
00162         inline bool operator < (const String&) const;
00167         inline int compare(const String& str) const;
00172         inline int compareIgnoreCase(const String& str) const;
00177         static inline int compare(const String& str1, const String& str2);
00182         static inline int compareIgnoreCase(const String& str1, const String& str2);
00184         inline bool startsWith(const String &str) const;
00186         inline bool endsWith(const String &str) const;
00187         
00190         String replace(char oldCh, char newCh) const;
00193         String replace(const String &oldStr, const String &newStr) const;
00195         enum SplitFlags {
00196                 NONE = 0,
00197                 CREATE_EMPTY = 1, 
00198         };
00216         Array<String> split(const String &separators = ", ", const String &combiners = "\"\'", 
00217                 int maxParts = -1, SplitFlags flags = NONE) const;
00218         
00224         static String join(const Array<String> &arr, const String &joiner = ", ", const int upTo = Math::MAX_INT);
00225 
00232         const char *cStr() const;
00241         int intValue(int def, int radix = 10) const;
00249         double doubleValue(double def) const;
00250 
00251         virtual ~String();
00252 
00253 private:
00254         String(const String& str, int start, int end);
00255         int compare(int thisPos, const String& other, int otherPos, int length) const;
00256         int compareIgnoreCase(int thisPos, const String& other, int otherPos, int length) const;
00257         int findNextOf(const String &what, int start) const;
00258         static int cStrLength(const char *);
00259         
00260 };
00261 
00263 String operator + (const String&, const String&);
00264 
00265 } // namespace
00266 
00267 
00268 #include "rtstring.inline.cpp"
00269 
00270 #endif

This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer