OpenMS
Loading...
Searching...
No Matches
StringUtils.h File Reference
#include <OpenMS/CONCEPT/Types.h>
#include <OpenMS/CONCEPT/Exception.h>
#include <OpenMS/OpenMSConfig.h>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/home/karma/numeric/detail/real_utils.hpp>
#include <boost/type_traits.hpp>
#include <boost/functional/hash.hpp>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <limits>
#include <ranges>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>
Include dependency graph for StringUtils.h:

Go to the source code of this file.

Classes

class  BK_PrecPolicyFull< T >
 Karma full-precision float/double/long double policy with NaN→"NaN". More...
 
class  BK_PrecPolicyShort< T >
 Karma low-precision (≤3 fractional digits) policy with NaN→"NaN". More...
 
class  StringUtilsHelper
 
struct  StringUtilsHelper::real_policies_NANfixed_< T >
 

Namespaces

namespace  OpenMS
 Main OpenMS namespace.
 
namespace  OpenMS::StringConversions
 
namespace  OpenMS::StringConversions::Detail
 
namespace  OpenMS::StringUtils
 

Typedefs

using FloatFullGen = boost::spirit::karma::real_generator< float, BK_PrecPolicyFull< float > >
 
using DoubleFullGen = boost::spirit::karma::real_generator< double, BK_PrecPolicyFull< double > >
 
using LDFullGen = boost::spirit::karma::real_generator< long double, BK_PrecPolicyFull< long double > >
 
using FloatShortGen = boost::spirit::karma::real_generator< float, BK_PrecPolicyShort< float > >
 
using DoubleShortGen = boost::spirit::karma::real_generator< double, BK_PrecPolicyShort< double > >
 
using LDShortGen = boost::spirit::karma::real_generator< long double, BK_PrecPolicyShort< long double > >
 

Enumerations

enum class  QuotingMethod { NONE , ESCAPE , DOUBLE }
 How to handle embedded quotes when quoting strings. More...
 

Functions

template<typename T >
void appendToStr (const T &i, std::string &target)
 Append i to target (Boost.Karma, fast)
 
void appendToStr (int i, std::string &target)
 Append integer i to target.
 
void appendToStr (unsigned int i, std::string &target)
 
void appendToStr (short int i, std::string &target)
 
void appendToStr (short unsigned int i, std::string &target)
 
void appendToStr (long int i, std::string &target)
 
void appendToStr (long unsigned int i, std::string &target)
 
void appendToStr (long long unsigned int i, std::string &target)
 
void appendToStr (long long signed int i, std::string &target)
 
void appendToStr (float f, std::string &target)
 Append float (high precision, 6 fractional digits) to target.
 
void appendToStrLowP (float f, std::string &target)
 Append float (low precision, 3 fractional digits) to target.
 
void appendToStr (double d, std::string &target)
 Append double (high precision, 15 fractional digits) to target.
 
void appendToStrLowP (double d, std::string &target)
 Append double (low precision, 3 fractional digits) to target.
 
void appendToStr (long double ld, std::string &target)
 Append long double (high precision) to target.
 
void appendToStrLowP (long double ld, std::string &target)
 Append long double (low precision) to target.
 
void appendToStr (const DataValue &d, bool full_precision, std::string &target)
 Append DataValue string representation to target (non-inline; defined in StringUtils.cpp)
 
std::string toStr (int i)
 
std::string toStr (unsigned int i)
 
std::string toStr (short int i)
 
std::string toStr (short unsigned int i)
 
std::string toStr (long int i)
 
std::string toStr (long unsigned int i)
 
std::string toStr (long long unsigned int i)
 
std::string toStr (long long signed int i)
 
std::string toStr (float f, bool full_precision=true)
 Float to string; full_precision selects 6-digit (true) or 3-digit (false) output.
 
std::string toStr (double d, bool full_precision=true)
 Double to string; full_precision selects 15-digit (true) or 3-digit (false) output.
 
std::string toStr (long double ld, bool full_precision=true)
 Long double to string; full_precision selects full-precision or 3-digit output.
 
std::string toStr (char c)
 
std::string toStr (const std::string &s)
 
std::string toStr (const char *s)
 
std::string toStr (const DataValue &d, bool full_precision=true)
 DataValue to string — the LENIENT stringification (non-inline; defined in StringUtils.cpp).
 
std::string toStr (const ParamValue &p, bool full_precision=true)
 ParamValue to string — lenient, like toStr(const DataValue&) (non-inline; defined in StringUtils.cpp)
 
Int32 toInt32 (const std::string &s)
 
Int64 toInt64 (const std::string &s)
 
float toFloat (const std::string &s)
 
double toDouble (const std::string &s)
 
template<typename IteratorT >
bool extractDouble (IteratorT &begin, const IteratorT &end, double &target)
 
template<typename IteratorT >
bool extractInt (IteratorT &begin, const IteratorT &end, int &target)
 
