Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_DATASTRUCTURES_STRING_H
00036 #define OPENMS_DATASTRUCTURES_STRING_H
00037
00038 #include <OpenMS/CONCEPT/Types.h>
00039
00040 #include <string>
00041 #include <vector>
00042
00043 class QString;
00044
00045
00046 namespace OpenMS
00047 {
00048 class DataValue;
00056 class String :
00057 public std::string
00058 {
00059 public:
00060
00062 OPENMS_DLLAPI static const String EMPTY;
00063
00067
00068 typedef iterator Iterator;
00070 typedef const_iterator ConstIterator;
00072 typedef reverse_iterator ReverseIterator;
00074 typedef const_reverse_iterator ConstReverseIterator;
00076 typedef size_type SizeType;
00077
00079 enum QuotingMethod {NONE, ESCAPE, DOUBLE};
00080
00082
00086
00087 OPENMS_DLLAPI String();
00089 OPENMS_DLLAPI String(const std::string & s);
00091 OPENMS_DLLAPI String(const QString & s);
00093 OPENMS_DLLAPI String(const char * s);
00095 OPENMS_DLLAPI String(const char c);
00097 OPENMS_DLLAPI String(const char * s, SizeType length);
00099 OPENMS_DLLAPI String(size_t len, char c);
00101 template <class InputIterator>
00102 String(InputIterator first, InputIterator last) :
00103 std::string(first, last)
00104 {
00105
00106 }
00107
00109 OPENMS_DLLAPI String(int i);
00111 OPENMS_DLLAPI String(unsigned int i);
00113 OPENMS_DLLAPI String(short int i);
00115 OPENMS_DLLAPI String(short unsigned int i);
00117 OPENMS_DLLAPI String(long int i);
00119 OPENMS_DLLAPI String(long unsigned int i);
00121 OPENMS_DLLAPI String(long long unsigned int i);
00123 OPENMS_DLLAPI String(long long signed int i);
00125 OPENMS_DLLAPI String(float f);
00127 OPENMS_DLLAPI String(double d);
00129 OPENMS_DLLAPI String(long double ld);
00131 OPENMS_DLLAPI String(const DataValue & d);
00132
00134
00138
00139 OPENMS_DLLAPI bool hasPrefix(const String & string) const;
00140
00142 OPENMS_DLLAPI bool hasSuffix(const String & string) const;
00143
00145 OPENMS_DLLAPI bool hasSubstring(const String & string) const;
00146
00148 OPENMS_DLLAPI bool has(Byte byte) const;
00150
00151
00160 OPENMS_DLLAPI String prefix(SizeType length) const;
00161
00167 OPENMS_DLLAPI String suffix(SizeType length) const;
00168
00175 OPENMS_DLLAPI String prefix(Int length) const;
00176
00183 OPENMS_DLLAPI String suffix(Int length) const;
00184
00190 OPENMS_DLLAPI String prefix(char delim) const;
00191
00197 OPENMS_DLLAPI String suffix(char delim) const;
00198
00211 OPENMS_DLLAPI String substr(size_t pos = 0, size_t n = npos) const;
00212
00220 OPENMS_DLLAPI String chop(Size n) const;
00221
00223
00224
00231
00232 OPENMS_DLLAPI String & reverse();
00233
00235 OPENMS_DLLAPI String & trim();
00236
00244 OPENMS_DLLAPI String & quote(char q = '"', QuotingMethod method = ESCAPE);
00245
00255 OPENMS_DLLAPI String & unquote(char q = '"', QuotingMethod method = ESCAPE);
00256
00258 OPENMS_DLLAPI String & simplify();
00259
00261 OPENMS_DLLAPI String & fillLeft(char c, UInt size);
00262
00264 OPENMS_DLLAPI String & fillRight(char c, UInt size);
00265
00267 OPENMS_DLLAPI String & toUpper();
00268
00270 OPENMS_DLLAPI String & toLower();
00271
00273 OPENMS_DLLAPI String & firstToUpper();
00274
00276 OPENMS_DLLAPI String & substitute(char from, char to);
00277
00279 OPENMS_DLLAPI String & substitute(const String & from, const String & to);
00280
00282 OPENMS_DLLAPI String & remove(char what);
00283
00285 OPENMS_DLLAPI String & ensureLastChar(char end);
00286
00288 OPENMS_DLLAPI String & removeWhitespaces();
00290
00294
00303 OPENMS_DLLAPI Int toInt() const;
00304
00310 OPENMS_DLLAPI Real toFloat() const;
00311
00317 OPENMS_DLLAPI DoubleReal toDouble() const;
00318
00320 OPENMS_DLLAPI QString toQString() const;
00321
00323
00327
00328 OPENMS_DLLAPI String operator+(int i) const;
00330 OPENMS_DLLAPI String operator+(unsigned int i) const;
00332 OPENMS_DLLAPI String operator+(short int i) const;
00334 OPENMS_DLLAPI String operator+(short unsigned int i) const;
00336 OPENMS_DLLAPI String operator+(long int i) const;
00338 OPENMS_DLLAPI String operator+(long unsigned int i) const;
00340 OPENMS_DLLAPI String operator+(long long unsigned int i) const;
00342 OPENMS_DLLAPI String operator+(float f) const;
00344 OPENMS_DLLAPI String operator+(double d) const;
00346 OPENMS_DLLAPI String operator+(long double ld) const;
00348 OPENMS_DLLAPI String operator+(char c) const;
00350 OPENMS_DLLAPI String operator+(const char * s) const;
00352 OPENMS_DLLAPI String operator+(const String & s) const;
00354 OPENMS_DLLAPI String operator+(const std::string & s) const;
00356
00360
00361 OPENMS_DLLAPI String & operator+=(int i);
00363 OPENMS_DLLAPI String & operator+=(unsigned int i);
00365 OPENMS_DLLAPI String & operator+=(short int i);
00367 OPENMS_DLLAPI String & operator+=(short unsigned int i);
00369 OPENMS_DLLAPI String & operator+=(long int i);
00371 OPENMS_DLLAPI String & operator+=(long unsigned int i);
00373 OPENMS_DLLAPI String & operator+=(long long unsigned int i);
00375 OPENMS_DLLAPI String & operator+=(float f);
00377 OPENMS_DLLAPI String & operator+=(double d);
00379 OPENMS_DLLAPI String & operator+=(long double d);
00381 OPENMS_DLLAPI String & operator+=(char c);
00383 OPENMS_DLLAPI String & operator+=(const char * s);
00385 OPENMS_DLLAPI String & operator+=(const String & s);
00387 OPENMS_DLLAPI String & operator+=(const std::string & s);
00389
00391 OPENMS_DLLAPI static String random(UInt length);
00392
00394 OPENMS_DLLAPI static String number(DoubleReal d, UInt n);
00400 OPENMS_DLLAPI static String numberLength(DoubleReal d, UInt n);
00401
00402
00419 OPENMS_DLLAPI bool split(const char splitter, std::vector<String> & substrings, bool quote_protect = false) const;
00420
00432 OPENMS_DLLAPI bool split(const String & splitter, std::vector<String> & substrings) const;
00433
00448 OPENMS_DLLAPI bool split_quoted(const String & splitter, std::vector<String> & substrings,
00449 char q = '"', QuotingMethod method = ESCAPE) const;
00450
00456 template <class StringIterator>
00457 void concatenate(StringIterator first, StringIterator last, const String & glue = "")
00458 {
00459
00460 if (first == last)
00461 {
00462 std::string::clear();
00463 return;
00464 }
00465
00466 std::string::operator=(* first);
00467 for (StringIterator it = ++first; it != last; ++it)
00468 {
00469 std::string::operator+=(glue + (*it));
00470 }
00471 }
00472
00473 };
00474
00475 }
00476
00477 #endif // OPENMS_DATASTRUCTURES_STRING_H