Audio Processing Framework (APF) version 0.5.0
|
Helper functions for string manipulation. More...
Functions | |
template<typename T > | |
std::string | A2S (const T &input) |
Converter "Anything to String". More... | |
template<typename out_T > | |
bool | convert (std::istream &input, out_T &output) |
Convert a stream to a given type. More... | |
bool | convert (std::istream &input, bool &output) |
This is a overloaded function for boolean output. More... | |
template<typename out_T > | |
bool | S2A (const std::string &input, out_T &output) |
Converter "String to Anything". More... | |
bool | S2A (const std::string &input, std::string &output) |
Overloaded function with a std::string as output. More... | |
template<typename out_T > | |
out_T | S2RV (const std::string &input, out_T def) |
Converter "String to Return Value". More... | |
std::string | S2RV (const std::string &input, const char *def) |
Overloaded function with C-string as default value. More... | |
template<typename out_T , typename in_T > | |
out_T | S2RV (const in_T &input) |
Throwing version of S2RV(). More... | |
template<typename char_T , typename traits > | |
std::basic_ios< char_T, traits > & | clear_iostate_except_eof (std::basic_ios< char_T, traits > &stream) |
Clear the state of a stream but leave eofbit as is. More... | |
template<int digits, typename char_T , typename traits , typename out_T > | |
std::basic_istream< char_T, traits > & | convert_chars (std::basic_istream< char_T, traits > &input, out_T &output) |
Remove a specified number of characters from a stream and convert them to a numeric type. More... | |
template<typename char_T , typename traits > | |
std::basic_istream< char_T, traits > & | remove_char (std::basic_istream< char_T, traits > &input, const char_T character) |
Remove a character from a stream and check if it is the one given as parameter. More... | |
template<typename char_T , typename traits > | |
std::basic_istream< char_T, traits > & | remove_colon (std::basic_istream< char_T, traits > &input) |
Remove a colon from an input stream. More... | |
template<template< typename, typename, typename > class in_T, typename char_T , typename traits , typename Allocator , typename out_T > | |
bool | string2time (const in_T< char_T, traits, Allocator > &input, out_T &output) |
Convert time string to numeric value in seconds. More... | |
template<typename char_T , typename out_T > | |
bool | string2time (const char_T *input, out_T &output) |
Overloaded function for a character array. More... | |
Helper functions for string manipulation.
std::string apf::str::A2S | ( | const T & | input | ) |
Converter "Anything to String".
Converts a numeric value to a std::string
. A boolean value is converted to either "true"
or "false"
.
T | given input type |
input | anything you want to convert to a std::string |
std::stringstream
could handle it, a std::string
representation of input, if something went wrong, an empty string. Definition at line 52 of file stringtools.h.
Referenced by apf::mex::convert(), apf::load_sndfile(), and apf::parameter_map::set().
|
inline |
Convert a stream to a given type.
If the item of interest is followed by anything non-whitespace, the conversion is invalid and false is returned.
out_T | desired output type |
[in,out] | input | input stream |
[out] | output | output |
Definition at line 69 of file stringtools.h.
Referenced by S2A().
|
inline |
This is a overloaded function for boolean output.
[in,out] | input | input stream |
[out] | output | output (boolean) |
Definition at line 90 of file stringtools.h.
bool apf::str::S2A | ( | const std::string & | input, |
out_T & | output | ||
) |
Converter "String to Anything".
Convert a std::string
or C-string to a given numeric type. Also, convert "1"
, "true"
, "0"
and "false"
to the respective boolean values.
out_T | desired output type (must have an input stream operator!) |
input | a std::string or char* | |
[out] | output | result converted to the desired type. |
Definition at line 122 of file stringtools.h.
References convert().
Referenced by S2RV().
|
inline |
Overloaded function with a std::string
as output.
The input is simply assigned to the output.
Definition at line 132 of file stringtools.h.
out_T apf::str::S2RV | ( | const std::string & | input, |
out_T | def | ||
) |
Converter "String to Return Value".
Convert a string (either a zero-terminated char*
or a std::string
) to a given numeric type and return the result.
out_T | desired output type (must have an input stream operator!) |
input | string to be converted. |
def | default value. |
input
converted to the desired type. If conversion failed, the default value def
is returned. def
, there is no way to know if the conversion was successful, sorry! You have to use S2A() if you want to make sure. Definition at line 152 of file stringtools.h.
References S2A().
Referenced by S2RV().
|
inline |
Overloaded function with C-string as default value.
std::string
Definition at line 162 of file stringtools.h.
References S2A().
out_T apf::str::S2RV | ( | const in_T & | input | ) |
Throwing version of S2RV().
int_T | string type |
out_T | desired output type (must have an input stream operator!) |
input | string to be converted. |
input
converted to the desired type. If conversion failed, an exception is thrown. std::invalid_argument | if input cannot be converted to out_T . |
Definition at line 178 of file stringtools.h.
std::basic_ios< char_T, traits > & apf::str::clear_iostate_except_eof | ( | std::basic_ios< char_T, traits > & | stream | ) |
Clear the state of a stream but leave eofbit
as is.
It can be used as stream modifier to ignore failbit
and badbit
but still respect eofbit:
This may be useful because some implementations (e.g. libc++) set failbit
if std::ws
is used to extract whitespace from the end of a stream but no whitespace is present.
char_T | character type of the stream (also used for the output) |
traits | traits class for std::basic_ios |
[in,out] | stream | the stream to manipulate |
Definition at line 206 of file stringtools.h.
Referenced by string2time().
std::basic_istream< char_T, traits > & apf::str::convert_chars | ( | std::basic_istream< char_T, traits > & | input, |
out_T & | output | ||
) |
Remove a specified number of characters from a stream and convert them to a numeric type.
If the stream flag skipws
is set, leading whitespace is removed first.
digits | number of digits to read. The rest of the template parameters are determined automatically. |
char_T | character type of the stream |
traits | traits class for std::basic_istream |
out_T | desired (numerical) output type |
[in,out] | input | input stream |
[out] | output | resulting number |
std::ios_base::failbit
to know if the conversion was successful. Definition at line 228 of file stringtools.h.
std::basic_istream< char_T, traits > & apf::str::remove_char | ( | std::basic_istream< char_T, traits > & | input, |
const char_T | character | ||
) |
Remove a character from a stream and check if it is the one given as parameter.
If the stream flag skipws
is set, leading whitespace is removed first.
char_T | character type of the stream (also used for the output) |
traits | traits class for std::basic_istream |
[in,out] | input | input stream |
character | character to remove |
std::ios_base::failbit
to know if the conversion was successful. Definition at line 270 of file stringtools.h.
Referenced by remove_colon().
std::basic_istream< char_T, traits > & apf::str::remove_colon | ( | std::basic_istream< char_T, traits > & | input | ) |
Remove a colon from an input stream.
This function is just a convenient shortcut for remove_char(stream, ':')
. Contrary to remove_char(), this can be used as a stream modifier like this:
If the stream flag skipws
is set, leading whitespace is removed first.
char_T | character type of the stream |
traits | traits class for std::basic_istream |
[in,out] | input | input stream |
std::ios_base::failbit
to know if there actually was a colon and that is was successfully removed. Definition at line 304 of file stringtools.h.
References remove_char().
Referenced by string2time().
bool apf::str::string2time | ( | const in_T< char_T, traits, Allocator > & | input, |
out_T & | output | ||
) |
Convert time string to numeric value in seconds.
input can be in format "h:mm:ss.x"
or "xx.x h|min|s|ms"
or just in seconds. Decimals and hours are optional. Time can also be negative. Multiple whitespace is allowed before and after. See http://www.w3.org/TR/SMIL2/smil-timing.html#Timing-ClockValueSyntax for the similar SMIL time syntax.
in_T | input string type (e.g. std::string ) |
char_T | character type of the input string (e.g. char ) |
traits | traits class for the string type in_T |
Allocator | allocator for the string type in_T |
out_T | desired output type |
input | time string (similar to SMIL format) | |
[out] | output | numeric result in seconds. This can be either of an integer or a floating point type. Conversion to an integer only works if the resulting value in seconds is a whole number. |
Definition at line 330 of file stringtools.h.
References clear_iostate_except_eof(), and remove_colon().
Referenced by string2time().
bool apf::str::string2time | ( | const char_T * | input, |
out_T & | output | ||
) |
Overloaded function for a character array.
char_T | character type of the input array |
out_T | desired output type |
input | character array holding time string | |
[out] | output | see above |
Definition at line 458 of file stringtools.h.
References string2time().