Claw  1.7.3
Classes | Functions
claw::text Namespace Reference

Everything about text processing. More...

Classes

class  kmp
 Exact pattern finding with the Knuth-Morris-Pratt's algorithm. More...

Functions

template<typename StreamType , typename StringType >
StreamType & getline (StreamType &is, StringType &str)
 A portable version of std::getline( is, str, '\n' ) that removes a tailing '\r'.
template<typename StringType >
void trim_left (StringType &str, const typename StringType::value_type *const s=" ")
 Remove characters at the begining of a string.
template<typename StringType >
void trim_right (StringType &str, const typename StringType::value_type *const s=" ")
 Remove characters at the end of a string.
template<typename StringType >
void trim (StringType &str, const typename StringType::value_type *const s=" ")
 Remove characters at the begining end at the end of a string.
template<typename StringType >
void squeeze (StringType &str, const typename StringType::value_type *const s)
 Squeeze successive characters of a string into one character.
template<typename StringType >
std::size_t replace (StringType &str, const StringType &e1, const StringType &e2)
 Replace a set of characters by other characters.
template<typename T , typename StringType >
bool is_of_type (const StringType &str)
 Test if the content of a string is immediately convertible to a type.
template<typename Sequence >
void split (Sequence &sequence, const typename Sequence::value_type &str, const typename Sequence::value_type::value_type sep)
 Split a string into several substrings, according to a given separator.
template<typename Sequence >
void split (Sequence &sequence, typename Sequence::value_type::const_iterator first, typename Sequence::value_type::const_iterator last, const typename Sequence::value_type::value_type sep)
 Split a string into several substrings, according to a given separator.
template<typename InputIterator , typename OutputIterator >
void c_escape (InputIterator first, InputIterator last, OutputIterator out)
 Find escaped symbols in a sequence of characters and replace them by their c-equivalent.
template<typename StringType >
bool glob_match (const StringType &pattern, const StringType &text, const typename StringType::value_type any_sequence= '*', const typename StringType::value_type zero_or_one= '?', const typename StringType::value_type any= '.')
 Check if a string matches a given pattern.
template<typename StringType >
bool glob_potential_match (const StringType &pattern, const StringType &text, const typename StringType::value_type any_sequence= '*', const typename StringType::value_type zero_or_one= '?', const typename StringType::value_type any= '.')
 Check if a string may match a given pattern.

Detailed Description

Everything about text processing.

Function Documentation

template<typename InputIterator , typename OutputIterator >
void claw::text::c_escape ( InputIterator  first,
InputIterator  last,
OutputIterator  out 
)

Find escaped symbols in a sequence of characters and replace them by their c-equivalent.

Parameters
firstIterator on the beginning of the string to escape.
lastIterator just past the end of the string to escape.
outIterator on the beginning of the output string.
Precondition
out points on a range long enough to store the resulting string.
std::string s("\\a\\t\\n\\r");
std::string r;
claw::text::c_escape( s.begin(), s.end(), std::insert_iterator(r, r.end()) );
if ( r == "\a\t\n\r" )
std::cout << "It works!" << std::endl;
Remarks
This method has not been tested with wide chars yet.

Definition at line 261 of file string_algorithm.tpp.

References claw::find_first_not_of().

template<typename StreamType , typename StringType >
StreamType & claw::text::getline ( StreamType &  is,
StringType &  str 
)

A portable version of std::getline( is, str, '\n' ) that removes a tailing '\r'.

Parameters
isThe stream in which we read.
strThe line read from the stream.

Definition at line 46 of file string_algorithm.tpp.

Referenced by split().

template<typename StringType >
bool claw::text::glob_match ( const StringType &  pattern,
const StringType &  text,
const typename StringType::value_type  any_sequence = '*',
const typename StringType::value_type  zero_or_one = '?',
const typename StringType::value_type  any = '.' 
)

Check if a string matches a given pattern.

Parameters
patternThe pattern.
textThe text to check.
any_sequenceA value representing any sequence of values, empty or not.
zero_or_oneA value representing any value or no value.
anyA value representing any value.

Definition at line 338 of file string_algorithm.tpp.

References claw::glob_match().

template<typename StringType >
bool claw::text::glob_potential_match ( const StringType &  pattern,
const StringType &  text,
const typename StringType::value_type  any_sequence = '*',
const typename StringType::value_type  zero_or_one = '?',
const typename StringType::value_type  any = '.' 
)

Check if a string may match a given pattern.

Parameters
patternThe pattern.
textThe text to check.
any_sequenceA value representing any sequence of values, empty or not.
zero_or_oneA value representing any value or no value.
anyA value representing any value.

Definition at line 360 of file string_algorithm.tpp.

References claw::glob_potential_match().

template<typename T , typename StringType >
bool claw::text::is_of_type ( const StringType &  str)

Test if the content of a string is immediately convertible to a type.

Parameters
strThe string to test.

Definition at line 180 of file string_algorithm.tpp.

template<typename StringType >
std::size_t claw::text::replace ( StringType &  str,
const StringType &  e1,
const StringType &  e2 
)

Replace a set of characters by other characters.

Parameters
strThe string to modify.
e1The characters to remove.
e2The characters replacing the ones in e1.
Returns
The number of replaced characters.

Each character e1[i] will be replaced with e2[i]. If e1 is smaller than e2, the latter will be completed by repeating its last character.

Example : std::string s("word aaa bbb abab"); claw::replace( s, "ab", "ba" ); std::cout << s << std::end; // result is "word bbb aaa baba"

Definition at line 167 of file string_algorithm.tpp.

References claw::replace().

template<typename Sequence >
void claw::text::split ( Sequence &  sequence,
const typename Sequence::value_type &  str,
const typename Sequence::value_type::value_type  sep 
)

Split a string into several substrings, according to a given separator.

Parameters
sequenceA sequence in which the substrings are added.
strThe string to split.
sepThe separator on which the string is splitted.

Definition at line 205 of file string_algorithm.tpp.

template<typename Sequence >
void claw::text::split ( Sequence &  sequence,
typename Sequence::value_type::const_iterator  first,
typename Sequence::value_type::const_iterator  last,
const typename Sequence::value_type::value_type  sep 
)

Split a string into several substrings, according to a given separator.

Parameters
sequenceA sequence in which the substrings are added.
firstIterator on the beginning of the string to split.
lastIterator just past the end of the string to split.
sepThe separator on which the string is splitted.

Definition at line 222 of file string_algorithm.tpp.

References getline().

template<typename StringType >
void claw::text::squeeze ( StringType &  str,
const typename StringType::value_type *const  s 
)

Squeeze successive characters of a string into one character.

Parameters
strThe string to modify.
sThe characters to remove.

Example : std::string s("word aaa bbb abab"); claw::squeeze( s, "ab" ); std::cout << s << std::end; // result is "word a b abab"

Definition at line 120 of file string_algorithm.tpp.

template<typename StringType >
void claw::text::trim ( StringType &  str,
const typename StringType::value_type *const  s = " " 
)

Remove characters at the begining end at the end of a string.

Parameters
strThe string to modify.
sThe characters to remove.

Definition at line 96 of file string_algorithm.tpp.

template<typename StringType >
void claw::text::trim_left ( StringType &  str,
const typename StringType::value_type *const  s = " " 
)

Remove characters at the begining of a string.

Parameters
strThe string to modify.
sThe characters to remove.

Definition at line 64 of file string_algorithm.tpp.

template<typename StringType >
void claw::text::trim_right ( StringType &  str,
const typename StringType::value_type *const  s = " " 
)

Remove characters at the end of a string.

Parameters
strThe string to modify.
sThe characters to remove.

Definition at line 80 of file string_algorithm.tpp.

Referenced by claw::configuration_file::open().