const char * skipWhitespace (const char *p, const char *p_end)
 Returns pointer to first non-whitespace character in [p, p_end), or p_end.
 
int skipWhitespace (const std::string_view &data)
 Returns count of leading whitespace characters in data.
 
const char * skipNonWhitespace (const char *p, const char *p_end)
 Returns pointer to first whitespace character in [p, p_end), or p_end.
 
int skipNonWhitespace (const std::string_view &data)
 Returns count of leading non-whitespace characters in data.
 
std::string number (double d, UInt n)
 Returns a string with exactly n decimal places for d.
 
std::string numberLength (double d, UInt n)
 Returns a string for d with at most n characters total (scientific notation if needed)
 
std::string random (UInt length)
 Returns a random string of length characters from [0-9a-zA-Z].
 
bool hasPrefix (const std::string &s, const std::string &prefix)
 
bool hasPrefix (const std::string &s, char c)
 
bool hasSuffix (const std::string &s, const std::string &sfx)
 
bool hasSuffix (const std::string &s, char c)
 
bool hasSubstring (const std::string &s, const std::string &sub)
 
bool hasSubstring (const std::string &s, char c)
 
bool has (const std::string &s, Byte byte)
 
bool has (const std::string &s, char c)
 
std::string prefix (const std::string &s, size_t length)
 
std::string suffix (const std::string &s, size_t length)
 
std::string prefix (const std::string &s, Int length)
 
std::string suffix (const std::string &s, Int length)
 
std::string prefix (const std::string &s, char delim)
 Returns the part of s before the first occurrence of delim (excluding it).
 
std::string suffix (const std::string &s, char delim)
 Returns the part of s after the last occurrence of delim (excluding it).
 
std::string substr (const std::string &s, size_t pos=0, size_t n=std::string::npos)
 Wrapper around std::string::substr; clamps pos to [0, size].
 
std::string substr (std::string_view s, size_t pos=0, size_t n=std::string::npos)
 string_view overload — implicit conversions from string_view to const string& don't work
 
std::string toStr (std::string_view sv)
 toStr overload for string_view (returns a copy as std::string)
 
bool hasPrefix (std::string_view s, const std::string &prefix)
 hasPrefix / hasSuffix / hasSubstring for string_view
 
bool hasSuffix (std::string_view s, const std::string &sfx)
 
bool hasSubstring (std::string_view s, const std::string &sub)
 
std::string chop (const std::string &s, Size n)
 Remove n characters from the end; returns empty string if n >= size.
 
std::string & trim (std::string &s)
 
std::string trimmed (std::string s)
 Returns a trimmed copy of s (for use in chained/rvalue expressions)
 
std::string & toUpper (std::string &s)
 
std::string & toLower (std::string &s)
 
std::string toUppered (std::string s)
 Returns an upper-cased copy of s (for use in chained/rvalue expressions)
 
std::string toLowered (std::string s)
 Returns a lower-cased copy of s (for use in chained/rvalue expressions)
 
std::string & firstToUpper (std::string &s)
 
std::string & reverse (std::string &s)
 
std::string & simplify (std::string &s)
 
std::string & fillLeft (std::string &s, char c, UInt size)
 
std::string & fillRight (std::string &s, char c, UInt size)
 
std::string & substitute (std::string &s, char from, char to)
 
std::string & substitute (std::string &s, const std::string &from, const std::string &to)
 Replace all occurrences of from with to in s.
 
std::string substituted (std::string s, char from, char to)
 substitute on a copy (for chained/rvalue expressions)
 
std::string substituted (std::string s, const std::string &from, const std::string &to)
 
std::string & remove (std::string &s, char what)
 
std::string fillLeft (std::string &&s, char c, UInt size)
 
std::string fillRight (std::string &&s, char c, UInt size)
 
std::string & ensureLastChar (std::string &s, char end)
 
std::string ensureLastChar (std::string &&s, char end)
 rvalue-ref overload (defined after the lvalue version it delegates to)
 
std::string & removeWhitespaces (std::string &s)
 
bool isQuoted (const std::string &s, char q)
 
std::string & quote (std::string &s, char q='"', QuotingMethod method = QuotingMethod::ESCAPE)
 
std::string & unquote (std::string &s, char q='"', QuotingMethod method = QuotingMethod::ESCAPE)
 
bool split (const std::string &s, char splitter, std::vector< std::string > &substrings, bool quote_protect=false)
 
bool split (const std::string &s, const std::string &splitter, std::vector< std::string > &substrings)
 
bool split_quoted (const std::string &s, const std::string &splitter, std::vector< std::string > &substrings, char q='"', QuotingMethod method = QuotingMethod::ESCAPE)
 
template<class StringIterator >
void concatenate (std::string &target, StringIterator first, StringIterator last, const std::string &glue="")
 Join elements [first, last) with glue between them, storing result in target.
 
template<class StringIterator >
std::string concatenate (StringIterator first, StringIterator last, const std::string &glue="")
 Join elements [first, last) with glue and return the result.
 
