FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
FEAT::String Class Reference

String class implementation. More...

#include <string.hpp>

Inheritance diagram for FEAT::String:

Classes

class  NoCaseLess
 A class providing case-insensitive String comparison. More...
 

Public Member Functions

 String ()
 default constructor More...
 
 String (const char *str)
 CTOR. More...
 
 String (const char *str, size_type count)
 CTOR. More...
 
 String (const std::string &str)
 CTOR. More...
 
 String (const std::string &str, size_type offset, size_type count=npos)
 CTOR. More...
 
 String (const String &str)
 copy CTOR More...
 
 String (size_type count, char c)
 CTOR. More...
 
 String (std::string &&str)
 CTOR. More...
 
 String (String &&str)
 move CTOR More...
 
int compare_no_case (const String &other) const
 Compares two strings without regard to case. More...
 
bool ends_with (const char tail) const
 Checks whether this string ends with a specified character. More...
 
bool ends_with (const String &tail) const
 Checks whether this string ends with another string. More...
 
bool is_one_of (const String &set, const String &sep=" ", bool case_insensitive=false) const
 Checks whether this string is equal to one in a set of strings. More...
 
String lower () const
 Converts the string to lower case. More...
 
String pad_back (size_type len, char c=' ') const
 Pads the back of the string up to a desired length. More...
 
String pad_front (size_type len, char c=' ') const
 Pads the front of the string up to a desired length. More...
 
template<typename T_ >
bool parse (T_ &t) const
 Parses the string and stores its value in the provided variable. More...
 
void pop_back ()
 Removes the last character from the string. More...
 
void pop_front ()
 Removes the first character from the string. More...
 
void push_front (char value)
 Inserts a character at the front of the string. More...
 
size_type replace_all (const String &find_string, const String &replace_string)
 Replaces all occurrences of a substring by another substring. More...
 
std::deque< Stringsplit_by_charset (const String &charset) const
 Splits the string by a delimiter charset. More...
 
std::deque< Stringsplit_by_string (const String &delimiter) const
 Splits the string by a delimiter substring. More...
 
std::deque< Stringsplit_by_whitespaces () const
 Splits the string by white-spaces. More...
 
bool starts_with (const char head) const
 Checks whether this string starts with a specified character. More...
 
bool starts_with (const String &head) const
 Checks whether this string starts with another string. More...
 
String trim () const
 Trims the string of all white-spaces. More...
 
String trim (const String &charset) const
 Trims the string. More...
 
String trim_back () const
 Trims the back of the string of all white-spaces. More...
 
String trim_back (const String &charset) const
 Trims the back of the string. More...
 
String trim_front () const
 Trims the front of the string of all white-spaces. More...
 
String trim_front (const String &charset) const
 Trims the front of the string. More...
 
Stringtrim_me ()
 Trims this string of all white-spaces. More...
 
Stringtrim_me (const String &charset)
 Trims this string. More...
 
String trunc_back (size_type len) const
 Truncates the back of the string to a given maximum length. More...
 
String trunc_front (size_type len) const
 Truncates the front of the string to a given maximum length. More...
 
String upper () const
 Converts the string to upper case. More...
 

Static Public Member Functions

static const char * whitespaces ()
 Returns a null-terminated char string containing all white-space characters. More...
 

Detailed Description

String class implementation.

This class inherits from the STL class std::string, so in consequence any algorithm working with std::string will also work with this class.

Author
Peter Zajac

Definition at line 44 of file string.hpp.

Constructor & Destructor Documentation

◆ String() [1/9]

FEAT::String::String ( )
inline

default constructor

Definition at line 81 of file string.hpp.

Referenced by pad_back(), pad_front(), FEAT::stringify_join(), trim_back(), and trim_front().

◆ String() [2/9]

FEAT::String::String ( const char *  str)
inline

CTOR.

Definition at line 87 of file string.hpp.

◆ String() [3/9]

FEAT::String::String ( const char *  str,
size_type  count 
)
inline

CTOR.

Definition at line 93 of file string.hpp.

◆ String() [4/9]

FEAT::String::String ( const std::string &  str)
inline

CTOR.

Definition at line 99 of file string.hpp.

◆ String() [5/9]

FEAT::String::String ( std::string &&  str)
inline

CTOR.

Definition at line 106 of file string.hpp.

◆ String() [6/9]

FEAT::String::String ( const String str)
inline

