Free Electron
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
fe::DualString Class Reference

Automatically reference-counted string container. More...

#include <DualString.h>

Public Member Functions

 DualString (void)
 Construct an empty string. More...
 
 DualString (const DualString &operand)
 Copy constructor. More...
 
 DualString (const FESTRING_I8 *operand)
 Construct using a signed byte buffer. More...
 
 DualString (const FESTRING_U8 *operand)
 Construct using a unsigned byte buffer. More...
 
 DualString (const FESTRING_WIDE *operand)
 Construct using a wide buffer, presumably Unicode. More...
 
 DualString (I32 operand)
 allow init as 0 in templates More...
 
 operator const FESTRING_I8 * (void) const
 Cast the contents of the 8-bit buffer as signed bytes. More...
 
 operator const FESTRING_U8 * (void) const
 Cast the contents of the 8-bit buffer as unsigned bytes. More...
 
 operator const FESTRING_WIDE * (void) const
 Cast the contents of the wide buffer as Unicode. More...
 
DualStringoperator= (const DualString &operand)
 Compare to another DualString. More...
 
DualStringoperator= (const FESTRING_I8 *operand)
 Compare to a signed byte buffer (using 8-bit). More...
 
DualStringoperator= (const FESTRING_U8 *operand)
 Compare to an unsigned byte buffer (using 8-bit). More...
 
DualStringoperator= (const FESTRING_WIDE *operand)
 Compare to an unicode buffer (using wide chars). More...
 
I32 compare (const DualString &operand) const
 Standard string compare: returns -1, 0, or 1 if the string is alphabetically less than, equal, or greater than the operand. More...
 
BWORD operator< (const DualString &operand) const
 
BWORD dotMatch (const DualString &operand) const
 Compares to another string assuming the given string is a dot-delimited ordered list containing optional substrings. More...
 
void forceUppercase (void)
 Force all applicable characters to upper case. More...
 
void forceLowercase (void)
 Force all applicable characters to lower case. More...
 
U32 length (void) const
 Return the number of represented characters, but not necessarily the size of any buffer. More...
 
DualStringsPrintf (const char *fmt,...)
 Populate the string in the manner of sprintf(). More...
 
DualStringcatf (const char *fmt,...)
 Populate the string as with SPrintf(), but by concatenating the results to the existing string. More...
 
DualStringcat (std::list< DualString > &strList, DualString sep="")
 Concatenate the strings in a list. More...
 
DualStringvsPrintf (const char *fmt, va_list ap)
 Populate using variable arg format. More...
 
const FESTRING_I8 * raw (void) const
 Return the contents of the 8-bit buffer cast as signed bytes. More...
 
const FESTRING_I8 * c_str (void) const
 Return the contents of the 8-bit buffer cast as signed bytes. More...
 
const FESTRING_U8 * rawU8 (void) const
 Return the contents of the 8-bit buffer cast as unsigned bytes. More...
 
const FESTRING_WIDE * rawWide (void) const
 Return the contents of the wide buffer cast in native unicode format. More...
 
void output (std::ostream &ostrm) const
 
void input (std::istream &istrm)
 

Private Member Functions

DualString copy (void) const
 Returns a new string with a copied underlying representation. More...
 
void init (void)
 
void forceCase (BWORD upper)
 
void confirm8 (void)
 
void confirmWide (void)
 
virtual Rep * newRep (void)
 
virtual void deleteRep (void)
 

Static Private Member Functions

static U32 strlenWide (const FESTRING_WIDE *buffer)
 

Private Attributes

Rep * m_pRep
 

Detailed Description

Automatically reference-counted string container.

Designed to behave as a native type, like float or int. All allocation worries are completely hidden.

To assign a string just use simple assignments.

DualString name("me");
name="you";
DualString id=name;

You can compare strings in a boolean or lexical fashion.

if(name!="Bob" && name.compare("M")<0)
...

To print a string in printf fashion, cast it to (char*) or use c_str().

printf("%s %s\n",(char*)firstname,lastname.c_str());

Operates in multiple formats with JIT conversion.

TODO consider fixed local buffer for small strings to avoid new()

Reference: Stroustrup C++ Ref Man, 2nd ed., pg. 248

Constructor & Destructor Documentation

◆ DualString() [1/6]

fe::DualString::DualString ( void  )

Construct an empty string.

◆ DualString() [2/6]

fe::DualString::DualString ( const DualString operand)

Copy constructor.

◆ DualString() [3/6]

fe::DualString::DualString ( const FESTRING_I8 *  operand)

Construct using a signed byte buffer.

◆ DualString() [4/6]

fe::DualString::DualString ( const FESTRING_U8 *  operand)

Construct using a unsigned byte buffer.

