|
NAMEticc_string - A collection of C++ string manipulating utilities.SYNOPSIS#include ticcutils/StringOps.husing namespace TiCC; DESCRIPTIONTicc String Utilities provides a few convenient functions for manipulating C++ 'string' objects. These functions are widely used in the TiCC software stack , but are of general use too.List of Functionsstring trim( const string& in, const string& filter= " \t\r\n" );Remove from in all leading and trailing characters
that are present in filter.
Embedded characters are retained. string trim_front( const string& in, const string& filter = " \t\r\n" ); Remove from in all leading characters that are
present in filter.
Embedded characters are retained. string trim_back( const string& in, const string& filter = " \t\r\n" ); Remove from in all trailing characters that are
present in filter.
Embedded characters are retained. void to_lower( string& s ); convert all characters in s to lowercase
filter.
void to_upper( string& s ); convert all characters in s to uppercase
filter.
string lowercase( const string& in ); Return a string that contains the lowercase of the
characters in in.
string uppercase( const string& in ); Return a string that contains the uppercase of the
characters in in.
size_t split_at( const string& s, vector<string>& vec, const string& sep, bool exact=false ); split the input string s at every position of the
string sep and return the parts in the string vector vec.
consecutive occurrences of sep are all skipped, so vec will never contain empty strings, except when exact is set to true. return value: The size of vec. size_t split_at_first_of( const string& s, vector<string>& vec, const string& filter, bool exact=false ); split the input string s at every occurrence of
one of the characters from filter and return the parts in the string
vector vec.
consecutive occurrences of filter characters are all skipped, so vec will never contain empty strings, except when exact is set to true. return value: The size of vec. inline size_t split( const string& s, vector<string>& vec, bool exact=false return split_at_first_of( s, vec, " \t\r\n" ); } split the input string s at every occurrence of a
whitespace character, and return the parts in the string vector vec
consecutive occurrences of filter characters are all skipped, so vec will never contain empty strings, except when exact is set to true. return value: The size of vec bool match_front( const string& s, const string& f ); does the string s start with the string f
?
bool match_back( const string& s, const string& b ); does the string s end with the string b
?
template< typename T > T stringTo( const std::string& s ) convert the string s into a value of type T
Might throw when the conversion fails. template< typename T > bool stringTo( const std::string& s, T& result ) convert the string s into a result value of
type T return false when the conversion fails, otherwise returns
true
template<> bool stringTo( const std::string& s ) convert the string s into a value of type
bool
The string values: YES , TRUE , 1 yield true (case insensitive) The string values: NO , FALSE , 0 yield false (case insensitive) Will throw when conversion fails. template< typename T > string toString ( const T& obj ); convert the obj of type T to a string. It
uses the << output operator for obj so it will fail if
that operator is unavailable
string basename( const string& f ); returns the basename for filename f. The basename
is defined as the string after the last / in f. If there is no
/ present, it will return the input string f.
string dirname( const string& f ); returns the pathname for filename f. The pathname
is defined as the string before the last / in f. If there is no
/ present, it will return ..
string format_nonascii( const string& s ); given a string s with possibly unprintable
(non-ascii) characters, produce a string where these are replaced by
hexadecimal representations. Useful for debugging Unicode stuff.
AUTHORSKo van der Sloot lamasoftware@science.ru.nl
Visit the GSP FreeBSD Man Page Interface. |