copy CTOR

Definition at line 113 of file string.hpp.

◆ String() [7/9]

FEAT::String::String ( String &&  str)
inline

move CTOR

Definition at line 120 of file string.hpp.

◆ String() [8/9]

FEAT::String::String ( const std::string &  str,
size_type  offset,
size_type  count = npos 
)
inline

CTOR.

Definition at line 127 of file string.hpp.

◆ String() [9/9]

FEAT::String::String ( size_type  count,
char  c 
)
inline

CTOR.

Definition at line 133 of file string.hpp.

Member Function Documentation

◆ compare_no_case()

◆ ends_with() [1/2]

bool FEAT::String::ends_with ( const char  tail) const
inline

Checks whether this string ends with a specified character.

Parameters
[in]tailThe character that the back of this string is to be checked against.
Returns
true, if this ends with tail, otherwise false

Definition at line 791 of file string.hpp.

◆ ends_with() [2/2]

bool FEAT::String::ends_with ( const String tail) const
inline

Checks whether this string ends with another string.

Parameters
[in]tailThe string that the back of this string is to be checked against.
Returns
true, if this ends with tail, otherwise false

Definition at line 754 of file string.hpp.

Referenced by FEAT::Xml::Scanner::scan(), and FEAT::Xml::Scanner::scan_markup().

◆ is_one_of()

bool FEAT::String::is_one_of ( const String set,
const String sep = " ",
bool  case_insensitive = false 
) const
inline

Checks whether this string is equal to one in a set of strings.

Parameters
[in]setThe set of strings that this string is to be checked against, separated by sep.
[in]sepThe separator string.
[in]case_insensitiveSpecifies whether to perform a case sensitive or case insensitive comparison.
Returns
true, if this is equal to at least one of the substrings in set, otherwise false.

Definition at line 811 of file string.hpp.

References compare_no_case(), and split_by_string().

◆ lower()

String FEAT::String::lower ( ) const
inline

Converts the string to lower case.

Returns
The lower-case string.

Definition at line 652 of file string.hpp.

◆ pad_back()

String FEAT::String::pad_back ( size_type  len,
char  c = ' ' 
) const
inline

Pads the back of the string up to a desired length.

This function returns a string that is back-padded with a specific character up to a desired minimum length. If the length of this already has the desired minimum length, this function returns *this.

Note
This function is virtually the counter-part of trim_back() and trunc_back().
Parameters
[in]lenThe desired (minimum) length of the string.
[in]cThe character to be used for padding.
Returns
The padded string.

Definition at line 415 of file string.hpp.

References String().

Referenced by FEAT::Global::PMDCDSCMatrix< Global::Matrix< LAFEM::SparseMatrixBCSR< DT_, IT_, dim_, 1 >, MirrorV_, MirrorP_ >, Global::Matrix< LAFEM::SparseMatrixBCSR< DT_, IT_, 1, dim_ >, MirrorP_, MirrorV_ > >::_fmt_time(), FEAT::Assembly::VelocityInfo< DataType_, dim_ >::format_string(), FEAT::Assembly::ScalarErrorInfo< DataType_ >::format_string(), FEAT::Assembly::VectorErrorInfo< DataType_, dim_ >::format_string(), FEAT::MemoryUsage::get_formatted_memory_usage(), FEAT::Statistics::get_formatted_solver_internals(), FEAT::Statistics::get_formatted_times(), FEAT::Meshopt::HyperelasticityFunctional< DT_, IT_, Trafo_, CellFunctionalType_, RefCellTrafo_ >::info(), FEAT::Meshopt::ConcentrationFunctionDefault< DT_ >::info(), FEAT::Meshopt::ConcentrationFunctionPowOfDist< DT_ >::info(), FEAT::Meshopt::RumpfFunctionalBase< DataType_ >::info(), FEAT::Control::Meshopt::DuDvFunctionalControl< DT_, IT_, DomainControl_ >::info(), FEAT::Control::Meshopt::HyperelasticityFunctionalControl< DT_, IT_, DomainControl_, Hyperelasticity_ >::info(), FEAT::Meshopt::ChartDistanceFunction< ElementalFunction_, Trafo_, RefCellTrafo_ >::info(), FEAT::Assembly::FunctionIntegralInfo< DataType_, ValueType_, GradientType_, HessianType_ >::print_field_info(), FEAT::Assembly::FunctionIntegralInfo< DataType_, ValueType_, GradientType_, HessianType_ >::print_norms(), and FEAT::Control::Statistics::report().

◆ pad_front()

String FEAT::String::pad_front ( size_type  len,
char  c = ' ' 
) const
inline

◆ parse()

template<typename T_ >
bool FEAT::String::parse ( T_ &  t) const
inline

Parses the string and stores its value in the provided variable.

Parameters
[out]tA transient reference to an object that receives the parsed value, if the parse succeeded.
Returns
true, if the parse succeeds, otherwise false.

Definition at line 837 of file string.hpp.

References trim().

Referenced by FEAT::Geometry::Atlas::BezierParamsParser< Mesh_ >::content(), FEAT::Cubature::DriverFactory< Driver_, Shape_, true >::create(), and FEAT::Cubature::Scalar::DriverFactory< Driver_, true >::create().

◆ pop_back()

void FEAT::String::pop_back ( )
inline

Removes the last character from the string.

Definition at line 245 of file string.hpp.

Referenced by FEAT::PropertyMap::read(), and FEAT::Xml::Scanner::scan_markup().

◆ pop_front()

void FEAT::String::pop_front ( )
inline

Removes the first character from the string.

Definition at line 239 of file string.hpp.

Referenced by FEAT::Analytic::ParsedVectorFunction< dom_dim_, img_dim_ >::parse(), FEAT::PropertyMap::read(), and FEAT::Xml::Scanner::scan_markup().

◆ push_front()

void FEAT::String::push_front ( char  value)
inline

Inserts a character at the front of the string.

Parameters
[in]valueThe character to the pushed.

Definition at line 233 of file string.hpp.

References FEAT::value.

◆ replace_all()

size_type FEAT::String::replace_all ( const String find_string,
const String replace_string 
)
inline

Replaces all occurrences of a substring by another substring.

This function will replace all occurrences of a substring find_string by replace_string.

Note
This function is not successive, i.e. it will not replace an occurrence of the find-string if this occurrence is a result of a previous replacement, e.g. for the combination *this = "aaa", find_string = "aa" and replace_string = "pa" the resulting string will be "paa" and not "ppa".
Parameters
[in]find_stringThe substring that is to be searched for. Must not be empty.
[in]replace_stringThe substring that is to be replaced by.
Returns
The total number of replacements made.

Definition at line 598 of file string.hpp.

◆ split_by_charset()

std::deque< String > FEAT::String::split_by_charset ( const String charset) const
inline

Splits the string by a delimiter charset.

This function separates the string into substrings, where two substrings are separated a delimiter substring consisting only of delimiter charset characters.

This function is frequently used by parsers, which split strings by whitespace characters.

Example:
When using the default whitespace delimiter character set, the string " 5 42\t7 " will be split into 3 substrings: "5", "42" and "7".

Parameters
[in]charsetThe character set which is to be treated as the delimiter charset.
Returns
A deque of the sub-strings that resulted from the splitting.

Definition at line 467 of file string.hpp.

Referenced by FEAT::Dist::Comm::allprint(), and split_by_whitespaces().

◆ split_by_string()

std::deque< String > FEAT::String::split_by_string ( const String delimiter) const
inline

Splits the string by a delimiter substring.

This function separates the string into substrings, where the substrings are separated by a delimiter string.

Example:
When using "," as a delimiter string, the input string " ,5,,3" will be split into 4 substrings: " ", "5", "" and "3".

Parameters
[in]delimiterThe string that is to be treated as a delimiter.
Returns
A deque of the sub-strings that resulted from the splitting.

Definition at line 539 of file string.hpp.

Referenced by is_one_of(), FEAT::Analytic::Common::ParProfileBase< DataType_ >::parse(), and FEAT::Geometry::MeshFileReader::read_root_markup().

◆ split_by_whitespaces()

std::deque< String > FEAT::String::split_by_whitespaces ( ) const
inline

◆ starts_with() [1/2]

bool FEAT::String::starts_with ( const char  head) const
inline

Checks whether this string starts with a specified character.

Parameters
[in]headThe character that the front of this string is to be checked against.
Returns
true, if this starts with head, otherwise false

Definition at line 777 of file string.hpp.

◆ starts_with() [2/2]

bool FEAT::String::starts_with ( const String head) const
inline

Checks whether this string starts with another string.

Parameters
[in]headThe string that the front of this string is to be checked against.
Returns
true, if this starts with head, otherwise false

