SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
stringops.hpp File Reference

String conversion and manipulation. More...

Go to the source code of this file.

Classes

struct  shore::iless
 A case insensitive string comparator. More...
 
class  shore::tok_occurrence< iter_type, delim_type >
 Tokenizer for strings and other containers. Splits at delimiter occurences. More...
 
class  shore::tok_occurrences< iter_type, delim_iter_type >
 Tokenizer for strings and other containers. Splits at delimiter occurences and allows multiple alternative delimiters. More...
 
class  shore::tok_transition< iter_type, delim_type >
 Tokenizer for strings and other containers. Splits at no-delimiter-delimiter transitions (and vice versa). More...
 
class  shore::tok_transitions< iter_type, delim_iter_type >
 Tokenizer for strings and other containers. Splits at no-delimiter-delimiter transitions (and vice versa) and allows multiple alternative delimiters. More...
 
class  shore::ltok_occurrence< iter_type, delim_iter_type >
 Tokenizer for strings and other containers. Splits at delimiter occurences, where the delimiter consists of multiple characters/items. More...
 
class  shore::ltok_transition< iter_type, delim_iter_type >
 Tokenizer for strings and other containers. Splits at no-delimiter-delimiter transitions (and vice versa), where the delimiter consists of multiple characters/items. More...
 
class  shore::valterm_iterator< T, termval >
 A forward iterator over null-terminated character arrays or other value-terminated arrays. More...
 
class  shore::chartable< conv_type, initfunc >
 String conversion tables. More...
 
struct  shore::manipd< T >
 Class that associates values with stream manipulators and formatting. More...
 

Namespaces

 shore
 SHORE core API.
 

Constant Groups

 shore
 SHORE core API.
 

Macros

#define MAKE_ENUM_TRAITS(T)
 Declare an enum_traits specialization for enum<->string conversion. More...
 
#define S_MAKE_ENUM_TRAITS(T)
 

Functions

void shore::tolower (std::string &str)
 In-place conversion to lower case.
 
void shore::toupper (std::string &str)
 In-place conversion to upper case.
 
template<typename Iter >
bool shore::is_numeric (Iter b, Iter e)
 Test if a range of characters contains only digits.
 
std::vector< std::string > shore::split (const std::string &s, const char delim='\t')
 Tokenize a string. Splits at delimiter occurences.
 
std::vector< std::string > shore::split (const std::string &s, const char *const delims)
 Tokenize a string. Splits at delimiter occurences and allows multiple alternative delimiters.
 
std::vector< std::string > shore::tsplit (const std::string &s, const char delim='\t')
 Tokenize a string. Splits at no-delimiter-delimiter transitions (and vice versa).
 
std::vector< std::string > shore::tsplit (const std::string &s, const char *const delims)
 Tokenize a string. Splits at no-delimiter-delimiter transitions (and vice versa) and allows multiple alternative delimiters.
 
std::vector< std::string > shore::lsplit (const std::string &s, const std::string &delim)
 Tokenize a string. Splits at delimiter occurences, where the delimiter consists of multiple characters.
 
std::vector< std::string > shore::ltsplit (const std::string &s, const std::string &delim)
 Tokenize a string. Splits at no-delimiter-delimiter transitions (and vice versa), where the delimiter consists of multiple characters/items.
 
template<class StringIterator >
size_t shore::split (const std::string &s, StringIterator destination, const char delim='\t', const size_t limit=std::numeric_limits< size_t >::max()-1)
 Tokenize a string into a container. More...
 
template<class StringIterator >
size_t shore::split (const std::string &s, StringIterator destination, const char *const delims, const size_t limit=std::numeric_limits< size_t >::max()-1)
 Tokenize a string into a container using multiple alternative delimiters. More...
 
template<class StringIterator >
size_t shore::tsplit (const std::string &s, StringIterator destination, const char delim='\t', const size_t limit=std::numeric_limits< size_t >::max()-1)
 Tokenize a into a container. Splits at no-delimiter-delimiter transitions (and vice versa). More...
 
template<class StringIterator >
size_t shore::tsplit (const std::string &s, StringIterator destination, const char *const delims, const size_t limit=std::numeric_limits< size_t >::max()-1)
 Tokenize a into a container using multiple alternative delimiters. Splits at no-delimiter-delimiter transitions (and vice versa). More...
 
template<typename T >
std::string shore::to_string (const T &value, const int prec)
 Format the given value as a string.
 
template<typename T , int precision>
std::string shore::to_string (const T &value)
 Format the given value as a string.
 
template<typename T >
std::string shore::to_string (const T &value)
 Format the given value as a string.
 
template<>
std::string shore::to_string< bool > (const bool &value)
 
template<>
std::string shore::to_string< std::ostringstream > (const std::ostringstream &str)
 Format the given value as a string (override the template for ostringstreams).
 
template<>
std::string shore::to_string< std::string > (const std::string &s)
 Format the given value as a string (override the template for strings).
 
template<class Iter >
std::string shore::join (Iter begin, Iter end, const std::string &delim)
 Join the values in a range into a string.
 
template<class Iter >
std::string shore::join (const Iter begin, const Iter end)
 Join the values in a range into a string, using TAB as delimiter.
 
template<typename T >
std::string shore::join (const std::vector< T > &sv, const std::string &delim)
 Join the values in a std::vector into a string.
 
template<typename T >
std::string shore::join (const std::vector< T > &sv)
 Join the values in a std::vector into a string, using TAB as delimiter.
 
template<class Iteriter >
std::string shore::ijoin (Iteriter begin, Iteriter end, const std::string &delim)
 Join the given range of string iterators into a string.
 
template<typename Iter >
std::string shore::ijoin (const std::vector< Iter > &sv, const std::string &delim)
 Join the given vector of string iterators into a string.
 
std::vector< std::string > shore::join2d (std::vector< std::vector< std::string > > &pv, const std::string &delim)
 Join a 2-dimensional std::vector into a one-dimensional std::vector<std::string> >.
 
template<typename T >
std::string shore::to_string (const std::vector< T > &v)
 Format the given value as a string (override the template for vector).
 
template<typename T >
std::string shore::to_string (const std::vector< std::vector< T > > &v)
 Format the given value as a string (override the template for vector).
 
template<typename conv_type , void(*)(conv_type *const) initfunc>
const conv_type * shore::chartab ()
 String conversion tables.
 
void shore::ctabinit_digit (int *const table)
 String conversion tables.
 
template<int exp>
void shore::ctabinit_expdigit (int64_t *const table)
 String conversion tables.
 
void shore::ctabinit_base32hex (int *const table)
 String conversion tables.
 
template<typename iter_type >
uint64_t shore::parse_uint64 (iter_type beg, iter_type end)
 Parse an unsigned int from an iterator range.
 
template<typename iter_type >
int64_t shore::parse_int64 (iter_type beg, iter_type end)
 Parse a signed int from an iterator range.
 
template<typename T >
void shore::parse_value (T *dest, const std::string &str)
 Parse a value from a string. More...
 
template<>
void shore::parse_value< std::string > (std::string *dest, const std::string &str)
 Parse a value from a string (std::string specialization).
 
template<>
void shore::parse_value< bool > (bool *dest, const std::string &str)
 Parse a value from a string (bool specialization). More...
 
template<typename T >
shore::parse_value (const std::string &str)
 Parse a value from a string.
 
template<>
double shore::parse_value< double > (const std::string &str)
 Parse a value from a string (speedup for double).
 
template<typename iter_type >
void shore::parse_value (std::string *const dest, iter_type beg, iter_type end)
 Parse a value from an iterator range.
 
template<typename iter_type >
void shore::parse_value (uint64_t *const dest, iter_type beg, iter_type end)
 Parse a value from an iterator range.
 
template<typename iter_type >
void shore::parse_value (int64_t *const dest, iter_type beg, iter_type end)
 Parse a value from an iterator range.
 
template<typename T , typename iter_type >
void shore::parse_value (T *const dest, iter_type beg, iter_type end, typename boost::enable_if< boost::is_integral< T > >::type *dummy_int=0, typename boost::enable_if< boost::is_signed< T > >::type *dummy_sign=0)
 Parse a value from an iterator range.
 
template<typename T , typename iter_type >
void shore::parse_value (T *const dest, iter_type beg, iter_type end, typename boost::enable_if< boost::is_integral< T > >::type *dummy_int=0, typename boost::disable_if< boost::is_signed< T > >::type *dummy_sign=0)
 Parse a value from an iterator range.
 
template<typename Dest , typename Default >
void shore::parse_envvar (Dest *const dest, const std::string &envvar, const Default &def)
 Stores the value of an environment variable into a variable, or or assigns the given default if the environment variable is not set.
 
template<typename Dest , typename Default >
Dest shore::parse_envvar (const std::string &envvar, const Default &def)
 Gets the value of an environment variable, or returns the given default if the environment variable is not set.
 
bool shore::charcmp_ci (const char a, const char b)
 Case insensitive char comparator function.
 
bool shore::charcmp_equal_ci (const char a, const char b)
 Case insensitive test if two chars are equal.
 
template<typename Iterator >
bool shore::equal_ci (const std::string &s, Iterator b, Iterator e)
 Case insensitive test if a string equals the character in a range.
 
bool shore::starts_with_cs (const std::string &s, const std::string &pref)
 Case sensitive test if a string starts with a given prefix.
 
bool shore::ends_with_cs (const std::string &s, const std::string &suff)
 Case sensitive test if a string ends with a given suffix.
 
bool shore::starts_with_ci (const std::string &s, const std::string &pref)
 Case insensitive test if a string starts with a given prefix.
 
bool shore::ends_with_ci (const std::string &s, const std::string &suff)
 Case insensitive test if a string ends with a given suffix.
 
std::string shore::toggle_suffix_cs (const std::string &s, const std::string &suff)
 Add or remove the given suffix to a string (case sensitive).
 
std::string shore::remove_suffix_cs (const std::string &s, const std::string &suff)
 Remove the given suffix from a string, should it exist (case sensitive).
 
std::string shore::toggle_suffix_ci (const std::string &s, const std::string &suff)
 Add or remove the given suffix to a string (case insensitive).
 
std::string shore::remove_suffix_ci (const std::string &s, const std::string &suff)
 Remove the given suffix from a string, should it exist (case insensitive).
 
template<class T >
std::string shore::lprefix (const T &what, const std::string &prefix)
 Add a prefix to each line in a string.
 
std::vector< std::string > shore::wrap_line (const std::string &line, const size_t maxlw)
 Wrap a line of text at white space positions.
 
void shore::expand_tabs (std::istream &in, std::ostream &out, const int colsep=4, const std::vector< size_t > &maxwidths=std::vector< size_t >(), const bool headings=true)
 Aligns all TAB positions in a text by converting them to spaces.
 
std::string shore::expand_tabs (const std::string &str, const int colsep=4, const std::vector< size_t > &maxwidths=std::vector< size_t >(), const bool headings=true)
 Aligns all TAB positions in a text by converting them to spaces.
 
template<class Iter >
std::string shore::expand_tabs (const std::string &str, const int colsep, Iter b_maxwidths, Iter e_maxwidths, const bool headings=true)
 Aligns all TAB positions in a text by converting them to spaces.
 
template<typename Iter >
std::pair< Iter, Iter > shore::trim (Iter beg, Iter end)
 Get a pair of iterators indicating the white space trimmed version of the given range.
 
template<class T >
std::ostream & shore::operator<< (std::ostream &os, const manipd< T > &mp)
 
template<class T >
std::istream & shore::operator>> (std::istream &is, manipd< T > &mp)
 
template<typename exception_type >
void shore::throw_exception (const std::string &msg)
 
template<>
void shore::throw_exception< void > (const std::string &msg)
 
template<class exception_type , class Iter >
Iter shore::match_arg (const std::string &arg, Iter beg, Iter end, const std::string &exlabel=std::string("match_arg"))
 Try to find a match for a string in a given set of possible values. More...
 
template<class Ex , class Iter >
size_t shore::match_arg_idx (const std::string &arg, Iter beg, Iter end, const std::string &exlabel=std::string("match_arg"))
 Version of match_arg() that returns an array index instead of an iterator.
 
template<typename Enum , typename Iter >
std::istream & shore::parse_enum (std::istream &in, Enum &dest, Iter beg, Iter end)
 Parse an enum value using match_arg().
 
template<typename Enum , int SZ>
std::istream & shore::parse_enum (std::istream &in, Enum &dest, const std::string(&templ)[SZ])
 Parse an enum value using match_arg().
 
template<typename Enum >
enum_traits< Enum >::istream_type & shore::operator>> (std::istream &in, Enum &en)
 Enum<-string conversion operator.
 
template<typename Enum >
enum_traits< Enum >::ostream_type & shore::operator<< (std::ostream &out, const Enum &en)
 Enum->string conversion operator.
 

Variables

const int *const shore::ctab_digit
 
const int64_t *const shore::ctab_expdigit [21]
 

Detailed Description

String conversion and manipulation.

Author
Felix Ott

Macro Definition Documentation

#define MAKE_ENUM_TRAITS (   T)
Value:
namespace shore {\
template<>\
struct enum_traits<T>\
{\
typedef std::istream istream_type;\
typedef std::ostream ostream_type;\
static const std::string values;\
static const std::string description;\
};\
}

Declare an enum_traits specialization for enum<->string conversion.

#define S_MAKE_ENUM_TRAITS (   T)
Value:
template<>\
struct enum_traits<T>\
{\
typedef std::istream istream_type;\
typedef std::ostream ostream_type;\
static const std::string values;\
static const std::string description;\
};