BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
string.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_DATATYPE_STRING_H
6 #define BALL_DATATYPE_STRING_H
7 
8 #ifndef BALL_CONFIG_CONFIG_H
9 # include <BALL/CONFIG/config.h>
10 #endif
11 #ifndef BALL_COMMON_GLOBAL_H
12 # include <BALL/COMMON/global.h>
13 #endif
14 #ifndef BALL_COMMON_CREATE_H
15 # include <BALL/COMMON/create.h>
16 #endif
17 #ifndef BALL_COMMON_MACROS_H
18 # include <BALL/COMMON/macros.h>
19 #endif
20 #ifndef BALL_COMMON_EXCEPTION_H
21 # include <BALL/COMMON/exception.h>
22 #endif
23 #ifndef BALL_COMMON_DEBUG_H
24 # include <BALL/COMMON/debug.h>
25 #endif
26 
27 #include <string>
28 #include <cctype>
29 #include <cerrno>
30 #include <cstdlib>
31 #include <cstring>
32 #include <iostream>
33 #include <vector>
34 
35 #ifdef BALL_HAS_SSTREAM
36 # include <sstream>
37 #else
38 # include <strstream>
39 #endif
40 
41 using std::string;
42 
43 class QString;
44 class QByteArray;
45 
46 namespace BALL
47 {
48  // forward declaration
49  class Substring;
50 
57 
62  {
64  friend class Substring;
65 
66  public:
67 
68  // String has no copy constructor taking String&, bool as arguments.
69  // the compiler would confuse it with another copy constructor,
70  // cast true to 1 and copy only the string from the second character
71  // on! We could use BALL_CREATE_NODEEP, but this leads to trouble with
72  // inline constructors, so we code it by hand (here and in string.C)
73  virtual void* create(bool /* deep */ = true, bool empty = false) const;
74 
77 
86  {
88  CASE_SENSITIVE = 0,
89 
91  CASE_INSENSITIVE = 1
92  };
93 
99  static const Size EndPos;
100 
103  static const size_t npos = -1;
104 
106 
112 
114  static const char* CHARACTER_CLASS__ASCII_ALPHA;
115 
118 
120  static const char* CHARACTER_CLASS__ASCII_LOWER;
121 
123  static const char* CHARACTER_CLASS__ASCII_UPPER;
124 
126  static const char* CHARACTER_CLASS__ASCII_NUMERIC;
127 
129  static const char* CHARACTER_CLASS__ASCII_FLOAT;
130 
142  static const char* CHARACTER_CLASS__WHITESPACE;
143 
146  static const char* CHARACTER_CLASS__QUOTES;
147 
149 
152 
154  String();
155 
157  String(const string& string);
158 
160  String(const String& s);
161 
162 #ifdef BALL_STD_STRING_HAS_RVALUE_REFERENCES
163  String(String&& s);
165 
167  String(string&& s);
168 
170  String& operator=(String&& s);
171 
173  String& operator=(string&& s);
174 #endif
175 
177  explicit String(const QString& string);
178 
180  explicit String(const QByteArray& string);
181 
187  String(const String& s, Index from, Size len = EndPos);
188 
198  String(const char* char_ptr, Index from = 0, Size len = EndPos);
199 
210  String(Size buffer_size, const char* format, ... );
211 
217 #ifdef BALL_HAS_SSTREAM
218  String(std::stringstream& s);
219 #else
220  String(std::strstream& s);
221 #endif
222 
225  String(const char c, Size len = 1);
226 
228  String(const unsigned char uc);
229 
231  String(short s);
232 
234  String(unsigned short us);
235 
237  String(int i);
238 
240  String(unsigned int ui);
241 
243  String(long l);
244 
246  String(unsigned long);
247 
248 #ifdef BALL_ALLOW_LONG64_TYPE_OVERLOADS
249  String(LongIndex l);
251 
253  String(LongSize);
254 #endif
255 
257  String(float f);
258 
260  String(double d);
261 
263  operator string&();
264 
266  operator string const&() const;
267 
269  virtual ~String();
270 
272  void destroy();
273 
275 
279 
281  void set(const String& s);
282 
287  void set(const String& string, Index from, Size len = EndPos);
288 
294  void set(const char* char_ptr, Index from = 0, Size len = EndPos);
295 
300  void set(Size buffer_size, const char *format, ...);
301 
305 #ifdef BALL_HAS_SSTREAM
306  void set(std::stringstream& s);
307 #else
308  void set(std::strstream& s);
309 #endif
310 
312  void set(char c, Size len = 1);
313 
315  void set(unsigned char uc);
316 
318  void set(short s);
319 
321  void set(unsigned short us);
322 
324  void set(int i);
325 
327  void set(unsigned int ui);
328 
330  void set(long l);
331 
333  void set(unsigned long ul);
334 
335 #ifdef BALL_ALLOW_LONG64_TYPE_OVERLOADS
336  void set(LongIndex l);
338 
340  void set(LongSize ul);
341 #endif
342 
344  void set(float f);
345 
347  void set(double d);
348 
358  void get(char* char_ptr, Index from = 0, Size len = EndPos) const;
359 
361  const String& operator = (const String& s);
362 
366  const String& operator = (const char* pc);
367 
371 #ifdef BALL_HAS_SSTREAM
372  const String& operator = (std::stringstream& s);
373 #else
374  const String& operator = (std::strstream& s);
375 #endif
376 
378  const String& operator = (char c);
379 
381  const String& operator = (unsigned char uc);
382 
384  const String& operator = (short s);
385 
387  const String& operator = (unsigned short us);
388 
390  const String& operator = (int i);
391 
393  const String& operator = (unsigned int ui);
394 
396  const String& operator = (long l);
397 
399  const String& operator = (unsigned long ul);
400 
401 #ifdef BALL_ALLOW_LONG64_TYPE_OVERLOADS
402  const String& operator = (LongIndex l);
404 
406  const String& operator = (LongSize ul);
407 #endif
408 
410  const String& operator = (float f);
411 
413  const String& operator = (double d);
415 
422  static void setCompareMode(CompareMode compare_mode);
424 
426  static CompareMode getCompareMode();
428 
432 
437  bool toBool() const;
438 
440  char toChar() const;
441 
443  unsigned char toUnsignedChar() const;
444 
448  short toShort() const;
449 
453  unsigned short toUnsignedShort() const;
454 
458  int toInt() const;
459 
463  unsigned int toUnsignedInt() const;
464 
468  long toLong() const;
469 
473  unsigned long toUnsignedLong() const;
474 
478  float toFloat() const;
479 
483  double toDouble() const;
485 
486 
490 
495  void toLower(Index from = 0, Size len = EndPos);
496 
501  void toUpper(Index from = 0, Size len = EndPos);
502 
504 
507 
512  Substring getSubstring(Index from = 0, Size len = EndPos) const;
513 
518  Substring operator () (Index from, Size len = EndPos) const;
519 
522  Substring before(const String& s, Index from = 0) const;
523 
526  Substring through(const String& s, Index from = 0) const;
527 
530  Substring from(const String& s, Index from = 0) const;
531 
534  Substring after(const String& s, Index from = 0) const;
535 
537 
540 
544  Size countFields(const char* delimiters = CHARACTER_CLASS__WHITESPACE) const;
545 
549  Size countFieldsQuoted(const char* delimiters = CHARACTER_CLASS__WHITESPACE,
550  const char* quotes = CHARACTER_CLASS__QUOTES) const;
551 
556  String getField(Index index, const char* delimiters = CHARACTER_CLASS__WHITESPACE, Index* from = 0) const;
557 
562  String getFieldQuoted(Index index, const char* delimiters = CHARACTER_CLASS__WHITESPACE,
563  const char* quotes = CHARACTER_CLASS__QUOTES, Index* from = 0) const;
564 
569  Size split(String string_array[], Size array_size, const char* delimiters = CHARACTER_CLASS__WHITESPACE, Index from = 0) const;
570 
576  Size split(std::vector<String>& strings, const char* delimiters = CHARACTER_CLASS__WHITESPACE, Index from = 0) const;
577 
585  Size splitQuoted(std::vector<String>& strings, const char* delimiters = CHARACTER_CLASS__WHITESPACE,
586  const char* quotes = CHARACTER_CLASS__QUOTES, Index from = 0) const;
587 
589 
592 
599  String& trimLeft(const char* trimmed = CHARACTER_CLASS__WHITESPACE);
600 
607  String& trimRight(const char* trimmed = CHARACTER_CLASS__WHITESPACE);
608 
612  String& trim(const char* trimmed = CHARACTER_CLASS__WHITESPACE);
613 
614  // ?????
618  String trim(const char* trimmed = CHARACTER_CLASS__WHITESPACE) const;
619 
621  String& truncate(Size size);
622 
624  Substring left(Size len) const;
625 
627  Substring right(Size len) const;
628 
637  Substring instr(const String& pattern, Index from = 0) const;
638 
640 
643 
644  // NOTE: please, please, pretty please, only try to optimize away operator+ definitions
645  // if you *really* know what you are doing. We didn't, and we definitely don't want
646  // to touch this stinking heap of C++ garbage ever again!
647  // (dstoeckel & anhi)
650  friend String operator + (const String& s1, const string& s2);
651 
654  friend String operator + (const string& s1, const String& s2);
655 
658  friend String operator + (const String& s1, const String& s2);
659 
662  friend String operator + (const String& s1, const char* char_ptr);
663 
666  friend String operator + (const char* char_ptr, const String& s);
667 
670  friend String operator + (const String& s, char c);
671 
674  friend String operator + (char c, const String& s);
675 
676 #ifdef BALL_STD_STRING_HAS_RVALUE_REFERENCES
679  friend String operator + (String&& s1, const string& s2);
680 
683  friend String operator + (String&& s1, const String& s2);
684 
687  friend String operator + (String&& s1, String&& s2);
688 
690  friend String operator + (const String& s1, string&& s2);
691 
693  friend String operator + (string&& s1, const String& s2);
694 
696  friend String operator + (const string& s1, String&& s2);
697 
700  friend String operator + (const String& s1, String&& s2);
701 
704  friend String operator + (String&& s1, const char* char_ptr);
705 
708  friend String operator + (const char* char_ptr, String&& s);
709 
712  friend String operator + (String&& s, char c);
713 
716  friend String operator + (char c, String&& s);
717 #endif
718 
720  void swap(String& s);
721 
731  String& reverse(Index from = 0, Size len = EndPos);
732 
736  Size substitute(const String& to_replace, const String& replacing);
737 
739  void substituteAll(const String& to_replace, const String& replacing);
740 
742 
746 
748  bool has(char c) const;
749 
751  bool hasSubstring(const String& s, Index from = 0) const;
752 
754  bool hasPrefix(const String& s) const;
755 
757  bool hasSuffix(const String& s) const;
758 
760  bool isEmpty() const;
761 
765  bool isAlpha() const;
766 
770  bool isAlnum() const;
771 
775  bool isDigit() const;
776 
781  bool isFloat() const;
782 
786  bool isSpace() const;
787 
792  bool isWhitespace() const;
793 
795  static bool isAlpha(char c);
796 
798  static bool isAlnum(char c);
799 
801  static bool isDigit(char c);
802 
804  static bool isSpace(char c);
805 
809  static bool isWhitespace(char c);
810 
812 
815 
817  String encodeBase64();
818 
822  String decodeBase64();
823 
825 
828 
833  int compare(const String& string, Index from = 0) const;
834 
839  int compare(const String& string, Index from, Size len) const;
840 
841 
847  int compare(const char* char_ptr, Index from = 0) const;
848 
854  int compare(const char* char_ptr, Index from, Size len) const;
855 
860  int compare(char c, Index from = 0) const;
861 
865  friend bool operator == (const String& s1, const String& s2);
866 
870  friend bool operator != (const String& s1, const String& s2);
871 
875  friend bool operator < (const String& s1, const String& s2);
876 
880  friend bool operator <= (const String& s1, const String& s2);
881 
885  friend bool operator > (const String& s1, const String& s2);
886 
890  friend bool operator >= (const String& s1, const String& s2);
891 
896  friend bool operator == (const char* char_ptr, const String& string);
897 
902  friend bool operator != (const char* char_ptr, const String& string);
903 
908  friend bool operator < (const char* char_ptr, const String& string);
909 
914  friend bool operator <= (const char* char_ptr, const String& string);
915 
920  friend bool operator > (const char* char_ptr, const String& string);
921 
926  friend bool operator >= (const char* char_ptr, const String& string);
927 
931  bool operator == (const char* char_ptr) const;
932 
936  bool operator != (const char* char_ptr) const;
937 
941  bool operator < (const char* char_ptr) const;
942 
946  bool operator <= (const char* char_ptr) const;
947 
951  bool operator > (const char* char_ptr) const;
952 
956  bool operator >= (const char* char_ptr) const;
957 
960  friend bool operator == (char c, const String& string);
961 
964  friend bool operator != (char c, const String& string);
965 
968  friend bool operator < (char c, const String& string);
969 
972  friend bool operator <= (char c, const String& string);
973 
976  friend bool operator > (char c, const String& string);
977 
979  friend bool operator >= (char c, const String& string);
980 
982  bool operator == (char c) const;
983 
985  bool operator != (char c) const;
986 
988  bool operator < (char c) const;
989 
991  bool operator <= (char c) const;
992 
994  bool operator > (char c) const;
995 
997  bool operator >= (char c) const;
998 
1000 
1003 
1005  bool isValid() const;
1006 
1008  void dump(std::ostream& s = std::cout, Size depth = 0) const;
1009 
1011 
1014 
1016  std::istream& getline(std::istream& s = std::cin, char delimiter = '\n');
1017 
1019 // BALL_EXPORT
1020 // friend std::istream& getline(std::istream& s, String& string, char delimiter);
1021 
1023 
1025  static const String EMPTY;
1026 
1030 
1034  typedef string::value_type valuetype;
1035  typedef string::traits_type traits_type;
1036  typedef string::allocator_type allocator_type;
1037  typedef string::reference reference;
1038  typedef string::const_reference const_reference;
1039  typedef string::pointer pointer;
1040  typedef string::const_pointer const_pointer;
1041  typedef string::iterator iterator;
1042  typedef string::const_iterator const_iterator;
1043  typedef string::reverse_iterator reverse_iterator;
1044  typedef string::const_reverse_iterator const_reverse_iterator;
1045  typedef string::difference_type difference_type;
1046  typedef string::size_type size_type;
1048 
1052 
1054  iterator begin() BALL_NOEXCEPT;
1056  const_iterator begin() const BALL_NOEXCEPT;
1058  iterator end() BALL_NOEXCEPT;
1060  const_iterator end() const BALL_NOEXCEPT;
1062  reverse_iterator rbegin() BALL_NOEXCEPT;
1064  const_reverse_iterator rbegin() const BALL_NOEXCEPT;
1066  reverse_iterator rend() BALL_NOEXCEPT;
1068  const_reverse_iterator rend() const BALL_NOEXCEPT;
1069 
1070 #ifdef BALL_HAS_STD_STRING_CONST_ITERATORS
1071  const_iterator cbegin() const BALL_NOEXCEPT;
1074  const_iterator cend() const BALL_NOEXCEPT;
1076  const_reverse_iterator crbegin() const BALL_NOEXCEPT;
1078  const_reverse_iterator crend() const BALL_NOEXCEPT;
1079 #endif
1080 
1082 
1086 
1088  size_t size() const BALL_NOEXCEPT;
1090  size_t length() const BALL_NOEXCEPT;
1092  size_t max_size() const BALL_NOEXCEPT;
1094  void resize(size_t n);
1096  void resize(size_t n, char c);
1098  size_t capacity() const BALL_NOEXCEPT;
1100  void reserve(size_t n = 0);
1102  void clear() BALL_NOEXCEPT;
1104  bool empty() const BALL_NOEXCEPT;
1105 
1106 #ifdef BALL_HAS_STD_STRING_SHRINK_TO_FIT
1107  void shrink_to_fit();
1109 #endif
1110 
1111 
1115 
1117  char& operator[] (size_t pos);
1119  const char& operator[] (size_t pos) const;
1121  char& at(size_t pos);
1123  const char& at(size_t pos) const;
1124 
1125 #ifdef BALL_HAS_STD_STRING_FRONT_BACK
1126  char& front();
1129  const char& front() const;
1131  char& back();
1133  const char& back() const;
1134 #endif
1135 
1137 
1141  String& operator += (const String& str);
1144  String& operator += (const string& str);
1146  String& operator += (const char* s);
1148  String& operator += (char c);
1149 #ifdef BALL_HAS_INITIALIZER_LISTS
1150  String& operator += (std::initializer_list<char> il);
1152 #endif
1153  String& append(const String& str);
1156  String& append(const string& str);
1158  String& append(const string& str, size_t subpos, size_t sublen);
1160  String& append(const char* s);
1162  String& append(const char* s, size_t n);
1164  String& append(size_t n, char c);
1166  template <class InputIterator>
1167  String& append(InputIterator first, InputIterator last);
1168 #ifdef BALL_HAS_INITIALIZER_LISTS
1169  String& append(std::initializer_list<char> li);
1171 #endif
1172  void push_back(char c);
1175  String& assign(const String& str);
1177  String& assign(const string& str);
1179  String& assign(const string& str, size_t subpos, size_t sublen);
1181  String& assign(const char* s);
1183  String& assign(const char* s, size_t n);
1185  String& assign(size_t n, char c);
1187  template <class InputIterator>
1188  String& assign(InputIterator first, InputIterator last);
1189 #ifdef BALL_HAS_INITIALIZER_LISTS
1190  String& assign(std::initializer_list<char> li);
1192 #endif
1193 #ifdef BALL_STD_STRING_HAS_RVALUE_REFERENCES
1194  String& assign(string&& str) BALL_NOEXCEPT;
1196 #endif
1197 
1199  String& insert(size_t pos, const string& str);
1201  String& insert(size_t pos, const string& str, size_t subpos, size_t sublen);
1203  String& insert(size_t pos, const char* s);
1205  String& insert(size_t pos, const char* s, size_t n);
1207  String& insert(size_t pos, size_t n, char c);
1208 #ifdef BALL_HAS_STD_STRING_CONST_ITERATOR_FUNCTIONS
1209  iterator insert(const_iterator p, size_t n, char c);
1212  iterator insert(const_iterator p, char c);
1213 #else
1214  void insert(iterator p, size_t n, char c);
1217  iterator insert(iterator p, char c);
1218 #endif
1219  template <class InputIterator>
1221  iterator insert(iterator p, InputIterator first, InputIterator last);
1222 #if defined(BALL_HAS_INITIALIZER_LISTS) && defined(BALL_HAS_STD_STRING_CONST_ITERATOR_FUNCTIONS)
1223  String& insert(const_iterator p, std::initializer_list<char> li);
1225 #endif
1226 
1228  String& erase(size_t pos = 0, size_t len = npos);
1229 #ifdef BALL_HAS_STD_STRING_CONST_ITERATOR_FUNCTIONS
1230  iterator erase(const_iterator p);
1233  iterator erase(const_iterator first, const_iterator last);
1234 #else
1235  iterator erase(iterator p);
1238  iterator erase(iterator first, iterator last);
1239 #endif
1240 
1242  String& replace(size_t pos, size_t len, const string& str);
1244  String& replace(size_t pos, size_t len, const string& str, size_t subpos, size_t sublen);
1246  String& replace(size_t pos, size_t len, const char* s);
1248  String& replace(size_t pos, size_t len, const char* s, size_t n);
1250  String& replace(size_t pos, size_t len, size_t n, char c);
1251 #ifdef BALL_HAS_STD_STRING_CONST_ITERATOR_FUNCTIONS
1252  String& replace(const_iterator i1, const_iterator i2, const string& str);
1255  String& replace(const_iterator i1, const_iterator i2, const char* s);
1257  String& replace(const_iterator i1, const_iterator i2, const char* s, size_t n);
1259  String& replace(const_iterator i1, const_iterator i2, size_t n, char c);
1261  template <class InputIterator>
1262  String& replace(const_iterator i1, const_iterator i2, InputIterator first, InputIterator last);
1263 #else
1264  String& replace(iterator i1, iterator i2, const string& str);
1267  String& replace(iterator i1, iterator i2, const char* s);
1269  String& replace(iterator i1, iterator i2, const char* s, size_t n);
1271  String& replace(iterator i1, iterator i2, size_t n, char c);
1273  template <class InputIterator>
1274  String& replace(iterator i1, iterator i2, InputIterator first, InputIterator last);
1275 #endif
1276 #if defined(BALL_HAS_INITIALIZER_LISTS) && defined(BALL_HAS_STD_STRING_CONST_ITERATOR_FUNCTIONS)
1277  String& replace(const_iterator i1, const_iterator i2, std::initializer_list<char> li);
1279 #endif
1280 
1282  void swap(string& str);
1283 
1284 #ifdef BALL_HAS_STD_STRING_POP_BACK
1285  void pop_back();
1287 #endif
1288 
1289 
1293 
1295  const char* c_str() const BALL_NOEXCEPT;
1297  const char* data() const BALL_NOEXCEPT;
1299  allocator_type get_allocator() const BALL_NOEXCEPT;
1301  size_t copy(char* s, size_t len, size_t pos = 0) const;
1302 
1304  size_t find(const string& str, size_t pos = 0) const BALL_NOEXCEPT;
1306  size_t find(const char* s, size_t pos = 0) const;
1308  size_t find(const char* s, size_t pos, size_t n) const;
1310  size_t find(char c, size_t pos = 0) const BALL_NOEXCEPT;
1311 
1313  size_t rfind(const string& str, size_t pos = npos) const BALL_NOEXCEPT;
1315  size_t rfind(const char* s, size_t pos = npos) const;
1317  size_t rfind(const char* s, size_t pos, size_t n) const;
1319  size_t rfind(char c, size_t pos = npos) const BALL_NOEXCEPT;
1320 
1322  size_t find_first_of(const string& str, size_t pos = 0) const BALL_NOEXCEPT;
1324  size_t find_first_of(const char* s, size_t pos = 0) const;
1326  size_t find_first_of(const char* s, size_t pos, size_t n) const;
1328  size_t find_first_of(char c, size_t pos = 0) const BALL_NOEXCEPT;
1329 
1331  size_t find_last_of(const string& str, size_t pos = npos) const BALL_NOEXCEPT;
1333  size_t find_last_of(const char* s, size_t pos = npos) const;
1335  size_t find_last_of(const char* s, size_t pos, size_t n) const;
1337  size_t find_last_of(char c, size_t pos = npos) const BALL_NOEXCEPT;
1338 
1340  size_t find_first_not_of(const string& str, size_t pos = 0) const BALL_NOEXCEPT;
1342  size_t find_first_not_of(const char* s, size_t pos = 0) const;
1344  size_t find_first_not_of(const char* s, size_t pos, size_t n) const;
1346  size_t find_first_not_of(char c, size_t pos = 0) const BALL_NOEXCEPT;
1347 
1349  size_t find_last_not_of(const string& str, size_t pos = npos) const BALL_NOEXCEPT;
1351  size_t find_last_not_of(const char* s, size_t pos = npos) const;
1353  size_t find_last_not_of(const char* s, size_t pos, size_t n) const;
1355  size_t find_last_not_of(char c, size_t pos = npos) const BALL_NOEXCEPT;
1356 
1358  string substr(size_t pos = 0, size_t len = npos) const;
1359 
1361  int compare(const string& str) const BALL_NOEXCEPT;
1363  int compare(size_t pos, size_t len, const string& str) const;
1365  int compare(size_t pos, size_t len, const string& str, size_t subpos, size_t sublen) const;
1367  //int compare(const char* s) const;
1369  int compare(size_t pos, size_t len, const char* s) const;
1371  int compare(size_t pos, size_t len, const char* s, size_t n) const;
1372 
1374 
1376 
1377  protected:
1378 
1379  // the validate... methods check perform a thorough
1380  // index checking and an index translation
1381  // Indices below zero are interpreted as indices
1382  // relative to the end of the string
1383  // All methods throw IndexUnder|Overflow exceptions
1384  //
1385  void validateIndex_(Index& index) const;
1386 
1387  void validateRange_(Index& from, Size& len) const;
1388 
1389  static void validateCharPtrRange_(Index& from, Size& len, const char* char_ptr);
1390 
1391  static void valudateCharPtrIndex_(Index& index);
1392 
1393  private:
1394 
1396  string str_;
1397 
1398  static int compareAscendingly_(const char* a, const char* b);
1399 
1400  static int compareDescendingly_(const char* a, const char* b);
1401 
1402  static CompareMode compare_mode_;
1403 
1404  static char B64Chars_[64];
1405 
1406  static int Index_64_[128];
1407  };
1408 
1418  {
1419  friend class String;
1420 
1421  public:
1422 
1423  BALL_CREATE_DEEP(Substring)
1424 
1425 
1428 
1434  : public Exception::GeneralException
1435  {
1436  public:
1437  UnboundSubstring(const char* file, int line);
1438  };
1439 
1447  {
1448  public:
1449  InvalidSubstring(const char* file, int line);
1450  };
1451 
1453 
1456 
1460  Substring();
1461 
1467  Substring(const Substring& substring, bool deep = true);
1468 
1476  Substring(const String& string, Index from = 0, Size len = String::EndPos);
1477 
1481  virtual ~Substring();
1482 
1487  void destroy();
1488 
1493  virtual void clear();
1494 
1496 
1499 
1504  operator String() const;
1505 
1510  //explicit operator string() const;
1511 
1516  String toString() const;
1517 
1519 
1522 
1531  Substring& bind(const String& string, Index from = 0, Size len = String::EndPos);
1532 
1538  Substring& bind(const Substring& substring, Index from = 0, Size len = String::EndPos);
1539 
1541  void unbind();
1542 
1544  String* getBoundString();
1545 
1547  const String* getBoundString() const
1548 ;
1549 
1551 
1554 
1558  void set(const String& string);
1559 
1563  void set(const Substring& s);
1564 
1570  void set(const char* char_ptr, Size size = String::EndPos);
1571 
1575  const Substring& operator = (const String& string);
1576 
1580  const Substring& operator = (const Substring& substring);
1581 
1586  const Substring& operator = (const char* char_ptr);
1587 
1589 
1592 
1596  char* c_str();
1597 
1601  const char* c_str() const;
1602 
1607  Index getFirstIndex() const;
1608 
1613  Index getLastIndex() const;
1614 
1616  Size size() const;
1617 
1623  char& operator [] (Index index);
1624 
1630  char operator [] (Index index) const;
1631 
1635  Substring& toLower();
1636 
1640  Substring& toUpper();
1641 
1643 
1646 
1648  bool isBound() const;
1649 
1651  bool isEmpty() const;
1652 
1654 
1657 
1661  bool operator == (const Substring& substring) const;
1662 
1666  bool operator != (const Substring& substring) const;
1667 
1671  bool operator == (const String& string) const;
1672 
1676  bool operator != (const String& string) const;
1677 
1681  BALL_EXPORT
1682  friend bool operator == (const String& string, const Substring& substring);
1683 
1687  BALL_EXPORT
1688  friend bool operator != (const String& string, const Substring& substring);
1689 
1694  bool operator == (const char* char_ptr) const;
1695 
1700  bool operator != (const char* char_ptr) const;
1701 
1705  bool operator == (char c) const;
1706 
1710  bool operator != (char c) const;
1711 
1713 
1716 
1718  BALL_EXPORT
1719  friend std::ostream& operator << (std::ostream& s, const Substring& substring);
1720 
1722 
1725 
1730  bool isValid() const;
1731 
1735  void dump(std::ostream& s = std::cout, Size depth = 0) const;
1736 
1738 
1739  protected:
1740 
1741  // throws IndexUnderflow|IndexOverflow
1742  void validateRange_(Index& from, Size& len) const;
1743 
1744  private:
1745 
1746  /*_ @name Attributes
1747  */
1748  //_@{
1749 
1750  //_ pointer to the bound String
1751  String* bound_;
1752 
1753  //_ start index in the bound String
1754  Index from_;
1755 
1756  //_ end index in the bound String
1757  Index to_;
1758  //_@}
1759  };
1760 
1761  // non-member functions of String
1762 
1765  BALL_EXPORT
1766  bool operator == (const String& s1, const String& s2);
1767 
1770  BALL_EXPORT
1771  bool operator != (const String& s1, const String& s2);
1772 
1775  BALL_EXPORT
1776  bool operator < (const String& s1, const String& s2);
1777 
1780  BALL_EXPORT
1781  bool operator <= (const String& s1, const String& s2);
1782 
1785  BALL_EXPORT
1786  bool operator > (const String& s1, const String& s2);
1787 
1790  BALL_EXPORT
1791  bool operator >= (const String& s1, const String& s2);
1792 
1794  BALL_EXPORT
1795  String operator + (const String& s1, const string& s2);
1796 
1798  BALL_EXPORT
1799  String operator + (const string& s1, const String& s2);
1800 
1802  BALL_EXPORT
1803  String operator + (const String& s1, const String& s2);
1804 
1806  BALL_EXPORT
1807  String operator + (const String& s1, const char* char_ptr);
1808 
1810  BALL_EXPORT
1811  String operator + (const char* char_ptr, const String& s);
1812 
1814  BALL_EXPORT
1815  String operator + (const String& s, char c);
1816 
1818  BALL_EXPORT
1819  String operator + (char c, const String& s);
1820 
1821 #ifdef BALL_STD_STRING_HAS_RVALUE_REFERENCES
1822  BALL_EXPORT
1824  String operator + (String&& s1, const string& s2);
1825 
1827  BALL_EXPORT
1828  String operator + (String&& s1, const String& s2);
1829 
1831  BALL_EXPORT
1832  String operator + (String&& s1, String&& s2);
1833 
1835  BALL_EXPORT
1836  String operator + (const String& s1, string&& s2);
1837 
1839  BALL_EXPORT
1840  String operator + (string&& s1, const String& s2);
1841 
1843  BALL_EXPORT
1844  String operator + (const string& s1, String&& s2);
1845 
1847  BALL_EXPORT
1848  String operator + (const String& s1, String&& s2);
1849 
1851  BALL_EXPORT
1852  String operator + (String&& s1, const char* char_ptr);
1853 
1855  BALL_EXPORT
1856  String operator + (const char* char_ptr, String&& s);
1857 
1859  BALL_EXPORT
1860  String operator + (String&& s, char c);
1861 
1863  BALL_EXPORT
1864  String operator + (char c, String&& s);
1865 #endif
1866 } // namespace BALL
1867 
1868 namespace std
1869 {
1870  // Non-member functions for string
1871 
1873  istream& operator>> (istream& is, BALL::String& str);
1874 
1876  ostream& operator<< (ostream& os, BALL::String const& str);
1877 
1879  istream& getline(istream& is, BALL::String& str, char delim);
1881  istream& getline(istream& is, BALL::String& str);
1882 
1883 
1884 #ifdef BALL_STD_STRING_HAS_RVALUE_REFERENCES
1885  istream& getline(istream& is, BALL::String&& str, char delim);
1888  istream& getline(istream& is, BALL::String&& str);
1889 #endif
1890 }
1891 
1893 
1894 # ifndef BALL_NO_INLINE_FUNCTIONS
1895 # include <BALL/DATATYPE/string.iC>
1896 # endif
1897 
1898 #endif // BALL_DATATYPE_STRING_H
static const char * CHARACTER_CLASS__ASCII_LOWER
Character class containing all lower case letters.
Definition: string.h:120
static const char * CHARACTER_CLASS__ASCII_ALPHA
Character class containing all letters (lower and upper case)
Definition: string.h:114
string::const_reverse_iterator const_reverse_iterator
Definition: string.h:1044
static const char * CHARACTER_CLASS__QUOTES
Definition: string.h:146
static const String EMPTY
Constant empty string.
Definition: string.h:1025
static const char * CHARACTER_CLASS__ASCII_FLOAT
Character class containing the digits from 0 to 9 and a dot.
Definition: string.h:129
string::difference_type difference_type
Definition: string.h:1045
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
string::pointer pointer
Definition: string.h:1039
static const char * CHARACTER_CLASS__ASCII_ALPHANUMERIC
Character class containing all letters and digits.
Definition: string.h:117
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
BALL_EXPORT bool operator>(const String &s1, const String &s2)
string::iterator iterator
Definition: string.h:1041
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
string::const_iterator const_iterator
Definition: string.h:1042
static const char * CHARACTER_CLASS__ASCII_UPPER
Character class containing all upper case letters.
Definition: string.h:123
BALL_EXPORT bool operator!=(const String &s1, const String &s2)
string::const_pointer const_pointer
Definition: string.h:1040
#define BALL_CREATE_DEEP(name)
Definition: create.h:26
static const Size EndPos
Definition: string.h:99
BALL_ULONG64_TYPE LongSize
string::allocator_type allocator_type
Definition: string.h:1036
BALL_LONG64_TYPE LongIndex
static const char * CHARACTER_CLASS__WHITESPACE
Definition: string.h:142
BALL_SIZE_TYPE Size
BALL_EXPORT bool operator>=(const String &s1, const String &s2)
string::traits_type traits_type
Definition: string.h:1035
BALL_EXPORT bool operator==(const String &s1, const String &s2)
static const char * CHARACTER_CLASS__ASCII_NUMERIC
Character class containing the digits from 0 to 9.
Definition: string.h:126
string::const_reference const_reference
Definition: string.h:1038
BALL_EXPORT bool operator<=(const String &s1, const String &s2)
string::value_type valuetype
Definition: string.h:1034
ConstRandomAccessIterator< Container, DataType, Position, Traits > operator+(Distance distance, const ConstRandomAccessIterator< Container, DataType, Position, Traits > &iterator)
string::reverse_iterator reverse_iterator
Definition: string.h:1043
string::size_type size_type
Definition: string.h:1046
string::reference reference
Definition: string.h:1037
#define BALL_EXPORT
Definition: COMMON/global.h:50
Index compare(const T1 &a, const T2 &b)
Definition: MATHS/common.h:314
BALL_EXPORT bool operator<(const String &s1, const String &s2)