A more convenient string class. More...
#include <OpenMS/DATASTRUCTURES/String.h>
Public Types | |
Type definitions | |
enum | QuotingMethod { NONE, ESCAPE, DOUBLE } |
How to handle embedded quotes when quoting strings. More... | |
typedef iterator | Iterator |
Iterator. More... | |
typedef const_iterator | ConstIterator |
Const Iterator. More... | |
typedef reverse_iterator | ReverseIterator |
Reverse Iterator. More... | |
typedef const_reverse_iterator | ConstReverseIterator |
Const reverse Iterator. More... | |
typedef size_type | SizeType |
UInt type. More... | |
Public Member Functions | |
bool | split (const char splitter, std::vector< String > &substrings, bool quote_protect=false) const |
Splits a string into substrings using splitter as delimiter. More... | |
bool | split (const String &splitter, std::vector< String > &substrings) const |
Splits a string into substrings using splitter (the whole string) as delimiter. More... | |
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 within quoted substrings. More... | |
template<class StringIterator > | |
void | concatenate (StringIterator first, StringIterator last, const String &glue="") |
Concatenates all elements from first to last-1 and inserts glue between the elements. More... | |
Constructors | |
String () | |
Default constructor. More... | |
String (const std::string &s) | |
Constructor from std::string. More... | |
String (const QString &s) | |
Constructor from Qt QString. More... | |
String (const char *s) | |
Constructor from char*. More... | |
String (const char c) | |
Constructor from a char. More... | |
String (const char *s, SizeType length) | |
Constructor from char* (only length characters) More... | |
String (size_t len, char c) | |
Constructor from char (repeats the char len times) More... | |
template<class InputIterator > | |
String (InputIterator first, InputIterator last) | |
Constructor from a char range. More... | |
String (int i) | |
Constructor from an integer. More... | |
String (unsigned int i) | |
Constructor from an unsigned integer. More... | |
String (short int i) | |
Constructor from an integer. More... | |
String (short unsigned int i) | |
Constructor from an unsigned integer. More... | |
String (long int i) | |
Constructor from an integer. More... | |
String (long unsigned int i) | |
Constructor from an unsigned integer. More... | |
String (long long unsigned int i) | |
Constructor from an unsigned integer. More... | |
String (long long signed int i) | |
Constructor from an unsigned integer. More... | |
String (float f) | |
Constructor from float. More... | |
String (double d) | |
Constructor from double. More... | |
String (long double ld) | |
Constructor from long double. More... | |
String (const DataValue &d) | |
Constructor from DataValue (casted to String) More... | |
Predicates | |
bool | hasPrefix (const String &string) const |
true if String begins with string , false otherwise More... | |
bool | hasSuffix (const String &string) const |
true if String ends with string , false otherwise More... | |
bool | hasSubstring (const String &string) const |
true if String contains the string , false otherwise More... | |
bool | has (Byte byte) const |
true if String contains the byte , false otherwise More... | |
Accessors | |
String | prefix (SizeType length) const |
returns the prefix of length length More... | |
String | suffix (SizeType length) const |
returns the suffix of length length More... | |
String | prefix (Int length) const |
returns the prefix of length length More... | |
String | suffix (Int length) const |
returns the suffix of length length More... | |
String | prefix (char delim) const |
returns the prefix up to the first occurrence of char delim (excluding it) More... | |
String | suffix (char delim) const |
returns the suffix up to the last occurrence of char delim (excluding it) More... | |
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 substring of the current object. More... | |
String | chop (Size n) const |
Returns a substring where n characters were removed from the end of the string. More... | |
Mutators | |
All these methods return a reference to the string in order to make them chainable | |
String & | reverse () |
inverts the direction of the string More... | |
String & | trim () |
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the string More... | |
String & | quote (char q='"', QuotingMethod method = ESCAPE) |
Wraps the string in quotation marks. More... | |
String & | unquote (char q='"', QuotingMethod method = ESCAPE) |
Reverses changes made by the quote method. More... | |
String & | simplify () |
merges subsequent whitespaces to one blank character More... | |
String & | fillLeft (char c, UInt size) |
Adds c on the left side until the size of the string is size . More... | |
String & | fillRight (char c, UInt size) |
Adds c on the right side until the size of the string is size . More... | |
String & | toUpper () |
Converts the string to uppercase. More... | |
String & | toLower () |
Converts the string to lowercase. More... | |
String & | firstToUpper () |
Converts the first letter of the string to uppercase. More... | |
String & | substitute (char from, char to) |
Replaces all occurrences of the character from by the character to . More... | |
String & | substitute (const String &from, const String &to) |
Replaces all occurrences of the string from by the string to . More... | |
String & | remove (char what) |
Remove all occurrences of the character what . More... | |
String & | ensureLastChar (char end) |
Makes sure the string ends with the character end . More... | |
String & | removeWhitespaces () |
removes whitespaces (space, tab, line feed, carriage return) More... | |
Converters | |
Int | toInt () const |
Conversion to int. More... | |
float | toFloat () const |
Conversion to float. More... | |
double | toDouble () const |
Conversion to double. More... | |
QString | toQString () const |
Conversion to Qt QString. More... | |
Sum operator overloads | |
String | operator+ (int i) const |
Sum operator for an integer. More... | |
String | operator+ (unsigned int i) const |
Sum operator for an unsigned integer. More... | |
String | operator+ (short int i) const |
Sum operator for an integer. More... | |
String | operator+ (short unsigned int i) const |
Sum operator for an unsigned integer. More... | |
String | operator+ (long int i) const |
Sum operator for an integer. More... | |
String | operator+ (long unsigned int i) const |
Sum operator for an unsigned integer. More... | |
String | operator+ (long long unsigned int i) const |
Sum operator for an unsigned integer. More... | |
String | operator+ (float f) const |
Sum operator for float. More... | |
String | operator+ (double d) const |
Sum operator for double. More... | |
String | operator+ (long double ld) const |
Sum operator for long double. More... | |
String | operator+ (char c) const |
Sum operator for char. More... | |
String | operator+ (const char *s) const |
Sum operator for char*. More... | |
String | operator+ (const String &s) const |
Sum operator for String. More... | |
String | operator+ (const std::string &s) const |
Sum operator for std::string. More... | |
Append operator overloads | |
String & | operator+= (int i) |
Sum operator for an integer. More... | |
String & | operator+= (unsigned int i) |
Sum operator for an unsigned integer. More... | |
String & | operator+= (short int i) |
Sum operator for an integer. More... | |
String & | operator+= (short unsigned int i) |
Sum operator for an unsigned integer. More... | |
String & | operator+= (long int i) |
Sum operator for an integer. More... | |
String & | operator+= (long unsigned int i) |
Sum operator for an unsigned integer. More... | |
String & | operator+= (long long unsigned int i) |
Sum operator for an unsigned integer. More... | |
String & | operator+= (float f) |
Sum operator for float. More... | |
String & | operator+= (double d) |
Sum operator for double. More... | |
String & | operator+= (long double d) |
Sum operator for long double. More... | |
String & | operator+= (char c) |
Sum operator for char. More... | |
String & | operator+= (const char *s) |
Sum operator for char*. More... | |
String & | operator+= (const String &s) |
Sum operator for String. More... | |
String & | operator+= (const std::string &s) |
Sum operator for std::string. More... | |
Static Public Member Functions | |
static String | random (UInt length) |
returns a random string of the given length. It consists of [0-9a-zA-Z] More... | |
static String | number (double d, UInt n) |
returns a string for d with exactly n decimal places More... | |
static String | numberLength (double d, UInt n) |
Returns a string with at maximum n characters for d . More... | |
Static Public Attributes | |
static const String | EMPTY |
Empty string for comparisons. More... | |
A more convenient string class.
It is based on std::string but adds a lot of methods for convenience.
typedef const_iterator ConstIterator |
Const Iterator.
typedef const_reverse_iterator ConstReverseIterator |
Const reverse Iterator.
typedef iterator Iterator |
Iterator.
typedef reverse_iterator ReverseIterator |
Reverse Iterator.
typedef size_type SizeType |
UInt type.
enum QuotingMethod |
String | ( | ) |
Default constructor.
Referenced by StringView::getString(), and String::String().
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)
|
inline |
Constructor from a char range.
References String::chop(), String::ensureLastChar(), String::ESCAPE, String::fillLeft(), String::fillRight(), String::firstToUpper(), String::has(), String::hasPrefix(), String::hasSubstring(), String::hasSuffix(), String::number(), String::numberLength(), String::operator+(), String::operator+=(), String::prefix(), String::quote(), String::random(), String::removeWhitespaces(), String::reverse(), String::simplify(), String::split(), String::split_quoted(), String::String(), String::substitute(), String::substr(), String::suffix(), String::toDouble(), String::toFloat(), String::toInt(), String::toLower(), String::toQString(), String::toUpper(), String::trim(), and String::unquote().
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 | ( | long long signed int | i | ) |
Constructor from an unsigned integer.
Returns a substring where n
characters were removed from the end of the string.
If n
is greater than size(), the result is an empty string.
n | Number of characters that will be removed from the end of the string. |
Referenced by String::String().
|
inline |
Concatenates all elements from first
to last-1
and inserts glue
between the elements.
Referenced by MetaProSIPReporting::plotFilteredSpectra(), MetaProSIPReporting::plotHeatMap(), MetaProSIPReporting::plotScoresAndWeights(), and StringUtils::substitute().
String& ensureLastChar | ( | char | end | ) |
Makes sure the string ends with the character end
.
Referenced by String::String().
Adds c
on the left side until the size of the string is size
.
Referenced by String::String().
Adds c
on the right side until the size of the string is size
.
Referenced by String::String().
String& firstToUpper | ( | ) |
Converts the first letter of the string to uppercase.
Referenced by String::String().
bool has | ( | Byte | byte | ) | const |
true if String contains the byte
, false otherwise
Referenced by DTAFile::load(), DTA2DFile::load(), TOPPRNPxl::main_(), RNPxlSearch::main_(), String::String(), and XMLHandler::writeXMLEscape().
bool hasPrefix | ( | const String & | string | ) | const |
true if String begins with string
, false otherwise
Referenced by XMLHandler::expectList_(), MascotGenericFile::getNextSpectrum_(), XMassFile::load(), DTA2DFile::load(), RNPxlSearch::postScoreHits_(), and String::String().
bool hasSubstring | ( | const String & | string | ) | const |
true if String contains the string
, false otherwise
Referenced by RNPxlSearch::getFeasibleFragmentAdducts_(), RNPxlSearch::getModifications_(), MascotGenericFile::getNextSpectrum_(), main(), RNPxlSearch::normalizeAdductName_(), RNPxlSearch::postScoreHits_(), and String::String().
bool hasSuffix | ( | const String & | string | ) | const |
true if String ends with string
, false otherwise
Referenced by StringUtils::ensureLastChar(), XMLHandler::expectList_(), XMassFile::load(), TOPPViewBase::showCurrentPeaksAs2D(), SortPairDoubleByFirst(), and String::String().
returns a string for d
with exactly n
decimal places
Referenced by MetaProSIPReporting::createCSVReport(), MetaProSIPReporting::createPeptideCentricCSVReport(), FragmentAnnotationHelper::fragmentAnnotationDetailsToString(), RNPxlSearch::postScoreHits_(), FragmentAnnotationHelper::shiftedIonsToString(), TOPPViewBase::showCursorStatus(), String::String(), MetaProSIPReporting::writeHTML(), and TOPPMetaProSIP::writePeakIntensities_().
Returns a string with at maximum n
characters for d
.
If d
is larger, scientific notation is used.
Referenced by String::String().
String operator+ | ( | int | i | ) | const |
Sum operator for an integer.
Referenced by String::String().
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+ | ( | 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.
Referenced by String::String().
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+= | ( | 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 the prefix of length length
Exception::IndexOverflow | is thrown if length is bigger than the size |
Referenced by XMassFile::importExperimentalSettings(), XMassFile::load(), TOPPViewBase::showCurrentPeaksAs2D(), StringUtils::split(), and String::String().
returns the prefix of length length
Exception::IndexUnderflow | is thrown if length is smaller than zero |
Exception::IndexOverflow | is thrown if length is bigger than the size |
String prefix | ( | char | delim | ) | const |
returns the prefix up to the first occurrence of char delim
(excluding it)
Exception::ElementNotFound | is thrown if delim is not found |
String& quote | ( | char | q = '"' , |
QuotingMethod | method = ESCAPE |
||
) |
Wraps the string in quotation marks.
The quotation mark can be specified by parameter q
(typically single or double quote); embedded quotation marks are handled according to method
by backslash-escaping, doubling, or not at all.
Referenced by String::String().
returns a random string of the given length. It consists of [0-9a-zA-Z]
Referenced by RIntegration::checkRDependencies(), TOPPMetaProSIP::main_(), and String::String().
String& remove | ( | char | what | ) |
Remove all occurrences of the character what
.
Referenced by MascotGenericFile::getNextSpectrum_().
String& removeWhitespaces | ( | ) |
removes whitespaces (space, tab, line feed, carriage return)
Referenced by RNPxlSearch::getPrecursorToFragmentAdducts_(), and String::String().
String& reverse | ( | ) |
inverts the direction of the string
Referenced by String::String().
String& simplify | ( | ) |
merges subsequent whitespaces to one blank character
Referenced by MascotGenericFile::getNextSpectrum_(), MS2File::load(), and String::String().
bool split | ( | const char | splitter, |
std::vector< String > & | substrings, | ||
bool | quote_protect = false |
||
) | const |
Splits a string into substrings
using splitter
as delimiter.
If splitter
is not found, the whole string is put into substrings
. If splitter
is empty, the string is split into individual characters. If the invoking string is empty, substrings
will also be empty.
quote_protect
(default: false) can be used to split only between quoted blocks e.g. ' "a string" , "another string with , in it" ' results in only two substrings (with double quotation marks removed). Every returned substring is trimmed and then (if present) has surrounding quotation marks removed.
Referenced by ListUtils::create(), extractCachedMetaFilename(), MascotGenericFile::getNextSpectrum_(), RNPxlSearch::getPrecursorToFragmentAdducts_(), MS2File::load(), SpecArrayFile::load(), MsInspectFile::load(), DTAFile::load(), DTA2DFile::load(), RNPxlSearch::postScoreHits_(), String::String(), and StringUtils::substitute().
Splits a string into substrings
using splitter
(the whole string) as delimiter.
If splitter
is not found, the whole string is put into substrings
. If splitter
is empty, the string is split into individual characters. If the invoking string is empty, substrings
will also be empty.
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 within quoted substrings.
A "quoted substring" has the format as produced by quote(q, method)
, where q
is the quoting character and method
defines the handling of embedded quotes. Substrings will not be "unquoted" or otherwise processed.
If splitter
is not found, the whole string is put into substrings
. If splitter
or the invoking string is empty, substrings
will also be empty.
Exception::ConversionError | is thrown if quotation marks are not balanced |
Referenced by String::String().
String& substitute | ( | char | from, |
char | to | ||
) |
Replaces all occurrences of the character from
by the character to
.
Referenced by RNPxlSearch::getModifications_(), MascotGenericFile::getNextSpectrum_(), TOPPRNPxl::main_(), TOPPMetaProSIP::main_(), RNPxlSearch::postScoreHits_(), StringUtils::quote(), String::String(), StringUtils::unquote(), and XMLHandler::writeXMLEscape().
Replaces all occurrences of the string from
by the string to
.
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 substring of the current object.
pos | Position of a character in the current string object to be used as starting character for the substring. If the pos is past the end of the string, it is set to the end of the string. |
n | Length of the substring. If this value would make the substring to span past the end of the current string content, only those characters until the end of the string are used. npos is a static member constant value with the greatest possible value for an element of type size_t, therefore, when this value is used, all the characters between pos and the end of the string are used as the initialization substring. |
Referenced by XMLHandler::asDateTime_(), XMLHandler::attributeAsDoubleList_(), XMLHandler::attributeAsIntList_(), XMLHandler::attributeAsStringList_(), MascotGenericFile::getNextSpectrum_(), DTA2DFile::load(), StringUtils::prefix(), OpenSwathTSVWriter::prepareLine(), StringUtils::split(), StringUtils::split_quoted(), String::String(), StringUtils::suffix(), and StringUtils::unquote().
returns the suffix of length length
Exception::IndexOverflow | is thrown if length is bigger than the size |
Referenced by XMassFile::load(), SortPairDoubleByFirst(), StringUtils::split(), and String::String().
returns the suffix of length length
Exception::IndexUnderflow | is thrown if length is smaller than zero |
Exception::IndexOverflow | is thrown if length is bigger than the size |
String suffix | ( | char | delim | ) | const |
returns the suffix up to the last occurrence of char delim
(excluding it)
Exception::ElementNotFound | is thrown if delim is not found |
double toDouble | ( | ) | const |
Conversion to double.
Exception::ConversionError | is thrown if the string could not be converted to double |
Referenced by XMLHandler::asDouble_(), MascotGenericFile::getNextSpectrum_(), and String::String().
float toFloat | ( | ) | const |
Conversion to float.
Exception::ConversionError | is thrown if the string could not be converted to float |
Referenced by XMLHandler::asFloat_(), and String::String().
Int toInt | ( | ) | const |
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.
Exception::ConversionError | is thrown if the string could not be converted to int |
Referenced by XMLHandler::asInt_(), XMLHandler::asUInt_(), MascotGenericFile::getNextSpectrum_(), RNPxlSearch::postScoreHits_(), and String::String().
String& toLower | ( | ) |
Converts the string to lowercase.
Referenced by AccurateMassSearchEngine::resolveAutoMode_(), SortPairDoubleByFirst(), and String::String().
QString toQString | ( | ) | const |
Conversion to Qt QString.
Referenced by FileWatcher::addFile(), TOPPViewBase::addRecentFile_(), TOPPASBase::addTOPPASFile(), TOPPViewBase::annotateWithID(), RIntegration::checkRDependencies(), TOPPASBase::createTOPPToolsTreeWidget(), TOPPASBase::exportAsImage(), TOPPViewBase::fileChanged_(), TOPPViewBase::filterContextMenu(), TOPPViewBase::finishTOPPToolExecution(), TOPPViewBase::getFileList_(), TOPPASBase::includePipeline(), TOPPViewBase::layerContextMenu(), TOPPASBase::loadPipelineResourceFile(), TOPPViewBase::loadPreferences(), TOPPRNPxl::main_(), TOPPMetaProSIP::main_(), INIFileEditorWindow::openFile(), TOPPASBase::openFileDialog(), IDEvaluationBase::openFileDialog(), MetaProSIPReporting::plotFilteredSpectra(), MetaProSIPReporting::plotHeatMap(), MetaProSIPReporting::plotScoresAndWeights(), QApplicationTOPP::QApplicationTOPP(), TOPPASBase::refreshParameters(), FileWatcher::removeFile(), TOPPViewBase::runTOPPTool_(), TOPPASBase::saveCurrentPipelineAs(), INIFileEditorWindow::saveFileAs(), IDEvaluationBase::saveImageAs(), TOPPASBase::savePipeline(), TOPPASBase::savePipelineAs(), TOPPASBase::savePipelineResourceFile(), TOPPASBase::showAsWindow_(), IDEvaluationBase::showLogMessage_(), TOPPASBase::showLogMessage_(), TOPPViewBase::showLogMessage_(), TOPPViewBase::showSpectrumWidgetInWindow(), String::String(), TOPPASBase::TOPPASBase(), TOPPASBase::toppasFileDownloaded_(), TOPPViewBase::updateLayerBar(), and MetaProSIPReporting::writeHTML().
String& toUpper | ( | ) |
Converts the string to uppercase.
Referenced by MetaProSIPReporting::createCSVReport(), MetaProSIPReporting::createPeptideCentricCSVReport(), TOPPMetaProSIP::main_(), and String::String().
String& trim | ( | ) |
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the string
Referenced by XMLHandler::asDateTime_(), MetaProSIPReporting::createCSVReport(), MetaProSIPReporting::createPeptideCentricCSVReport(), MascotGenericFile::getNextSpectrum_(), MS2File::load(), DTAFile::load(), DTA2DFile::load(), TOPPMetaProSIP::main_(), StringUtils::split(), String::String(), and TOPPASBase::toppasFileDownloaded_().
String& unquote | ( | char | q = '"' , |
QuotingMethod | method = ESCAPE |
||
) |
Reverses changes made by the quote
method.
Removes surrounding quotation marks (given by parameter q
); handles embedded quotes according to method
.
Exception::ConversionError | is thrown if the string does not have the format produced by quote |
Referenced by String::String().
|
static |
Empty string for comparisons.
OpenMS / TOPP release 2.3.0 | Documentation generated on Tue Jan 9 2018 18:22:13 using doxygen 1.8.13 |