Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

CB2::PString< Tchar > Class Template Reference

String template. More...

#include <utils.h>

Inheritance diagram for CB2::PString< Tchar >:

CB2::Class List of all members.

Public Types

typedef PString< Tchar > this_type
 Template type alias.

typedef Array< Tchar > storage_type
 Data storage type.

typedef storage_type::size_type size_type
 Size type.

typedef storage_type::ref_type ref_type
 Item reference type.

typedef Iterator< this_type,
ref_type, Tchar > 
iterator
 Iterator.

typedef RevIterator< this_type,
ref_type, Tchar > 
rev_iterator
 Iterator.


Public Member Functions

 PString ()
 Default constructor.

 PString (const this_type &prev)
 Copy constructors.

 PString (const Tchar *dt, const size_type ln)
 PString (const Tchar *prev)
 PString (const std::basic_string< Tchar > &prev)
 PString (const Tchar prev)
 PString (const signed int prev, const size_type base=10)
 PString (const unsigned int prev, const size_type base=10)
 PString (const signed long int prev, const size_type base=10)
 PString (const unsigned long int prev, const size_type base=10)
 PString (const signed long long int prev, const size_type base=10)
 PString (const unsigned long long int prev, const size_type base=10)
 PString (const float prev)
 PString (const double prev)
const this_typeoperator= (const this_type &prev)
 Assignment operator.

const this_typeoperator= (const Tchar *prev)
const this_typeoperator= (const std::basic_string< Tchar > prev)
const this_typeoperator= (const Tchar prev)
const this_typeoperator= (const signed int prev)
const this_typeoperator= (const unsigned int prev)
const this_typeoperator= (const signed long int prev)
const this_typeoperator= (const unsigned long int prev)
const this_typeoperator= (const signed long long int prev)
const this_typeoperator= (const unsigned long long int prev)
const this_typeoperator= (const float prev)
const this_typeoperator= (const double prev)
const this_typeoperator<< (const Tchar &right)
 Append a character.

const this_typeoperator+= (const this_type &right)
 Concatenation operators.

const this_typeoperator+ (const this_type &right)
 operator const Tchar * () const
 Implicit conversion operators.

 operator std::basic_string () const
 operator Tchar () const
 operator signed int () const
 operator unsigned int () const
 operator signed long int () const
 operator unsigned long int () const
 operator signed long long int () const
 operator unsigned long long int () const
 operator float () const
 operator double () const
size_type Len () const
 Number of Tchar elements.

size_type Size () const
 Real size of the string in bytes.

Tchar & operator[] (const size_type pos) const
 Indexaation operator.

bool operator== (const this_type &str) const
 Compare strings.

bool operator!= (const this_type &str) const
bool operator== (const Tchar *str) const
bool operator!= (const Tchar *str) const
this_type Substr (const size_type base, const size_type length=(size_type)-1) const
 Get substring.

bool Empty () const
 Check for empty.

void Discart (const bool shrink=false)
 Discart the string.

bool Pos (const this_type &needle, size_type &pos, const size_type from=0) const
 Find position of substring.

size_type Subst (const this_type &needle, const this_type &replacement)
 Substitute substring.

this_type HTML (const this_type &nl="") const
 Escape HTML special characters.

this_type HTMLdecode () const
 Decode HTML special characters.

this_type SQL () const
 Escape SQL special characters.

this_type SQLdecode () const
 Decode SQL special characters.

this_type URL () const
 Escape URL special characters.

this_type URLdecode () const
 Decode URL special characters.

ref_type RefBegin () const
 Get starting reference.

ref_type RefEnd () const
 Get final reference.

ref_type RevRefBegin () const
 Get starting reverse reference.

ref_type RevRefEnd () const
 Get final reverse reference.

ref_type RefNext (const ref_type &prev) const
 Get succeding reference.

ref_type RefPrev (const ref_type &prev) const
 Get predecessing reference.

const Tchar & Deref (const ref_type &ref) const
 Dereference.

const Tchar & RevDeref (const ref_type &ref) const
 Reverse dereference.

iterator Begin () const
 Get starting iterator.

iterator End () const
 Get final iterator.

rev_iterator RevBegin () const
 Get starting reverse iterator.

rev_iterator RevEnd () const
 Get final reverse iterator.