Definition at line 731 of file string.hpp.

Referenced by FEAT::SimpleArgParser::query_unsupported(), FEAT::Xml::Scanner::scan(), FEAT::Xml::Scanner::scan_markup(), and FEAT::MemoryUsage::stamp().

◆ trim() [1/2]

String FEAT::String::trim ( ) const
inline

Trims the string of all white-spaces.

Note
If you want to trim this string, use trim_me() instead.
Returns
The trimmed string.

Definition at line 341 of file string.hpp.

References trim(), and whitespaces().

Referenced by parse(), trim(), and trim_me().

◆ trim() [2/2]

◆ trim_back() [1/2]

String FEAT::String::trim_back ( ) const
inline

Trims the back of the string of all white-spaces.

Returns
The back-trimmed string.

Definition at line 309 of file string.hpp.

References trim_back(), and whitespaces().

Referenced by trim_back().

◆ trim_back() [2/2]

String FEAT::String::trim_back ( const String charset) const
inline

Trims the back of the string.

This method removes any trailing characters contained in the character set from the string.

Parameters
[in]charsetThe character set which is to be trimmed from the back of the string.
Returns
The back-trimmed string.

Definition at line 293 of file string.hpp.

References String().

Referenced by trim().

◆ trim_front() [1/2]

String FEAT::String::trim_front ( ) const
inline

Trims the front of the string of all white-spaces.

Returns
The front-trimmed string.

Definition at line 277 of file string.hpp.

References trim_front(), and whitespaces().

Referenced by trim(), and trim_front().

◆ trim_front() [2/2]

String FEAT::String::trim_front ( const String charset) const
inline

Trims the front of the string.

This method removes any leading characters contained in the character set from the string.

Parameters
[in]charsetThe character set which is to be trimmed from the front of the string.
Returns
The front-trimmed string.

Definition at line 261 of file string.hpp.

References String().

◆ trim_me() [1/2]

String & FEAT::String::trim_me ( )
inline

Trims this string of all white-spaces.

Note
If you want to have the trimmed string without modifying this string, use trim() instead.
Returns
*this

Definition at line 370 of file string.hpp.

References trim().

◆ trim_me() [2/2]

String & FEAT::String::trim_me ( const String charset)
inline

Trims this string.

This method removes any leading and trailing characters contained in the character set from this string.

Note
If you want to have the trimmed string without modifying this string, use trim() instead.
Parameters
[in]charsetThe character set which is to be trimmed from the string.
Returns
*this

Definition at line 358 of file string.hpp.

References trim().

Referenced by FEAT::LAFEM::PowerColMatrix< SubType_, blocks_ >::PowerColMatrix(), FEAT::LAFEM::PowerDiagMatrix< SubType_, blocks_ >::PowerDiagMatrix(), FEAT::LAFEM::PowerRowMatrix< SubType_, blocks_ >::PowerRowMatrix(), FEAT::LAFEM::TupleDiagMatrix< First_, Rest_ >::TupleDiagMatrix(), FEAT::PropertyMap::query(), FEAT::PropertyMap::query_section(), FEAT::PropertyMap::read(), FEAT::LAFEM::SaddlePointMatrix< MatrixA_, MatrixB_, MatrixD_ >::read_from(), and FEAT::Xml::Scanner::read_next_line().

◆ trunc_back()

String FEAT::String::trunc_back ( size_type  len) const
inline

Truncates the back of the string to a given maximum length.

Parameters
[in]lenThe desired maximum length of the string.
Returns
The truncated string.

Definition at line 444 of file string.hpp.

◆ trunc_front()

String FEAT::String::trunc_front ( size_type  len) const
inline

Truncates the front of the string to a given maximum length.

Parameters
[in]lenThe desired maximum length of the string.
Returns
The truncated string.

Definition at line 430 of file string.hpp.

◆ upper()

String FEAT::String::upper ( ) const
inline

Converts the string to upper case.

Returns
The upper-case string.

Definition at line 630 of file string.hpp.

◆ whitespaces()

static const char * FEAT::String::whitespaces ( )
inlinestatic

Returns a null-terminated char string containing all white-space characters.

Definition at line 222 of file string.hpp.

Referenced by FEAT::Xml::Scanner::scan_markup(), split_by_whitespaces(), trim(), trim_back(), and trim_front().


The documentation for this class was generated from the following file: