This class contains string parsing functions.
#include <utility/YiStringParsing.h>
Classes | |
struct | NumberWithSuffix |
Static Public Member Functions | |
static bool | ParseBooleanValue (CYIStringView value, bool *pError=nullptr, bool logParsingErrors=true) |
static float | ParseFloatValue (CYIStringView value, bool *pError=nullptr, bool logParsingErrors=true) |
static uint32_t | ParseTimeValue (CYIStringView value, bool *pError=nullptr, bool logParsingErrors=true) |
static float | ParseLengthValue (CYIStringView length, bool *pError=nullptr, bool logParsingErrors=true) |
static NumberWithSuffix | SplitSuffixFromNumber (CYIStringView input) |
|
static |
Parses a String value as a boolean.
Any of these values will be considered true: 1
, yes
, true
, on
, enabled
, enable
, and active
. The following values will be considered false: 0
, no
, false
, off
, disabled
, disable
, and inactive
. Any other value will be considered a parsing error and will result in a value of false being returned.
A pointer to a boolean, pError, can optionally be provided – if a parsing error occurs, its pointed-to boolean will be set to true. If no parsing error occurs, the pointed-to boolean will be set to false.
By default, parsing errors will result in a warning being logged. This can be disabled by setting logParsingErrors to false.
|
static |
Parses a String value as a float.
An empty or invalid String will result in a value of 0.0f being returned.
A pointer to a boolean, pError, can optionally be provided – if a parsing error occurs, its pointed-to boolean will be set to true. If no parsing error occurs, the pointed-to boolean will be set to false.
By default, parsing errors will result in a warning being logged. This can be disabled by setting logParsingErrors to false.
5.1ms
would result in 5.1f being returned.
|
static |
Parses a String as a length value.
An empty or invalid String will result in a value of 0.0f being returned.
A pointer to a boolean, pError, can optionally be provided – if a parsing error occurs, its pointed-to boolean will be set to true. If no parsing error occurs, the pointed-to boolean will be set to false.
By default, parsing errors will result in a warning being logged. This can be disabled by setting logParsingErrors to false.
|
static |
Parses a String value as a time, in milliseconds.
An empty or invalid String will result in a value of 0 being returned.
A pointer to a boolean, pError, can optionally be provided – if a parsing error occurs, its pointed-to boolean will be set to true. If no parsing error occurs, the pointed-to boolean will be set to false.
By default, parsing errors will result in a warning being logged. This can be disabled by setting logParsingErrors to false.
|
static |
An utility function that splits an input string into a number and a 'suffix'.
This function splits a text suffix from a number, storing the number in pNumber and the suffix in pSuffix. For example, if called with "54.2 ms" for inOutNumber, the returned object will have the string "54.2" in its number
field, and will have the string "ms" in its suffix
field. Spaces between the number and the suffix are removed. Leading and trailing spaces are also removed.
The suffix is considered to start at the first non-space character encountered that is not within this group: '0123456789 .-' For example, if called with "54.2+ suffix" for input, the number portion of the returned object will be set to "54.2" and the suffix portion of the returned object will be set to "+ suffix".
number
field (excluding leading and trailing spaces) and the suffix
field is left empty. If the provided string does not start with a 'digit' character, the number
field is left blank and the suffix
field is set to input (excluding leading and trailing spaces).