This is a detail namespace of module ALib Strings.
|
| template<typename TChar> |
| uint64_t | ParseBin (const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| uint64_t | ParseDec (const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| uint64_t | ParseDecDigits (const TString< TChar > &src, integer &idx) |
| template<typename TChar> |
| double | ParseFloat (const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| uint64_t | ParseHex (const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| int64_t | ParseInt (const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| uint64_t | ParseOct (const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| integer | WriteBin (uint64_t value, TChar *buffer, integer idx, int minWidth, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| integer | WriteDecSigned (int64_t value, TChar *buffer, integer idx, int minWidth, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| integer | WriteDecUnsigned (uint64_t value, TChar *buffer, integer idx, int minWidth, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| integer | WriteFloat (double value, TChar *buffer, integer idx, int minWidth, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| integer | WriteHex (uint64_t value, TChar *buffer, integer idx, int minWidth, const TNumberFormat< TChar > &nf) |
| template<typename TChar> |
| integer | WriteOct (uint64_t value, TChar *buffer, integer idx, int minWidth, const TNumberFormat< TChar > &nf) |
Reads an unsigned integral value in hexadecimal format from the given character array at the given position.
Sign literals '-' or '+' are not accepted and parsing will fail if found. Whitespace and grouping characters, as defined in fields Whitespaces, HexByteGroupChar, HexWordGroupChar and HexWord32GroupChar of the NumberFormat object given with nf, will be ignored (tolerated) regardless of their position between digits. To suppress the parsing of group characters, set the fields to '\0'. To suppress whitespace consumption, set field Whitespaces to nulled or empty string.
Letters 'a' to 'f' are parsed ignoring their case. This is independent of the setting of the flag HexLowerCase in the field Flags of the given nf.
- Template Parameters
-
| TChar | The character type of the string to parse from. |
- Parameters
-
| src | The string to read the value from. |
| [in,out] | idx | The start point for parsing within src. Will be set to point behind the last character consumed. If unchanged, this indicates that no parsable number was found. |
| nf | The number format to use. |
- Returns
- The parsed value. In addition, on success, parameter idx is moved to point to the first character behind the parsed number.
Parses signed integer numbers, optionally in binary, hexadecimal or octal format.
Leading characters defined in field Whitespaces of the NumberFormat object given with nf are ignored. An optional sign character '+' or '-' is parsed. If found, again whitespace characters may follow behind such sign and are ignored.
Then, the function detects any literal prefixes as defined in fields BinLiteralPrefix, HexLiteralPrefix and OctLiteralPrefix (usually 0b, 0x and 0o) and invokes one of the functions ParseDec, ParseBin, ParseHex or ParseOct.
- Template Parameters
-
| TChar | The character type of the string to parse from. |
- Parameters
-
| src | The string to read the value from. |
| [in,out] | idx | The start point for parsing within src. Will be set to point behind the last character consumed. If unchanged, this indicates that no parsable number was found. |
| nf | The number format to use. |
- Returns
- The parsed value. In addition, on success, parameter idx is moved to point to the first character behind the parsed number.
template<typename TChar>
| integer alib::strings::detail::WriteBin |
( |
uint64_t | value, |
|
|
TChar * | buffer, |
|
|
integer | idx, |
|
|
int | minWidth, |
|
|
const TNumberFormat< TChar > & | nf ) |
Converts the given long value to a string representation in binary format.
The maximum number of digits written is 64. In addition, grouping characters may be written according the settings of the flags and fields WriteGroupChars, BinNibbleGroupChar, BinByteGroupChar, BinWordGroupChar, BinWord32GroupChar and LeadingGroupCharReplacement
of the NumberFormat object given with nf.
The minimum width of the output is taken from field BinFieldWidth unless overwritten by parameter minWidth. If the width is greater than digits found in value, '0' digits are prepended. The width is taking group characters into account.
- Attention
- The function does not (and cannot) check an overflow of the given character buffer when writing.
-
If the value is greater than can be represented by the output width, these greater digits are cut. This is true for this function as well as for WriteHex and WriteOct. The rationale behind this is that this way, larger numbers do not need to be masked before writing. (In other words: it is assumed that there is a reason for providing the width).
- Note
- The literal prefix found in field BinLiteralPrefix of nf is not written. The field is only used for detecting formats with function ParseInt.
- Template Parameters
-
| TChar | The character type of the string to write into. |
- Parameters
-
| value | The value to write. |
| buffer | The character array to write the value to. Needs to be long enough (after idx) to carry the string written. |
| idx | The index within buffer to start writing. |
| minWidth | The minimum width of the output. If 0, the value of BinFieldWidth of argument nf is used. |
| nf | Number format definitions. |
- Returns
- The index pointing to behind the last character written in buffer.
template<typename TChar>
| integer alib::strings::detail::WriteDecUnsigned |
( |
uint64_t | value, |
|
|
TChar * | buffer, |
|
|
integer | idx, |
|
|
int | minWidth, |
|
|
const TNumberFormat< TChar > & | nf ) |
Converts the given long value to a string representation in decimal format.
The maximum number of digits written is 20. In addition, grouping characters may be written according the flag WriteGroupChars and the fields ThousandsGroupChar and LeadingGroupCharReplacement of the given nf.
The minimum width of the output is taken from field DecMinimumFieldWidth unless overwritten by parameter minWidth. If the minimum width is greater than the sum of digits and* grouping characters needed to write value, then '0' digits are prepended between the sign and the number.
- Attention
- The function does not (and cannot) check an overflow of the given character buffer when writing.
- See also
- Function WriteDecSigned to write signed decimals.
- Template Parameters
-
| TChar | The character type of the string to write into. |
- Parameters
-
| value | The value to write. |
| buffer | The character array to write the value to. Needs to be long enough (after idx) to carry the string written. |
| idx | The index within buffer to start writing. |
| minWidth | The minimum width of the output. If 0, the value of DecMinimumFieldWidth of argument nf is used. |
| nf | Number format definitions. |
- Returns
- The index pointing to behind the last character written in buffer.
template<typename TChar>
| integer alib::strings::detail::WriteFloat |
( |
double | value, |
|
|
TChar * | buffer, |
|
|
integer | idx, |
|
|
int | minWidth, |
|
|
const TNumberFormat< TChar > & | nf ) |
Writes a string representation of the given double value.
Grouping characters are written according to the flags and members WriteGroupChars, ThousandsGroupChar and LeadingGroupCharReplacement:
The minimum width of the integral part of the output is taken from field IntegralPartMinimumWidth unless overwritten by parameter minWidth. If the width is greater than integral digits found in value, '0' digits are prepended. The width is taking group characters into account.
If field FractionalPartWidth as well as the width of the integral part (provided or set) equals -1 the function may choose scientific notation. This is done for numbers smaller than 10E-4 or larger than 10E+6.
If the given value is not a number, NANLiteral is written. If infinite, INFLiteral.
The output format is dependent on various further settings provided in the flas and fields of the given nf. Those are ForceScientific, ForceDecimalPoint, WriteExponentPlusSign, DecimalPointChar, and ExponentSeparator.
- Attention
- The function does not (and cannot) check an overflow of the given character buffer when writing.
- Template Parameters
-
| TChar | The character type of the string to write into. |
- Parameters
-
| value | The value to write. |
| buffer | The character array to write the value to. Needs to be long enough (after idx) to carry the string written. |
| idx | The index within buffer to start writing. |
| minWidth | The minimum width of the integral part of the output. If 0, the value of IntegralPartMinimumWidth of argument nf is used. |
| nf | Number format definitions. |
- Returns
- The index pointing to behind the last character written in buffer.
template<typename TChar>
| integer alib::strings::detail::WriteHex |
( |
uint64_t | value, |
|
|
TChar * | buffer, |
|
|
integer | idx, |
|
|
int | minWidth, |
|
|
const TNumberFormat< TChar > & | nf ) |
Converts the given long value to a string representation in hexadecimal format.
The maximum number of digits written is 16. In addition, grouping characters may be written according the settings of the flags and fields WriteGroupChars, HexByteGroupChar, HexWordGroupChar, HexWord32GroupChar and LeadingGroupCharReplacement of the given nf.
The minimum width of the output is taken from field HexFieldWidth unless overwritten by the parameter minWidth. If the width is greater than digits found in value, '0' digits are prepended. The width is taking group characters into account.
- Attention
- The function does not (and cannot) check an overflow of the given character buffer when writing.
-
If the value is greater than can be represented by the output width, these greater digits are cut. This is true for this function as well as WriteBin and writeOct. The rationale behind this is that this way, larger numbers do not need to be masked before writing. (In other words: it is assumed that there is a reason for providing the width).
- Note
- The literal prefix found in field HexLiteralPrefix of nf is not written. The field is only used for detecting formats with function ParseInt.
- Template Parameters
-
| TChar | The character type of the string to write into. |
- Parameters
-
| value | The value to write. |
| buffer | The character array to write the value to. Needs to be long enough (after idx) to carry the string written. |
| idx | The index within buffer to start writing. |
| minWidth | The minimum width of the output. If 0, the value of HexFieldWidth of argument nf is used. |
| nf | Number format definitions. |
- Returns
- The index pointing to behind the last character written in buffer.
template<typename TChar>
| integer alib::strings::detail::WriteOct |
( |
uint64_t | value, |
|
|
TChar * | buffer, |
|
|
integer | idx, |
|
|
int | minWidth, |
|
|
const TNumberFormat< TChar > & | nf ) |
Converts the given long value to a string representation in octal format.
The maximum number of digits written is 64. In addition, grouping characters may be written according the settings of the flags and fields WriteGroupChars, OctGroupChar and LeadingGroupCharReplacement
of the given nf.
The minimum width of the output is taken from field OctFieldWidth unless overwritten by parameter minWidth. If the width is greater than digits found in value, '0' digits are prepended. The width is taking group characters into account.
- Attention
- The function does not (and cannot) check an overflow of the given character buffer when writing.
-
If the value is greater than can be represented by the output width, these greater digits are cut. This is true for this function as well as WriteBin and writeHex. The rationale behind this is that this way, larger numbers do not need to be masked before writing. (In other words: it is assumed that there is a reason for providing the width).
- Note
- The literal prefix found in field OctLiteralPrefix of nf is not written. The field is only used for detecting formats with function ParseInt.
- Template Parameters
-
| TChar | The character type of the string to write into. |
- Parameters
-
| value | The value to write. |
| buffer | The character array to write the value to. Needs to be long enough (after idx) to carry the string written. |
| idx | The index within buffer to start writing. |
| minWidth | The minimum width of the output. If 0, the value of OctFieldWidth of argument nf is used. |
| nf | Number format definitions. |
- Returns
- The index pointing to behind the last character written in buffer.