◆ DualString() [5/6]

fe::DualString::DualString ( const FESTRING_WIDE *  operand)

Construct using a wide buffer, presumably Unicode.

◆ DualString() [6/6]

fe::DualString::DualString ( I32  operand)

allow init as 0 in templates

Member Function Documentation

◆ c_str()

const FESTRING_I8* fe::DualString::c_str ( void  ) const
inline

Return the contents of the 8-bit buffer cast as signed bytes.

Referenced by cat(), catf(), fe::operator!=(), and output().

◆ cat()

DualString & fe::DualString::cat ( std::list< DualString > &  strList,
DualString  sep = "" 
)

Concatenate the strings in a list.

References c_str(), and catf().

Referenced by forceLowercase().

◆ catf()

DualString & fe::DualString::catf ( const char *  fmt,
  ... 
)

Populate the string as with SPrintf(), but by concatenating the results to the existing string.

References c_str(), sPrintf(), and vsPrintf().

Referenced by cat(), forceLowercase(), and fe::operator!=().

◆ compare()

I32 fe::DualString::compare ( const DualString operand) const

Standard string compare: returns -1, 0, or 1 if the string is alphabetically less than, equal, or greater than the operand.

Referenced by fe::operator!=(), and fe::operator==().

◆ copy()

DualString fe::DualString::copy ( void  ) const
private

Returns a new string with a copied underlying representation.

Note that the normal operator=() uses the same representation. This method is provided in case data from an alternate heap may be destroyed. This is primarily a Win32 DLL issue. Note that DualString is already safe across live heaps.

References length().

◆ dotMatch()

BWORD fe::DualString::dotMatch ( const DualString operand) const

Compares to another string assuming the given string is a dot-delimited ordered list containing optional substrings.

Returns true if strings are exactly the same, or if they match only up to the length of the operand and the operand's terminating zero matches a period.

◆ forceLowercase()

void fe::DualString::forceLowercase ( void  )
inline

Force all applicable characters to lower case.

References cat(), catf(), length(), sPrintf(), and vsPrintf().

◆ forceUppercase()

void fe::DualString::forceUppercase ( void  )
inline

Force all applicable characters to upper case.

◆ length()

U32 fe::DualString::length ( void  ) const

Return the number of represented characters, but not necessarily the size of any buffer.

Referenced by copy(), and forceLowercase().

◆ operator const FESTRING_I8 *()

fe::DualString::operator const FESTRING_I8 * ( void  ) const
inline

Cast the contents of the 8-bit buffer as signed bytes.

◆ operator const FESTRING_U8 *()

fe::DualString::operator const FESTRING_U8 * ( void  ) const
inline

Cast the contents of the 8-bit buffer as unsigned bytes.

◆ operator const FESTRING_WIDE *()

fe::DualString::operator const FESTRING_WIDE * ( void  ) const
inline

Cast the contents of the wide buffer as Unicode.

◆ operator=() [1/4]

DualString & fe::DualString::operator= ( const DualString operand)

Compare to another DualString.

Referenced by output().

◆ operator=() [2/4]

DualString& fe::DualString::operator= ( const FESTRING_I8 *  operand)
inline

Compare to a signed byte buffer (using 8-bit).

◆ operator=() [3/4]

DualString & fe::DualString::operator= ( const FESTRING_U8 *  operand)

Compare to an unsigned byte buffer (using 8-bit).

◆ operator=() [4/4]

DualString & fe::DualString::operator= ( const FESTRING_WIDE *  operand)

Compare to an unicode buffer (using wide chars).

◆ output()

void fe::DualString::output ( std::ostream &  ostrm) const
Todo:
: string serialization currently hacked in.

only works for 8bit and does too much copying

References c_str(), and operator=().

◆ raw()

const FESTRING_I8* fe::DualString::raw ( void  ) const
inline

Return the contents of the 8-bit buffer cast as signed bytes.

◆ rawU8()

const FESTRING_U8 * fe::DualString::rawU8 ( void  ) const

Return the contents of the 8-bit buffer cast as unsigned bytes.

◆ rawWide()

const FESTRING_WIDE * fe::DualString::rawWide ( void  ) const

Return the contents of the wide buffer cast in native unicode format.

◆ sPrintf()

DualString & fe::DualString::sPrintf ( const char *  fmt,
  ... 
)

Populate the string in the manner of sprintf().

References vsPrintf().

Referenced by catf(), and forceLowercase().

◆ vsPrintf()

DualString & fe::DualString::vsPrintf ( const char *  fmt,
va_list  ap 
)

Populate using variable arg format.

Referenced by catf(), forceLowercase(), and sPrintf().


The documentation for this class was generated from the following files: