basic_const_super_string< char_type > Class Template Reference

#include <const_super_string.hpp>

List of all members.


Detailed Description

template<class char_type>
class basic_const_super_string< char_type >

Souped up immutable string class based on boost::const_string that includes fancy query, replacement, and conversion functions.
Examples:

test/css_example.cpp.


Public Member Functions

basic_const_super_string append_file (const std_string_type &filepath) const
 Make a string from the contents of a file.
bool contains_regex (const base_string_type &s) const
 Query function using regular expression.
bool contains (const base_string_type &s) const
 Query function to see if a string contains given string.
bool starts_with (const base_string_type &s, size_type offset=0) const
 Query function to see if a string or substring starts with a given string.
bool ends_with (const base_string_type &s) const
 Query function to see if a string or substring ends with a given string.
bool icontains (const base_string_type &s) const
 Case insensitive query function to see if a string contains a given string.
bool istarts_with (const base_string_type &s, size_type offset=0) const
 Case insensitive query function to see if a string or substring starts with a given string.
bool iends_with (const base_string_type &s) const
 Case insensitive query function to see if a string or substring ends with a given string.
unsigned int split (const base_string_type &predicate, string_vector &result) const
 Split a string into a string of vectors based on equality to a string.
unsigned int split_regex (const base_string_type &predicate_regex, string_vector &result) const
 Split a string into a string of vectors based regex string.
basic_const_super_string replace_all_regex (const base_string_type &match_regex, const base_string_type &replace_regex) const
 Replace the all instance of the match_string with the replace_format.
basic_const_super_string replace_first (const base_string_type &match_string, const base_string_type &replace_string) const
 Replace the first instance of the match_string with the replace_string Has no effect on the string if there is match_string does not appear in the string.
basic_const_super_string replace_last (const base_string_type &match_string, const base_string_type &replace_string) const
 Replace the last instance of the match_string with the replace_string Has no effect on the string if there is match_string does not appear in the string.
basic_const_super_string replace_nth (const base_string_type &match_string, const base_string_type &replace_string, size_type n) const
 Replace the nth instance of the match_string with the replace_string Has no effect on the string if there is no 'nth' version of the match string.
basic_const_super_string replace_all (const base_string_type &match_string, const base_string_type &replace_string) const
 Replace the all instance of the match_string with the replace_string Has no effect on the string if there are no instances of match_string in the string.
basic_const_super_string ireplace_first (const base_string_type &match_string, const base_string_type &replace_string) const
 Case insensitive replace the first instance of the match_string with the replace_string.
basic_const_super_string ireplace_last (const base_string_type &match_string, const base_string_type &replace_string) const
 Case insensitive replace of the last instance of the match_string with the replace_string.
basic_const_super_string ireplace_nth (const base_string_type &match_string, const base_string_type &replace_string, size_type n) const
 Case insensitive replace of the nth instance of the match_string with the replace_string.
basic_const_super_string ireplace_all (const base_string_type &match_string, const base_string_type &replace_string) const
 Case insensitive replace the all instance of the match_string with the replace_string Has no effect on the string if there are no instances of match_string in the string.
basic_const_super_string trim () const
 Trim whitespace from the both sides of the string making a copy.
basic_const_super_string trim_left () const
 Trim whitespace from the left side of the string making a copy.
basic_const_super_string trim_right () const
 Trim whitespace from the right side of the string making a copy.
basic_const_super_string to_lower () const
 Change to lower case using the global locale The global local can be replaced by calling std::global(locale).
basic_const_super_string to_upper () const
 Change to upper case using the global locale The global local can be replaced by calling std::global(locale).
template<typename T>
basic_const_super_string<
char_type > 
append (const T &value) const
 Generic function to append any type to the string This function will work with any type that is OutputStreamable.
template<typename T1, typename T2>
basic_const_super_string<
char_type > 
append (const T1 &val1, const T2 &val2) const
 Generic function to append 2 values This function will work with any type that is OutputStreamable.
template<typename T1, typename T2, typename T3>
basic_const_super_string<
char_type > 
append (const T1 &val1, const T2 &val2, const T3 &val3) const
 Generic function to append 3 values This function will work with any type that is OutputStreamable.
