Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

oofString Class Reference

#include <oofstr.h>

Inheritance diagram for oofString:

Inheritance graph
[legend]
List of all members.

Detailed Description

Portable highly capable string class.

Written because ANSI strings lack features on older compilers. Also Mac-aware if running on a Mac (not if using Quicktime for Windows).

Todo:
add reference-counting subclass oofRefString


Public Types

typedef short(* oofCompareFunc )(const void *inLeft, const void *inRight, long inLeftLength, long inRightLength)
 string comparison nearly directly compatible with PowerPlant's except doesn't have inherent size limits from assumption of Str255 types (Pascal strings)

enum  { CR = 13, LF = 10, kNotFound = -1 }

Public Member Functions

 oofString (char, int repeatCount)
 oofString (const char *str=0)
 oofString (const oofString &)
 oofString (const char *chars, unsigned long numChars)
 oofString (char *adoptedChars, unsigned long numChars, bool adopt)
void loadResource (unsigned long strID)
 oofString (std::ostream &)
 ctor taking an output stream.

 oofString (std::stringstream &)
 oofString (const std::string &)
 oofString (const Str255)
 oofString (const oofString &, const char *)
 oofString (const oofString &, const oofString &)
 oofString (const oofString &, const char, const char *)
 oofString (const oofString &, const char *, const oofString &)
 oofString (char, const oofString &, char)
virtual ~oofString ()
oofStringoperator= (const std::string &)
oofStringoperator= (const oofString &)
oofStringoperator= (const char *)
void insertChars (const char *, unsigned long, unsigned long beforeChar=ULONG_MAX)
void setChars (const char *, unsigned long)
 Replace current contents of string with incoming buffer.

void adopt (char *)
void adopt (oofString &)
void shorten (unsigned short)
void padTo (unsigned short paddedLength, char padWith=' ', bool rightAlign=false)
void operator+= (char)
void operator+= (const char *)
void operator+= (const oofString &)
void append (const char *, unsigned long appendLen)
void clear ()
char & operator[] (int) const
char & operator[] (short) const
char & operator[] (unsigned long) const
void convertNumber (int, const char *printfMask=0, bool appendIt=false)
void convertNumber (unsigned long, const char *printfMask=0, bool appendIt=false)
void convertNumber (double, const char *printfMask=0, bool appendIt=false)
int format (const char *inStr,...)
 Create string content using printf formatting.

unsigned long replaceChar (char fromChar, char toChar, unsigned long startAt=0)
void replaceAt (unsigned long startAt, unsigned long numChars, const char *newStr, unsigned long newLen=ULONG_MAX)
unsigned long replaceFirstString (const char *replaceStr, const char *newStr, bool caseSensitive=false)
unsigned long replaceString (const char *replaceStr, const char *newStr, unsigned long startAt=0, bool caseSensitive=false)
 Search and replace a substring with optional starting offset and case sensitivity.

unsigned long replaceBetween (const char *leftStr, const char *rightStr, const char *insertStr, bool caseSensitive=false)
unsigned long replaceStringWholeWord (const char *replaceStr, const char *newStr, unsigned long startAt=0, bool caseSensitive=false)
 Search and replace a substring with optional starting offset and case sensitivity.

unsigned long stripChar (char, unsigned long startAt=0)
void makeRandomChars (unsigned long numChars)
void encodeURL ()
void setStr255 (const Str255)
oofStringoperator= (const Str255)
 operator const char * () const
const char * chars () const
char * charsForOldInterfacesNotWriting () const
char * orphan (bool neverReturnNil=true)
char firstChar () const
char lastChar () const
bool startsWith (char) const
bool startsWith (const char *) const
bool endsWith (char) const
bool endsWith (const char *, int inLen=-1) const
void getChars (char *ioBuff, unsigned long &ioLen) const
void getStr255 (Str255 s) const
 operator std::string () const
oofString left (unsigned long numChars) const
oofString right (unsigned long numChars) const
oofString subString (unsigned long fromChars, unsigned long numChars=ULONG_MAX) const
oofString subStringBetween (const char *, const char *) const
oofString subStringBetween (char, char) const
oofString operator- (const char *) const
long find (const char *, unsigned long startFrom=0, bool caseSensitive=false, unsigned long inLen=ULONG_MAX) const
 Character-based search with optional case sensitivity.

long findLast (const char *, bool caseSensitive=false, unsigned long inLen=ULONG_MAX) const
 Character-based reverse search with optional case sensitivity.

bool contains (const char *, bool caseSensitive=false) const
bool contains (char, bool caseSensitive=false) const
long find (char, unsigned long startFrom=0, bool caseSensitive=false) const
 Optionally caseSensitive find of first match.

long findLast (char, bool caseSensitive=false) const
long findEnd (const char *, unsigned long startFrom=0, bool caseSensitive=false) const
unsigned short asUnsignedShort () const
short asShort () const
long asLong () const
unsigned long asUnsignedLong () const
double asDouble () const
bool isEmpty () const
unsigned long length () const
bool isAlphaNumeric () const
bool operator== (const Str255) const
bool operator== (const oofString &rhs) const
bool operator== (const char *) const
bool operator!= (const char *) const
bool operator!= (const oofString &rhs) const
bool lineEndingsCurrentPlatform ()
bool lineEndingsMac ()
bool lineEndingsUnix ()
bool lineEndingsDOS ()

Static Public Member Functions

char * lineEndingsCurrentPlatform (char *, unsigned long &ioLen)
 forward to appropriate platform method for static converters

char * lineEndingsMac (char *, unsigned long &ioLen)
char * lineEndingsUnix (char *, unsigned long &ioLen)
char * lineEndingsDOS (char *, unsigned long &ioLen)
oofString encodeEntity (const oofString &)
 Return a string encoded suitable for use in HTML or XML.

oofString decodeEntity (const oofString &)
 Return a string decoded from HTML or XML.

oofString utf8To8BitAscii (const oofString &)
oofString utf8To8BitAscii (const char *, unsigned long)
 Change string contents to decoded version of Unicode 8 bit string.

oofString quoteString (const oofString &, char quoteChar='\'')
oofString singular (const oofString &)
oofString legalName (const oofString &, char nonAlphaReplace='_', char leadingDigitReplace='n', char spaceReplace='_')

Protected Attributes

char * mBody
unsigned long mLen

Static Protected Attributes

char sEmptyChar = '\0'


Member Typedef Documentation

typedef short(* oofString::oofCompareFunc)( const void* inLeft, const void* inRight, long inLeftLength, long inRightLength)
 

string comparison nearly directly compatible with PowerPlant's except doesn't have inherent size limits from assumption of Str255 types (Pascal strings)

left == right, returns 0 left > right, returns 1 left < right, returns -1


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
CR 
LF 
kNotFound 


Constructor & Destructor Documentation

oofString::oofString char  ,
int  repeatCount
 

oofString::oofString const char *  str = 0  ) 
 

oofString::oofString const oofString  ) 
 

oofString::oofString const char *  chars,
unsigned long  numChars
 

oofString::oofString char *  adoptedChars,
unsigned long  numChars,
bool  adopt
 

oofString::oofString std::ostream &  os  ) 
 

ctor taking an output stream.

Note:
you will call this constructor even from an expression like oofString jack(ostringstream() << flush << "first line\n" << "second\n"); because it is the type of the return value from the operator<< which is last evaluated, NOT the type of temporary stream object you start with.

oofString::oofString std::stringstream &   ) 
 

oofString::oofString const std::string &   ) 
 

oofString::oofString const  Str255  ) 
 

oofString::oofString const oofString ,
const char * 
 

oofString::oofString const oofString ,
const oofString
 

oofString::oofString const oofString ,
const  char,
const char * 
 

oofString::oofString const oofString ,
const char *  ,
const oofString
 

oofString::oofString char  ,
const oofString ,
char 
 

oofString::~oofString  )  [virtual]
 


Member Function Documentation

void oofString::adopt oofString  ) 
 

void oofString::adopt char *   ) 
 

void oofString::append const char *  ,
unsigned long  appendLen
 

double oofString::asDouble  )  const
 

long oofString::asLong  )  const
 

short oofString::asShort  )  const
 

unsigned long oofString::asUnsignedLong  )  const
 

unsigned short oofString::asUnsignedShort  )  const
 

const char * oofString::chars  )  const [inline]
 

