StringConversion Class Reference

#include <stringconversion.h>

Detailed Description

Class that controls string to value conversion. There is no need to use this class directly, use String instead.

Static Public Member Functions

static MAXON_METHOD String FloatToString (Float32 value, Int charsBeforeComma, Int digitsAfterComma, Bool exponent, Utf32Char fillChar, const FormatStatement *formatStatement)
 
static MAXON_METHOD String FloatToString (Float64 value, Int charsBeforeComma, Int digitsAfterComma, Bool exponent, Utf32Char fillChar, const FormatStatement *formatStatement)
 
static MAXON_METHOD void AppendInt (StringInterface *str, Int64 value, Int datatypeSize, const FormatStatement *formatStatement)
 
static MAXON_METHOD void AppendUInt (StringInterface *str, UInt64 value, Int datatypeSize, const FormatStatement *formatStatement)
 
static MAXON_METHOD void AppendInt (CStringInterface *str, Int64 value, Int datatypeSize, const FormatStatement *formatStatement)
 
static MAXON_METHOD void AppendUInt (CStringInterface *str, UInt64 value, Int datatypeSize, const FormatStatement *formatStatement)
 
static MAXON_METHOD String MemorySizeToString (Int64 mem, Bool mebibytes)
 
static MAXON_METHOD String HexToString (UInt32 value, Bool prefix0x, Bool leadingZeros, const FormatStatement *formatStatement)
 
static MAXON_METHOD String HexToString (UInt64 value, Bool prefix0x, Bool leadingZeros, const FormatStatement *formatStatement)
 
static MAXON_METHOD Result< Float32ToFloat32 (const Block< const Utf32Char > &str, STRINGCONVERSION flags)
 
static MAXON_METHOD Result< Float64ToFloat64 (const Block< const Utf32Char > &str, STRINGCONVERSION flags)
 
static MAXON_METHOD Result< Int64ToInt64 (const Block< const Utf32Char > &str, STRINGCONVERSION flags)
 
static MAXON_METHOD Result< Int32ToInt32 (const Block< const Utf32Char > &str, STRINGCONVERSION flags)
 
static MAXON_METHOD Result< UInt64ToUInt64 (const Block< const Utf32Char > &str, STRINGCONVERSION flags)
 
static MAXON_METHOD Result< UInt32ToUInt32 (const Block< const Utf32Char > &str, STRINGCONVERSION flags)
 
static MAXON_METHOD Result< Float64StringToFloat (const Block< const Utf32Char > &str, Int &processedChars)
 
static MAXON_METHOD Result< UInt64StringToInteger (const Block< const Utf32Char > &str, Int base, Bool autodetect0x, Bool signedMode, Int &processedChars)
 
static MAXON_METHOD const StringGetLineEnd ()
 
static MAXON_METHOD const CStringGetLineEndC ()
 
static MAXON_METHOD StringProxyFormatXArgs (const String &formatString, Int argsCnt, const void **args, const TOSTR *argFuncs)
 
static MAXON_METHOD Bool ScanStringXArgs (const String &str, const String &format, Int *parsedCharacters, Int argsCnt, void **args, FROMSTR *argFuncs)
 
static MAXON_METHOD Int64 ScanParameterBasic (const Block< const Utf32Char > &str, Bool signedMode, Int &processed, const String &formatStatement, Bool &error)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (StringConversion, MAXON_REFERENCE_NONE, "net.maxon.interface.stringconversion")
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( StringConversion  ,
MAXON_REFERENCE_NONE  ,
"net.maxon.interface.stringconversion"   
)
private

◆ FloatToString() [1/2]

static MAXON_METHOD String FloatToString ( Float32  value,
Int  charsBeforeComma,
Int  digitsAfterComma,
Bool  exponent,
Utf32Char  fillChar,
const FormatStatement formatStatement 
)
static

Converts a floating point value into formatted text.

Parameters
[in]valueFloating point value to convert into text.
[in]charsBeforeCommaCharacters before the decimal point. If -1 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.
[in]digitsAfterCommaDigits after the decimal point. If a negative number is passed the number of digits is automatically chosen and up to (-digitsAfterComma).
[in]exponentForce exponential-style output (e.g. 1.0e+10).
[in]fillCharFill 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.
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Floating point values.
Returns
String object with the decimal text of the value.

◆ FloatToString() [2/2]

