#include <OpenMS/DATASTRUCTURES/String.h>
It based on std::string but adds a lot of methods for convenience.
Public Types | |
Type definitions | |
typedef iterator | Iterator |
Iterator. | |
typedef const_iterator | ConstIterator |
Const Iterator. | |
typedef reverse_iterator | ReverseIterator |
Reverse Iterator. | |
typedef const_reverse_iterator | ConstReverseIterator |
Const reverse Iterator. | |
typedef size_type | SizeType |
UInt type. | |
Public Member Functions | |
bool | split (char splitter, std::vector< String > &substrings) const |
splits a string into substrings using splitter as delimiter | |
template<class StringIterator> | |
void | implode (StringIterator first, StringIterator last, const String &glue="") |
Concatenates all elements from first to last-1 and inserts glue between the elements. | |
Constructors | |
String () | |
Default constructor. | |
String (const std::string &s) | |
Constructor from std::string. | |
String (const QString &s) | |
Constructor from Qt QString. | |
String (const char *s) | |
Constructor from char*. | |
String (const char c) | |
Constructor from a char. | |
String (const char *s, SizeType length) | |
Constructor from char* (only length chracters). | |
String (size_t len, char c) | |
Constructor from char (repeats the char len times). | |
template<class InputIterator> | |
String (InputIterator first, InputIterator last) | |
Constructor from a char range. | |
String (int i) | |
Constructor from an integer. | |
String (unsigned int i) | |
Constructor from an unsigned integer. | |
String (short int i) | |
Constructor from an integer. | |
String (short unsigned int i) | |
Constructor from an unsigned integer. | |
String (long int i) | |
Constructor from an integer. | |
String (long unsigned int i) | |
Constructor from an unsigned integer. | |
String (long long unsigned int i) | |
Constructor from an unsigned integer. | |
String (float f) | |
Constructor from float (precision is 7). | |
String (double d) | |
Constructor from double (precision is 10). | |
String (long double d) | |
Constructor from long double (precision is 16). | |
String (double d, UInt size) | |
Constructor from double, that is converted to string of maximum length size . | |
String (const DataValue &d) | |
Constructor from DataValue (casted to String). | |
Predicates | |
bool | hasPrefix (const String &string) const |
true if String begins with string , false otherwise | |
bool | hasSuffix (const String &string) const |
true if String ends with string , false otherwise | |
bool | hasSubstring (const String &string) const |
true if String contains the string , false otherwise | |
bool | has (Byte byte) const |
true if String contains the byte , false otherwise | |
Accessors | |
String | prefix (SizeType length) const throw (Exception::IndexOverflow) |
returns the prefix of length length | |
String | suffix (SizeType length) const throw (Exception::IndexOverflow) |
returns the suffix of length length | |
String | prefix (Int length) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
returns the prefix of length length | |
String | suffix (Int length) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
returns the suffix of length length | |
String | prefix (char delim) const throw (Exception::ElementNotFound<char>) |
returns the prefix up to the first occurence of char delim (excluding it) | |
String | suffix (char delim) const throw (Exception::ElementNotFound<char>) |
returns the suffix up to the last occurence of char delim (excluding it) | |
String | substr (Int start, Int n) const |
Returns a substring. | |
String | substr (Int start) const |
Returns the suffix of the string from position start . | |
Mutators | |
All these methods return a reference to the string in order to make them chainable | |
String & | reverse () |
inverts the direction of the string | |
String & | trim () |
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the string | |
String & | fillLeft (char c, UInt size) |
Adds c on the left side until the size of the string is size . | |
String & | fillRight (char c, UInt size) |
Adds c on the right side until the size of the string is size . | |
String & | toUpper () |
Converts the string to uppercase. | |
String & | toLower () |
Converts the string to lowercase. | |
String & | firstToUpper () |
Converts the first letter of the string to uppercase. | |
String & | substitute (char from, char to) |
Replaces all occurences of the character from by the character to . | |
String & | substitute (const String &from, const String &to) |
Replaces all occurences of the string from by the string to . | |
String & | remove (char what) |
Remove all occurences of the character what . | |
String & | ensureLastChar (char end) |
Makes sure the string ends with the character end . | |
String & | removeWhitespaces () |
removes whitespaces (space, tab, line feed, carriage return) | |
Converters | |
Int | toInt () const throw (Exception::ConversionError) |
Conversion to int. | |
Real | toFloat () const throw (Exception::ConversionError) |
Conversion to float. | |
DoubleReal | toDouble () const throw (Exception::ConversionError) |
Conversion to double. | |
QString | toQString () const |
Conversion to Qt QString. | |
Sum operator overloads | |
String | operator+ (int i) const |
Sum operator for an integer. | |
String | operator+ (unsigned int i) const |
Sum operator for an unsigned integer. | |
String | operator+ (short int i) const |
Sum operator for an integer. | |
String | operator+ (short unsigned int i) const |
Sum operator for an unsigned integer. | |
String | operator+ (long int i) const |
Sum operator for an integer. | |
String | operator+ (long unsigned int i) const |
Sum operator for an unsigned integer. | |
String | operator+ (long long unsigned int i) const |
Sum operator for an unsigned integer. | |
String | operator+ (float f) const |
Sum operator for float (precision is 7). | |
String | operator+ (double d) const |
Sum operator for double (precision is 10). | |
String | operator+ (long double d) const |
Sum operator for long double (precision is 16). | |
String | operator+ (char c) const |
Sum operator for char. | |
String | operator+ (const char *s) const |
Sum operator for char*. | |
String | operator+ (const String &s) const |
Sum operatr for String. | |
String | operator+ (const std::string &s) const |
Sum operator for std::string. | |
Append operator overloads | |
String & | operator+= (int i) |
Sum operator for an integer. | |
String & | operator+= (unsigned int i) |
Sum operator for an unsigned integer. | |
String & | operator+= (short int i) |
Sum operator for an integer. | |
String & | operator+= (short unsigned int i) |
Sum operator for an unsigned integer. | |
String & | operator+= (long int i) |
Sum operator for an integer. | |
String & | operator+= (long unsigned int i) |
Sum operator for an unsigned integer. | |
String & | operator+= (long long unsigned int i) |
Sum operator for an unsigned integer. | |
String & | operator+= (float f) |
Sum operator for float (precision is 7). | |
String & | operator+= (double d) |
Sum operator for double (precision is 10). | |
String & | operator+= (long double d) |
Sum operator for long double (precision is 16). | |
String & | operator+= (char c) |
Sum operator for char. | |
String & | operator+= (const char *s) |
Sum operator for char*. | |
String & | operator+= (const String &s) |
Sum operatr for String. | |
String & | operator+= (const std::string &s) |
Sum operator for std::string. | |
Static Public Member Functions | |
static String | random (UInt length) |
returns a random string of the given length. It consists of [0-9a-zA-Z] | |
Static Public Attributes | |
static const String | EMPTY |
Empty string for comparisons. |
typedef iterator Iterator |
Iterator.
typedef const_iterator ConstIterator |
Const Iterator.
typedef reverse_iterator ReverseIterator |
Reverse Iterator.
typedef const_reverse_iterator ConstReverseIterator |
Const reverse Iterator.
typedef size_type SizeType |
UInt type.
String | ( | ) |
Default constructor.
String | ( | const std::string & | s | ) |
Constructor from std::string.
String | ( | const QString & | s | ) |
Constructor from Qt QString.
String | ( | const char * | s | ) |
Constructor from char*.
String | ( | const char | c | ) |
Constructor from a char.
String | ( | size_t | len, | |
char | c | |||
) |
Constructor from char (repeats the char len
times).
String | ( | InputIterator | first, | |
InputIterator | last | |||
) | [inline] |
Constructor from a char range.
String | ( | int | i | ) |
Constructor from an integer.
String | ( | unsigned int | i | ) |
Constructor from an unsigned integer.
String | ( | short int | i | ) |
Constructor from an integer.
String | ( | short unsigned int | i | ) |
Constructor from an unsigned integer.
String | ( | long int | i | ) |
Constructor from an integer.
String | ( | long unsigned int | i | ) |
Constructor from an unsigned integer.
String | ( | long long unsigned int | i | ) |
Constructor from an unsigned integer.
String | ( | float | f | ) |
Constructor from float (precision is 7).
String | ( | double | d | ) |
Constructor from double (precision is 10).
String | ( | long double | d | ) |
Constructor from long double (precision is 16).
Constructor from double, that is converted to string of maximum length size
.
If d
is larger, scientific notation is used.
bool hasSubstring | ( | const String & | string | ) | const |
true if String contains the string
, false otherwise
String prefix | ( | SizeType | length | ) | const throw (Exception::IndexOverflow) |
returns the prefix of length length
String suffix | ( | SizeType | length | ) | const throw (Exception::IndexOverflow) |
returns the suffix of length length
String prefix | ( | Int | length | ) | const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
returns the prefix of length length
String suffix | ( | Int | length | ) | const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
returns the suffix of length length
String prefix | ( | char | delim | ) | const throw (Exception::ElementNotFound<char>) |
returns the prefix up to the first occurence of char delim
(excluding it)
String suffix | ( | char | delim | ) | const throw (Exception::ElementNotFound<char>) |
returns the suffix up to the last occurence of char delim
(excluding it)
Returns a substring.
start | start position of the substring. If start is negative, the returned string will start at the start'th character from the end of string. | |
n | length of the substring. If a negative length is given, then that many characters will be omitted from the end of string. |
Returns the suffix of the string from position start
.
start | start position of the substring. If start is negative, the returned string will start at the start'th character from the end of string. |
String& reverse | ( | ) |
inverts the direction of the string
String& trim | ( | ) |
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the string
Adds c
on the left side until the size of the string is size
.
Adds c
on the right side until the size of the string is size
.
String& toUpper | ( | ) |
Converts the string to uppercase.
String& toLower | ( | ) |
Converts the string to lowercase.
String& firstToUpper | ( | ) |
Converts the first letter of the string to uppercase.
String& substitute | ( | char | from, | |
char | to | |||
) |
Replaces all occurences of the character from
by the character to
.
Replaces all occurences of the string from
by the string to
.
String& remove | ( | char | what | ) |
Remove all occurences of the character what
.
String& ensureLastChar | ( | char | end | ) |
Makes sure the string ends with the character end
.
String& removeWhitespaces | ( | ) |
removes whitespaces (space, tab, line feed, carriage return)
Int toInt | ( | ) | const throw (Exception::ConversionError) |
Conversion to int.
This method extracts only the integral part of the string. If you want the result rounded, use toFloat() and round the result.
Real toFloat | ( | ) | const throw (Exception::ConversionError) |
Conversion to float.
DoubleReal toDouble | ( | ) | const throw (Exception::ConversionError) |
Conversion to double.
QString toQString | ( | ) | const |
Conversion to Qt QString.
String operator+ | ( | int | i | ) | const |
Sum operator for an integer.
String operator+ | ( | unsigned int | i | ) | const |
Sum operator for an unsigned integer.
String operator+ | ( | short int | i | ) | const |
Sum operator for an integer.
String operator+ | ( | short unsigned int | i | ) | const |
Sum operator for an unsigned integer.
String operator+ | ( | long int | i | ) | const |
Sum operator for an integer.
String operator+ | ( | long unsigned int | i | ) | const |
Sum operator for an unsigned integer.
String operator+ | ( | long long unsigned int | i | ) | const |
Sum operator for an unsigned integer.
String operator+ | ( | float | f | ) | const |
Sum operator for float (precision is 7).
String operator+ | ( | double | d | ) | const |
Sum operator for double (precision is 10).
String operator+ | ( | long double | d | ) | const |
Sum operator for long double (precision is 16).
String operator+ | ( | char | c | ) | const |
Sum operator for char.
String operator+ | ( | const char * | s | ) | const |
Sum operator for char*.
String operator+ | ( | const std::string & | s | ) | const |
Sum operator for std::string.
String& operator+= | ( | int | i | ) |
Sum operator for an integer.
String& operator+= | ( | unsigned int | i | ) |
Sum operator for an unsigned integer.
String& operator+= | ( | short int | i | ) |
Sum operator for an integer.
String& operator+= | ( | short unsigned int | i | ) |
Sum operator for an unsigned integer.
String& operator+= | ( | long int | i | ) |
Sum operator for an integer.
String& operator+= | ( | long unsigned int | i | ) |
Sum operator for an unsigned integer.
String& operator+= | ( | long long unsigned int | i | ) |
Sum operator for an unsigned integer.
String& operator+= | ( | float | f | ) |
Sum operator for float (precision is 7).
String& operator+= | ( | double | d | ) |
Sum operator for double (precision is 10).
String& operator+= | ( | long double | d | ) |
Sum operator for long double (precision is 16).
String& operator+= | ( | char | c | ) |
Sum operator for char.
String& operator+= | ( | const char * | s | ) |
Sum operator for char*.
String& operator+= | ( | const std::string & | s | ) |
Sum operator for std::string.
returns a random string of the given length. It consists of [0-9a-zA-Z]
bool split | ( | char | splitter, | |
std::vector< String > & | substrings | |||
) | const |
splits a string into substrings
using splitter
as delimiter
If the splitter
is not found, substrings
is empty.
void implode | ( | StringIterator | first, | |
StringIterator | last, | |||
const String & | glue = "" | |||
) | [inline] |
Concatenates all elements from first
to last-1
and inserts glue
between the elements.
Generated Tue Apr 1 15:36:44 2008 -- using doxygen 1.5.4 | OpenMS / TOPP 1.1 |