ReXGlue SDK
Loading...
Searching...
No Matches
numeric.h File Reference
#include <bit>
#include <charconv>
#include <cerrno>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <format>
#include <string>
#include <string_view>
#include <type_traits>
#include <rex/assert.h>
#include <rex/platform.h>
#include <rex/string/text.h>
#include <rex/types.h>

Go to the source code of this file.

Namespaces

namespace  rex

Functions

std::string rex::string::to_hex_string (u32 value)
std::string rex::string::to_hex_string (u64 value)
std::string rex::string::to_hex_string (f32 value)
std::string rex::string::to_hex_string (f64 value)
template<typename T>
T rex::string::from_string (const std::string_view value, bool force_hex=false)
template<>
bool rex::string::from_string< bool > (const std::string_view value, bool force_hex)
template<>
i8 rex::string::from_string< i8 > (const std::string_view value, bool force_hex)
template<>
u8 rex::string::from_string< u8 > (const std::string_view value, bool force_hex)
template<>
i16 rex::string::from_string< i16 > (const std::string_view value, bool force_hex)
template<>
u16 rex::string::from_string< u16 > (const std::string_view value, bool force_hex)
template<>
i32 rex::string::from_string< i32 > (const std::string_view value, bool force_hex)
template<>
u32 rex::string::from_string< u32 > (const std::string_view value, bool force_hex)
template<>
i64 rex::string::from_string< i64 > (const std::string_view value, bool force_hex)
template<>
u64 rex::string::from_string< u64 > (const std::string_view value, bool force_hex)
template<>
f32 rex::string::from_string< f32 > (const std::string_view value, bool force_hex)
template<>
f64 rex::string::from_string< f64 > (const std::string_view value, bool force_hex)

Detailed Description

License
BSD 3-Clause License See LICENSE file in the project root for full license text.
Remarks
Derived from Xenia's xenia/base/string_util.h (Ben Vanik, 2020).

Function Documentation

◆ from_string()

template<typename T>
T rex::string::from_string ( const std::string_view value,
bool force_hex = false )
inline

Parses a value from a string. Only the specializations parse.

Parameters
force_hexTrue to parse integers and floats as hex without a prefix.

◆ from_string< bool >()

template<>
bool rex::string::from_string< bool > ( const std::string_view value,
bool force_hex )
inline

Parses a boolean. Accepts "true", "1" or "yes".

Parameters
force_hexUnused.
Returns
True for "true", "1" or "yes", false otherwise.

◆ from_string< f32 >()

template<>
f32 rex::string::from_string< f32 > ( const std::string_view value,
bool force_hex )
inline

Parses a 32 bit float. Hex text gives the raw bits.

Parameters
force_hexTrue to parse as raw hex bits without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ from_string< f64 >()

template<>
f64 rex::string::from_string< f64 > ( const std::string_view value,
bool force_hex )
inline

Parses a 64 bit float. Hex text gives the raw bits.

Parameters
force_hexTrue to parse as raw hex bits without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ from_string< i16 >()

template<>
i16 rex::string::from_string< i16 > ( const std::string_view value,
bool force_hex )
inline

Parses a signed 16 bit integer. Hex takes a "0x" prefix or an "h" suffix.

Parameters
force_hexTrue to parse as hex without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ from_string< i32 >()

template<>
i32 rex::string::from_string< i32 > ( const std::string_view value,
bool force_hex )
inline

Parses a signed 32 bit integer. Hex takes a "0x" prefix or an "h" suffix.

Parameters
force_hexTrue to parse as hex without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ from_string< i64 >()

template<>
i64 rex::string::from_string< i64 > ( const std::string_view value,
bool force_hex )
inline

Parses a signed 64 bit integer. Hex takes a "0x" prefix or an "h" suffix.

Parameters
force_hexTrue to parse as hex without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ from_string< i8 >()

template<>
i8 rex::string::from_string< i8 > ( const std::string_view value,
bool force_hex )
inline

Parses a signed 8 bit integer. Hex takes a "0x" prefix or an "h" suffix.

Parameters
force_hexTrue to parse as hex without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ from_string< u16 >()

template<>
u16 rex::string::from_string< u16 > ( const std::string_view value,
bool force_hex )
inline

Parses an unsigned 16 bit integer. Hex takes a "0x" prefix or an "h" suffix.

Parameters
force_hexTrue to parse as hex without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ from_string< u32 >()

template<>
u32 rex::string::from_string< u32 > ( const std::string_view value,
bool force_hex )
inline

Parses an unsigned 32 bit integer. Hex takes a "0x" prefix or an "h" suffix.

Parameters
force_hexTrue to parse as hex without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ from_string< u64 >()

template<>
u64 rex::string::from_string< u64 > ( const std::string_view value,
bool force_hex )
inline

Parses an unsigned 64 bit integer. Hex takes a "0x" prefix or an "h" suffix.

Parameters
force_hexTrue to parse as hex without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ from_string< u8 >()

template<>
u8 rex::string::from_string< u8 > ( const std::string_view value,
bool force_hex )
inline

Parses an unsigned 8 bit integer. Hex takes a "0x" prefix or an "h" suffix.

Parameters
force_hexTrue to parse as hex without a prefix.
Returns
The value, or 0 when the text does not parse.

◆ to_hex_string() [1/4]

std::string rex::string::to_hex_string ( f32 value)
inline

Formats the bits of a 32 bit float as 8 uppercase hex digits.

Returns
The hex digits without a prefix.

◆ to_hex_string() [2/4]

std::string rex::string::to_hex_string ( f64 value)
inline

Formats the bits of a 64 bit float as 16 uppercase hex digits.

Returns
The hex digits without a prefix.

◆ to_hex_string() [3/4]

std::string rex::string::to_hex_string ( u32 value)
inline

Formats a 32 bit value as 8 uppercase hex digits.

Returns
The hex digits without a prefix.

◆ to_hex_string() [4/4]

std::string rex::string::to_hex_string ( u64 value)
inline

Formats a 64 bit value as 16 uppercase hex digits.

Returns
The hex digits without a prefix.