template<std::ranges::range Container>
std::string concatenate (const Container &container, const std::string &glue="")
 Join the string elements of a container with glue between them and return the result.
 
template<typename T >
void append (const T &i, std::string &target)
 
void append (float f, std::string &target)
 
void append (double d, std::string &target)
 
void append (long double ld, std::string &target)
 
void appendLowP (float f, std::string &target)
 
void appendLowP (double d, std::string &target)
 
void appendLowP (long double ld, std::string &target)
 
void append (const DataValue &d, bool full_precision, std::string &target)
 
template<typename T >
std::string toString (const T &i)
 
std::string toString (float f, bool fp=true)
 
std::string toString (double d, bool fp=true)
 
std::string toString (long double ld, bool fp=true)
 
std::string toString (const DataValue &d, bool fp=true)
 
std::string toString ()
 
std::string toStringLowP (float f)
 
std::string toStringLowP (double d)
 
std::string toStringLowP (long double ld)
 
std::string & operator+= (std::string &s, int i)
 
std::string & operator+= (std::string &s, unsigned int i)
 
std::string & operator+= (std::string &s, short int i)
 
std::string & operator+= (std::string &s, short unsigned int i)
 
std::string & operator+= (std::string &s, long int i)
 
std::string & operator+= (std::string &s, long unsigned int i)
 
std::string & operator+= (std::string &s, long long unsigned int i)
 
std::string & operator+= (std::string &s, long long signed int i)
 
std::string & operator+= (std::string &s, float f)
 
std::string & operator+= (std::string &s, double d)
 
std::string & operator+= (std::string &s, long double ld)
 
std::string operator+ (std::string s, int i)
 
std::string operator+ (std::string s, unsigned int i)
 
std::string operator+ (std::string s, short int i)
 
std::string operator+ (std::string s, short unsigned int i)
 
std::string operator+ (std::string s, long int i)
 
std::string operator+ (std::string s, long unsigned int i)
 
std::string operator+ (std::string s, long long unsigned int i)
 
std::string operator+ (std::string s, long long signed int i)
 
std::string operator+ (std::string s, float f)
 
std::string operator+ (std::string s, double d)
 
std::string operator+ (std::string s, long double ld)
 

Variables

const FloatFullGen floatFull {}
 
const DoubleFullGen doubleFull {}
 
const LDFullGen ldFull {}
 
const FloatShortGen floatShort {}
 
const DoubleShortGen doubleShort {}
 
const LDShortGen ldShort {}
 

Function Documentation

◆ operator+() [1/11]

std::string operator+ ( std::string  s,
double  d 
)
inline

◆ operator+() [2/11]

std::string operator+ ( std::string  s,
float  f 
)
inline

◆ operator+() [3/11]

std::string operator+ ( std::string  s,
int  i 
)
inline

◆ operator+() [4/11]

std::string operator+ ( std::string  s,
long double  ld 
)
inline

◆ operator+() [5/11]

std::string operator+ ( std::string  s,
long int  i 
)
inline

◆ operator+() [6/11]

std::string operator+ ( std::string  s,
long long signed int  i 
)
inline

◆ operator+() [7/11]

std::string operator+ ( std::string  s,
long long unsigned int  i 
)
inline

◆ operator+() [8/11]

std::string operator+ ( std::string  s,
long unsigned int  i 
)
inline

◆ operator+() [9/11]

std::string operator+ ( std::string  s,
short int  i 
)
inline

◆ operator+() [10/11]

std::string operator+ ( std::string  s,
short unsigned int  i 
)
inline

◆ operator+() [11/11]

std::string operator+ ( std::string  s,
unsigned int  i 
)
inline

◆ operator+=() [1/11]

std::string & operator+= ( std::string &  s,
double  d 
)
inline

◆ operator+=() [2/11]

std::string & operator+= ( std::string &  s,
float  f 
)
inline

◆ operator+=() [3/11]

std::string & operator+= ( std::string &  s,
int  i 
)
inline

◆ operator+=() [4/11]

std::string & operator+= ( std::string &  s,
long double  ld 
)
inline

◆ operator+=() [5/11]

std::string & operator+= ( std::string &  s,
long int  i 
)
inline

◆ operator+=() [6/11]

std::string & operator+= ( std::string &  s,
long long signed int  i 
)
inline

◆ operator+=() [7/11]

std::string & operator+= ( std::string &  s,
long long unsigned int  i 
)
inline

◆ operator+=() [8/11]

std::string & operator+= ( std::string &  s,
long unsigned int  i 
)
inline

◆ operator+=() [9/11]

std::string & operator+= ( std::string &  s,
short int  i 
)
inline

◆ operator+=() [10/11]

std::string & operator+= ( std::string &  s,
short unsigned int  i 
)
inline

◆ operator+=() [11/11]

std::string & operator+= ( std::string &  s,
unsigned int  i 
)
inline