Public Attributes

int tag
 Tag for user-specific data.


Private Member Functions

void cpy (const Tchar *prev)
 Copy string.

void cpy (const std::basic_string< Tchar > &prev)
void cpy (const Tchar prev)
template<class Tnum> void cpy_numeric_int (const Tnum prev, const size_type base)
 Copy string from integer numeric data type.

template<class Tnum> void cpy_numeric_float (const Tnum prev)
 Copy string from floating point numeric data type.

template<class Tnum> Tnum numeric_int (const bool signed_type, const Tnum zero) const
 Convert to integer data type.

template<class Tnum> Tnum numeric_float (const Tnum zero) const
 Convert to floating point data type.


Private Attributes

storage_type data
 Data storage.


Static Private Attributes

const size_type def_frag = 1024
 Default array fragment size.


Friends

PString< Tchar > operator+ (const PString< Tchar > &left, const PString< Tchar > &right)
 Binary concatenation operator (friend variant).

std::basic_ostream< Tchar,
std::char_traits< Tchar > > & 
operator<< (std::basic_ostream< Tchar, std::char_traits< Tchar > > &stream, const PString< Tchar > &str)
 Stream output friend operator.


Detailed Description

template<class Tchar>
class CB2::PString< Tchar >

String template.

Template for representing character strings. Supports many features not even available by STL's string template.

NB: The character (Tchar) type should be "primitive" (i.e. char, int, wchar_t, etc.), because Array< Tchar> is used as underlying data storage (which stores characters as bit copies).


Member Typedef Documentation

template<class Tchar>
typedef Iterator< this_type, ref_type, Tchar> CB2::PString< Tchar >::iterator
 

Iterator.

template<class Tchar>
typedef storage_type::ref_type CB2::PString< Tchar >::ref_type
 

Item reference type.

template<class Tchar>
typedef RevIterator< this_type, ref_type, Tchar> CB2::PString< Tchar >::rev_iterator
 

Iterator.

template<class Tchar>
typedef storage_type::size_type CB2::PString< Tchar >::size_type
 

Size type.

template<class Tchar>
typedef Array< Tchar> CB2::PString< Tchar >::storage_type
 

Data storage type.

template<class Tchar>
typedef PString< Tchar> CB2::PString< Tchar >::this_type
 

Template type alias.


Constructor & Destructor Documentation

template<class Tchar>
CB2::PString< Tchar >::PString  )  [inline]
 

Default constructor.

Create an empty string.

template<class Tchar>
CB2::PString< Tchar >::PString const this_type prev  )  [inline]
 

Copy constructors.

Copy string data from another string repersentation.

Parameters:
prev String to copy.
dt Raw character data.
ln Length of raw character data.
Parameters:
prev  From PString

template<class Tchar>
CB2::PString< Tchar >::PString const Tchar *  dt,
const size_type  ln
[inline]
 

Parameters:
ln  From raw character data

template<class Tchar>
CB2::PString< Tchar >::PString const Tchar *  prev  )  [inline]
 

Parameters:
prev  From NULL-terminated string

template<class Tchar>
CB2::PString< Tchar >::PString const std::basic_string< Tchar > &  prev  )  [inline]
 

Parameters:
prev  From std::basic_string< Tchar>

template<class Tchar>
CB2::PString< Tchar >::PString const Tchar  prev  )  [inline]
 

Parameters:
prev  From single Tchar

template<class Tchar>
CB2::PString< Tchar >::PString const signed int  prev,
const size_type  base = 10
[inline]
 

Parameters:
base  From signed int

template<class Tchar>
CB2::PString< Tchar >::PString const unsigned int  prev,
const size_type  base = 10
[inline]
 

Parameters:
base  From unsigned int

template<class Tchar>
CB2::PString< Tchar >::PString const signed long int  prev,
const size_type  base = 10
[inline]
 

Parameters:
base  From signed long int

template<class Tchar>
CB2::PString< Tchar >::PString const unsigned long int  prev,
const size_type  base = 10
[inline]
 

Parameters:
base  From unsigned long int

template<class Tchar>
CB2::PString< Tchar >::PString const signed long long int  prev,
const size_type  base = 10
[inline]
 

Parameters:
base  From signed long long int

