Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields

std::ext_string Class Reference

An extension of STL's string providing additional functionality that is often availiable in higher-level languages such as Python. More...

#include <ext_string.h>

Inheritance diagram for std::ext_string:

Inheritance graph
[legend]
Collaboration diagram for std::ext_string:

Collaboration graph
[legend]

Public Member Functions

vector< ext_stringchunk_split (size_type chunklen) const
 Split a string into chunks of size chunklen.
size_type count (const string &str) const
 Count the occurances of str in the string.
template<class InputIterator>
 ext_string (InputIterator first, InputIterator last)
 Create a string from a range.
 ext_string (size_type n, value_type c)
 Create an ext_string with n copies of c.
 ext_string (const value_type *s, size_type n)
 Construct an ext_string from a character array and a length.
 ext_string (const value_type *s)
 Construct an ext_string from a null-terminated character array.
 ext_string (const string &s, size_type pos=0, size_type n=npos)
 Duplicate the STL string copy constructor.
 ext_string ()
 Default constructor.
long int integer () const
 Convert the string to an integer.
bool is_alnum () const
 Determine if the string is alphanumeric.
bool is_alpha () const
 Determine if the string is alphabetic only.
bool is_lower () const
 Determine if a string is all lower case.
bool is_numeric () const
 Determine if the string is numeric only.
bool is_upper () const
 Determine if a string is all upper case.
ext_string operator * (size_type n)
 Repeat a string n times.
ext_stringreplace (value_type needle, value_type c)
 Search of any instances of needle and replace them with c.
ext_stringreplace (const string &needle, const string &s)
 Search for any instances of needle and replace them with s.
vector< ext_stringsplit (const string &separator, size_type limit=npos) const
 Split a string by another string.
vector< ext_stringsplit (value_type separator, size_type limit=npos) const
 Split a string by a character.
vector< ext_stringsplit (size_type limit=npos) const
 Split a string by whitespace.
ext_stringswapcase ()
 Swap the case of a string.
ext_stringtolower ()
 Convert the string to lowercase.
ext_stringtoupper ()
 Convert the string to uppercase.
 ~ext_string ()
 The destructor.

Static Public Member Functions

static long int integer (const string &s)
 Convert a string into an integer.
template<class InputIterator>
static ext_string join (value_type glue, InputIterator first, InputIterator last)
 Join a sequence of strings by some glue to create a new string.
template<class InputIterator>
static ext_string join (const string &glue, InputIterator first, InputIterator last)
 Join a sequence of strings by some glue to create a new string.

Detailed Description

An extension of STL's string providing additional functionality that is often availiable in higher-level languages such as Python.

Definition at line 109 of file ext_string.h.


Constructor & Destructor Documentation

std::ext_string::ext_string  )  [inline]
 

Default constructor.

Constructs an empty ext_string ("")

Definition at line 117 of file ext_string.h.

Referenced by chunk_split(), and split().

std::ext_string::ext_string const string s,
size_type  pos = 0,
size_type  n = npos
[inline]
 

Duplicate the STL string copy constructor.

Parameters:
[in] s The string to copy
[in] pos The starting position in the string to copy from
[in] n The number of characters to copy

Definition at line 126 of file ext_string.h.

std::ext_string::ext_string const value_type *  s  )  [inline]
 

Construct an ext_string from a null-terminated character array.

Parameters:
[in] s The character array to copy into the new string

Definition at line 133 of file ext_string.h.

std::ext_string::ext_string const value_type *  s,
size_type  n
[inline]
 

Construct an ext_string from a character array and a length.

Parameters:
[in] s The character array to copy into the new string
[in] n The number of characters to copy

Definition at line 141 of file ext_string.h.

std::ext_string::ext_string size_type  n,
value_type  c
[inline]
 

Create an ext_string with n copies of c.

Parameters:
[in] n The number of copies
[in] c The character to copy n times

Definition at line 149 of file ext_string.h.

template<class InputIterator>
std::ext_string::ext_string InputIterator  first,
InputIterator  last
[inline]
 

Create a string from a range.

Parameters:
[in] first The first element to copy in
[in] last The last element to copy in

Definition at line 158 of file ext_string.h.

std::ext_string::~ext_string  )  [inline]
 

The destructor.

Definition at line 163 of file ext_string.h.


Member Function Documentation

vector<ext_string> std::ext_string::chunk_split size_type  chunklen  )  const [inline]
 

Split a string into chunks of size chunklen.

Returns a vector of strings.

Splits a string into chunks of the given size. The final chunk may not fill its entire allocated number of characters.

Parameters:
[in] chunklen The number of characters per chunk
Returns:
A vector of strings, each of length <= chunklen

Example

 std::ext_string s("abcdefghijk");
 std::vector<std::ext_string> v = s.chunk_split(3);
 std::copy(v.begin(), v.end(), ostream_iterator<std::ext_string>(cout, " "));

 abc def ghi jk

Definition at line 376 of file ext_string.h.

References count(), and ext_string().

size_type std::ext_string::count const string str  )  const [inline]
 

Count the occurances of str in the string.

Returns:
The count of substrings str in the string

Definition at line 570 of file ext_string.h.

References count().

Referenced by chunk_split(), and count().

long int std::ext_string::integer  )  const [inline]
 

Convert the string to an integer.

Convert the initial portion of the string into a signed integer. Once a non-numeric character is reached, the remainder of the string is ignored and the integer that had been read thus far is returned.

Returns:
The integer converted from the string

Definition at line 353 of file ext_string.h.

static long int std::ext_string::integer const string s  )  [inline, static]
 

Convert a string into an integer.

Convert the initial portion of a string into a signed integer. Once a non-numeric character is reached, the remainder of string is ignored and the integer that was read returned.

Parameters:
s The string to convert
Returns:
The integer converted from string

Definition at line 312 of file ext_string.h.

bool std::ext_string::is_alnum  )  const [inline]
 

Determine if the string is alphanumeric.

Returns:
true if the string contains only characters between a-z, A-Z and 0-9 and contains at least one character, else false

Definition at line 592 of file ext_string.h.

bool std::ext_string::is_alpha  )  const [inline]
 

Determine if the string is alphabetic only.

Returns:
true of the string contains only characters between a-z and A-Z and contains at least one character, else false

Definition at line 614 of file ext_string.h.

bool std::ext_string::is_lower  )  const [inline]
 

Determine if a string is all lower case.

Returns:
true if there is at least one character, and all characters are lowercase letters, else false

Definition at line 650 of file ext_string.h.

bool std::ext_string::is_numeric  )  const [inline]
 

Determine if the string is numeric only.

Returns:
true if the string contains only characters between 0-9 and contains at least one character, else false

Definition at line 632 of file ext_string.h.

bool std::ext_string::is_upper  )  const [inline]
 

Determine if a string is all upper case.

Returns:
true if there is at least one character, and all characters are uppercase letters, else false

Definition at line 668 of file ext_string.h.

template<class InputIterator>
static ext_string std::ext_string::join value_type  glue,
InputIterator  first,
InputIterator  last
[inline, static]
 

Join a sequence of strings by some glue to create a new string.

Glue is not added to the end of the string.

Precondition:
[first, last) is a valid range

InputIterator is a model of STL's Input Iterator

InputIterator must point to a string type (std::string, std::ext_string, char *)

Parameters:
[in] glue The glue to join strings with
[in] first The beginning of the range to join
[in] last The end of the range to join
Returns:
A string constructed of each element of the range connected together with glue
Example

Definition at line 449 of file ext_string.h.

References std::basic_string< _CharT, _Traits, _Alloc >::append(), std::basic_string< _CharT, _Traits, _Alloc >::erase(), and std::basic_string< _CharT, _Traits, _Alloc >::length().

template<class InputIterator>
static ext_string std::ext_string::join const string glue,
InputIterator  first,
InputIterator  last
[inline, static]
 

Join a sequence of strings by some glue to create a new string.

Glue is not added to the end of the string.

Precondition:
[first, last) is a valid range

InputIterator is a model of STL's Input Iterator

InputIterator must point to a string type (std::string, std::ext_string, char *)

Parameters:
[in] glue The glue to join strings with
[in] first The beginning of the range to join
[in] last The end of the range to join
Returns:
A string constructed of each element of the range connected together with glue

