You.i Engine
CYIStringParsing Class Reference

Detailed Description

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)
 

Member Function Documentation

◆ ParseBooleanValue()

static bool CYIStringParsing::ParseBooleanValue ( CYIStringView  value,
bool *  pError = nullptr,
bool  logParsingErrors = true 
)
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.

Note
The case of value is ignored. Leading and trailing spaces (and space-like characters) are ignored.
See also
CYIStringView::ToBool

◆ ParseFloatValue()

static float CYIStringParsing::ParseFloatValue ( CYIStringView  value,
bool *  pError = nullptr,
bool  logParsingErrors = true 
)
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.

Note
Suffixes to a numerical value are ignored. For example, 5.1ms would result in 5.1f being returned.
See also
CYIStringView::ToFloat

◆ ParseLengthValue()

static float CYIStringParsing::ParseLengthValue ( CYIStringView  length,
bool *  pError = nullptr,
bool  logParsingErrors = true 
)
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.

Note
This function is used to facilitate eventually supporting multiple length 'units'.
Suffixes are ignored but this may change in the future.
See also
ParseFloatValue

◆ ParseTimeValue()

static uint32_t CYIStringParsing::ParseTimeValue ( CYIStringView  value,
bool *  pError = nullptr,
bool  logParsingErrors = true 
)
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.

Note
The following suffixes are supported: ms (millisecond), s (second), m (minute) and h (hour). If no suffix is present, the value is assumed to be in milliseconds.
The case of the suffixes is ignored.

◆ SplitSuffixFromNumber()

static NumberWithSuffix CYIStringParsing::SplitSuffixFromNumber ( CYIStringView  input)
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".

Note
If no suffix is found, the returned object contains input in its 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).
Warning
The string views contained in the returned struct are valid only so long as the input string view is valid. Avoid calling this function with a temporary.

The documentation for this class was generated from the following file: