wavelength 1.0.0
Loading...
Searching...
No Matches
String Class Reference

Growable text buffer that is also a PrnStream. More...

#include <string.h>

Inheritance diagram for String:
Collaboration diagram for String:

Public Types

enum  { npos = -1 }
 The result of a search that finds nothing. More...

Public Member Functions

 String ()
 Construct an empty string.
 String (const char *pszText)
 Construct a copy of a C string.
 String (const String &other)
 Copy another string.
 ~String () override
 Release the text.
void Print (const char *pszText) override
 Append text.
String & operator= (const String &other)
 Replace the text with a copy of another string's text.
String & operator= (const char *pszText)
 Replace the text with a copy of a C string.
String & Clear ()
 Release the text and leave the string empty.
char operator[] (int nIndex) const
 Report one character.
String & Replace (int nPos, int nCount, const String &text)
 Replace a run of characters with another string's text.
String & Truncate (int nLength)
 Cut the text to a length.
String & Erase (int nPos, int nCount)
 Remove a run of characters.
String & operator+= (const String &other)
 Append another string's text.
String & operator+= (const char *pszText)
 Append a C string.
String & operator+= (char ch)
 Append a character.
int Compare (int nPos, int nCount, const char *pszText) const
 Compare a run of characters with a C string.
int Find (const char *pszText) const
 Find the first occurrence of a C string in the text.
int Find (char ch) const
 Find the first occurrence of a character.
int Find (char ch, int nPos) const
 Find the first occurrence of a character at or after a position.
int RFind (char ch) const
 Find the last occurrence of a character.
String Substring (int nPos) const
 Copy the characters from a position to the end.
String Substring (int nPos, int nCount) const
 Copy a run of characters, or the characters from a position to the end when the run reaches the end.
String & Insert (int nPos, int nCount, char ch)
 Insert copies of one character.
String & Insert (int nPos, const String &text)
 Insert a copy of another string's text.
bool operator< (const String &other) const
 Report whether the text sorts before another string's text.
bool operator== (const char *pszText) const
 Report whether the text equals a C string.
bool operator== (const String &other) const
 Report whether the text equals another string's text.
bool operator!= (const char *pszText) const
 Report whether the text differs from a C string.
bool operator!= (const String &other) const
 Report whether the text differs from another string's text.
String operator+ (const char *pszText) const
 Report a copy of the string with text appended.
String operator+ (char ch) const
 Report a copy of the string with a character appended.
String operator+ (const String &other) const
 Report a copy of the string with another string's text appended.
void Resize (int nLength)
 Replace the text with nLength zero bytes.
const char * c_str () const
 Report the text.
int GetLength () const
char * GetBuffer () const
 String ()
 String (const char *str)
 Copy text.
 String (const String &other)
 Copy another String.
virtual ~String ()
 Free the buffer.
virtual void Print (const char *str)
 Append printed text.
String & operator+= (const String &other)
 Append another String.
String & operator+= (const char *str)
 Append text.
String & operator= (const char *str)
 Replace the text.
String & operator= (const String &other)
 Replace the text with a copy of another String.
bool operator!= (const char *str) const
 Compare with text.
bool operator!= (const String &other) const
 Compare with another String.
bool operator== (const char *str) const
 Compare with text.
bool operator== (const String &other) const
 Compare with another String.
bool operator< (const String &other) const
 Order by the bytes of the text.
void Resize (unsigned int length)
 Replace the text with a length of zero bytes.
int Find (const char *str) const
 Find the first occurrence of text.
int FindLast (char c) const
 Find the last occurrence of a character.
String Substring (unsigned int pos) const
 Copy the text from a position to the end.
String Substring (unsigned int pos, unsigned int count) const
 Copy part of the text.
String & Replace (unsigned int pos, unsigned int count, const String &str)
 Replace part of the text with another String.
String & Clear ()
 Empty the String.
const char * c_str () const
 operator const char * () const
unsigned int size () const
Public Member Functions inherited from PrnStream
 PrnStream ()
 Construct a stream with a dump level of 0.
