00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
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
00074
00078 String &operator += (const char);
00079
00083 String &operator += (const int);
00084
00088 String &operator += (const String&);
00089
00092 String& operator= (const String&);
00093
00096
00097
00100
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
00122
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 }
00266
00267
00268 #include "rtstring.inline.cpp"
00269
00270 #endif