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 #ifndef OPENMS_DATASTRUCTURES_STRING_H
00028 #define OPENMS_DATASTRUCTURES_STRING_H
00029
00030 #include <OpenMS/CONCEPT/Types.h>
00031 #include <OpenMS/CONCEPT/Exception.h>
00032
00033 #include <string>
00034 #include <vector>
00035
00036 class QString;
00037
00038 namespace OpenMS
00039 {
00040 class DataValue;
00048 class String:
00049 public std::string
00050 {
00051 public:
00052
00054 static const String EMPTY;
00055
00059
00060 typedef iterator Iterator;
00062 typedef const_iterator ConstIterator;
00064 typedef reverse_iterator ReverseIterator;
00066 typedef const_reverse_iterator ConstReverseIterator;
00068 typedef size_type SizeType;
00069
00071
00075
00076 String();
00078 String(const std::string& s);
00080 String(const QString& s);
00082 String(const char* s);
00084 String(const char c);
00086 String(const char* s, SizeType length);
00088 String(size_t len, char c);
00090 template <class InputIterator>
00091 String(InputIterator first, InputIterator last)
00092 : std::string(first,last)
00093 {
00094
00095 }
00097 String(int i);
00099 String(unsigned int i);
00101 String(short int i);
00103 String(short unsigned int i);
00105 String(long int i);
00107 String(long unsigned int i);
00109 String(long long unsigned int i);
00111 String(float f);
00113 String(double d);
00115 String(long double d);
00121 String(double d, UInt size);
00123 String(const DataValue& d);
00124
00126
00130
00131 bool hasPrefix(const String& string) const;
00132
00134 bool hasSuffix(const String& string) const;
00135
00137 bool hasSubstring(const String& string) const;
00138
00140 bool has(Byte byte) const;
00142
00143
00147
00148 String prefix(SizeType length) const throw(Exception::IndexOverflow);
00149
00151 String suffix(SizeType length) const throw(Exception::IndexOverflow);
00152
00154 String prefix(Int length) const throw(Exception::IndexUnderflow, Exception::IndexOverflow);
00155
00157 String suffix(Int length) const throw(Exception::IndexUnderflow, Exception::IndexOverflow);
00158
00160 String prefix(char delim) const throw(Exception::ElementNotFound<char>);
00161
00163 String suffix(char delim) const throw(Exception::ElementNotFound<char>);
00172 String substr(Int start, Int n) const;
00179 String substr(Int start) const;
00180
00182
00183
00190
00191 String& reverse();
00192
00194 String& trim();
00195
00197 String& fillLeft(char c, UInt size);
00198
00200 String& fillRight(char c, UInt size);
00201
00203 String& toUpper();
00204
00206 String& toLower();
00207
00209 String& firstToUpper();
00210
00212 String& substitute(char from, char to);
00213
00215 String& substitute(const String& from, const String& to);
00216
00218 String& remove(char what);
00219
00221 String& ensureLastChar(char end);
00222
00224 String& removeWhitespaces();
00226
00230
00237 Int toInt() const throw(Exception::ConversionError);
00238
00240 Real toFloat() const throw(Exception::ConversionError);
00241
00243 DoubleReal toDouble() const throw(Exception::ConversionError);
00244
00246 QString toQString() const;
00247
00249
00253
00254 String operator+ (int i) const;
00256 String operator+ (unsigned int i) const;
00258 String operator+ (short int i) const;
00260 String operator+ (short unsigned int i) const;
00262 String operator+ (long int i) const;
00264 String operator+ (long unsigned int i) const;
00266 String operator+ (long long unsigned int i) const;
00268 String operator+ (float f) const;
00270 String operator+ (double d) const;
00272 String operator+ (long double d) const;
00274 String operator+ (char c) const;
00276 String operator+ (const char* s) const;
00278 String operator+ (const String& s) const;
00280 String operator+ (const std::string& s) const;
00282
00286
00287 String& operator+= (int i);
00289 String& operator+= (unsigned int i);
00291 String& operator+= (short int i);
00293 String& operator+= (short unsigned int i);
00295 String& operator+= (long int i);
00297 String& operator+= (long unsigned int i);
00299 String& operator+= (long long unsigned int i);
00301 String& operator+= (float f);
00303 String& operator+= (double d);
00305 String& operator+= (long double d);
00307 String& operator+= (char c);
00309 String& operator+= (const char* s);
00311 String& operator+= (const String& s);
00313 String& operator+= (const std::string& s);
00315
00317 static String random(UInt length);
00318
00327 bool split(char splitter, std::vector<String>& substrings) const;
00328
00329
00335 template<class StringIterator>
00336 void implode(StringIterator first, StringIterator last, const String& glue = "")
00337 {
00338
00339 if (first==last)
00340 {
00341 std::string::clear();
00342 return;
00343 }
00344
00345 std::string::operator=(*first);
00346 for (StringIterator it = ++first; it != last; ++it)
00347 {
00348 std::string::operator+=( glue + (*it));
00349 }
00350 }
00351
00352 };
00353
00354 }
00355
00356 #endif // OPENMS_DATASTRUCTURES_HASHMAP_H