#include <super_string.hpp>
Overall, this class is mostly a convience wrapper around functions available in boost.string_algo and boost.regex.
Public Member Functions | |
Construction | |
Various constructors | |
basic_super_string () | |
Default constructor. | |
basic_super_string (const char_type *const s) | |
Construct from a char pointer. | |
basic_super_string (const base_string_type &s) | |
Construct from std::basic_string type. | |
basic_super_string (iterator_type beg, iterator_type end) | |
Construct from iterators. | |
Basic Queries | |
Content checking query functions to check for substrings. | |
bool | contains (const base_string_type &s) const |
Query function to see if a string contains given string. | |
bool | contains_regex (const base_string_type &s) const |
Query function using regular expression This is meant to function much like the perl =~ operator. | |
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. | |
Case Insentitive Queries | |
Case Insensitive content checking query functions to check for substrings. | |
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. | |
Split Functions | |
Split the string based on the predicate 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. | |
Acquire File Content | |
Append contents of a file to the string | |
basic_super_string & | append_file (const base_string_type &filepath) |
Make a string from the contents of a file. | |
Replace Functions | |
Enhanced replace functions | |
basic_super_string & | replace_all_regex (const base_string_type &match_regex, const base_string_type &replace_regex) |
Replace the all instance of the match_string with the replace_format. | |
basic_super_string & | replace_first (const base_string_type &match_string, const base_string_type &replace_string) |
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_super_string & | replace_last (const base_string_type &match_string, const base_string_type &replace_string) |
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_super_string & | replace_nth (const base_string_type &match_string, const base_string_type &replace_string, size_type n) |
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_super_string & | replace_all (const base_string_type &match_string, const base_string_type &replace_string) |
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. | |
Replace Functions - case insensitve | |
Case insensitive enhanced replace functions | |
basic_super_string & | ireplace_first (const base_string_type &match_string, const base_string_type &replace_string) |
Case insensitive replace the first instance of the match_string with the replace_string. | |
basic_super_string & | ireplace_last (const base_string_type &match_string, const base_string_type &replace_string) |
Case insensitive replace of the last instance of the match_string with the replace_string. | |
basic_super_string & | ireplace_nth (const base_string_type &match_string, const base_string_type &replace_string, size_type n) |
Case insensitive replace of the nth instance of the match_string with the replace_string. | |
basic_super_string & | ireplace_all (const base_string_type &match_string, const base_string_type &replace_string) |
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. | |
Trim Functions | |
White space trimming functions | |
basic_super_string & | trim () |
Trim in-place whitespace from the both sides of the string. | |
basic_super_string & | trim_left () |
Trim in-place whitespace from the left side of the string. | |
basic_super_string & | trim_right () |
Trim in-place whitespace from the right side of the string. | |
Case Conversion Functions | |
Convert the string case using the global locale. | |
basic_super_string & | to_upper () |
Change to upper case using the global locale The global local can be replaced by calling std::global(locale). | |
basic_super_string & | to_lower () |
Change to lower case using the global locale The global local can be replaced by calling std::global(locale). | |
Basic Type Conversion | |
Convert and append, prepend, and insert a streamable type to the the string. | |
template<typename T1, typename T2, typename T3, typename T4, typename T5> | |
basic_super_string< char_type > & | append (const T1 &val1, const T2 &val2, const T3 &val3, const T4 &val4, const T5 &val5) |
Generic function to append 5 values This function will work with any type that is OutputStreamable. | |
template<class T> | |
basic_super_string< char_type > & | prepend (const T &value) |
Generic function to prepend any type to the string This function will work with any type that is OutputStreamable. | |
template<class T> | |
basic_super_string< char_type > & | insert_at (size_type pos, const T &value) |
Generic function to insert an OutputStreamable type into the string. | |
Basic Type Conversion with supplied Stringstream | |
Convert and append a streamable type to the string. | |
template<typename T1, typename T2, typename T3, typename T4, typename T5> | |
basic_super_string< char_type > & | append (const T1 &val1, const T2 &val2, const T3 &val3, const T4 &val4, const T5 &val5, string_stream_type &ss) |
Generic function to append any type to the string This is a faster version of the convert and append function. | |
Formatted Type Conversion | |
Use formatting strings to append arbitrary types to string. | |
template<typename T1, typename T2, typename T3, typename T4, typename T5> | |
basic_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) |
Generic function to append 5 values of any to the string including formatting Users can append up to 5 values at once. |
|
Generic function to append any type to the string This is a faster version of the convert and append function. Use this version if doing a large number of conversions. This version of the function also allows the user to control format settings on the conversion by applying changes to the stringstream used to do the conversion. This function will work with any type that is OutputStreamable.
std::ostringstream ss; s.setprecision( super_string s; ss << std::setprecision(3); double dbl = 1.987654321; int i = 1000; s.append(dbl, i, i, " stuff", dbl, ss); //s == "1.99 1000 1000 1.99 stuff" //ss -- has been modified
|
|
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"
|
|
Make a string from the contents of a file.
super_string data; data.append_file("data1.txt").append_file(data2.txt);
|
|
Generic function to append 5 values of any to the string including formatting Users can append up to 5 values at once. See: Boost Format specification syntax for details on the formmatting strings.
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" //other overloadings available with less parameters super_string s1; s1.append_formatted(dbl, "This is the value: %-7.2f"); //s1 == "This is the value: 1.12" - The value to append to the end of the string. - Formatting string for the value.
|
|
Query function to see if a string contains given string.
|
|
Query function using regular expression This is meant to function much like the perl =~ operator.
super_string s("hello 2006-02-23"); s.contains_regex("\\d{4}-\\d{2}-\\d{2}")); //true s.contains_regex("[A-Z]")); //false
|
|
Query function to see if a string or substring ends with a given string.
|
|
Case insensitive query function to see if a string contains a given string.
|
|
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
|
|
Generic function to insert an OutputStreamable type into the string.
super_string s( "Hello There"); double dbl = 1.543; s.insert_at(6, dbl); //s == "Hello 1.543 There"
|
|
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"
|
|
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"
|
|
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"
|
|
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"
|
|
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
|
|
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"
|
|
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"
|
|
Replace the all instance of the match_string with the replace_format.
|
|
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"
|
|
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"
|
|
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"
|
|
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 }
|
|
Split a string into a string of vectors based regex string.
|
|
Query function to see if a string or substring starts with a given string.
|
|
Change to lower case using the global locale The global local can be replaced by calling std::global(locale).
super_string s("UPPsdf sdf sdf E sdf d 123&88))"); s.to_lower(); //s == "uppsdf sdf sdf e sdf d 123&88
|
|
Change to upper case using the global locale The global local can be replaced by calling std::global(locale).
super_string s("lower"); s.to_upper(); check("to upper test", s == std::string("LOWER"));
|
|
Trim in-place whitespace from the both sides of the string.
super_string s( " \t hello world "); s.trim(); //s == "hello world"
|
|
Trim in-place whitespace from the left side of the string.
|
|
Trim in-place whitespace from the right side of the string.
|