|
resonance 1.0.1
|
Heap-allocated NUL-terminated string. More...
#include <hxstr.h>

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. | |
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.
|
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::HxStr | ( | const char * | pszText | ) |
Construct a copy of a C string.
A null argument produces an empty string with no allocation.
| pszText | The text to copy. |
| 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.
| other | The string to copy. |
| HxStr::HxStr | ( | unsigned | nCount, |
| char | ch ) |
Construct a run of one repeated character.
| nCount | The number of characters, which becomes the length. |
| ch | The character to repeat. |
|
inline |
Append another string.
| other | The string to append. |
|
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.
| pszText | The text to append. |
| HxStr & HxStr::operator+= | ( | char | ch | ) |
Append one character.
| ch | The character to append. |
| HxStr & HxStr::operator= | ( | const char * | pszText | ) |
Replace this string with a copy of a C string.
| pszText | The text to copy, or null for an empty string. |
Replace this string with a copy of another.
| other | The string to copy. |
| char HxStr::operator[] | ( | unsigned | i | ) | const |
Read one character.
The index is permitted to equal the length, which reads the terminator.
| i | The index. |
| 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().
| pszRight | The text to compare against. |
| bool HxStr::operator!= | ( | const HxStr & | right | ) | const |
Compare against another string for inequality.
| right | The string to compare against. |
| bool HxStr::operator== | ( | const char * | pszRight | ) | const |
Compare against a C string for equality.
In the PAL build a null argument never compares equal.
| pszRight | The text to compare against. |
| bool HxStr::operator== | ( | const HxStr & | right | ) | const |
Compare against another string for equality.
| right | The string to compare against. |
| bool HxStr::operator< | ( | const HxStr & | right | ) | const |
Order against another string.
An empty string sorts before every non-empty string.
| right | The string to compare against. |
| 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.
| nLen | The new length, excluding the terminator. |
| int HxStr::Find | ( | char | ch | ) | const |
Find the first occurrence of a character.
| ch | The character to look for. |
| int HxStr::Find | ( | char | ch, |
| unsigned | nStart ) const |
Find the first occurrence of a character at or after a position.
| ch | The character to look for. |
| nStart | The index to start from. |
| int HxStr::Find | ( | const char * | pszText | ) | const |
Find the first occurrence of a substring.
| pszText | The text to look for. |
| int HxStr::ReverseFind | ( | char | ch | ) | const |
Find the last occurrence of a character.
| ch | The character to look for. |
| int HxStr::ReverseFindOneOf | ( | const char * | pszChars | ) | const |
Find the last occurrence of any of a set of characters.
| pszChars | The candidate characters, as a NUL-terminated set. |
| 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.
| pos | The index to compare from. |
| len | The number of characters to compare. |
| str | The text to compare against. |
| HxStr HxStr::Mid | ( | unsigned | pos | ) | const |
Extract the text from a position to the end.
| pos | The index to start from. |
| 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.
| pos | The index to start from. |
| len | The number of characters to extract. |
| 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.
| pos | The index to overwrite. |
| len | The number of characters to overwrite, which must be 1. |
| ch | The replacement character. |
Overwrite a run of text with another string.
A run that would pass the end is shortened to the text from pos onward.
| pos | The index to overwrite from. |
| len | The number of characters to overwrite. |
| other | The replacement text. |
| 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.
| 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.
| pos | The index to cut at, which must not exceed the current length. |
| 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.
| pos | The index to remove from. |
| len | The number of characters to remove. |
| HxStr & HxStr::Insert | ( | unsigned | pos, |
| unsigned | nCount, | ||
| char | ch ) |
Insert a run of one repeated character.
| pos | The index to insert at. |
| nCount | The number of characters to insert. |
| ch | The character to insert. |
Insert another string.
| pos | The index to insert at. |
| other | The text to insert. |
| 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.
| stream | The stream to write to. |
| 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
| 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