virtual ~PrnStream ()
 Release the stream.
void Printf (const char *pszFormat,...)
 Format text into the shared format buffer and write the result through Print().
PrnStream & operator<< (const char *pszText)
 Write text.
PrnStream & operator<< (char ch)
 Write a character.
PrnStream & operator<< (short nValue)
 Write a short integer in decimal.
PrnStream & operator<< (int nValue)
 Write an integer in decimal.
PrnStream & operator<< (unsigned char nValue)
 Write a byte as an unsigned integer in decimal.
PrnStream & operator<< (unsigned short nValue)
 Write an unsigned short integer in decimal.
PrnStream & operator<< (unsigned int nValue)
 Write an unsigned integer in decimal.
PrnStream & operator<< (unsigned long long nValue)
 Write an unsigned 64-bit number in decimal.
PrnStream & operator<< (float fValue)
 Write a number with two decimals.
PrnStream & operator<< (bool bValue)
 Write true or false.
void Space (int nCount)
 Write a number of spaces, one Print() call each.
int GetDumpLevel () const
 PrnStream ()
virtual ~PrnStream ()
 Destroy the stream.
void Printf (const char *format,...)
 Format text with printf() conventions and write it.
PrnStream & operator<< (char c)
 Write a character.
PrnStream & operator<< (int i)
 Write an integer in decimal.
PrnStream & operator<< (float f)
 Write a number with two decimal places.
PrnStream & operator<< (const char *str)
 Write text.
void Space (int count)
 Write spaces.

Static Public Attributes

static constexpr int npos = -1
 The position Find() reports when the text does not occur.

Friends

class BinStream

Detailed Description

Growable text buffer that is also a PrnStream.

Text that grows as it is printed to.

The RTTI includes the class name and records PrnStream as the base. An empty string points mBuffer at g_szStringEmptyBuffer rather than at an allocation of its own.

The RTTI records the class as deriving from PrnStream. The object is 0x14 bytes. The buffer comes from the pool allocator and is replaced, not grown, by every change. An empty String points at gStringEmptyBuffer. The length is named by the assertion text of the source; the other member names, and the names of the members compiled inline (c_str(), size(), the default constructor), are inferred.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

The result of a search that finds nothing.

Enumerator
npos 

Constructor & Destructor Documentation

◆ String() [1/6]

String::String ( )
inline

Construct an empty string.

The constructor has no out-of-line copy, and it does not set mCapacity.

◆ String() [2/6]

String::String ( const char * pszText)
explicit

Construct a copy of a C string.

Parameters
pszTextThe text.
Ghidra address:
NTSC-U/C: 0x0029e9b0
Ghidra address:
PAL: 0x002a8670

◆ String() [3/6]

String::String ( const String & other)

Copy another string.

Parameters
otherThe string.
Ghidra address:
NTSC-U/C: 0x0029ea40
Ghidra address:
PAL: 0x002a8700

◆ ~String() [1/2]

String::~String ( )
override

Release the text.

Ghidra address:
NTSC-U/C: 0x0029ead8
Ghidra address:
PAL: 0x002a8798

◆ String() [4/6]

String::String ( )
inline

◆ String() [5/6]

String::String ( const char * str)

Copy text.

A null pointer makes an empty String.

Parameters
strThe text, or null.
Ghidra address:
0x10010d20

◆ String() [6/6]

String::String ( const String & other)

Copy another String.

Parameters
otherThe String.
Ghidra address:
0x10010de0

◆ ~String() [2/2]

virtual String::~String ( )
virtual

Free the buffer.

Ghidra address:
0x10010ea0

Member Function Documentation

◆ Print() [1/2]

void String::Print ( const char * pszText)
overridevirtual

Append text.

Parameters
pszTextThe text.
Ghidra address:
NTSC-U/C: 0x0029eb48
Ghidra address:
PAL: 0x002a8808

Implements PrnStream.

◆ operator=() [1/4]

String & String::operator= ( const String & other)

Replace the text with a copy of another string's text.

The shared empty buffer is shared again rather than copied.