template<typename T1, typename T2, typename T3, typename T4>
basic_const_super_string<
char_type > 
append (const T1 &val1, const T2 &val2, const T3 &val3, const T4 &val4) const
 Generic function to append 4 values This function will work with any type that is OutputStreamable.
template<typename T1, typename T2, typename T3, typename T4, typename T5>
basic_const_super_string<
char_type > 
append (const T1 &val1, const T2 &val2, const T3 &val3, const T4 &val4, const T5 &val5) const
 Generic function to append 5 values This function will work with any type that is OutputStreamable.
template<class T>
basic_const_super_string<
char_type > 
prepend (const T &value) const
 Generic function to prepend any type to the string This function will work with any type that is OutputStreamable.
template<class T>
basic_const_super_string<
char_type > 
insert_at (size_type pos, const T &value) const
 Generic function to insert an OutputStreamable type into the string.
template<typename T>
basic_const_super_string<
char_type > 
append_formatted (const T &value, const base_string_type &fmt) const
 Generic function to append any type to the string including formatting.
template<typename T1, typename T2>
basic_const_super_string<
char_type > 
append_formatted (const T1 &val1, const T2 &val2, const base_string_type &fmt) const
 Generic function to append 2 values of any to the string including formatting.
template<typename T1, typename T2, typename T3>
basic_const_super_string<
char_type > 
append_formatted (const T1 &val1, const T2 &val2, const T3 &val3, const base_string_type &fmt) const
 Generic function to append 3 values of any to the string including formatting.
template<typename T1, typename T2, typename T3, typename T4>
basic_const_super_string<
char_type > 
append_formatted (const T1 &val1, const T2 &val2, const T3 &val3, const T4 &val4, const base_string_type &fmt) const
 Generic function to append 4 values of any to the string including formatting.
template<typename T1, typename T2, typename T3, typename T4, typename T5>
basic_const_super_string<
char_type > 
append_formatted (const T1 &val1, const T2 &val2, const T3 &val3, const T4 &val4, const T5 &val5, const base_string_type &fmt) const
 Generic function to append 5 values of any to the string including formatting.


Member Function Documentation

template<class char_type>
template<typename T1, typename T2, typename T3, typename T4, typename T5>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append const T1 &  val1,
const T2 &  val2,
const T3 &  val3,
const T4 &  val4,
const T5 &  val5
const [inline]
 

Generic function to append 5 values This function will work with any type that is OutputStreamable.

    super_string s;
    double dbl = 1.543;
    int i = 10;
    s.append("value is: ", dbl, " int: ", i);
    //s == "double: 1.543 int: 10"
Parameters:
value Value to be appended to the string.
Returns:
Returns self-reference for chained operations

template<class char_type>
template<typename T1, typename T2, typename T3, typename T4>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append const T1 &  val1,
const T2 &  val2,
const T3 &  val3,
const T4 &  val4
const [inline]
 

Generic function to append 4 values This function will work with any type that is OutputStreamable.

    super_string s;
    double dbl = 1.543;
    int i = 10;
    s.append("value is: ", dbl, " int: ", i);
    //s == "double: 1.543 int: 10"
Parameters:
value Value to be appended to the string.
Returns:
Returns self-reference for chained operations

template<class char_type>
template<typename T1, typename T2, typename T3>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append const T1 &  val1,
const T2 &  val2,
const T3 &  val3
const [inline]
 

Generic function to append 3 values This function will work with any type that is OutputStreamable.

    super_string s;
    double dbl = 1.543;
    int i = 10;
    s.append("value is: ", dbl, i);
    //s == "double: 1.54310"
Parameters:
value Value to be appended to the string.
Returns:
Returns self-reference for chained operations

template<class char_type>
template<typename T1, typename T2>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append const T1 &  val1,
const T2 &  val2
const [inline]
 

Generic function to append 2 values This function will work with any type that is OutputStreamable.

    super_string s;
    double dbl = 1.543;
    s.append("double: ", dbl);
    //s == "double: 1.543"
Parameters:
value Value to be appended to the string.
Returns:
Returns self-reference for chained operations

template<class char_type>
template<typename T>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append const T &  value  )  const [inline]
 

Generic function to append any type to the string This function will work with any type that is OutputStreamable.

    super_string s;
    double dbl = 1.543;
    s.append(dbl);
    s += " - "; //std::string method
    //append a date to the string
    boost::gregorian::date d(2006, boost::gregorian::Jun, 29);
    s.append(d);
    //s == "1.543 - 2006-Jun-29"
