resonance 1.0.1
Loading...
Searching...
No Matches
HxStr Class Reference

Heap-allocated NUL-terminated string. More...

#include <hxstr.h>

Inheritance diagram for HxStr:

Public Member Functions

 HxStr ()
 Construct an empty string.
 HxStr (const char *pszText)
 Construct a copy of a C string.
 HxStr (const HxStr &other)
 Construct a copy of another string.
 HxStr (unsigned nCount, char ch)
 Construct a run of one repeated character.
 ~HxStr ()
HxStr & operator+= (const HxStr &other)
 Append another string.
HxStr & operator+= (const char *pszText)
 Append a C string.
HxStr & operator+= (char ch)
 Append one character.
HxStr & operator= (const char *pszText)
 Replace this string with a copy of a C string.
HxStr & operator= (const HxStr &other)
 Replace this string with a copy of another.
char operator[] (unsigned i) const
 Read one character.
bool operator!= (const char *pszRight) const
 Compare against a C string for inequality.
bool operator!= (const HxStr &right) const
 Compare against another string for inequality.
bool operator== (const char *pszRight) const
 Compare against a C string for equality.
bool operator== (const HxStr &right) const
 Compare against another string for equality.
bool operator< (const HxStr &right) const
 Order against another string.
void Alloc (unsigned nLen)
 Discard the text and reserve a zero-filled buffer.
int Find (char ch) const
 Find the first occurrence of a character.
int Find (char ch, unsigned nStart) const
 Find the first occurrence of a character at or after a position.
int Find (const char *pszText) const
 Find the first occurrence of a substring.
int ReverseFind (char ch) const
 Find the last occurrence of a character.
int ReverseFindOneOf (const char *pszChars) const
 Find the last occurrence of any of a set of characters.
int Compare (unsigned pos, unsigned len, const char *str) const
 Compare a run of this string against a C string.
HxStr Mid (unsigned pos) const
 Extract the text from a position to the end.
HxStr Mid (unsigned pos, unsigned len) const
 Extract a run of text.
HxStr & Replace (unsigned pos, unsigned len, char ch)
 Overwrite one character.
HxStr & Replace (unsigned pos, unsigned len, const HxStr &other)
 Overwrite a run of text with another string.
HxStr & Clear ()
 Empty the string in place.
HxStr & Truncate (unsigned pos)
 Shorten the string in place.
HxStr & Erase (unsigned pos, unsigned len)
 Remove a run of text.
HxStr & Insert (unsigned pos, unsigned nCount, char ch)
 Insert a run of one repeated character.
HxStr & Insert (unsigned pos, const HxStr &other)
 Insert another string.
std::ostream & Print (std::ostream &stream) const
 Write this string to a stream.

Public Attributes

unsigned mLen
 Length excluding the terminator.
char * mStr
 Text buffer.

Detailed Description

Heap-allocated NUL-terminated string.

Named after HxStr.cpp, the file recorded by its own asserts. The member mStr comes from the text of the assert mStr != 0, and mLen from pos <= mLen. The class is not polymorphic and has no RTTI, so it has no vptr. Its destructor is inlined at every call site in the image, which is why it is defined here.

The North American release represents an empty string by a null mStr with mLen zero. Every accessor that dereferences mStr asserts first, and the comparison operators treat a null pointer and an empty buffer as equal. In the PAL build an empty string points at g_szEmptyString as the European release does. That release drops the null asserts, never frees the shared text, and compares through strcmp() alone.

mLen excludes the terminator, and the buffer is always mLen + 1 bytes.

Both members are public, and each records its own evidence below. The comparison operators are written as members because a member and a free function with the string as its first operand compile to the same two-argument call, which leaves the image unable to distinguish them.

Constructor & Destructor Documentation

◆ HxStr() [1/4]

HxStr::HxStr ( )
inline

Construct an empty string.

Defined in the header rather than compiled out of line, which is why it has no address of its own. A static initialisation that constructs a string global writes the two members in place with no call, which is what establishes both that the constructor exists and that it does nothing beyond producing the empty representation.

◆ HxStr() [2/4]

HxStr::HxStr ( const char * pszText)

Construct a copy of a C string.

A null argument produces an empty string with no allocation.

Parameters
pszTextThe text to copy.
Ghidra address:
NTSC-U/C: 0x004b7ad0
Ghidra address:
PAL: 0x004f5f00

◆ HxStr() [3/4]

HxStr::HxStr ( const HxStr & other)

Construct a copy of another string.

Only a null buffer produces the empty representation. In the PAL build a source pointing at g_szEmptyString is copied into a fresh one-byte buffer, as the European release does.

Parameters
otherThe string to copy.
Ghidra address:
NTSC-U/C: 0x004b7b50
Ghidra address:
PAL: 0x004f5f88

◆ HxStr() [4/4]

HxStr::HxStr ( unsigned nCount,
char ch )

Construct a run of one repeated character.

Parameters
nCountThe number of characters, which becomes the length.
chThe character to repeat.
Ghidra address:
NTSC-U/C: 0x004b7bd0
Ghidra address:
PAL: 0x004f6010

◆ ~HxStr()

HxStr::~HxStr ( )
inline

Member Function Documentation

◆ operator+=() [1/3]

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

Append another string.

Parameters
otherThe string to append.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b7c68
Ghidra address:
PAL: 0x004f60a8

◆ operator+=() [2/3]

HxStr & HxStr::operator+= ( const char * pszText)
inline

Append a C string.

The routine builds the temporary string itself rather than taking one a call site built, which is what establishes that the overload exists rather than callers converting and reaching the HxStr overload. The temporary is released before returning.

The body is inline. Units that use it emit their own identical out-of-line copy. The North American copies are at 0x00183a70, 0x00254870, 0x0028c198, 0x0030d618, 0x0038fc58, 0x003fc688, 0x00429500, 0x00431c30, 0x00453d88, 0x004beb98, 0x004dfaa0, and 0x0050cc00. The European ones are at 0x00188ca0, 0x00269f18, 0x002a7e08, 0x00333128, 0x003c1508, 0x00435068, 0x00464b20, 0x0046d8b8, 0x00491288, 0x004fcc00, 0x0051e1e0, and 0x0054c098.

Parameters
pszTextThe text to append.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x0010edb0
Ghidra address:
PAL: 0x0010f1f0

◆ operator+=() [3/3]

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

Append one character.

Parameters
chThe character to append.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b7d28
Ghidra address:
PAL: 0x004f6170

◆ operator=() [1/2]

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

Replace this string with a copy of a C string.

Parameters
pszTextThe text to copy, or null for an empty string.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b7dd8
Ghidra address:
PAL: 0x004f6228

◆ operator=() [2/2]

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

Replace this string with a copy of another.

Parameters
otherThe string to copy.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b7e78
Ghidra address:
PAL: 0x004f62e0

◆ operator[]()

char HxStr::operator[] ( unsigned i) const

Read one character.

The index is permitted to equal the length, which reads the terminator.

Parameters
iThe index.
Returns
The character.
Ghidra address:
NTSC-U/C: 0x004b7f18
Ghidra address:
PAL: 0x004f63a0

◆ operator!=() [1/2]

bool HxStr::operator!= ( const char * pszRight) const

Compare against a C string for inequality.

A null pointer and an empty buffer compare equal. In the PAL build a null argument always differs and every other argument goes straight to strcmp().

Parameters
pszRightThe text to compare against.
Returns
True when the two differ.
Ghidra address:
NTSC-U/C: 0x004b7f98
Ghidra address:
PAL: 0x004f6400

◆ operator!=() [2/2]

bool HxStr::operator!= ( const HxStr & right) const

Compare against another string for inequality.

Parameters
rightThe string to compare against.
Returns
True when the two differ.
Ghidra address:
NTSC-U/C: 0x004b8018
Ghidra address:
PAL: 0x004f6438

◆ operator==() [1/2]

bool HxStr::operator== ( const char * pszRight) const

Compare against a C string for equality.

In the PAL build a null argument never compares equal.

Parameters
pszRightThe text to compare against.
Returns
True when the two agree.
Ghidra address:
NTSC-U/C: 0x004b80a0
Ghidra address:
PAL: 0x004f6460

◆ operator==() [2/2]

bool HxStr::operator== ( const HxStr & right) const

Compare against another string for equality.

Parameters
rightThe string to compare against.
Returns
True when the two agree.
Ghidra address:
NTSC-U/C: 0x004b8120
Ghidra address:
PAL: 0x004f6498

◆ operator<()

bool HxStr::operator< ( const HxStr & right) const

Order against another string.

An empty string sorts before every non-empty string.

Parameters
rightThe string to compare against.
Returns
True when this string sorts before the other.
Ghidra address:
NTSC-U/C: 0x004b81a8
Ghidra address:
PAL: 0x004f64c0

◆ Alloc()

void HxStr::Alloc ( unsigned nLen)

Discard the text and reserve a zero-filled buffer.

The previous buffer is released through the single-object operator delete rather than through operator delete[]. It is the one place in HxStr that uses the scalar release path. The new length is recorded before the allocation is checked.

Parameters
nLenThe new length, excluding the terminator.
Ghidra address:
NTSC-U/C: 0x004b8230
Ghidra address:
PAL: 0x004f64e8

◆ Find() [1/3]

int HxStr::Find ( char ch) const

Find the first occurrence of a character.

Parameters
chThe character to look for.
Returns
The index, or -1 when the character is absent.
Ghidra address:
NTSC-U/C: 0x004b82b8
Ghidra address:
PAL: 0x004f6580

◆ Find() [2/3]

int HxStr::Find ( char ch,
unsigned nStart ) const

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

Parameters
chThe character to look for.
nStartThe index to start from.
Returns
The index from the start of the string, or -1 when the character is absent.
Ghidra address:
NTSC-U/C: 0x004b8350
Ghidra address:
PAL: 0x004f65c8

◆ Find() [3/3]

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

Find the first occurrence of a substring.

Parameters
pszTextThe text to look for.
Returns
The index, or -1 when the text is absent.
Ghidra address:
NTSC-U/C: 0x004b83f0
Ghidra address:
PAL: 0x004f6620

◆ ReverseFind()

int HxStr::ReverseFind ( char ch) const

Find the last occurrence of a character.

Parameters
chThe character to look for.
Returns
The index, or -1 when the character is absent.
Ghidra address:
NTSC-U/C: 0x004b84b0
Ghidra address:
PAL: 0x004f66c0

◆ ReverseFindOneOf()

int HxStr::ReverseFindOneOf ( const char * pszChars) const

Find the last occurrence of any of a set of characters.

Parameters
pszCharsThe candidate characters, as a NUL-terminated set.
Returns
The highest index at which any candidate appears, or -1 when none appears and when the argument is null.
Ghidra address:
NTSC-U/C: 0x004b8550
Ghidra address:
PAL: 0x004f6720

◆ Compare()

int HxStr::Compare ( unsigned pos,
unsigned len,
const char * str ) const

Compare a run of this string against a C string.

In the PAL build a null argument reports -1 rather than tripping an assert.

Parameters
posThe index to compare from.
lenThe number of characters to compare.
strThe text to compare against.
Returns
A negative value, zero, or a positive value, as strncmp() defines it.
Ghidra address:
NTSC-U/C: 0x004b8678
Ghidra address:
PAL: 0x004f67d0

◆ Mid() [1/2]

HxStr HxStr::Mid ( unsigned pos) const

Extract the text from a position to the end.

Parameters
posThe index to start from.
Returns
The extracted text.
Ghidra address:
NTSC-U/C: 0x004b8738
Ghidra address:
PAL: 0x004f6858

◆ Mid() [2/2]

HxStr HxStr::Mid ( unsigned pos,
unsigned len ) const

Extract a run of text.

A run that would pass the end is shortened to the text from pos onward.

Parameters
posThe index to start from.
lenThe number of characters to extract.
Returns
The extracted text.
Ghidra address:
NTSC-U/C: 0x004b78b8
Ghidra address:
PAL: 0x004f5bc8

◆ Replace() [1/2]

HxStr & HxStr::Replace ( unsigned pos,
unsigned len,
char ch )

Overwrite one character.

Only a single-character replacement is implemented. A run of any other length trips the len == 1 assert and is then written as a single character regardless.

Parameters
posThe index to overwrite.
lenThe number of characters to overwrite, which must be 1.
chThe replacement character.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b8818
Ghidra address:
PAL: 0x004f6918

◆ Replace() [2/2]

HxStr & HxStr::Replace ( unsigned pos,
unsigned len,
const HxStr & other )

Overwrite a run of text with another string.

A run that would pass the end is shortened to the text from pos onward.

Parameters
posThe index to overwrite from.
lenThe number of characters to overwrite.
otherThe replacement text.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b88d0
Ghidra address:
PAL: 0x004f69d8

◆ Clear()

HxStr & HxStr::Clear ( )

Empty the string in place.

This is a distinct routine rather than Truncate(0). It tolerates an empty string, where Truncate() would assert, and it asserts nothing itself. The buffer is retained.

Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b89f0
Ghidra address:
PAL: 0x004f6ad8

◆ Truncate()

HxStr & HxStr::Truncate ( unsigned pos)

Shorten the string in place.

The buffer is not reallocated. The excess capacity remains until the next assignment. In the PAL build an empty string is left untouched rather than written through.

Parameters
posThe index to cut at, which must not exceed the current length.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b8a10
Ghidra address:
PAL: 0x004f6b00

◆ Erase()

HxStr & HxStr::Erase ( unsigned pos,
unsigned len )

Remove a run of text.

The tail is shifted down in place with no reallocation. A run that would pass the end shortens the string to pos instead.

Parameters
posThe index to remove from.
lenThe number of characters to remove.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b8a98
Ghidra address:
PAL: 0x004f6b70

◆ Insert() [1/2]

HxStr & HxStr::Insert ( unsigned pos,
unsigned nCount,
char ch )

Insert a run of one repeated character.

Parameters
posThe index to insert at.
nCountThe number of characters to insert.
chThe character to insert.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b8bd8
Ghidra address:
PAL: 0x004f6c70

◆ Insert() [2/2]

HxStr & HxStr::Insert ( unsigned pos,
const HxStr & other )

Insert another string.

Parameters
posThe index to insert at.
otherThe text to insert.
Returns
This string.
Ghidra address:
NTSC-U/C: 0x004b8cd8
Ghidra address:
PAL: 0x004f5dd0

◆ Print()

std::ostream & HxStr::Print ( std::ostream & stream) const

Write this string to a stream.

The same write as operator<<(), with the string as the receiver, and likewise without a null check. No routine in the image calls it. The name is inferred.

Parameters
streamThe stream to write to.
Returns
The stream.
Ghidra address:
NTSC-U/C: 0x004b8e00
Ghidra address:
PAL: 0x004f6d78

Member Data Documentation

◆ mLen

unsigned HxStr::mLen

Length excluding the terminator.

Public because nine sites across four files in other subsystems read this member and mStr directly, and the image exposes no accessor for either. A trivial inline accessor and a public member emit the same single load, so the evidence cannot distinguish them, and the public member is preferred because it adds no function that no address can be attached to.

+0x00

◆ mStr

char* HxStr::mStr

Text buffer.

Public for the same reason as mLen. In the North American release an empty string is a null buffer rather than a pointer to a terminator. Every reader tests for null first. In the PAL build it points at g_szEmptyString.

+0x04


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