#include <string.h>
Classes | |
class | CharPtr |
Public Types | |
using | Super = StringTemplate |
using | CharType = CHARTYPE |
Static Public Member Functions | |
static MAXON_FUNCTION REFTYPE | FloatToString (Float32 value, Int charsBeforeComma=STRING_DYNAMIC_DIGITS, Int digitsAfterComma=-3, Bool exponent=false, CHARTYPE fillChar=' ') |
static MAXON_FUNCTION REFTYPE | FloatToString (Float64 value, Int charsBeforeComma=STRING_DYNAMIC_DIGITS, Int digitsAfterComma=-3, Bool exponent=false, CHARTYPE fillChar=' ') |
static MAXON_FUNCTION REFTYPE | IntToString (Int32 v) |
static MAXON_FUNCTION REFTYPE | UIntToString (UInt32 v) |
static MAXON_FUNCTION REFTYPE | IntToString (Int64 v) |
static MAXON_FUNCTION REFTYPE | UIntToString (UInt64 v) |
static MAXON_FUNCTION REFTYPE | MemorySizeToString (Int64 v, Bool mebibytes=true) |
static MAXON_FUNCTION REFTYPE | HexToString (UInt32 v, Bool prefix0x=true) |
static MAXON_FUNCTION REFTYPE | HexToString (UInt64 v, Bool prefix0x=true) |
static MAXON_FUNCTION REFTYPE | PointerToString (const void *v) |
using Super = StringTemplate |
using CharType = CHARTYPE |
MAXON_METHOD Int GetLength | ( | ) | const |
Returns the length (number of elements) of the string, not the size of the block.
MAXON_METHOD Result<void> Init | ( | Int | count = 0 , |
CHARTYPE | fillChar = 0 |
||
) |
Initializes the string with a specific length and a default character.
[in] | count | Number of characters of the new string. |
[in] | fillChar | Character to fill the string with. |
MAXON_METHOD Result<void> Shrink | ( | ) |
Optimizes the memory usage. This can only be done if the string previously contained 16- or 32-bit Unicode characters that now have been removed or if the string was longer before.
MAXON_METHOD Result<void> Append | ( | const INTERFACETYPE * | str | ) |
Concatenates 2 strings, use this operation instead of a = a + b as it is much faster.
MAXON_FUNCTION Result<void> Append | ( | const REFTYPE & | str | ) |
Concatenates 2 strings, use this operation instead of a = a + b as it is much faster.
MAXON_METHOD Result<void> Append | ( | const CHARTYPE * | str, |
Int | len | ||
) |
Concatenates 2 strings of which the second is represented by len characters at address str in memory.
[in] | str | Character pointer. |
[in] | len | Number of characters. |
MAXON_FUNCTION Result<void> Append | ( | const Block< const CHARTYPE > & | block | ) |
Concatenates 2 strings of which the second is represented by a block of characters.
[in] | block | Character block. |
MAXON_FUNCTION Result<void> AppendChar | ( | CHARTYPE | v | ) |
Appends a character to the current string.
[in] | v | The character that will be added. |
MAXON_METHOD Int FindIndex | ( | const INTERFACETYPE * | str, |
StringPosition | start = 0 |
||
) | const |
Searches for the first occurrence of 'str' within a string.
[in] | str | The search string. |
[in] | start | Starting position within the current string to search from. If it is out of bounds the function will return InvalidArrayIndex. |
MAXON_METHOD Int FindLastIndex | ( | const INTERFACETYPE * | str, |
StringPosition | start = StringEnd() |
||
) | const |
Searches for the last occurrence of 'str' within a string.
[in] | str | The search string. |
[in] | start | Starting position within the current string to search from (backwards). The character at the given position will not be included in the search. If it is out of bounds the function will return InvalidArrayIndex. |
MAXON_METHOD Int FindIndex | ( | CHARTYPE | ch, |
StringPosition | start = 0 |
||
) | const |
Searches for the first occurrence of character 'ch' within a string.
[in] | ch | The search character. |
[in] | start | Starting position within the current string to search from. If it is out of bounds the function will return InvalidArrayIndex. |
MAXON_METHOD Int FindLastIndex | ( | CHARTYPE | ch, |
StringPosition | start = StringEnd() |
||
) | const |
Searches for the last occurrence of character 'ch' within a string.
[in] | ch | The search character. |
[in] | start | Starting position within the current string to search from (backwards). The character at the given position will not be included in the search. If it is out of bounds the function will return InvalidArrayIndex. |
MAXON_METHOD Int FindUpperIndex | ( | const INTERFACETYPE * | str, |
StringPosition | start = 0 |
||
) | const |
Uppercase search for the first occurrence of 'str' within a string (which doesn't need to contain uppercase characters).
[in] | str | The search string, must be completely uppercase, otherwise no matches will be found. |
[in] | start | Starting position within the current string to search from. If it is out of bounds the function will return InvalidArrayIndex. |
MAXON_METHOD Int FindLastUpperIndex | ( | const INTERFACETYPE * | str, |
StringPosition | start = StringEnd() |
||
) | const |
Uppercase search for the last occurrence of 'str' within a string (which doesn't need to contain uppercase characters).
[in] | str | The search string, must be completely uppercase, otherwise no matches will be found. |
[in] | start | Starting position within the current string to search from (backwards). The character at the given position will not be included in the search. If it is out of bounds the function will return InvalidArrayIndex. |
MAXON_METHOD Result<void> Erase | ( | StringPosition | position, |
StringCount | count | ||
) |
Erases a range of characters within a string.
[in] | position | The starting position to delete 'count' characters. If the position is out of bounds an error will be returned. |
[in] | count | Number of characters to delete. If you want to delete all characters until the end pass StringEnd(). If the number is larger than what is available an error will be returned. |
MAXON_METHOD Result<void> Insert | ( | StringPosition | position, |
const INTERFACETYPE * | str, | ||
StringPosition | strStart = 0 , |
||
StringCount | strCount = StringEnd() |
||
) |
Inserts a string at a specific position.
[in] | position | Insert position in the current string. StringEnd() is a valid position. If the position is out of bounds an error is returned. |
[in] | str | String to be inserted. |
[in] | strStart | Starting position of the string to be inserted. If the position is out of bounds an error is returned. |
[in] | strCount | Number of characters to be inserted. If the number of characters is too large an error is returned. |
MAXON_METHOD Result<void> Insert | ( | StringPosition | position, |
CHARTYPE | ch | ||
) |
Inserts a single unicode character at a specific position.
[in] | position | Insert position, needs to be within boundaries. |
[in] | ch | Unicode character to insert. |
MAXON_METHOD INTERFACETYPE* GetPart | ( | StringPosition | start, |
StringCount | count | ||
) | const |
Creates a part of the current string.
[in] | start | Position where the new partial string will start. |
[in] | count | Number of characters for the partial string. If it is larger than the number of available characters an empty string will be returned. |
MAXON_METHOD INTERFACETYPE* ToUpper | ( | ) | const |
Returns the uppercase version of a string.
MAXON_METHOD INTERFACETYPE* ToLower | ( | ) | const |
Returns the lowercase version of a string.
MAXON_METHOD COMPARERESULT ComparePart | ( | const INTERFACETYPE * | str, |
STRINGCOMPARISON | mode, | ||
StringPosition | position, | ||
StringCount | count | ||
) | const |
Compares a part of this against 'str' for exact match. Example:
returns COMPARESTRING::EQUAL for matching "bcd"
[in] | str | Comparison object. |
[in] | mode | Comparison mode. |
[in] | position | Starting position in the current string that 'str' will be compared against. The interval [position..count] will be clipped against valid boundaries. |
[in] | count | Number of characters in the current string that 'str' will be compared against. count can be longer than the string length and will be clipped accordingly. |
MAXON_FUNCTION COMPARERESULT Compare | ( | const INTERFACETYPE * | str, |
STRINGCOMPARISON | mode = STRINGCOMPARISON::UNICODE_NUMBERS |
||
) | const |
Compares the object against 'str' for exact match.
[in] | str | Comparison object. |
[in] | mode | Comparison mode. |
MAXON_FUNCTION Bool IsEqual | ( | const INTERFACETYPE * | str | ) | const |
Compare strings for equality.
MAXON_METHOD HashInt GetHashCode | ( | ) | const |
Returns the hash code of this @CLASS.
MAXON_METHOD UniqueHash GetUniqueHashCode | ( | ) | const |
Returns the 128-bit hash value of this @CLASS. The implementation ensures uniform distribution, so for practical purposes you can safely assume that two objects are equal if their hash values are equal.
MAXON_METHOD void SetChar | ( | Int | pos, |
CHARTYPE | ch | ||
) |
Changes the character at the given position (used internally by CharPtr).
[in] | pos | Character index. If it is negative the position is relative to end, e.g. -1 indicates the last character. The position must be within boundaries, however only a debug assert will happen otherwise. |
[in] | ch | Character value. |
@MAXON_ANNOTATION{refclass=false}
MAXON_METHOD CHARTYPE GetChar | ( | Int | pos | ) | const |
Retrieves the character at a given position. If the position is out of bounds 0 will be returned.
[in] | pos | Character position. If it is negative the position is relative to end, e.g. -1 indicates the last character. The position must be within boundaries, however only a debug assert will happen otherwise. |
@MAXON_ANNOTATION{refclass=false}
MAXON_FUNCTION Result<Float64> ToFloat64 | ( | STRINGCONVERSION | flags = STRINGCONVERSION::NONE | ) | const |
Converts a string to a 64-bit floating point value. This routine does no formula parsing. While leading whitespaces are allowed by default no trailing characters of any kind are allowed.
[in] | flags | Optional flags for the conversion. |
MAXON_FUNCTION Result<Float32> ToFloat32 | ( | STRINGCONVERSION | flags = STRINGCONVERSION::NONE | ) | const |
Converts a string to a 32-bit floating point value. This routine does no formula parsing. While leading whitespaces are allowed by default no trailing characters of any kind are allowed.
[in] | flags | Optional flags for the conversion. |
MAXON_FUNCTION Result<Float> ToFloat | ( | STRINGCONVERSION | flags = STRINGCONVERSION::NONE | ) | const |
Converts a string to a floating point value. This routine does no formula parsing. While leading whitespaces are allowed by default no trailing characters of any kind are allowed.
[in] | flags | Optional flags for the conversion. |
MAXON_FUNCTION Result<Int64> ToInt64 | ( | STRINGCONVERSION | flags = STRINGCONVERSION::NONE | ) | const |
Converts a string to a 64 bit integer value. This routine does no formula parsing and does not support any suffixes/prefixes except for 0x (hexadecimal numbers). While leading whitespaces are allowed by default no trailing characters of any kind are allowed.
[in] | flags | Optional flags for the conversion. |
MAXON_FUNCTION Result<Int32> ToInt32 | ( | STRINGCONVERSION | flags = STRINGCONVERSION::NONE | ) | const |
Converts a string to a 32 bit integer value. This routine does no formula parsing and does not support any suffixes/prefixes except for 0x (hexadecimal numbers). While leading whitespaces are allowed by default no trailing characters of any kind are allowed.
[in] | flags | Optional flags for the conversion. |
MAXON_FUNCTION Result<Int> ToInt | ( | STRINGCONVERSION | flags = STRINGCONVERSION::NONE | ) | const |
Converts a string to an integer value. This routine does no formula parsing and does not support any suffixes/prefixes except for 0x (hexadecimal numbers). While leading whitespaces are allowed by default no trailing characters of any kind are allowed.
[in] | flags | Optional flags for the conversion. |
MAXON_FUNCTION Result<UInt64> ToUInt64 | ( | STRINGCONVERSION | flags = STRINGCONVERSION::NONE | ) | const |
Converts a string to a 64 bit unsigned integer value. This routine does no formula parsing and does not support any suffixes/prefixes except for 0x (hexadecimal numbers). While leading whitespaces are allowed by default no trailing characters of any kind are allowed.
[in] | flags | Optional flags for the conversion. |
MAXON_FUNCTION Result<UInt32> ToUInt32 | ( | STRINGCONVERSION | flags = STRINGCONVERSION::NONE | ) | const |
Converts a string to a 32 bit unsigned integer value. This routine does no formula parsing and does not support any suffixes/prefixes except for 0x (hexadecimal numbers). While leading whitespaces are allowed by default no trailing characters of any kind are allowed.
[in] | flags | Optional flags for the conversion. |
MAXON_FUNCTION Result<UInt> ToUInt | ( | STRINGCONVERSION | flags = STRINGCONVERSION::NONE | ) | const |
Converts a string to an unsigned integer value. This routine does no formula parsing and does not support any suffixes/prefixes except for 0x (hexadecimal numbers). While leading whitespaces are allowed by default no trailing characters of any kind are allowed.
[in] | flags | Optional flags for the conversion. |
|
static |
Converts a floating point value into formatted text.
[in] | value | Floating point value to convert into text. |
[in] | charsBeforeComma | Characters before the decimal point. If STRING_DYNAMIC_DIGITS is passed or 'charsBeforeComma' is too low to represent 'value' it is automatically increased/adjusted. If 'charsBeforeComma' is positive and exponent is false fill characters will be added to the beginning. If STRING_MAXIMUM_PRECISION is passed, then the result will be an exact representation of the value (possibly using exponential notation). |
[in] | digitsAfterComma | Digits after the decimal point. If a negative number is passed the number of digits is automatically chosen and up to (-digitsAfterComma). |
[in] | exponent | Force exponential-style output (e.g. 1.0e+10). |
[in] | fillChar | Fill character for digits before the decimal point. E.g. if you specify 4 for charsBeforeComma, '*' for fillChar and your value is 1.5 you'll get ***1.5 as a result. This value has no impact if exponent is true. |
|
static |
Converts a floating point value into formatted text.
[in] | value | Floating point value to convert into text. |
[in] | charsBeforeComma | Characters before the decimal point. If STRING_DYNAMIC_DIGITS is passed or 'charsBeforeComma' is too low to represent 'value' it is automatically increased/adjusted. If 'charsBeforeComma' is positive and exponent is false fill characters will be added to the beginning. If STRING_MAXIMUM_PRECISION is passed, then the result will be an exact representation of the value (possibly using exponential notation). |
[in] | digitsAfterComma | Digits after the decimal point. If a negative number is passed the number of digits is automatically chosen and up to (-digitsAfterComma). |
[in] | exponent | Force exponential-style output (e.g. 1.0e+10). |
[in] | fillChar | Fill character for digits before the decimal point. E.g. if you specify 4 for charsBeforeComma, '*' for fillChar and your value is 1.5 you'll get ***1.5 as a result. This value has no impact if exponent is true. |
MAXON_FUNCTION INTERFACETYPE* AppendInt | ( | Int32 | v | ) |
Appends a number to the current string.
[in] | v | The number that will be added. |
MAXON_FUNCTION INTERFACETYPE* AppendUInt | ( | UInt32 | v | ) |
Appends a number to the current string.
[in] | v | The number that will be added. |
MAXON_FUNCTION INTERFACETYPE* AppendInt | ( | Int64 | v | ) |
Appends a number to the current string.
[in] | v | The number that will be added. |
MAXON_FUNCTION INTERFACETYPE* AppendUInt | ( | UInt64 | v | ) |
Appends a number to the current string.
[in] | v | The number that will be added. |
|
static |
Formats a Int32 value as decimal text.
[in] | v | Int32 value. |
|
static |
Formats a UInt32 value as decimal text.
[in] | v | UInt32 value. |
|
static |
Formats a Int64 value as decimal text.
[in] | v | Int64 value. |
|
static |
Formats a UInt64 value as decimal text.
[in] | v | Int64 value. |
|
static |
Formats a Int64 value as a memory information.
[in] | v | The size of bytes that should be formated as memory text. |
[in] | mebibytes | defines if a value of 1343443 is either output as "1.28 MiB" (mebibytes) or "1.34 MB" (megabytes). |
|
static |
Formats a Int32 value as hexadecimal text.
[in] | v | Int32 value. |
[in] | prefix0x | Start the string with 0x as prefix. |
|
static |
Formats a Int64 value as hexadecimal text.
[in] | v | Int64 value. |
[in] | prefix0x | Start the string with 0x as prefix. |
|
static |
Formats a pointer as hexadecimal text. The pointer starts with 0x prefix.
[in] | v | Pointer to convert. |
MAXON_METHOD Result<void> GetUtf32 | ( | Utf32CharBuffer & | stringData | ) | const |
Copies the string as UTF-32 encoded characters into the passed array. The array will be resized and contain the non \0 - terminated data.
[out] | stringData | The array to receive the data. |
MAXON_METHOD Result<void> TrimLeft | ( | ) |
Removes all characters with value <= 0x20 (e.g. space, tab, line feed) at the beginning of the string.
MAXON_METHOD Result<void> TrimRight | ( | ) |
Removes all characters with value <= 0x20 (e.g. space, tab, line feed) at the end of the string.
MAXON_METHOD Result<void> Split | ( | const REFTYPE & | splitSymbol, |
Bool | trim, | ||
const ValueReceiver< const REFTYPE & > & | parts | ||
) | const |
MAXON_METHOD Result<Int> Replace | ( | CHARTYPE | find, |
CHARTYPE | replace | ||
) |
Replaces all occurrences of the character 'find' in the current string with the given character 'replace'.
[in] | find | Search character. Each occurrence will be replaced with 'replace'. |
[in] | replace | Replacement of 'find'. |
MAXON_METHOD Result<Int> Replace | ( | const REFTYPE & | find, |
const REFTYPE & | replace | ||
) |
Replaces all occurrences of string 'find' in the current string with the given string 'replace'.
[in] | find | Search string. Each occurrence will be replaced with 'replace'. |
[in] | replace | Replacement of 'find'. Can be an empty string, in which case all 'find' strings will be removed. |
MAXON_METHOD Result<Int> Replace | ( | CHARTYPE | find, |
const REFTYPE & | replace | ||
) |
Replaces all occurrences of the character 'find' in the current string with the given string 'replace'.
[in] | find | Search character. Each occurrence will be replaced with 'replace'. |
[in] | replace | Replacement of 'find'. Can be an empty string, in which case all 'find' characters will be removed. |
MAXON_FUNCTION Bool Find | ( | const REFTYPE & | str, |
Int * | pos, | ||
StringPosition | start = 0 |
||
) | const |
Searches for the first occurrence of 'str' within a string.
[in] | str | The search string. |
[out] | pos | Pointer to be filled with the position where 'str' was found. This parameter can be a nullptr. In case no occurence was found *pos is initialized with InvalidArrayIndex. |
[in] | start | Starting position within the current string to search from. If it is out of bounds the function will return false. |
MAXON_FUNCTION Bool FindLast | ( | const REFTYPE & | str, |
Int * | pos, | ||
StringPosition | start = StringEnd() |
||
) | const |
Searches for the last occurrence of 'str' within a string.
[in] | str | The search string. |
[out] | pos | Pointer to be filled with the position where 'str' was found. This parameter can be a nullptr. In case no occurence was found *pos is initialized with InvalidArrayIndex. |
[in] | start | Starting position within the current string to search from (backwards). The character at the given position will not be included in the search. If it is out of bounds the function will return false. |
MAXON_FUNCTION Bool Find | ( | CHARTYPE | ch, |
Int * | pos, | ||
StringPosition | start = 0 |
||
) | const |
Searches for the first occurrence of character 'ch' within a string.
[in] | ch | The search character. |
[out] | pos | Pointer to be filled with the position where 'ch' was found. This parameter can be a nullptr. In case no occurence was found, *pos is initialized with InvalidArrayIndex. |
[in] | start | Starting position within the current string to search from. If it is out of bounds the function will return false. |
MAXON_FUNCTION Bool FindLast | ( | CHARTYPE | ch, |
Int * | pos, | ||
StringPosition | start = StringEnd() |
||
) | const |
Searches for the last occurrence of character 'ch' within a string.
[in] | ch | The search character. |
[out] | pos | Pointer to be filled with the position where 'ch' was found. This parameter can be a nullptr. In case no occurence was found, *pos is initialized with InvalidArrayIndex. |
[in] | start | Starting position within the current string to search from (backwards). The character at the given position will not be included in the search. If it is out of bounds the function will return false. |
MAXON_FUNCTION Bool FindUpper | ( | const REFTYPE & | str, |
Int * | pos, | ||
StringPosition | start = 0 |
||
) | const |
Uppercase search for the first occurrence of 'str' within a string (which doesn't need to contain uppercase characters).
[in] | str | The search string, must be completely uppercase, otherwise no matches will be found. |
[out] | pos | Pointer to be filled with the position where 'str' was found. This parameter can be a nullptr. In case no occurence was found, *pos is initialized with InvalidArrayIndex. |
[in] | start | Starting position within the current string to search from. If it is out of bounds the function will return false. |
MAXON_FUNCTION Bool FindLastUpper | ( | const REFTYPE & | str, |
Int * | pos, | ||
StringPosition | start = StringEnd() |
||
) | const |
Uppercase search for the last occurrence of 'str' within a string (which doesn't need to contain uppercase characters).
[in] | str | The search string, must be completely uppercase, otherwise no matches will be found. |
[out] | pos | Pointer to be filled with the position where 'str' was found. This parameter can be a nullptr. In case no occurence was found, *pos is initialized with InvalidArrayIndex. |
[in] | start | Starting position within the current string to search from (backwards). The character at the given position will not be included in the search. If it is out of bounds the function will return false. |
MAXON_FUNCTION INTERFACETYPE* GetLeftPart | ( | StringPosition | start | ) | const |
Returns the string part left of the given position. The character at position will not be included.
[in] | start | Partitioning position. |
MAXON_FUNCTION INTERFACETYPE* GetRightPart | ( | StringPosition | start | ) | const |
Returns the string part right of the given position. The character at position will be included.
[in] | start | Partitioning position. |
MAXON_FUNCTION Bool StartsWith | ( | CHARTYPE | ch | ) | const |
Checks if the string starts with a certain character.
[in] | ch | The character to be checked. |
MAXON_FUNCTION Bool StartsWith | ( | const REFTYPE & | str | ) | const |
Checks if the current string starts with a given string.
[in] | str | The string part. |
MAXON_FUNCTION Bool EndsWith | ( | CHARTYPE | ch | ) | const |
Checks if the string ends with a certain character.
[in] | ch | The character to be checked. |
MAXON_FUNCTION Bool EndsWith | ( | const REFTYPE & | str | ) | const |
Checks if the current string end with a given string.
[in] | str | The string part. |
MAXON_FUNCTION Result<void> Trim | ( | ) |
Removes all characters with value <= 0x20 (e.g. space, tab, line feed) at the beginning and the end of the string.