template<class Tchar>
CB2::PString< Tchar >::PString const unsigned long long int  prev,
const size_type  base = 10
[inline]
 

Parameters:
base  From unsigned long long int

template<class Tchar>
CB2::PString< Tchar >::PString const float  prev  )  [inline]
 

Parameters:
prev  From float

template<class Tchar>
CB2::PString< Tchar >::PString const double  prev  )  [inline]
 

Parameters:
prev  From double


Member Function Documentation

template<class Tchar>
iterator CB2::PString< Tchar >::Begin  )  const [inline]
 

Get starting iterator.

Returns:
Starting iterator.

template<class Tchar>
void CB2::PString< Tchar >::cpy const Tchar  prev  )  [inline, private]
 

template<class Tchar>
void CB2::PString< Tchar >::cpy const std::basic_string< Tchar > &  prev  )  [inline, private]
 

template<class Tchar>
void CB2::PString< Tchar >::cpy const Tchar *  prev  )  [inline, private]
 

Copy string.

Do the conversion from another data type.

Parameters:
prev Data to convert from.

< From NULL-terminated string

template<class Tchar>
template<class Tnum>
void CB2::PString< Tchar >::cpy_numeric_float const Tnum  prev  )  [inline, private]
 

Copy string from floating point numeric data type.

Do the conversion from floating point numeric data type.

Parameters:
prev Numeric value to convert from.

template<class Tchar>
template<class Tnum>
void CB2::PString< Tchar >::cpy_numeric_int const Tnum  prev,
const size_type  base
[inline, private]
 

Copy string from integer numeric data type.

Do the conversion from integer numeric data type.

NB: The numeric base is not stored in the string

Parameters:
prev Numeric value to convert from.
base Numeric base.

template<class Tchar>
const Tchar& CB2::PString< Tchar >::Deref const ref_type ref  )  const [inline]
 

Dereference.

Get the character referenced by 'ref'. If the reference is out of range, ExceptionMemory is thrown.

Parameters:
ref Item reference.
Returns:
Item value.

template<class Tchar>
void CB2::PString< Tchar >::Discart const bool  shrink = false  )  [inline]
 

Discart the string.

Discart the contents of the string.

Parameters:
shrink Whether the memory should be disposed.

template<class Tchar>
bool CB2::PString< Tchar >::Empty  )  const [inline]
 

Check for empty.

Returns:
True if string is empty.

template<class Tchar>
iterator CB2::PString< Tchar >::End  )  const [inline]
 

Get final iterator.

Returns:
Final iterator.

template<class Tchar>
this_type CB2::PString< Tchar >::HTML const this_type nl = ""  )  const [inline]
 

Escape HTML special characters.

Escape special HTML characters by its equivalents. Currently &, <, > and " are handled.

Parameters:
nl If non-empty, all newlines are substituted by this string.
Returns:
Escaped string.

template<class Tchar>
this_type CB2::PString< Tchar >::HTMLdecode  )  const [inline]
 

Decode HTML special characters.

Currently &, <, > and " are interpreted.

Returns:
Decoded string.

template<class Tchar>
size_type CB2::PString< Tchar >::Len  )  const [inline]
 

Number of Tchar elements.

Returns:
Length of the string.

template<class Tchar>
template<class Tnum>
Tnum CB2::PString< Tchar >::numeric_float const Tnum  zero  )  const [inline, private]
 

Convert to floating point data type.

Convert current string value to floating point numeric data type.

Just simple representations are accepted.

Parameters:
signed_type Is the numeric type signed?
zero Zero value of the numeric type.
Returns:
Requested value.

template<class Tchar>
template<class Tnum>
Tnum CB2::PString< Tchar >::numeric_int const bool  signed_type,
const Tnum  zero
const [inline, private]
 

Convert to integer data type.

Convert current string value to numeric data type.

Parameters:
signed_type Is the numeric type signed?
zero Zero value of the numeric type.
Returns:
Requested value.

template<class Tchar>
CB2::PString< Tchar >::operator const Tchar *  )  const [inline]
 

Implicit conversion operators.

These operators do the implicit conversion to various data types.

If the destination type cannot represent the current string value, ExceptionConversion is thrown.

If the range of the destination type is not sufficient, ExceptionRange is thrown.

Returns:
String representation in given type.

< To NULL-terminated string

template<class Tchar>
CB2::PString< Tchar >::operator double  )  const [inline]
 

template<class Tchar>
CB2::PString< Tchar >::operator float  )  const [inline]
 

template<class Tchar>
CB2::PString< Tchar >::operator signed int  )  const [inline]
 

template<class Tchar>
CB2::PString< Tchar >::operator signed long int  )  const [inline]
 

template<class Tchar>
CB2::PString< Tchar >::operator signed long long int  )  const [inline]
 

template<class Tchar>
CB2::PString< Tchar >::operator std::basic_string  )  const [inline]
 

template<class Tchar>
CB2::PString< Tchar >::operator Tchar  )  const [inline]
 

template<class Tchar>
CB2::PString< Tchar >::operator unsigned int  )  const [inline]
 

template<class Tchar>
CB2::PString< Tchar >::operator unsigned long int  )  const [inline]
 

template<class Tchar>
CB2::PString< Tchar >::operator unsigned long long int  )  const [inline]
 

template<class Tchar>
bool CB2::PString< Tchar >::operator!= const Tchar *  str  )  const [inline]
 

template<class Tchar>
bool CB2::PString< Tchar >::operator!= const this_type str  )  const [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator+ const this_type right  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator+= const this_type right  )  [inline]
 

Concatenation operators.

Unary and binary concatenation operators

Parameters:
right Right concatenation operand.
left Left concatenation operand.
Returns:
Reference to the result.

< Unary concatenation (+=)

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator<< const Tchar &  right  )  [inline]
 

Append a character.

Append a single character to the end of the string.

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const double  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const float  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const unsigned long long int  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const signed long long int  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const unsigned long int  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const signed long int  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const unsigned int  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const signed int  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const Tchar  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const std::basic_string< Tchar >  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const Tchar *  prev  )  [inline]
 

template<class Tchar>
const this_type& CB2::PString< Tchar >::operator= const this_type prev  )  [inline]
 

Assignment operator.

Copy string data from another string repersentation.

Parameters:
prev String to copy.
Returns:
Reference to the result.

< From PString

template<class Tchar>
bool CB2::PString< Tchar >::operator== const Tchar *  str  )  const [inline]
 

template<class Tchar>
bool CB2::PString< Tchar >::operator== const this_type str  )  const [inline]
 

Compare strings.

Compare string contents with another string.

Parameters:
str String to compare with.
Returns:
Compare result.

< With PString< Tchar>

template<class Tchar>
Tchar& CB2::PString< Tchar >::operator[] const size_type  pos  )  const [inline]
 

Indexaation operator.

Access to a random character of the string. If out of range, ExceptionRange is thrown.

Parameters:
pos Index to access.
Returns:
Reference to the character on the given position.

template<class Tchar>
bool CB2::PString< Tchar >::Pos const this_type needle,
size_type pos,
const size_type  from = 0
const [inline]
 

Find position of substring.

Get the position of the nearest appearance of 'needle' beginning at index 'from'.

If 'needle' or this string are empty, false is returned.

Parameters:
needle Substring to search.
pos Position of the appearance.
from Index to search from.
Returns:
True if substring is found.

template<class Tchar>
ref_type CB2::PString< Tchar >::RefBegin  )  const [inline]
 

Get starting reference.

Get the reference to the first character in the string (as a reference to the array).

Returns:
Starting reference.

template<class Tchar>
ref_type CB2::PString< Tchar >::RefEnd  )  const [inline]
 

Get final reference.

Get the final reference. This is the reference to the last character in the array (NULL-termination).

Returns:
Final reference.

template<class Tchar>
ref_type CB2::PString< Tchar >::RefNext const ref_type prev  )  const [inline]
 

Get succeding reference.

Get the reference to a character succeding the character referenced by 'prev'. If the reference is final or invalid, final reference is returned).

Parameters:
prev Original reference.
Returns:
Next reference.

template<class Tchar>
ref_type CB2::PString< Tchar >::RefPrev const ref_type prev  )  const [inline]
 

Get predecessing reference.

Get the reference to a character predecessing the character referenced by 'prev'. If the reference is final or invalid, final reference is returned).

Parameters:
prev Original reference.
Returns:
Previous reference.

template<class Tchar>
rev_iterator CB2::PString< Tchar >::RevBegin  )  const [inline]
 

Get starting reverse iterator.

Returns:
Starting reverse iterator.

template<class Tchar>
const Tchar& CB2::PString< Tchar >::RevDeref const ref_type ref  )  const [inline]
 

Reverse dereference.

Get the character referenced by 'ref'. If the reference is out of range, ExceptionMemory is thrown.

Parameters:
ref Item reference.
Returns:
Item value.

template<class Tchar>
rev_iterator CB2::PString< Tchar >::RevEnd  )  const [inline]
 

Get final reverse iterator.

Returns:
Final reverse iterator.

template<class Tchar>
ref_type CB2::PString< Tchar >::RevRefBegin  )  const [inline]
 

Get starting reverse reference.

Get the reference to the last character.

Returns:
Starting reverse reference.

template<class Tchar>
ref_type CB2::PString< Tchar >::RevRefEnd  )  const [inline]
 

Get final reverse reference.

Get the reference to the first character.

Returns:
Final reverse reference.

template<class Tchar>
size_type CB2::PString< Tchar >::Size  )  const [inline]
 

Real size of the string in bytes.

Returns:
Size of bytes representing the string.

template<class Tchar>
this_type CB2::PString< Tchar >::SQL  )  const [inline]
 

Escape SQL special characters.

Escape special SQL characters by its equivalents. Currently ', ", \ and NULL are handled.

Returns:
Escaped string.

template<class Tchar>
this_type CB2::PString< Tchar >::SQLdecode  )  const [inline]
 

Decode SQL special characters.

Simply all characters escaped as are decoded as given symbol (except , which is interpreted as NULL character).

Returns:
Escaped string.

template<class Tchar>
size_type CB2::PString< Tchar >::Subst const this_type needle,
const this_type replacement
[inline]
 

Substitute substring.

Substitute all appearances of 'needle' by 'replacement'.

Parameters:
needle String to search.
replacement String to substitute.
Returns:
Number of substitutes done.

template<class Tchar>
this_type CB2::PString< Tchar >::Substr const size_type  base,
const size_type  length = (size_type) -1
const [inline]
 

Get substring.

Get substring from the current string. The substring is defined by the index of the first character and length.

If 'base' is out of range or the string is empty, an empty string is returned. If 'length' is too long (or contains special value (size_type) -1, which is default), it is truncated to the maximal possible length.

Parameters:
base Index of first character.
length Number of characters to copy.
Returns:
Substring.

template<class Tchar>
this_type CB2::PString< Tchar >::URL  )  const [inline]
 

Escape URL special characters.

Escape all non-alphanumeric characters as xx (where xx is the hexadecimal representation of the character) as defined by RFC1738, but leave '-' and '_' untouched and substitute space by '+'.

Returns:
Escaped string.

template<class Tchar>
this_type CB2::PString< Tchar >::URLdecode  )  const [inline]
 

Decode URL special characters.

Decode string according to RFC1738 (interpreting xx as hexadecimal representation of characters). Plus interpreting '+' as space.

Returns:
Escaped string.


Friends And Related Function Documentation

template<class Tchar>
PString< Tchar> operator+ const PString< Tchar > &  left,
const PString< Tchar > &  right
[friend]
 

Binary concatenation operator (friend variant).

Concatenate two strings and get the output string.

Parameters:
left Left operand.
right Right operand.
Returns:
Concatenated strign.

template<class Tchar>
std::basic_ostream< Tchar, std::char_traits< Tchar> >& operator<< std::basic_ostream< Tchar, std::char_traits< Tchar > > &  stream,
const PString< Tchar > &  str
[friend]
 

Stream output friend operator.

Outpus the contents of a PString object to an output stream using the same basic type (Tchar).


Member Data Documentation

template<class Tchar>
storage_type CB2::PString< Tchar >::data [private]
 

Data storage.

template<class Tchar>
const size_type CB2::PString< Tchar >::def_frag = 1024 [static, private]
 

Default array fragment size.

int CB2::Class::tag [inherited]
 

Tag for user-specific data.


The documentation for this class was generated from the following file:
Generated on Thu Sep 16 23:26:49 2004 for ColorBox2 by doxygen 1.3.7