Parameters
otherThe other string.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029ef78
Ghidra address:
PAL: 0x002a8c38

◆ operator=() [2/4]

String & String::operator= ( const char * pszText)

Replace the text with a copy of a C string.

Parameters
pszTextThe text. A null pointer empties the string.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029eed8
Ghidra address:
PAL: 0x002a8b98

◆ Clear() [1/2]

String & String::Clear ( )

Release the text and leave the string empty.

The name is inferred.

Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029f528
Ghidra address:
PAL: 0x002a91e8

◆ operator[]()

char String::operator[] ( int nIndex) const

Report one character.

Parameters
nIndexThe character's position.
Returns
The character.
Ghidra address:
NTSC-U/C: 0x0029f020
Ghidra address:
PAL: 0x002a8ce0

◆ Replace() [1/2]

String & String::Replace ( int nPos,
int nCount,
const String & text )

Replace a run of characters with another string's text.

Parameters
nPosThe first character of the run.
nCountThe length of the run.
textThe replacement.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029f438
Ghidra address:
PAL: 0x002a90f8

◆ Truncate()

String & String::Truncate ( int nLength)

Cut the text to a length.

The shared empty buffer is left unchanged.

Parameters
nLengthThe new length.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029f580
Ghidra address:
PAL: 0x002a9240

◆ Erase()

String & String::Erase ( int nPos,
int nCount )

Remove a run of characters.

A run that reaches the end of the text truncates the text at nPos.

Parameters
nPosThe first character of the run.
nCountThe length of the run.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029f5a8
Ghidra address:
PAL: 0x002a9268

◆ operator+=() [1/5]

String & String::operator+= ( const String & other)

Append another string's text.

Parameters
otherThe other string.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029ec88
Ghidra address:
PAL: 0x002a8948

◆ operator+=() [2/5]

String & String::operator+= ( const char * pszText)

Append a C string.

Parameters
pszTextThe text.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029ed58
Ghidra address:
PAL: 0x002a8a18

◆ operator+=() [3/5]

String & String::operator+= ( char ch)

Append a character.

Parameters
chThe character.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029ee20
Ghidra address:
PAL: 0x002a8ae0

◆ Compare()

int String::Compare ( int nPos,
int nCount,
const char * pszText ) const

Compare a run of characters with a C string.

Parameters
nPosThe first character of the run.
nCountThe length of the run.
pszTextThe text to compare with.
Returns
0 when the run equals the text, otherwise the sign of the difference.
Ghidra address:
NTSC-U/C: 0x0029f2f0
Ghidra address:
PAL: 0x002a8fb0

◆ Find() [1/4]

int String::Find ( const char * pszText) const

Find the first occurrence of a C string in the text.

Parameters
pszTextThe text to find.
Returns
The position of the occurrence, or npos.
Ghidra address:
NTSC-U/C: 0x0029f250
Ghidra address:
PAL: 0x002a8f10

◆ Find() [2/4]

int String::Find ( char ch) const

Find the first occurrence of a character.

Parameters
chThe character to find.
Returns
The position of the occurrence, or npos.
Ghidra address:
NTSC-U/C: 0x0029f1a0
Ghidra address:
PAL: 0x002a8e60

◆ Find() [3/4]

int String::Find ( char ch,
int nPos ) const

Find the first occurrence of a character at or after a position.

Parameters
chThe character to find.
nPosThe first position searched.
Returns
The position of the occurrence, or npos, also for a position past the end.
Ghidra address:
NTSC-U/C: 0x0029f1f0
Ghidra address:
PAL: 0x002a8eb0

◆ RFind()

int String::RFind ( char ch) const

Find the last occurrence of a character.

Parameters
chThe character to find.
Returns
The position of the occurrence, or npos.
Ghidra address:
NTSC-U/C: 0x0029f298
Ghidra address:
PAL: 0x002a8f58

◆ Substring() [1/4]

String String::Substring ( int nPos) const

Copy the characters from a position to the end.

Parameters
nPosThe first character copied.
Returns
The copy.
Ghidra address:
NTSC-U/C: 0x0029f328
Ghidra address:
PAL: 0x002a8fe8

