OOFILE  1.9
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
oofString Class Reference

Portable highly capable string class. More...

#include <oofstr.h>

Inheritance diagram for oofString:
Inheritance graph
[legend]

Public Types

enum  { CR = 13, LF = 10, kNotFound =-1 }
 
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) More...
 

Public Member Functions

void adopt (char *)
 Take ownership of incoming buffer, replacing current contents. More...
 
void adopt (oofString &)
 Take ownership of buffer from incoming string, replacing current contents. More...
 
void append (const char *, unsigned long appendLen)
 
double asDouble () const
 Attempt to return real value of string. More...
 
long asLong () const
 Attempt to return integer value of string. More...
 
short asShort () const
 Attempt to return integer value of string. More...
 
unsigned long asUnsignedLong () const
 Attempt to return integer value of string. More...
 
unsigned short asUnsignedShort () const
 Attempt to return integer value of string. More...
 
const char * chars () const
 Primary test: oofStringTest::stringInitOneCharFromConstant () More...
 
char * charsForOldInterfacesNotWriting () const
 
void clear ()
 Abandon string contents, resetting length. More...
 
bool contains (const char *, bool caseSensitive=false) const
 
bool contains (char, bool caseSensitive=false) 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)
 
void encodeURL ()
 
bool endsWith (char) const
 
bool endsWith (const char *, int inLen=-1) 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. More...
 
long find (char, unsigned long startFrom=0, bool caseSensitive=false) const
 Optionally caseSensitive find of first match. More...
 
long findEnd (const char *, unsigned long startFrom=0, bool caseSensitive=false) const
 
long findLast (const char *, bool caseSensitive=false, unsigned long inLen=ULONG_MAX) const
 Character-based reverse search with optional case sensitivity. More...
 
long findLast (char, bool caseSensitive=false) const
 
char firstChar () const
 Constant access to first char. More...
 
int format (const char *inStr,...)
 Create string content using printf formatting. More...
 
void getChars (char *ioBuff, unsigned long &ioLen) const
 
void getStr255 (Str255 s) const
 
void insertChars (const char *, unsigned long, unsigned long beforeChar=ULONG_MAX)
 
bool isAlphaNumeric () const
 
bool isEmpty () const
 Test based on either length or null pointer. More...
 
char lastChar () const
 Constant access to last char. More...
 
oofString left (unsigned long numChars) const
 Create new string containing leftmost numChars. More...
 
unsigned long length () const
 Primary test: oofStringTest::emptyStringByNullInitIsLenZero() More...
 
bool lineEndingsCurrentPlatform ()
 
bool lineEndingsDOS ()
 Convert all line endings in string to DOS standard - CRLF. More...
 
bool lineEndingsMac ()
 Convert all line endings in string to Mac standard - CR. More...
 
bool lineEndingsUnix ()
 Convert all line endings in string to Unix standard - LF. More...
 
void loadResource (unsigned long strID)
 
void makeRandomChars (unsigned long numChars)
 Generate string of len numChars with random content, replacing existing contents. More...
 
 oofString (char, int repeatCount)
 Primary test: oofStringTest::stringInitOneCharFromConstant() More...
 
 oofString (const char *str=0)
 Primary test: oofStringTest::stringInitStrFromConstant() More...
 
 oofString (const oofString &)
 Copy constructor. More...
 
 oofString (const char *chars, unsigned long numChars)
 
 oofString (char *adoptedChars, unsigned long numChars, bool adopt)
 
 oofString (std::ostream &)
 
 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)
 
 operator const char * () const
 Primary test: oofStringTest::stringAppendNullStrFromConstant() More...
 
 operator std::string () const
 
bool operator!= (const char *) const
 Unique negative comparison to avoid compiler ambiguity complaints. More...
 
bool operator!= (const oofString &rhs) const
 Unique negative comparison to avoid compiler ambiguity complaints. More...
 
void operator+= (char)
 
void operator+= (const char *)
 Primary test: oofStringTest::stringAppendStrFromConstant() More...
 
void operator+= (const oofString &)
 Primary test: oofStringTest::stringAppendFromString() More...
 
oofString operator- (const char *) const
 
oofStringoperator= (const std::string &)
 
oofStringoperator= (const oofString &)
 
oofStringoperator= (const char *)
 Replace our contents by copying the specified c string. More...
 
oofStringoperator= (const Str255)
 
bool operator== (const Str255) const
 
bool operator== (const oofString &rhs) const
 Primary test: oofStringTest::stringReassignFromString() More...
 
bool operator== (const char *) const
 case-sensitive direct comparison with c string. More...
 
char & operator[] (int) const
 Primary test: oofStringTest::stringInitStrFromConstant () More...
 
char & operator[] (short) const
 
char & operator[] (unsigned long) const
 Primary test: oofStringTest::stringInitOneCharFromConstant() More...
 
char * orphan (bool neverReturnNil=true)
 Give away our internal buffer, clearing our length and pointer. More...
 
void padTo (unsigned short paddedLength, char padWith=' ', bool rightAlign=false)
 
void replaceAt (unsigned long startAt, unsigned long numChars, const char *newStr, unsigned long newLen=ULONG_MAX)
 
unsigned long replaceBetween (const char *leftStr, const char *rightStr, const char *insertStr, bool caseSensitive=false)
 
unsigned long replaceChar (char fromChar, char toChar, unsigned long startAt=0)
 
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. More...
 
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. More...
 
oofString right (unsigned long numChars) const
 Create new string containing rightmost numChars. More...
 
void setChars (const char *, unsigned long)
 Replace current contents of string with incoming buffer. More...
 
void setStr255 (const Str255)
 
void shorten (unsigned short)
 Reduce string length by dropChars. More...
 
bool startsWith (char) const
 
bool startsWith (const char *) const
 
unsigned long stripChar (char, unsigned long startAt=0)
 
oofString subString (unsigned long fromChars, unsigned long numChars=ULONG_MAX) const
 
oofString subStringBetween (const char *, const char *) const
 
oofString subStringBetween (char, char) const
 
virtual ~oofString ()
 

Static Public Member Functions

static oofString decodeEntity (const oofString &)
 Return a string decoded from HTML or XML. More...
 
static oofString encodeEntity (const oofString &)
 Return a string encoded suitable for use in HTML or XML. More...
 
static oofString legalName (const oofString &, char nonAlphaReplace='_', char leadingDigitReplace='n', char spaceReplace='_')
 
static char * lineEndingsCurrentPlatform (char *, unsigned long &ioLen)
 forward to appropriate platform method for static converters More...
 
static char * lineEndingsDOS (char *, unsigned long &ioLen)
 Convert all line endings in external buffer to DOS standard - CRLF. More...
 
static char * lineEndingsMac (char *, unsigned long &ioLen)
 Convert all line endings in external buffer to Mac standard - CR. More...
 
static char * lineEndingsUnix (char *, unsigned long &ioLen)
 Convert all line endings in external buffer to Unix standard - LF. More...
 
static oofString quoteString (const oofString &, char quoteChar='\'')
 
static oofString singular (const oofString &)
 
static oofString utf8To8BitAscii (const oofString &)
 
static oofString utf8To8BitAscii (const char *, unsigned long)
 Change string contents to decoded version of Unicode 8 bit string. More...
 

Protected Attributes

char * mBody
 
unsigned long mLen
 

Static Protected Attributes

static char sEmptyChar = '\0'
 

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).

This is a pure byte-oriented string. For a portable wide string class see the conditionally compiling oofTString which uses TCHAR.

Todo:
add reference-counting subclass oofRefString

Definition at line 101 of file oofstr.h.

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

Definition at line 114 of file oofstr.h.

Member Enumeration Documentation

anonymous enum
Enumerator
CR 
LF 
kNotFound 

Definition at line 103 of file oofstr.h.

Constructor & Destructor Documentation

oofString::oofString ( char  inChar,
int  repeatCount 
)

Primary test: oofStringTest::stringInitOneCharFromConstant()

Definition at line 141 of file oofstr.cpp.

References OOF_MEM_DEBUG_FORCE_POOL_CHECK.

Referenced by left(), operator-(), quoteString(), right(), subString(), and subStringBetween().

oofString::oofString ( const char *  str = 0)

Primary test: oofStringTest::stringInitStrFromConstant()

Definition at line 265 of file oofstr.cpp.

oofString::oofString ( const oofString rhs)

Copy constructor.

Primary test: oofStringTest::stringInitFromString()

Definition at line 90 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

oofString::oofString ( const char *  chars,
unsigned long  numChars 
)
Todo:
add unit test

Definition at line 278 of file oofstr.cpp.

oofString::oofString ( char *  chars,
unsigned long  numChars,
bool  adopt 
)
Todo:
add unit test

Definition at line 288 of file oofstr.cpp.

References chars(), mBody, and mLen.

oofString::oofString ( std::ostream &  )
oofString::oofString ( std::stringstream &  )
oofString::oofString ( const std::string &  )
oofString::oofString ( const Str255  str)
Todo:
add unit test

Definition at line 366 of file oofstr.cpp.

oofString::oofString ( const oofString str1,
const char *  chars 
)
Todo:
add unit test

Definition at line 206 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

oofString::oofString ( const oofString str1,
const oofString str2 
)
Todo:
add unit test

Definition at line 158 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

oofString::oofString ( const oofString str1,
const char  ch,
const char *  chars 
)
Todo:
add unit test

Definition at line 236 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

oofString::oofString ( const oofString str1,
const char *  chars,
const oofString str3 
)
Todo:
add unit test

Definition at line 109 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

oofString::oofString ( char  inChar1,
const oofString str1,
char  inChar2 
)
Todo:
add unit test

Definition at line 185 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

oofString::~oofString ( )
virtual
Todo:
add unit test

Definition at line 378 of file oofstr.cpp.

References mBody.

Member Function Documentation

void oofString::adopt ( char *  str)

Take ownership of incoming buffer, replacing current contents.

Primary test: oofStringTest::stringAdoptConstant()

Definition at line 2299 of file oofstr.cpp.

References mBody, and mLen.

Referenced by encodeEntity(), oofRepRTFEnv::encodeRTFString(), oofColumnGraph::finishConstruction(), oofPointGraph::finishConstruction(), oofLineGraph::finishConstruction(), oofBarGraph::finishConstruction(), oofStackedBarGraph::finishConstruction(), and oofOrdinalStackedBarGraph::finishConstruction().

void oofString::adopt ( oofString rhs)

Take ownership of buffer from incoming string, replacing current contents.

Primary test: oofStringTest::stringAdoptString()

Definition at line 2312 of file oofstr.cpp.

References length(), mBody, mLen, and orphan().

void oofString::append ( const char *  str,
unsigned long  appendLen 
)
double oofString::asDouble ( ) const

Attempt to return real value of string.

Returns
zero if doesn't contain integer.
Todo:
add unit test

Definition at line 2253 of file oofstr.cpp.

References length(), and mBody.

long oofString::asLong ( ) const

Attempt to return integer value of string.

Returns
zero if doesn't contain integer.
Todo:
add unit test

Definition at line 2217 of file oofstr.cpp.

References length(), and mBody.

Referenced by dbGUIAdaptControl::equalsString(), dbGUIAdapter::getValue(), and dbGUIAdaptControl::setString().

short oofString::asShort ( ) const

Attempt to return integer value of string.

Returns
zero if doesn't contain integer.
Todo:
add unit test

Definition at line 2200 of file oofstr.cpp.

References length(), and mBody.

unsigned long oofString::asUnsignedLong ( ) const

Attempt to return integer value of string.

Returns
zero if doesn't contain integer.
Todo:
add unit test

Definition at line 2235 of file oofstr.cpp.

References length(), and mBody.

Referenced by oofXMLschemaParser::attributes2fieldtype().

unsigned short oofString::asUnsignedShort ( ) const

Attempt to return integer value of string.

Returns
zero if doesn't contain integer.
Todo:
add unit test

Definition at line 2184 of file oofstr.cpp.

References length(), and mBody.

const char * oofString::chars ( ) const
inline
char * oofString::charsForOldInterfacesNotWriting ( ) const
inline
void oofString::clear ( )

Abandon string contents, resetting length.

Primary test: oofStringTest::explicitClears()

Definition at line 2325 of file oofstr.cpp.

References mBody, and mLen.

Referenced by oofRepDrawable::clearID(), oofXMLwriter::endElement(), format(), oofRepTextBlock::getCellText(), oofRepFieldBlock::getCellText(), shorten(), oofXMLserializableParser::startElement(), oofXMLdataParser::startElement(), and OOF_XMLrepLayoutParser::startElement().

bool oofString::contains ( const char *  schStr,
bool  caseSensitive = false 
) const
inline
Todo:
add unit test

Definition at line 361 of file oofstr.h.

References find(), and kNotFound.

bool oofString::contains ( char  schChar,
bool  caseSensitive = false 
) const
inline
Todo:
add unit test

Definition at line 372 of file oofstr.h.

References find(), and kNotFound.

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

Definition at line 898 of file oofstr.cpp.

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

Definition at line 914 of file oofstr.cpp.

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.

Todo:
add unit test

Definition at line 1501 of file oofstr.cpp.

oofString oofString::encodeEntity ( const oofString srcString)
static

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

Todo:
add unit test

Definition at line 1583 of file oofstr.cpp.

References adopt().

Referenced by oofRepGraphBand_XMLRender::describeLayout(), and oofTagMaker::makeSimpleBoundedElement().

void oofString::encodeURL ( )

Definition at line 1486 of file oofstr.cpp.

References replaceString().

bool oofString::endsWith ( char  inChar) const
Todo:
add unit test

Definition at line 1837 of file oofstr.cpp.

References lastChar().

Referenced by operator-(), and singular().

bool oofString::endsWith ( const char *  inStr,
int  inLen = -1 
) const
Todo:
add unit test

Definition at line 1848 of file oofstr.cpp.

References mBody, and mLen.

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
caseSensitivedefault false
inLenoptional 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
Todo:
add unit test

Definition at line 1135 of file oofstr.cpp.

References firstChar(), kNotFound, mBody, and mLen.

Referenced by oofMaskMultiStrings::appendTarget(), contains(), findEnd(), replaceBetween(), replaceFirstString(), replaceString(), replaceStringWholeWord(), and subStringBetween().

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
caseSensitivedefaults false.
Todo:
add unit test

Definition at line 1055 of file oofstr.cpp.

References kNotFound, mBody, and mLen.

long oofString::findEnd ( const char *  schStr,
unsigned long  startFrom = 0,
bool  caseSensitive = false 
) const
Todo:
add unit test

Definition at line 1312 of file oofstr.cpp.

References find(), and kNotFound.

Referenced by replaceBetween(), and subStringBetween().

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

Character-based reverse search with optional case sensitivity.

Parameters
caseSensitivedefault false
inLenoptional 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
Todo:
add unit test

Definition at line 1232 of file oofstr.cpp.

References firstChar(), kNotFound, mBody, and mLen.

long oofString::findLast ( char  inChar,
bool  caseSensitive = false 
) const
Todo:
add unit test

Definition at line 1090 of file oofstr.cpp.

References kNotFound, mBody, and mLen.

char oofString::firstChar ( ) const

Constant access to first char.

Returns
0 if string empty.
Todo:
add unit test

Definition at line 2270 of file oofstr.cpp.

References mBody, and mLen.

Referenced by find(), findLast(), and startsWith().

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.

add unit test

Definition at line 935 of file oofstr.cpp.

References clear(), OOF_OOFSTR_FORMAT_BUFFERSIZE, and setChars().

void oofString::getChars ( char *  ioBuff,
unsigned long &  ioLen 
) const
Todo:
add unit test

Definition at line 750 of file oofstr.cpp.

References mBody, and mLen.

Referenced by dbViewAsTableStorage::GetCellData().

void oofString::getStr255 ( Str255  s) const
void oofString::insertChars ( const char *  chars,
unsigned long  charLen,
unsigned long  beforeChar = ULONG_MAX 
)
Todo:
add unit test

Definition at line 682 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

Referenced by oofDirectory::FSSpecToPath().

bool oofString::isAlphaNumeric ( ) const
Todo:
add unit test

Definition at line 2444 of file oofstr.cpp.

References isEmpty(), mBody, and mLen.

Referenced by oofTagMaker::decodeName(), and oofTagMaker::encodeName().

bool oofString::isEmpty ( ) const
inline
char oofString::lastChar ( ) const

Constant access to last char.

Returns
0 if string empty.
Todo:
add unit test

Definition at line 2285 of file oofstr.cpp.

References mBody, and mLen.

Referenced by oofDirectory::CreateSubdirsAndWorkingDirID(), oofDirectory::CurrentPath(), endsWith(), oofDirectory::GetCurrentLocation(), oofDirectory::oofDirectory(), and oofRepBracketedTextBlock::oofRepBracketedTextBlock().

oofString oofString::left ( unsigned long  numChars) const

Create new string containing leftmost numChars.

Returns
new string with up to numChars contents, just returns shorter if existing string is less than numChars long.
Todo:
add unit test

Definition at line 2363 of file oofstr.cpp.

References mBody, mLen, and oofString().

oofString oofString::legalName ( const oofString inString,
char  nonAlphaReplace = '_',
char  leadingDigitReplace = 'n',
char  spaceReplace = '_' 
)
static
Todo:
add unit test

Definition at line 1744 of file oofstr.cpp.

References length().

unsigned long oofString::length ( ) const
inline

Primary test: oofStringTest::emptyStringByNullInitIsLenZero()

Definition at line 447 of file oofstr.h.

References mLen.

Referenced by adopt(), dbText::adoptString(), oofMaskMultiStrings::allocBuffer(), dbView::AppendOwnedField(), oofMaskMultiStrings::appendTarget(), asDouble(), asLong(), asShort(), asUnsignedLong(), asUnsignedShort(), oofSizedTextArray::CalculateWrapping(), oofXMLdataParser::charData(), OOF_XMLrepLayoutParser::charData(), oofMaskMultiStrings::copyParam(), oofTagMaker::decodeName(), oofRepViewBand_WinRender::draw(), oofRepViewBand_MacRender::draw(), oofRepTextBlock_MacRender::draw(), oofRepViewBand_WinRender::drawColumnHeaders(), oofRepViewBand_MacRender::drawColumnHeaders(), oofRepViewBand_WinRender::DrawContinuingOverPage(), oofRepViewBand_MacRender::DrawContinuingOverPage(), oofGeoText::DrawSelf(), oofTagMaker::encodeName(), dbView::extract(), oofE_RamConnectionError::extract(), oofE_RampConnectionError::extract(), oofE_CtreeBlobError::extract(), oofE_MacOSErr::extract(), dbDate::extract(), dbDateTime::extract(), dbNumericField::fieldMinWrapWidth(), oofRepPromiseCompleter::findStringForID(), oofMaskMultiStrings::finishedParse(), dbBLOB::generateTestData(), oofRepWinEnv::getTextExtent(), legalName(), OOF_dbaseBackend::loadBlob(), dbConnect::MakeOOFSchemaString(), oofYNC::msgBox(), operator+=(), RepSaveDlgHook(), oofDirectory::setDirFromPath(), dbChar::setString(), dbText::setString(), singular(), oofMaskMultiStrings::totalChunkLen(), oofGeoText::Transform(), oofGeoTitle::Transform(), oofGeoXLabel::Transform(), oofGeoYLabel::Transform(), oofGeoXTickLabel::Transform(), oofGeoYTickLabel::Transform(), dbNumericFieldLink::updateDerivedFieldDisplay(), dbDateLink2Editor::updateDerivedFieldDisplay(), dbDateTimeLink2Editor::updateDerivedFieldDisplay(), utf8To8BitAscii(), and oofRepTextBlock_MacRender::width().

bool oofString::lineEndingsCurrentPlatform ( )
inline
Todo:
add unit test

Definition at line 482 of file oofstr.h.

References lineEndingsDOS(), lineEndingsMac(), and lineEndingsUnix().

Referenced by OOF_mixRepAbstractCellEditor::LoadCellEditField().

char * oofString::lineEndingsCurrentPlatform ( char *  inChars,
unsigned long &  ioLen 
)
inlinestatic

forward to appropriate platform method for static converters

Todo:
add unit test

Definition at line 500 of file oofstr.h.

References lineEndingsDOS(), lineEndingsMac(), and lineEndingsUnix().

bool oofString::lineEndingsDOS ( )

Convert all line endings in string to DOS standard - CRLF.

Todo:
add unit test

Definition at line 2093 of file oofstr.cpp.

References mBody, and mLen.

Referenced by lineEndingsCurrentPlatform().

char * oofString::lineEndingsDOS ( char *  inChars,
unsigned long &  ioLen 
)
static

Convert all line endings in external buffer to DOS standard - CRLF.

Todo:
add unit test

Definition at line 2112 of file oofstr.cpp.

References CR, LF, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

bool oofString::lineEndingsMac ( )

Convert all line endings in string to Mac standard - CR.

Todo:
add unit test

Definition at line 1945 of file oofstr.cpp.

References mBody, and mLen.

Referenced by lineEndingsCurrentPlatform(), OOF_dbaseBackend::loadBlob(), and oofSchemaParser::parseSchemaText().

char * oofString::lineEndingsMac ( char *  inChars,
unsigned long &  ioLen 
)
static

Convert all line endings in external buffer to Mac standard - CR.

Todo:
add unit test

Definition at line 1964 of file oofstr.cpp.

References CR, LF, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

bool oofString::lineEndingsUnix ( )

Convert all line endings in string to Unix standard - LF.

Todo:
add unit test

Definition at line 2020 of file oofstr.cpp.

References mBody, and mLen.

Referenced by lineEndingsCurrentPlatform(), and OOF_dbaseBackend::loadBlob().

char * oofString::lineEndingsUnix ( char *  inChars,
unsigned long &  ioLen 
)
static

Convert all line endings in external buffer to Unix standard - LF.

Todo:
add unit test

Definition at line 2039 of file oofstr.cpp.

References CR, LF, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

void oofString::loadResource ( unsigned long  strID)
Todo:
add unit test

Definition at line 519 of file oofstr.cpp.

References setChars(), and setStr255().

void oofString::makeRandomChars ( unsigned long  numChars)

Generate string of len numChars with random content, replacing existing contents.

Todo:
add unit test

Definition at line 1922 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

Referenced by dbChar::generateTestData(), dbBLOB::generateTestData(), dbText::generateTestData(), and dbFixedBinary::generateTestData().

oofString::operator const char * ( ) const

Primary test: oofStringTest::stringAppendNullStrFromConstant()

Definition at line 764 of file oofstr.cpp.

oofString::operator std::string ( ) const
bool oofString::operator!= ( const char *  rhs) const
inline

Unique negative comparison to avoid compiler ambiguity complaints.

Primary test: oofStringTest::stringAdoptConstant ()

Definition at line 437 of file oofstr.h.

bool oofString::operator!= ( const oofString rhs) const
inline

Unique negative comparison to avoid compiler ambiguity complaints.

Primary test: oofStringTest::stringReassignFromString ()

Definition at line 425 of file oofstr.h.

void oofString::operator+= ( char  c)
Todo:
add unit test

Definition at line 791 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

void oofString::operator+= ( const char *  str)

Primary test: oofStringTest::stringAppendStrFromConstant()

Definition at line 817 of file oofstr.cpp.

void oofString::operator+= ( const oofString src)

Primary test: oofStringTest::stringAppendFromString()

Definition at line 831 of file oofstr.cpp.

References chars(), and length().

oofString oofString::operator- ( const char *  inTail) const
Todo:
add unit test

Definition at line 1018 of file oofstr.cpp.

References endsWith(), mLen, oofString(), and subString().

oofString& oofString::operator= ( const std::string &  )
oofString & oofString::operator= ( const oofString rhs)
Todo:
add unit test

Definition at line 463 of file oofstr.cpp.

References mBody, mLen, and setChars().

oofString & oofString::operator= ( const char *  chars)

Replace our contents by copying the specified c string.

Primary test: oofStringTest::stringReassignFromConstant()

Definition at line 587 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

oofString & oofString::operator= ( const Str255  s)
inline
Todo:
add unit test

Definition at line 470 of file oofstr.h.

References setStr255().

bool oofString::operator== ( const Str255  s) const
Todo:
add unit test

Definition at line 498 of file oofstr.cpp.

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

Primary test: oofStringTest::stringReassignFromString()

Definition at line 477 of file oofstr.cpp.

References mBody, and mLen.

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

case-sensitive direct comparison with c string.

Primary test: oofStringTest::stringInitStrFromConstant()

Definition at line 565 of file oofstr.cpp.

References mBody, and mLen.

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

Primary test: oofStringTest::stringInitStrFromConstant ()

Todo:
add unit test for update.

Definition at line 341 of file oofstr.h.

Referenced by operator[]().

char & oofString::operator[] ( short  index) const
inline
Todo:
add unit test

Definition at line 351 of file oofstr.h.

References operator[]().

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

Primary test: oofStringTest::stringInitOneCharFromConstant()

Todo:
add unit test for update

Definition at line 778 of file oofstr.cpp.

References mBody, mLen, and sEmptyChar.

char * oofString::orphan ( bool  neverReturnNil = true)

Give away our internal buffer, clearing our length and pointer.

Returns
pointer to buffer which caller must now delete
Todo:
add unit test

Definition at line 2339 of file oofstr.cpp.

References mBody, and mLen.

Referenced by adopt(), dbText::adoptString(), dbRepHTML::drawColumnar(), dbRepChar::drawColumnar(), dbRepHTML::drawPageWise(), dbRepChar::drawPageWise(), OOF_dbaseBackend::loadBlob(), oofCSS2GraphSettings::parseSettingsText(), oofCSS2ReportSettings::parseSettingsText(), and oofCSS2RepTextStyle::parseStyleText().

void oofString::padTo ( unsigned short  paddedLength,
char  padWith = ' ',
bool  rightAlign = false 
)
Todo:
add unit test

Definition at line 719 of file oofstr.cpp.

References mBody, mLen, and OOF_MEM_DEBUG_FORCE_POOL_CHECK.

oofString oofString::quoteString ( const oofString srcString,
char  quoteChar = '\'' 
)
static
void oofString::replaceAt ( unsigned long  replaceAtOffset,
unsigned long  replaceLen,
const char *  newStr,
unsigned long  newLen = ULONG_MAX 
)
Todo:
add unit test

Definition at line 1325 of file oofstr.cpp.

References mBody, and mLen.

Referenced by replaceBetween(), replaceFirstString(), replaceString(), and replaceStringWholeWord().

unsigned long oofString::replaceBetween ( const char *  leftStr,
const char *  rightStr,
const char *  insertStr,
bool  caseSensitive = false 
)
Todo:
add unit test

Definition at line 1872 of file oofstr.cpp.

References find(), findEnd(), kNotFound, and replaceAt().

unsigned long oofString::replaceChar ( char  fromChar,
char  toChar,
unsigned long  startAt = 0 
)
Todo:
add unit test

Definition at line 963 of file oofstr.cpp.

References mBody, and mLen.

Referenced by dbView::getHeading(), and oofErrorReporter::raise().

unsigned long oofString::replaceFirstString ( const char *  replaceStr,
const char *  newStr,
bool  caseSensitive = false 
)
Todo:
add unit test

Definition at line 1370 of file oofstr.cpp.

References find(), kNotFound, and replaceAt().

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
Todo:
add unit test

Definition at line 1393 of file oofstr.cpp.

References find(), kNotFound, OOF_stricmp(), and replaceAt().

Referenced by encodeURL().

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

add unit test

Definition at line 1443 of file oofstr.cpp.

References find(), kNotFound, mBody, OOF_stricmp(), and replaceAt().

oofString oofString::right ( unsigned long  numChars) const

Create new string containing rightmost numChars.

Returns
new string with up to numChars contents, just returns shorter if existing string is less than numChars long.
Todo:
add unit test

Definition at line 2379 of file oofstr.cpp.

References mBody, mLen, and oofString().

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.
Todo:
add unit test

Definition at line 624 of file oofstr.cpp.

References mBody, mLen, OOF_MEM_DEBUG_FORCE_POOL_CHECK, and OOF_OOFSTR_DONT_REALLOC_BELOW.

Referenced by dbQueryLiteralStrDelimited::current(), format(), loadResource(), operator=(), and setStr255().

void oofString::setStr255 ( const Str255  s)
Todo:
add unit test

Definition at line 426 of file oofstr.cpp.

References setChars().

Referenced by oofFileRef::extract(), dbGUIAdaptEditPane::getString(), loadResource(), and operator=().

void oofString::shorten ( unsigned short  dropChars)

Reduce string length by dropChars.

Parameters
dropCharsis amount to shorten by, can be greater than string length in which case string is cleared. Primary test: oofStringTest::stringShortened ()
Todo:
conditionally clear based on OOF_OOFSTR_DONT_REALLOC_BELOW when we have an mAllocLength to avoid hitting heap
Warning
never reallocates so a large buffer being shortened by a large amount wastes much space. This is for speed.

Definition at line 2396 of file oofstr.cpp.

References clear(), mBody, and mLen.

Referenced by oofCheckString::oofCheckString(), oofRepBracketedTextBlock::oofRepBracketedTextBlock(), and utf8To8BitAscii().

oofString oofString::singular ( const oofString inString)
static
Todo:
add unit test

Definition at line 1779 of file oofstr.cpp.

References endsWith(), length(), and subString().

Referenced by dbTable::tableSingularName().

bool oofString::startsWith ( char  inChar) const
Todo:
add unit test

Definition at line 1804 of file oofstr.cpp.

References firstChar().

Referenced by oofTagMaker::decodeName().

bool oofString::startsWith ( const char *  inStr) const
Todo:
add unit test

Definition at line 1815 of file oofstr.cpp.

References mBody, and mLen.

unsigned long oofString::stripChar ( char  toStrip,
unsigned long  startAt = 0 
)
Todo:
add unit test

Definition at line 1892 of file oofstr.cpp.

References mBody, and mLen.

Referenced by dbCharStripperCalculator::calc().

oofString oofString::subString ( unsigned long  fromChars,
unsigned long  numChars = ULONG_MAX 
) const
Todo:
add unit test

Definition at line 981 of file oofstr.cpp.

References mBody, mLen, and oofString().

Referenced by oofTagMaker::decodeName(), operator-(), singular(), and subStringBetween().

oofString oofString::subStringBetween ( const char *  leftStr,
const char *  rightStr 
) const
oofString oofString::subStringBetween ( char  leftChar,
char  rightChar 
) const
Todo:
add unit test

Definition at line 1033 of file oofstr.cpp.

References find(), kNotFound, oofString(), and subString().

oofString oofString::utf8To8BitAscii ( const oofString srcString)
inlinestatic
Todo:
add unit test

Definition at line 458 of file oofstr.h.

References chars(), and length().

Referenced by oofXMLdataParser::charData(), and OOF_XMLrepLayoutParser::charData().

oofString oofString::utf8To8BitAscii ( const char *  srcString,
unsigned long  len 
)
static

Change string contents to decoded version of Unicode 8 bit string.

Note
if normal ASCII printable characters are used, UTF8 looks same as an ASCII string
Parameters
srcString8 bit UTF as used in 8 bit XML.
Todo:
add unit test

Definition at line 1707 of file oofstr.cpp.

References length(), and shorten().

Member Data Documentation

char* oofString::mBody
protected
unsigned long oofString::mLen
protected
char oofString::sEmptyChar = '\0'
staticprotected

Definition at line 286 of file oofstr.h.

Referenced by operator[]().


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