Parameters:
value Value to be appended to the string.
Returns:
Returns self-reference for chained operations
Examples:
test/css_example.cpp.

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append_file const std_string_type &  filepath  )  const [inline]
 

Make a string from the contents of a file.

    super_string data;
    data.append_file("data1.txt").append_file(data2.txt);
 *
Returns:
String built from reading in the entire file.
Parameters:
filepath Path to the file
JKG TODO: throw an exception if file not found?

template<class char_type>
template<typename T1, typename T2, typename T3, typename T4, typename T5>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append_formatted const T1 &  val1,
const T2 &  val2,
const T3 &  val3,
const T4 &  val4,
const T5 &  val5,
const base_string_type &  format
const [inline]
 

Generic function to append 5 values of any to the string including formatting.

    super_string s;
    double dbl = 1.123456789;
    int i = 1000;
    s.append_formatted(dbl, i , dbl, i, "a string", "%-7.2f %-7d %-7.2f %-7d %s");
    //s == "1.12   1000  1.12   1000   a string"

- The value to append to the end of the string. - Formatting string for the value.

Returns:
Returns self-reference for chained operations
JKG TODO: explain formatting strings and rules

template<class char_type>
template<typename T1, typename T2, typename T3, typename T4>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append_formatted const T1 &  val1,
const T2 &  val2,
const T3 &  val3,
const T4 &  val4,
const base_string_type &  format
const [inline]
 

Generic function to append 4 values of any to the string including formatting.

    super_string s;
    double dbl = 1.123456789;
    int i = 1000;
    s.append_formatted(dbl, i , dbl, i, "%-7.2f %-7d %-7.2f %-7d");
    //s == "1.12   1000  1.12   1000   "

- The value to append to the end of the string. - Formatting string for the value.

Returns:
Returns self-reference for chained operations
JKG TODO: explain formatting strings and rules

template<class char_type>
template<typename T1, typename T2, typename T3>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append_formatted const T1 &  val1,
const T2 &  val2,
const T3 &  val3,
const base_string_type &  format
const [inline]
 

Generic function to append 3 values of any to the string including formatting.

    super_string s;
    double dbl = 1.123456789;
    int i = 1000;
    s.append_formatted(dbl, dbl, i , "%-7.2f %-7.2f %-7d");
    //s == "1.23  1.23  1000   "

- The value to append to the end of the string. - Formatting string for the value.

Returns:
Returns self-reference for chained operations
JKG TODO: explain formatting strings and rules

template<class char_type>
template<typename T1, typename T2>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append_formatted const T1 &  val1,
const T2 &  val2,
const base_string_type &  format
const [inline]
 

Generic function to append 2 values of any to the string including formatting.

    super_string s;
    double dbl = 1.123456789;
    s.append_formatted(dbl, "some string", "%-7.2f %s" );
    //s == "1.12  some string"

- The value to append to the end of the string. - Formatting string for the value.

Returns:
Returns self-reference for chained operations
JKG TODO: explain formatting strings and rules

template<class char_type>
template<typename T>
basic_const_super_string< char_type > basic_const_super_string< char_type >::append_formatted const T &  value,
const base_string_type &  format
const [inline]
 

Generic function to append any type to the string including formatting.

    super_string s;
    double dbl = 1.123456789;
    s.append_fmt(dbl, "%-7.2f");
    s += " - "; //std::string method
    //s == "1.543 - 2006-Jun-29"

- The value to append to the end of the string. - Formatting string for the value.

Returns:
Returns self-reference for chained operations
JKG TODO: explain formatting strings and rules JKG TODO: decide how to handle boost fmt exceptions

template<class char_type>
bool basic_const_super_string< char_type >::contains const base_string_type &  predicate_string  )  const [inline]
 

Query function to see if a string contains given string.

Parameters:
predicate_string string to check against

template<class char_type>
bool basic_const_super_string< char_type >::contains_regex const base_string_type &  predicate_regex  )  const [inline]
 

Query function using regular expression.

    super_string s("hello 2006-02-23");
    s.contains_regex("\\d{4}-\\d{2}-\\d{2}")); //true
    s.contains_regex("[A-Z]")); //false

Parameters:
predicate_regex regular expression predicate_string string to check against
Exceptions:
boost::regex_error if predicate_string is not a valid regular expression
Examples:
test/css_example.cpp.

template<class char_type>
bool basic_const_super_string< char_type >::ends_with const base_string_type &  predicate_string  )  const [inline]
 

Query function to see if a string or substring ends with a given string.

Parameters:
predicate_string string to check against

template<class char_type>
bool basic_const_super_string< char_type >::icontains const base_string_type &  predicate_string  )  const [inline]
 

Case insensitive query function to see if a string contains a given string.

Parameters:
predicate_string string to check against

template<class char_type>
bool basic_const_super_string< char_type >::iends_with const base_string_type &  predicate_string  )  const [inline]
 

Case insensitive query function to see if a string or substring ends with a given string.

    super_string s("hELlo");
    s.iends_with("llO"); //true
    s.iends_with("Hi")   //false

Parameters:
predicate_string string to check against

template<class char_type>
template<class T>
basic_const_super_string< char_type > basic_const_super_string< char_type >::insert_at size_type  position,
const T &  value
const [inline]
 

Generic function to insert an OutputStreamable type into the string.

    super_string s( "Hello  There");
    double dbl = 1.543;
    s.prepend(dbl);
    //s == "Hello 1.543 There"
Parameters:
position Zero-based index of location in string to insert data
value Value to insert into the string
Returns:
Returns self-reference for chained operations

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::ireplace_all const base_string_type &  match_string,
const base_string_type &  replace_string
const [inline]
 

Case insensitive replace the all instance of the match_string with the replace_string Has no effect on the string if there are no instances of match_string in the string.

    super_string s("foo FOO Foo");
    s.ireplace_all("foo", "bar", 1);
    //s == "bar bar bar"
Parameters:
match_string String to find and replace against
replace_string String to use in replacement

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::ireplace_first const base_string_type &  match_string,
const base_string_type &  replace_string
const [inline]
 

Case insensitive replace the first instance of the match_string with the replace_string.

Has no effect on the string if there match_string does not appear in the string.

    super_string s("FOO foo foo");
    s.ireplace_first("foo", "bar");
    //s == "bar foo foo"
Parameters:
match_string String to find and replace against
replace_string String to use in replacement

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::ireplace_last const base_string_type &  match_string,
const base_string_type &  replace_string
const [inline]
 

Case insensitive replace of the last instance of the match_string with the replace_string.

Has no effect on the string if there match_string does not appear in the string.

    super_string s("foo foo FOO");
    s.ireplace_last("foo", "bar");
    //s == "foo foo bar"
Parameters:
match_string String to find and replace against
replace_string String to use in replacement

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::ireplace_nth const base_string_type &  match_string,
const base_string_type &  replace_string,
size_type  n
const [inline]
 

Case insensitive replace of the nth instance of the match_string with the replace_string.

Has no effect on the string if there is no 'nth' version of the match string.

    super_string s("foo FOO foo");
    s.ireplace_nth("foo", "bar", 1);
    //s == "foo bar foo"
Parameters:
match_string String to find and replace against
replace_string String to use in replacement
n The instance to replace starting at 0

template<class char_type>
bool basic_const_super_string< char_type >::istarts_with const base_string_type &  predicate_string,
size_type  offset = 0
const [inline]
 

Case insensitive query function to see if a string or substring starts with a given string.

    super_string s("hELlo");
    s.istarts_with("el", 1); //returns true

 *
Parameters:
predicate_string string to check against
offset point in string to start at - 0 is first position.

template<class char_type>
template<class T>
basic_const_super_string< char_type > basic_const_super_string< char_type >::prepend const T &  value  )  const [inline]
 

Generic function to prepend any type to the string This function will work with any type that is OutputStreamable.

    super_string s( "Hello There");
    double dbl = 1.543;
    s.prepend(dbl);
    //s == "1.543 Hello There"

Returns:
Returns self-reference for chained operations

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::replace_all const base_string_type &  match_string,
const base_string_type &  replace_string
const [inline]
 

Replace the all instance of the match_string with the replace_string Has no effect on the string if there are no instances of match_string in the string.

    super_string s("foo foo foo");
    s.replace_all("foo", "bar", 1);
    //s == "bar bar bar"
Parameters:
match_string String to find and replace against
replace_string String to use in replacement

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::replace_all_regex const base_string_type &  match_regex,
const base_string_type &  replace_format
const [inline]
 

Replace the all instance of the match_string with the replace_format.

    super_string s("(abc)3333()(456789) [123] (1) (cde)");
    
    //replace parens around digits with #--the digits--#
    s = s.replace_all_regex("\\(([0-9]+)\\)", "#--$1--#");

    //s == "(abc)3333()#--456789--# [123] #--1--# (cde)"      

Exceptions:
boost::regex_error if match_regex is not a valid regular expression
Parameters:
match_regex Regular expression to match against
replace_format Replacement expresssion
Examples:
test/css_example.cpp.

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::replace_first const base_string_type &  match_string,
const base_string_type &  replace_string
const [inline]
 

Replace the first instance of the match_string with the replace_string Has no effect on the string if there is match_string does not appear in the string.

    super_string s("foo foo foo");
    s.replace_first("foo", "bar");
    //s == "bar foo foo"
Parameters:
match_string String to find and replace against
replace_string String to use in replacement

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::replace_last const base_string_type &  match_string,
const base_string_type &  replace_string
const [inline]
 

Replace the last instance of the match_string with the replace_string Has no effect on the string if there is match_string does not appear in the string.

    super_string s("foo foo foo");
    s.replace_last("foo", "bar");
    //s == "foo foo bar"
Parameters:
match_string String to find and replace against
replace_string String to use in replacement

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::replace_nth const base_string_type &  match_string,
const base_string_type &  replace_string,
size_type  n
const [inline]
 

Replace the nth instance of the match_string with the replace_string Has no effect on the string if there is no 'nth' version of the match string.

    super_string s("foo foo foo");
    s.replace_nth("foo", "bar", 1);
    //s == "foo bar foo"
Parameters:
match_string String to find and replace against
replace_string String to use in replacement
n The instance to replace starting at 0

template<class char_type>
unsigned int basic_const_super_string< char_type >::split const base_string_type &  predicate,
string_vector &  result
const [inline]
 

Split a string into a string of vectors based on equality to a string.

    super_string stuff("first-|-second-|-third");
    super_string::string_vector out_vec;
    if (stuff.split("-|-", out_vec)) {
      //iterate thru the vector and process
      //out_vec[0] == first
      //out_vec[1] == second
      //out_vec[2] == third
    }
 *
Returns:
count of splits found
Parameters:
predicate String used to test against.
result Returns the each split string or the whole string as the first element of the vector.

template<class char_type>
unsigned int basic_const_super_string< char_type >::split_regex const base_string_type &  predicate_regex,
string_vector &  result
const [inline]
 

Split a string into a string of vectors based regex string.

    super_string s("These   are   some    \t words--with whitespace");
    super_string::string_vector out_vec;
    unsigned int count = s.split_regex("\\s+|--", out_vec);

    if (count) {
      //iterate thru the vector and process
      //out_vec[0] == These
      //out_vec[4] == with
    }
 *
return count of splits found
Parameters:
predicate_regex Regular expression used to find string split points.
result Returns the each split string or the whole string as the first element of the vector.
Examples:
test/css_example.cpp.

template<class char_type>
bool basic_const_super_string< char_type >::starts_with const base_string_type &  predicate_string,
size_type  offset = 0
const [inline]
 

Query function to see if a string or substring starts with a given string.

Parameters:
predicate_string string to check against
offset point in string to start at - 0 is first position.

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::to_lower  )  const [inline]
 

Change to lower case using the global locale The global local can be replaced by calling std::global(locale).

Returns:
Returns modified string for chained operations

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::to_upper  )  const [inline]
 

Change to upper case using the global locale The global local can be replaced by calling std::global(locale).

Returns:
Returns modified string for chained operations
Examples:
test/css_example.cpp.

template<class char_type>
basic_const_super_string< char_type > basic_const_super_string< char_type >::trim  )  const [inline]
 

Trim whitespace from the both sides of the string making a copy.

Returns:
Copy of trimmed string
Examples:
test/css_example.cpp.


The documentation for this class was generated from the following file:
Generated on Sun Jul 9 15:43:03 2006 for SuperString by  doxygen 1.4.6