Example

 std::vector<std::ext_string> v;
 v.push_back("This");
 v.push_back("is");
 v.push_back("a");
 v.push_back("test.");
 std::cout << std::ext_string::join("|", v.begin(), v.end()) << std::endl;

 This|is|a|test.

Definition at line 428 of file ext_string.h.

References std::basic_string< _CharT, _Traits, _Alloc >::append(), std::basic_string< _CharT, _Traits, _Alloc >::erase(), and std::basic_string< _CharT, _Traits, _Alloc >::length().

ext_string std::ext_string::operator * size_type  n  )  [inline]
 

Repeat a string n times.

Parameters:
[in] n The number of times to repeat the string
Returns:
ext_string containing n copies of the string

Example

 std::ext_string s("123");
 s = s * 3;
 std::cout << s << std::endl;

 123123123

Definition at line 528 of file ext_string.h.

References std::basic_string< _CharT, _Traits, _Alloc >::append().

ext_string& std::ext_string::replace value_type  needle,
value_type  c
[inline]
 

Search of any instances of needle and replace them with c.

Parameters:
[in] needle The character to replace
[in] c The replacement character
Returns:
*this
Postcondition:
All instances of needle in the string are replaced with c
Example

Definition at line 504 of file ext_string.h.

ext_string& std::ext_string::replace const string needle,
const string s
[inline]
 

Search for any instances of needle and replace them with s.

Parameters:
[in] needle The string to replace
[in] s The replacement string
Returns:
*this
Postcondition:
All instances of needle in the string are replaced with s

Example

 std::ext_string s("This is a test.");
 s.replace("is", "ere");
 std::cout << s << std::endl;

 There ere a test.

Definition at line 480 of file ext_string.h.

vector<ext_string> std::ext_string::split const string separator,
size_type  limit = npos
const [inline]
 

Split a string by another string.

Returns a vector of ext_strings, each of which is a substring of the string formed by splitting it on boundaries formed by the string separator. If limit is set, the returned vector will contain a maximum of limit elements with the last element containing the rest of the string.

If separator is not found in the string, a single element will be returned in the vector containing the entire string.

The separators are removed from the output

Parameters:
[in] separator The string separator to split the string on
[in] limit The maximum number of output elements
Returns:
A vector of strings, each of which is a substring of the string
Example

Definition at line 274 of file ext_string.h.

References ext_string().

vector<ext_string> std::ext_string::split value_type  separator,
size_type  limit = npos
const [inline]
 

Split a string by a character.

Returns a vector of ext_strings, each of which is a substring of the string formed by splitting it on boundaries formed by the character separator. If limit is set, the returned vector will contain a maximum of limit elements with the last element containing the rest of the string.

If separator is not found in the string, a single element will be returned in the vector containing the entire string.

The separators are removed from the output

Parameters:
[in] separator The character separator to split the string on
[in] limit The maximum number of output elements
Returns:
A vector of strings, each of which is a substring of the string

Example

 std::ext_string s("This|is|a|test.");
 std::vector<std::ext_string> v = s.split('|');
 std::copy(v.begin(), v.end(), std::ostream_iterator<std::ext_string>(std::cout, "\n"));

 This
 is
 a
 test.

Definition at line 228 of file ext_string.h.

References ext_string().

vector<ext_string> std::ext_string::split size_type  limit = npos  )  const [inline]
 

Split a string by whitespace.

Returns:
A vector of strings, each of which is a substring of the string

Definition at line 170 of file ext_string.h.

References ext_string().

ext_string& std::ext_string::swapcase  )  [inline]
 

Swap the case of a string.

Postcondition:
Converts all uppercase to lowercase, and all lowercase to uppercase in the string
Returns:
*this

Definition at line 686 of file ext_string.h.

ext_string& std::ext_string::tolower  )  [inline]
 

Convert the string to lowercase.

Returns:
*this
Postcondition:
The string is converted to lowercase

Definition at line 543 of file ext_string.h.

ext_string& std::ext_string::toupper  )  [inline]
 

Convert the string to uppercase.

Returns:
*this
Postcondition:
The string is converted to uppercase

Definition at line 557 of file ext_string.h.


The documentation for this class was generated from the following file:
Generated on Sun Apr 17 05:08:48 2005 for Extended STL String by  doxygen 1.4.1