char * oofString::charsForOldInterfacesNotWriting  )  const [inline]
 

void oofString::clear  ) 
 

bool oofString::contains char  ,
bool  caseSensitive = false
const [inline]
 

bool oofString::contains const char *  ,
bool  caseSensitive = false
const [inline]
 

void oofString::convertNumber double  ,
const char *  printfMask = 0,
bool  appendIt = false
 

void oofString::convertNumber unsigned  long,
const char *  printfMask = 0,
bool  appendIt = false
 

void oofString::convertNumber int  ,
const char *  printfMask = 0,
bool  appendIt = false
 

oofString oofString::decodeEntity const oofString srcString  )  [static]
 

Return a string decoded from HTML or XML.

Doesn't do any special parsing, just decodes entities like & or other numbers. Uses the XML subset of encodings allowed in HTML, just lt, gt, amp, apos and quot.

oofString oofString::encodeEntity const oofString srcString  )  [static]
 

Return a string encoded suitable for use in HTML or XML.

void oofString::encodeURL  ) 
 

bool oofString::endsWith const char *  ,
int  inLen = -1
const
 

bool oofString::endsWith char   )  const
 

long oofString::find char  inChar,
unsigned long  startFrom = 0,
bool  caseSensitive = false
const
 

Optionally caseSensitive find of first match.

Returns:
kNotFound or index of first substring found.
Parameters:
caseSensitive defaults false.

long oofString::find const char *  inStr,
unsigned long  startFrom = 0,
bool  caseSensitive = false,
unsigned long  inLen = ULONG_MAX
const
 

Character-based search with optional case sensitivity.

Parameters:
caseSensitive default false
inLen optional length of search argument to save time doing strlen if known length
Warning:
only caseSensitive if pass in a totally alphabetic search string
Todo:
decide if caseSensitive policy should be changed

long oofString::findEnd const char *  ,
unsigned long  startFrom = 0,
bool  caseSensitive = false
const
 

long oofString::findLast char  ,
bool  caseSensitive = false
const
 

long oofString::findLast const char *  inStr,
bool  caseSensitive = false,
unsigned long  inLen = ULONG_MAX
const
 

Character-based reverse search with optional case sensitivity.

Parameters:
caseSensitive default false
inLen optional length of search argument to save time doing strlen if known length
Warning:
only caseSensitive if pass in a totally alphabetic search string
Todo:
decide if caseSensitive policy should be changed

char oofString::firstChar  )  const
 

int oofString::format const char *  inFormat,
... 
 

Create string content using printf formatting.

Warning:
may overrun buffer of size OOF_OOFSTR_FORMAT_BUFFERSIZE use at own risk!!
Todo:
possibly throw error instead of assert to guard overrun.

void oofString::getChars char *  ioBuff,
unsigned long &  ioLen
const
 

void oofString::getStr255 Str255  s  )  const
 

void oofString::insertChars const char *  ,
unsigned  long,
unsigned long  beforeChar = ULONG_MAX
 

bool oofString::isAlphaNumeric  )  const
 

bool oofString::isEmpty  )  const [inline]
 

char oofString::lastChar  )  const
 

oofString oofString::left unsigned long  numChars  )  const
 

oofString oofString::legalName const oofString ,
char  nonAlphaReplace = '_',
char  leadingDigitReplace = 'n',
char  spaceReplace = '_'
[static]
 

unsigned long oofString::length  )  const [inline]
 

char * oofString::lineEndingsCurrentPlatform char *  ,
unsigned long &  ioLen
[inline, static]
 

forward to appropriate platform method for static converters

bool oofString::lineEndingsCurrentPlatform  )  [inline]
 

char * oofString::lineEndingsDOS char *  ,
unsigned long &  ioLen
[static]
 

bool oofString::lineEndingsDOS  ) 
 

char * oofString::lineEndingsMac char *  ,
unsigned long &  ioLen
[static]
 

bool oofString::lineEndingsMac  ) 
 

char * oofString::lineEndingsUnix char *  ,
unsigned long &  ioLen
[static]
 

bool oofString::lineEndingsUnix  ) 
 

void oofString::loadResource unsigned long  strID  ) 
 

void oofString::makeRandomChars unsigned long  numChars  ) 
 

oofString::operator const char *  )  const
 

oofString::operator std::string  )  const
 

bool oofString::operator!= const oofString rhs  )  const [inline]
 

bool oofString::operator!= const char *   )  const [inline]
 

void oofString::operator+= const oofString  ) 
 

void oofString::operator+= const char *   ) 
 

void oofString::operator+= char   ) 
 

oofString oofString::operator- const char *   )  const
 

oofString & oofString::operator= const  Str255  )  [inline]
 

oofString & oofString::operator= const char *   ) 
 

oofString & oofString::operator= const oofString  ) 
 

oofString & oofString::operator= const std::string &   ) 
 

bool oofString::operator== const char *   )  const
 

bool oofString::operator== const oofString rhs  )  const
 

bool oofString::operator== const  Str255  )  const
 

char & oofString::operator[] unsigned  long  )  const
 

char & oofString::operator[] short   )  const [inline]
 

char & oofString::operator[] int   )  const [inline]
 

char * oofString::orphan bool  neverReturnNil = true  ) 
 

void oofString::padTo unsigned short  paddedLength,
char  padWith = ' ',
bool  rightAlign = false
 

oofString oofString::quoteString const oofString ,
char  quoteChar = '\''
[static]
 

void oofString::replaceAt unsigned long  startAt,
unsigned long  numChars,
const char *  newStr,
unsigned long  newLen = ULONG_MAX
 

unsigned long oofString::replaceBetween const char *  leftStr,
const char *  rightStr,
const char *  insertStr,
bool  caseSensitive = false
 

unsigned long oofString::replaceChar char  fromChar,
char  toChar,
unsigned long  startAt = 0
 

unsigned long oofString::replaceFirstString const char *  replaceStr,
const char *  newStr,
bool  caseSensitive = false
 

unsigned long oofString::replaceString const char *  replaceStr,
const char *  newStr,
unsigned long  startAt = 0,
bool  caseSensitive = false
 

Search and replace a substring with optional starting offset and case sensitivity.

Todo:
add an OOFILE sample to exercise edge conditions where input strings match

add an OOFILE sample to test if original string exactly matches replacement

check if David's increment is needed - startAt = foundAt + strlen(newStr);

Warning:
too much optimisation will may break - you may get substrings where the replace string in combination with surroundings causes a recurrence of the original

unsigned long oofString::replaceStringWholeWord const char *  replaceStr,
const char *  newStr,
unsigned long  startAt = 0,
bool  caseSensitive = false
 

Search and replace a substring with optional starting offset and case sensitivity.

Similar to replaceString except this only replaces whole word matches of sub string This to prevent calls like replaceStringWholeWord("htm", html) pm "html htm" giving htmll html A word is defined a s a sequence of matching chars, delimited by a non alpha/numeric char

Todo:
add an OOFILE sample to exercise edge conditions where input strings match

add an OOFILE sample to test if original string exactly matches replacement

check if David's increment is needed - startAt = foundAt + strlen(newStr);

Warning:
too much optimisation will may break - you may get substrings where the replace string in combination with surroundings causes a recurrence of the original

oofString oofString::right unsigned long  numChars  )  const
 

void oofString::setChars const char *  chars,
unsigned long  charLen
 

Replace current contents of string with incoming buffer.

Still deletes current contents if incoming empty string or null pointer, which makes this a way to clear contents. Common idiom is myString = 0 or myString = ""; to clear a string.

optimal setting
To avoid thrashing heap with lots of similar allocs, if incoming string is over half size of existing or string small, just copy chars without a delete.

Todo:
smarter avoid reallocs if mBody within certain size range that will fit chars - would require keeping alloc length as well as mLen as repeated reallocs here will be in ignorance of true buffer size.

void oofString::setStr255 const  Str255  ) 
 

void oofString::shorten unsigned  short  ) 
 

oofString oofString::singular const oofString  )  [static]
 

bool oofString::startsWith const char *   )  const
 

bool oofString::startsWith char   )  const
 

unsigned long oofString::stripChar char  ,
unsigned long  startAt = 0
 

oofString oofString::subString unsigned long  fromChars,
unsigned long  numChars = ULONG_MAX
const
 

oofString oofString::subStringBetween char  ,
char 
const
 

oofString oofString::subStringBetween