◆ Substring() [2/4]

String String::Substring ( int nPos,
int nCount ) const

Copy a run of characters, or the characters from a position to the end when the run reaches the end.

Parameters
nPosThe first character copied.
nCountThe length of the run.
Returns
The copy.
Ghidra address:
NTSC-U/C: 0x0029f358
Ghidra address:
PAL: 0x002a9018

◆ Insert() [1/2]

String & String::Insert ( int nPos,
int nCount,
char ch )

Insert copies of one character.

Parameters
nPosThe position the copies go before.
nCountThe number of copies.
chThe character.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029f630
Ghidra address:
PAL: 0x002a92f0

◆ Insert() [2/2]

String & String::Insert ( int nPos,
const String & text )

Insert a copy of another string's text.

Parameters
nPosThe position the text goes before.
textThe text.
Returns
The string.
Ghidra address:
NTSC-U/C: 0x0029f768
Ghidra address:
PAL: 0x002a9428

◆ operator<() [1/2]

bool String::operator< ( const String & other) const

Report whether the text sorts before another string's text.

Parameters
otherThe other string.
Returns
Whether strcmp() places this text first.
Ghidra address:
NTSC-U/C: 0x0029f0f0
Ghidra address:
PAL: 0x002a8db0

◆ operator==() [1/4]

bool String::operator== ( const char * pszText) const

Report whether the text equals a C string.

Parameters
pszTextThe C string, or null.
Returns
Whether strcmp() reports the texts equal, or false for a null C string.
Ghidra address:
NTSC-U/C: 0x0029f090
Ghidra address:
PAL: 0x002a8d50

◆ operator==() [2/4]

bool String::operator== ( const String & other) const

Report whether the text equals another string's text.

Parameters
otherThe other string.
Returns
Whether strcmp() reports the texts equal.
Ghidra address:
NTSC-U/C: 0x0029f0c8
Ghidra address:
PAL: 0x002a8d88

◆ operator!=() [1/4]

bool String::operator!= ( const char * pszText) const

Report whether the text differs from a C string.

Parameters
pszTextThe C string, or null.
Returns
Whether strcmp() reports the texts different, or true for a null C string.
Ghidra address:
NTSC-U/C: 0x0029f030
Ghidra address:
PAL: 0x002a8cf0

◆ operator!=() [2/4]

bool String::operator!= ( const String & other) const

Report whether the text differs from another string's text.

Parameters
otherThe other string.
Returns
Whether strcmp() reports the texts different.
Ghidra address:
NTSC-U/C: 0x0029f068
Ghidra address:
PAL: 0x002a8d28

◆ operator+() [1/3]

String String::operator+ ( const char * pszText) const

Report a copy of the string with text appended.

Parameters
pszTextThe text to append.
Returns
The new string.
Ghidra address:
NTSC-U/C: 0x0029eb68
Ghidra address:
PAL: 0x002a8828

◆ operator+() [2/3]

String String::operator+ ( char ch) const

Report a copy of the string with a character appended.

Parameters
chThe character to append.
Returns
The new string.
Ghidra address:
NTSC-U/C: 0x0029ebc8
Ghidra address:
PAL: 0x002a8888

◆ operator+() [3/3]

String String::operator+ ( const String & other) const

Report a copy of the string with another string's text appended.

Parameters
otherThe other string.
Returns
The new string.
Ghidra address:
NTSC-U/C: 0x0029ec28
Ghidra address:
PAL: 0x002a88e8

◆ Resize() [1/2]

void String::Resize ( int nLength)

Replace the text with nLength zero bytes.

Parameters
nLengthThe new length.
Ghidra address:
NTSC-U/C: 0x0029f120
Ghidra address:
PAL: 0x002a8de0

◆ c_str() [1/2]

const char * String::c_str ( ) const
inline

Report the text.

Returns
The terminated text, which the string retains.

◆ GetLength()

int String::GetLength ( ) const
inline
Returns
Characters before the terminator.

◆ GetBuffer()

char * String::GetBuffer ( ) const
inline
Returns
The terminated text.

◆ Print() [2/2]

virtual void String::Print ( const char * str)
virtual

Append printed text.

Parameters
strThe text.
Ghidra address:
0x10010f00

Implements PrnStream.

◆ operator+=() [4/5]

String & String::operator+= ( const String & other)

Append another String.

Parameters
otherThe String.
Returns
This String.
Ghidra address:
0x10010f10

◆ operator+=() [5/5]

String & String::operator+= ( const char * str)

Append text.

A null pointer appends nothing.

Parameters
strThe text, or null.
Returns
This String.
Ghidra address:
0x10010fe0

◆ operator=() [3/4]

String & String::operator= ( const char * str)

Replace the text.

A null pointer empties the String.

Parameters
strThe text, or null.
Returns
This String.
Ghidra address:
0x100110b0

◆ operator=() [4/4]

String & String::operator= ( const String & other)

Replace the text with a copy of another String.

Parameters
otherThe String.
Returns
This String.
Ghidra address:
0x10011140

◆ operator!=() [3/4]

bool String::operator!= ( const char * str) const

Compare with text.

A null pointer is unequal to every String.

Parameters
strThe text, or null.
Returns
Whether the texts differ.
Ghidra address:
0x100111f0

◆ operator!=() [4/4]

bool String::operator!= ( const String & other) const

Compare with another String.

Parameters
otherThe String.
Returns
Whether the texts differ.
Ghidra address:
0x10011250

◆ operator==() [3/4]

bool String::operator== ( const char * str) const

Compare with text.

A null pointer is unequal to every String.

Parameters
strThe text, or null.
Returns
Whether the texts are equal.
Ghidra address:
0x100112b0

◆ operator==() [4/4]

bool String::operator== ( const String & other) const

Compare with another String.

Parameters
otherThe String.
Returns
Whether the texts are equal.
Ghidra address:
0x10011310

◆ operator<() [2/2]

bool String::operator< ( const String & other) const

Order by the bytes of the text.

Parameters
otherThe String.
Returns
Whether this text sorts first.
Ghidra address:
0x10011370

◆ Resize() [2/2]

void String::Resize ( unsigned int length)

Replace the text with a length of zero bytes.

Parameters
lengthThe new length.
Ghidra address:
0x100113d0

◆ Find() [4/4]

int String::Find ( const char * str) const

Find the first occurrence of text.

Parameters
strThe text.
Returns
The position of the occurrence, or npos.
Ghidra address:
0x10011430

◆ FindLast()

int String::FindLast ( char c) const

Find the last occurrence of a character.

Parameters
cThe character.
Returns
The position of the character, or npos.
Ghidra address:
0x10011460

◆ Substring() [3/4]

String String::Substring ( unsigned int pos) const

Copy the text from a position to the end.

Parameters
posThe first character.
Returns
The copy.
Ghidra address:
0x10011490

◆ Substring() [4/4]

String String::Substring ( unsigned int pos,
unsigned int count ) const

Copy part of the text.

A count that passes the end copies to the end.

Parameters
posThe first character.
countThe number of characters.
Returns
The copy.
Ghidra address:
0x100114f0

◆ Replace() [2/2]

String & String::Replace ( unsigned int pos,
unsigned int count,
const String & str )

Replace part of the text with another String.

Parameters
posThe first character replaced.
countThe number of characters replaced. A count that passes the end is cut to it.
strThe new text.
Returns
This String.
Ghidra address:
0x10011610

◆ Clear() [2/2]

String & String::Clear ( )

Empty the String.

Returns
This String.
Ghidra address:
0x10011720

◆ c_str() [2/2]

const char * String::c_str ( ) const
inline
Returns
The terminated text.

◆ operator const char *()

String::operator const char * ( ) const
inline
Returns
The terminated text.

◆ size()

unsigned int String::size ( ) const
inline
Returns
The number of characters before the terminator.

◆ BinStream

friend class BinStream
friend

Member Data Documentation

◆ npos

int String::npos = -1
staticconstexpr

The position Find() reports when the text does not occur.


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