static MAXON_METHOD String FloatToString ( Float64  value,
Int  charsBeforeComma,
Int  digitsAfterComma,
Bool  exponent,
Utf32Char  fillChar,
const FormatStatement formatStatement 
)
static

Converts a floating point value into formatted text.

Parameters
[in]valueFloating point value to convert into text.
[in]charsBeforeCommaCharacters before the decimal point. If -1 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.
[in]digitsAfterCommaDigits after the decimal point. If a negative number is passed the number of digits is automatically chosen and up to (-digitsAfterComma).
[in]exponentForce exponential-style output (e.g. 1.0e+10).
[in]fillCharFill 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.
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Floating point values.
Returns
String object with the decimal text of the value.

◆ AppendInt() [1/2]

static MAXON_METHOD void AppendInt ( StringInterface str,
Int64  value,
Int  datatypeSize,
const FormatStatement formatStatement 
)
static

Appends an integer value to an existing string.

Parameters
[in]strThe existing string.
[in]valueThe value that will be appended as a string.
[in]datatypeSizeSize in bytes of the passed value, as this routine can be used for Char, Int16, Int32 and Int64 values. This becomes only relevant if formatStatement forces hexadecimal output.
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Integer values.

◆ AppendUInt() [1/2]

static MAXON_METHOD void AppendUInt ( StringInterface str,
UInt64  value,
Int  datatypeSize,
const FormatStatement formatStatement 
)
static

Appends an unsigned integer value to an existing string.

Parameters
[in]strThe existing string.
[in]valueThe value that will be appended as a string.
[in]datatypeSizeSize in bytes of the passed value, as this routine can be used for UChar, UInt16, UInt32 and UInt64 values. This becomes only relevant if formatStatement forces hexadecimal output.
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Integer values.

◆ AppendInt() [2/2]

static MAXON_METHOD void AppendInt ( CStringInterface str,
Int64  value,
Int  datatypeSize,
const FormatStatement formatStatement 
)
static

Appends an integer value to an existing string.

Parameters
[in]strThe existing string.
[in]valueThe value that will be appended as a string.
[in]datatypeSizeSize in bytes of the passed value, as this routine can be used for Char, Int16, Int32 and Int64 values. This becomes only relevant if formatStatement forces hexadecimal output.
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Integer values.

◆ AppendUInt() [2/2]

static MAXON_METHOD void AppendUInt ( CStringInterface str,
UInt64  value,
Int  datatypeSize,
const FormatStatement formatStatement 
)
static

Appends an unsigned integer value to an existing string.

Parameters
[in]strThe existing string.
[in]valueThe value that will be appended as a string.
[in]datatypeSizeSize in bytes of the passed value, as this routine can be used for UChar, UInt16, UInt32 and UInt64 values. This becomes only relevant if formatStatement forces hexadecimal output.
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Integer values.

◆ MemorySizeToString()

static MAXON_METHOD String MemorySizeToString ( Int64  mem,
Bool  mebibytes 
)
static

Creates a readable string from a memory size.

Parameters
[in]memThe memory size.
[in]mebibytesdefines if a value of 1343443 is either output as "1.28 MiB" (mebibytes) or "1.34 MB" (megabytes).
Returns
String that displays the memory size.

◆ HexToString() [1/2]

static MAXON_METHOD String HexToString ( UInt32  value,
Bool  prefix0x,
Bool  leadingZeros,
const FormatStatement formatStatement 
)
static

Converts a value into a hexadecimal string.

Parameters
[in]valueThe value.
[in]prefix0xIf true, the output string will have a '0x' prefix.
[in]leadingZerosIf false, the output string will have no leading zeros, so a value of 100 e.g. will be output as 64 (and not 00000064).
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Pointer values.
Returns
The converted string.

◆ HexToString() [2/2]

static MAXON_METHOD String HexToString ( UInt64  value,
Bool  prefix0x,
Bool  leadingZeros,
const FormatStatement formatStatement 
)
static

Converts a value into a hexadecimal string.

Parameters
[in]valueThe value.
[in]prefix0xIf true, the output string will have a '0x' prefix.
[in]leadingZerosIf false, the output string will have no leading zeros, so a value of 100 e.g. will be output as 64 (and not 0000000000000064).
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Pointer values.
Returns
The converted string.

◆ ToFloat32()

static MAXON_METHOD Result<Float32> ToFloat32 ( const Block< const Utf32Char > &  str,
STRINGCONVERSION  flags 
)
static

Converts a Utf32Char character sequence 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.

Parameters
[in]strThe input string.
[in]flagsOptional flags for the conversion.
Returns
Floating point value of string.

◆ ToFloat64()

static MAXON_METHOD Result<Float64> ToFloat64 ( const Block< const Utf32Char > &  str,
STRINGCONVERSION  flags 
)
static

Converts a Utf32Char character sequence 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.

Parameters
[in]strThe input string.
[in]flagsOptional flags for the conversion.
Returns
Floating point value of string.

◆ ToInt64()

static MAXON_METHOD Result<Int64> ToInt64 ( const Block< const Utf32Char > &  str,
STRINGCONVERSION  flags 
)
static

Converts a Utf32Char character sequence 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.

Parameters
[in]strThe input string.
[in]flagsOptional flags for the conversion.
Returns
Integer value of the string.

◆ ToInt32()

static MAXON_METHOD Result<Int32> ToInt32 ( const Block< const Utf32Char > &  str,
STRINGCONVERSION  flags 
)
static

Converts a Utf32Char character sequence 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.

Parameters
[in]strThe input string.
[in]flagsOptional flags for the conversion.
Returns
Integer value of the string.

◆ ToUInt64()

static MAXON_METHOD Result<UInt64> ToUInt64 ( const Block< const Utf32Char > &  str,
STRINGCONVERSION  flags 
)
static

Converts a Utf32Char character sequence 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.

Parameters
[in]strThe input string.
[in]flagsOptional flags for the conversion.
Returns
Integer value of the string.

◆ ToUInt32()

static MAXON_METHOD Result<UInt32> ToUInt32 ( const Block< const Utf32Char > &  str,
STRINGCONVERSION  flags 
)
static

Converts a Utf32Char character sequence 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.

Parameters
[in]strThe input string.
[in]flagsOptional flags for the conversion.
Returns
Integer value of the string.

◆ StringToFloat()

static MAXON_METHOD Result<Float64> StringToFloat ( const Block< const Utf32Char > &  str,
Int processedChars 
)
static

Converts a Utf32Char character sequence to a floating point value. This routine does no formula parsing. No leading whitespaces or characters that do not belong to the floating point value are allowed.

Parameters
[in]strThe character sequence.
[out]processedCharsThe actual number of characters that were read. This can be shorter than maxChars. The algorithm stops as soon as it finds a character that does not belong to the floating point value.
Returns
Floating point value of string.

◆ StringToInteger()

static MAXON_METHOD Result<UInt64> StringToInteger ( const Block< const Utf32Char > &  str,
Int  base,
Bool  autodetect0x,
Bool  signedMode,
Int processedChars 
)
static

Converts a Utf32Char character sequence to an integer value. This routine does no formula parsing. No leading whitespaces or characters that do not belong to the integer value are allowed.

Parameters
[in]strThe character sequence.
[in]baseNumerical base that is in the range of [2..36]. For regular decimal conversion pass 10, for hexadecimal conversion 16. NOTOK is valid.
[in]autodetect0xIf true the string is scanned for a '0x' prefix. If that is detected the base is automatically set to 16.
[in]signedModeIf false, negative numbers will result in an error. In signedMode numbers need to be within Int64 limits, otherwise UInt64.
[out]processedCharsThe actual number of characters that were read. This can be shorter than maxChars. The algorithm stops as soon as it finds a character that does not belong to the integer value.
Returns
Integer value of string. In signed mode the result must be cast to Int64.

◆ GetLineEnd()

static MAXON_METHOD const String& GetLineEnd ( )
static

Returns a string with the platform specific line ending.

Returns
String containing the line ending ("\r\n" or "\r").

◆ GetLineEndC()

static MAXON_METHOD const CString& GetLineEndC ( )
static

Returns a string with the platform specific line ending.

Returns
CString containing the line ending ("\r\n" or "\r").

◆ FormatXArgs()

static MAXON_METHOD StringProxy* FormatXArgs ( const String formatString,
Int  argsCnt,
const void **  args,
const TOSTR argFuncs 
)
static

◆ ScanStringXArgs()

static MAXON_METHOD Bool ScanStringXArgs ( const String str,
const String format,
Int parsedCharacters,
Int  argsCnt,
void **  args,
FROMSTR argFuncs 
)
static

◆ ScanParameterBasic()

static MAXON_METHOD Int64 ScanParameterBasic ( const Block< const Utf32Char > &  str,
Bool  signedMode,
Int processed,
const String formatStatement,
Bool error 
)
static