Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
String.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2013.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Stephan Aiche$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_DATASTRUCTURES_STRING_H
36 #define OPENMS_DATASTRUCTURES_STRING_H
37 
38 #include <OpenMS/CONCEPT/Types.h>
39 
40 #include <string>
41 #include <vector>
42 
43 class QString;
44 
45 
46 namespace OpenMS
47 {
48  class DataValue;
56  class String :
57  public std::string
58  {
59 public:
60 
62  OPENMS_DLLAPI static const String EMPTY;
63 
67  typedef iterator Iterator;
70  typedef const_iterator ConstIterator;
72  typedef reverse_iterator ReverseIterator;
74  typedef const_reverse_iterator ConstReverseIterator;
76  typedef size_type SizeType;
77 
80 
82 
86  OPENMS_DLLAPI String();
89  OPENMS_DLLAPI String(const std::string & s);
91  OPENMS_DLLAPI String(const QString & s);
93  OPENMS_DLLAPI String(const char * s);
95  OPENMS_DLLAPI String(const char c);
97  OPENMS_DLLAPI String(const char * s, SizeType length);
99  OPENMS_DLLAPI String(size_t len, char c);
101  template <class InputIterator>
102  String(InputIterator first, InputIterator last) :
103  std::string(first, last)
104  {
105 
106  }
107 
109  OPENMS_DLLAPI String(int i);
111  OPENMS_DLLAPI String(unsigned int i);
113  OPENMS_DLLAPI String(short int i);
115  OPENMS_DLLAPI String(short unsigned int i);
117  OPENMS_DLLAPI String(long int i);
119  OPENMS_DLLAPI String(long unsigned int i);
121  OPENMS_DLLAPI String(long long unsigned int i);
123  OPENMS_DLLAPI String(long long signed int i);
125  OPENMS_DLLAPI String(float f);
127  OPENMS_DLLAPI String(double d);
129  OPENMS_DLLAPI String(long double ld);
131  OPENMS_DLLAPI String(const DataValue & d);
132 
134 
138  OPENMS_DLLAPI bool hasPrefix(const String & string) const;
140 
142  OPENMS_DLLAPI bool hasSuffix(const String & string) const;
143 
145  OPENMS_DLLAPI bool hasSubstring(const String & string) const;
146 
148  OPENMS_DLLAPI bool has(Byte byte) const;
150 
151 
160  OPENMS_DLLAPI String prefix(SizeType length) const;
161 
167  OPENMS_DLLAPI String suffix(SizeType length) const;
168 
175  OPENMS_DLLAPI String prefix(Int length) const;
176 
183  OPENMS_DLLAPI String suffix(Int length) const;
184 
190  OPENMS_DLLAPI String prefix(char delim) const;
191 
197  OPENMS_DLLAPI String suffix(char delim) const;
198 
211  OPENMS_DLLAPI String substr(size_t pos = 0, size_t n = npos) const;
212 
220  OPENMS_DLLAPI String chop(Size n) const;
221 
223 
224 
231  OPENMS_DLLAPI String & reverse();
233 
235  OPENMS_DLLAPI String & trim();
236 
244  OPENMS_DLLAPI String & quote(char q = '"', QuotingMethod method = ESCAPE);
245 
255  OPENMS_DLLAPI String & unquote(char q = '"', QuotingMethod method = ESCAPE);
256 
258  OPENMS_DLLAPI String & simplify();
259 
261  OPENMS_DLLAPI String & fillLeft(char c, UInt size);
262 
264  OPENMS_DLLAPI String & fillRight(char c, UInt size);
265 
267  OPENMS_DLLAPI String & toUpper();
268 
270  OPENMS_DLLAPI String & toLower();
271 
273  OPENMS_DLLAPI String & firstToUpper();
274 
276  OPENMS_DLLAPI String & substitute(char from, char to);
277 
279  OPENMS_DLLAPI String & substitute(const String & from, const String & to);
280 
282  OPENMS_DLLAPI String & remove(char what);
283 
285  OPENMS_DLLAPI String & ensureLastChar(char end);
286 
288  OPENMS_DLLAPI String & removeWhitespaces();
290 
294 
303  OPENMS_DLLAPI Int toInt() const;
304 
310  OPENMS_DLLAPI Real toFloat() const;
311 
317  OPENMS_DLLAPI DoubleReal toDouble() const;
318 
320  OPENMS_DLLAPI QString toQString() const;
321 
323 
327  OPENMS_DLLAPI String operator+(int i) const;
330  OPENMS_DLLAPI String operator+(unsigned int i) const;
332  OPENMS_DLLAPI String operator+(short int i) const;
334  OPENMS_DLLAPI String operator+(short unsigned int i) const;
336  OPENMS_DLLAPI String operator+(long int i) const;
338  OPENMS_DLLAPI String operator+(long unsigned int i) const;
340  OPENMS_DLLAPI String operator+(long long unsigned int i) const;
342  OPENMS_DLLAPI String operator+(float f) const;
344  OPENMS_DLLAPI String operator+(double d) const;
346  OPENMS_DLLAPI String operator+(long double ld) const;
348  OPENMS_DLLAPI String operator+(char c) const;
350  OPENMS_DLLAPI String operator+(const char * s) const;
352  OPENMS_DLLAPI String operator+(const String & s) const;
354  OPENMS_DLLAPI String operator+(const std::string & s) const;
356 
360  OPENMS_DLLAPI String & operator+=(int i);
363  OPENMS_DLLAPI String & operator+=(unsigned int i);
365  OPENMS_DLLAPI String & operator+=(short int i);
367  OPENMS_DLLAPI String & operator+=(short unsigned int i);
369  OPENMS_DLLAPI String & operator+=(long int i);
371  OPENMS_DLLAPI String & operator+=(long unsigned int i);
373  OPENMS_DLLAPI String & operator+=(long long unsigned int i);
375  OPENMS_DLLAPI String & operator+=(float f);
377  OPENMS_DLLAPI String & operator+=(double d);
379  OPENMS_DLLAPI String & operator+=(long double d);
381  OPENMS_DLLAPI String & operator+=(char c);
383  OPENMS_DLLAPI String & operator+=(const char * s);
385  OPENMS_DLLAPI String & operator+=(const String & s);
387  OPENMS_DLLAPI String & operator+=(const std::string & s);
389 
391  OPENMS_DLLAPI static String random(UInt length);
392 
394  OPENMS_DLLAPI static String number(DoubleReal d, UInt n);
400  OPENMS_DLLAPI static String numberLength(DoubleReal d, UInt n);
401 
402 
419  OPENMS_DLLAPI bool split(const char splitter, std::vector<String> & substrings, bool quote_protect = false) const;
420 
432  OPENMS_DLLAPI bool split(const String & splitter, std::vector<String> & substrings) const;
433 
448  OPENMS_DLLAPI bool split_quoted(const String & splitter, std::vector<String> & substrings,
449  char q = '"', QuotingMethod method = ESCAPE) const;
450 
456  template <class StringIterator>
457  void concatenate(StringIterator first, StringIterator last, const String & glue = "")
458  {
459  //empty container
460  if (first == last)
461  {
462  std::string::clear();
463  return;
464  }
465 
466  std::string::operator=(* first);
467  for (StringIterator it = ++first; it != last; ++it)
468  {
469  std::string::operator+=(glue + (*it));
470  }
471  }
472 
473  };
474 
475 } // namespace OPENMS
476 
477 #endif // OPENMS_DATASTRUCTURES_STRING_H
String chop(Size n) const
Returns a substring where n characters were removed from the end of the string.
String & simplify()
merges subsequent whitespaces to one blank character
String & fillRight(char c, UInt size)
Adds c on the right side until the size of the string is size.
float Real
Real type.
Definition: Types.h:109
A more convenient string class.
Definition: String.h:56
DoubleReal toDouble() const
Conversion to double.
String & toUpper()
Converts the string to uppercase.
bool hasSuffix(const String &string) const
true if String ends with string, false otherwise
String()
Default constructor.
Definition: String.h:79
String & ensureLastChar(char end)
Makes sure the string ends with the character end.
static String number(DoubleReal d, UInt n)
returns a string for d with exactly n decimal places
iterator Iterator
Iterator.
Definition: String.h:68
String & unquote(char q= '"', QuotingMethod method = ESCAPE)
Reverses changes made by the quote method.
bool has(Byte byte) const
true if String contains the byte, false otherwise
void concatenate(StringIterator first, StringIterator last, const String &glue="")
Concatenates all elements from first to last-1 and inserts glue between the elements.
Definition: String.h:457
const double c
String & quote(char q= '"', QuotingMethod method = ESCAPE)
Wraps the string in quotation marks.
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:57
String(InputIterator first, InputIterator last)
Constructor from a char range.
Definition: String.h:102
QuotingMethod
How to handle embedded quotes when quoting strings.
Definition: String.h:79
const_iterator ConstIterator
Const Iterator.
Definition: String.h:70
Int toInt() const
Conversion to int.
String & reverse()
inverts the direction of the string
static String numberLength(DoubleReal d, UInt n)
Returns a string with at maximum n characters for d.
String & toLower()
Converts the string to lowercase.
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
Definition: String.h:79
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
String operator+(int i) const
Sum operator for an integer.
String & fillLeft(char c, UInt size)
Adds c on the left side until the size of the string is size.
QString toQString() const
Conversion to Qt QString.
Real toFloat() const
Conversion to float.
reverse_iterator ReverseIterator
Reverse Iterator.
Definition: String.h:72
size_type SizeType
UInt type.
Definition: String.h:76
Definition: String.h:79
String & firstToUpper()
Converts the first letter of the string to uppercase.
static String random(UInt length)
returns a random string of the given length. It consists of [0-9a-zA-Z]
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
String & removeWhitespaces()
removes whitespaces (space, tab, line feed, carriage return)
String prefix(SizeType length) const
returns the prefix of length length
const_reverse_iterator ConstReverseIterator
Const reverse Iterator.
Definition: String.h:74
String & substitute(char from, char to)
Replaces all occurences of the character from by the character to.
bool split_quoted(const String &splitter, std::vector< String > &substrings, char q= '"', QuotingMethod method = ESCAPE) const
Splits a string into substrings using splitter (the whole string) as delimiter, but does not split wi...
OPENMS_BYTE_TYPE Byte
Byte type.
Definition: Types.h:128
String substr(size_t pos=0, size_t n=npos) const
Wrapper for the STL substr() method. Returns a String object with its contents initialized to a subst...
String & operator+=(int i)
Sum operator for an integer.
String suffix(SizeType length) const
returns the suffix of length length
int Int
Signed integer type.
Definition: Types.h:100
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
static const String EMPTY
Empty string for comparisons.
Definition: String.h:62
bool hasPrefix(const String &string) const
true if String begins with string, false otherwise

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:21 using doxygen 1.8.5