NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
字符串转换

字符串与数据类型之间的转换功能 更多...

函数

template<typename T, enable_if_t< is_base_of_v< istringify< T >, T >, int > = 0>
constexpr string neforce::to_string (const T &obj)
 将实现了istringify接口的对象转换为字符串
constexpr float32_t neforce::to_float32 (const string_view sv, size_t *idx=nullptr)
 将字符串转换为32位浮点数
constexpr float64_t neforce::to_float64 (const string_view sv, size_t *idx=nullptr)
 将字符串转换为64位浮点数
constexpr decimal_t neforce::to_decimal (const string_view sv, size_t *idx=nullptr)
 将字符串转换为decimal浮点数
constexpr int64_t neforce::to_int64 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为64位有符号整数
constexpr uint64_t neforce::to_uint64 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为64位无符号整数
constexpr int32_t neforce::to_int32 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为32位有符号整数
constexpr uint32_t neforce::to_uint32 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为32位无符号整数
constexpr int16_t neforce::to_int16 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为16位有符号整数
constexpr uint16_t neforce::to_uint16 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为16位无符号整数
constexpr int8_t neforce::to_int8 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为8位有符号整数
constexpr uint8_t neforce::to_uint8 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为8位无符号整数
constexpr uint128_t neforce::to_uint128 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为128位无符号整数
constexpr int128_t neforce::to_int128 (const string_view sv, size_t *idx=nullptr, const int base=10)
 将字符串转换为128位有符号整数
template<typename T, typename P = package_t<T>, enable_if_t< is_packaged_v< T > &&is_base_of_v< istringify< P >, P >, int > = 0>
constexpr string neforce::to_string (const T &value)
 将可包装类型转换为字符串
constexpr string neforce::to_string (nullptr_t np)
 将空指针转换为字符串
template<typename IfEmpty, typename T>
constexpr string neforce::to_string (const compressed_pair< IfEmpty, T, true > &obj)
 将压缩对(已压缩版本)转换为字符串
template<typename IfEmpty, typename T>
constexpr string neforce::to_string (const compressed_pair< IfEmpty, T, false > &obj)
 将压缩对(未压缩版本)转换为字符串
template<typename T1, typename T2>
constexpr string neforce::to_string (const pair< T1, T2 > &obj)
 将对转换为字符串
template<typename... Args>
constexpr string neforce::to_string (const tuple< Args... > &tup)
 将元组转换为字符串
template<typename T, enable_if_t< is_floating_point< T >::value, int > = 0>
constexpr string neforce::to_string_with_precision (T x, int precision, bool scientific=false)
 将浮点数转换为字符串(带精度控制)
template<typename T, enable_if_t< is_floating_point< T >::value, int > = 0>
constexpr string neforce::to_string_general (T x, int precision=6)
 将浮点数转换为字符串(通用格式)
template<typename T, enable_if_t< is_floating_point< T >::value, int > = 0>
constexpr string neforce::to_string_fixed (T x, int precision=6)
 将浮点数转换为字符串(固定小数格式)
template<typename T, enable_if_t< is_floating_point< T >::value, int > = 0>
constexpr string neforce::to_string_scientific (T x, int precision=6)
 将浮点数转换为字符串(科学计数法格式)

详细描述

字符串与数据类型之间的转换功能

函数说明

◆ to_decimal()

decimal_t neforce::to_decimal ( const string_view sv,
size_t * idx = nullptr )
nodiscardconstexpr

将字符串转换为decimal浮点数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
返回
转换后的十进制浮点数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp547 行定义.

引用了 neforce::basic_string_view< CharT, Traits >::data() , 以及 to_decimal().

被这些函数引用 to_decimal().

◆ to_float32()

float32_t neforce::to_float32 ( const string_view sv,
size_t * idx = nullptr )
nodiscardconstexpr

将字符串转换为32位浮点数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
返回
转换后的32位浮点数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp509 行定义.

引用了 neforce::basic_string_view< CharT, Traits >::data() , 以及 to_float32().

被这些函数引用 to_float32().

◆ to_float64()

float64_t neforce::to_float64 ( const string_view sv,
size_t * idx = nullptr )
nodiscardconstexpr

将字符串转换为64位浮点数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
返回
转换后的64位浮点数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp528 行定义.

引用了 neforce::basic_string_view< CharT, Traits >::data() , 以及 to_float64().

被这些函数引用 to_float64().

◆ to_int128()

int128_t neforce::to_int128 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为128位有符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的128位有符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp733 行定义.

引用了 neforce::basic_string_view< CharT, Traits >::data() , 以及 to_int128().

被这些函数引用 neforce::integer128::integer128(), operator""_i128(), neforce::integer128::parse() , 以及 to_int128().

◆ to_int16()

int16_t neforce::to_int16 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为16位有符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的16位有符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp647 行定义.

引用了 neforce::numeric_traits< T, Dummy >::max(), neforce::numeric_traits< T, Dummy >::min(), to_int16() , 以及 to_int32().

被这些函数引用 to_int16().

◆ to_int32()

int32_t neforce::to_int32 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为32位有符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的32位有符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp607 行定义.

引用了 neforce::basic_string_view< CharT, Traits >::data() , 以及 to_int32().

被这些函数引用 neforce::boolean::parse(), to_int16(), to_int32() , 以及 to_int8().

◆ to_int64()

int64_t neforce::to_int64 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为64位有符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的64位有符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp567 行定义.

引用了 neforce::basic_string_view< CharT, Traits >::data() , 以及 to_int64().

被这些函数引用 to_int64().

◆ to_int8()

int8_t neforce::to_int8 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为8位有符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的8位有符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp680 行定义.

引用了 neforce::numeric_traits< T, Dummy >::max(), neforce::numeric_traits< T, Dummy >::min(), to_int32() , 以及 to_int8().

被这些函数引用 to_int8().

◆ to_string() [1/7]

template<typename IfEmpty, typename T>
string neforce::to_string ( const compressed_pair< IfEmpty, T, false > & obj)
nodiscardconstexpr

将压缩对(未压缩版本)转换为字符串

模板参数
IfEmpty空基类类型
T值类型
参数
obj压缩对
返回
格式为"{ value, empty }"的字符串

在文件 to_string.hpp159 行定义.

引用了 to_string() , 以及 neforce::compressed_pair< IfEmpty, T, Compressed >::value.

◆ to_string() [2/7]

template<typename IfEmpty, typename T>
string neforce::to_string ( const compressed_pair< IfEmpty, T, true > & obj)
nodiscardconstexpr

将压缩对(已压缩版本)转换为字符串

模板参数
IfEmpty空基类类型
T值类型
参数
obj压缩对
返回
值的字符串表示

在文件 to_string.hpp147 行定义.

引用了 to_string() , 以及 neforce::compressed_pair< IfEmpty, T, Compressed >::value.

◆ to_string() [3/7]

template<typename T1, typename T2>
string neforce::to_string ( const pair< T1, T2 > & obj)
nodiscardconstexpr

将对转换为字符串

模板参数
T1第一个类型
T2第二个类型
参数
obj
返回
格式为"{ first, second }"的字符串

在文件 to_string.hpp171 行定义.

引用了 neforce::pair< T1, T2 >::first, neforce::pair< T1, T2 >::second , 以及 to_string().

◆ to_string() [4/7]

template<typename T, enable_if_t< is_base_of_v< istringify< T >, T >, int > = 0>
string neforce::to_string ( const T & obj)
nodiscardconstexpr

将实现了istringify接口的对象转换为字符串

模板参数
T对象类型
参数
obj要转换的对象
返回
对象的字符串表示

全局辅助函数,用于方便地调用实现了istringify接口的对象的to_string方法。 仅当T是istringify<T>的派生类时可用。

在文件 istringify.hpp68 行定义.

引用了 to_string().

◆ to_string() [5/7]

template<typename T, typename P = package_t<T>, enable_if_t< is_packaged_v< T > &&is_base_of_v< istringify< P >, P >, int > = 0>
string neforce::to_string ( const T & value)
nodiscardconstexpr

将可包装类型转换为字符串

模板参数
T可包装类型
参数
value要转换的值
返回
字符串表示

通过包装类型进行字符串转换,要求包装类型实现了istringify接口。

在文件 to_string.hpp36 行定义.

引用了 to_string().

◆ to_string() [6/7]

template<typename... Args>
string neforce::to_string ( const tuple< Args... > & tup)
nodiscardconstexpr

将元组转换为字符串

模板参数
Args元组元素类型
参数
tup元组
返回
字符串表示

在文件 to_string.hpp214 行定义.

引用了 to_string().

◆ to_string() [7/7]

string neforce::to_string ( nullptr_t np)
nodiscardconstexpr

将空指针转换为字符串

参数
np空指针
返回
字符串"nullptr"

在文件 to_string.hpp45 行定义.

引用了 to_string().

◆ to_string_fixed()

template<typename T, enable_if_t< is_floating_point< T >::value, int > = 0>
string neforce::to_string_fixed ( T x,
int precision = 6 )
nodiscardconstexpr

将浮点数转换为字符串(固定小数格式)

模板参数
T浮点数类型
参数
x要转换的值
precision精度
返回
字符串表示

在文件 to_string.hpp503 行定义.

引用了 to_string_fixed().

被这些函数引用 neforce::formatter< T, enable_if_t< is_floating_point_v< T > > >::operator()() , 以及 to_string_fixed().

◆ to_string_general()

template<typename T, enable_if_t< is_floating_point< T >::value, int > = 0>
string neforce::to_string_general ( T x,
int precision = 6 )
nodiscardconstexpr

将浮点数转换为字符串(通用格式)

模板参数
T浮点数类型
参数
x要转换的值
precision精度
返回
字符串表示

在文件 to_string.hpp491 行定义.

引用了 to_string_general().

被这些函数引用 neforce::formatter< T, enable_if_t< is_floating_point_v< T > > >::operator()() , 以及 to_string_general().

◆ to_string_scientific()

template<typename T, enable_if_t< is_floating_point< T >::value, int > = 0>
string neforce::to_string_scientific ( T x,
int precision = 6 )
nodiscardconstexpr

将浮点数转换为字符串(科学计数法格式)

模板参数
T浮点数类型
参数
x要转换的值
precision精度
返回
字符串表示

在文件 to_string.hpp515 行定义.

引用了 to_string_scientific().

被这些函数引用 neforce::formatter< T, enable_if_t< is_floating_point_v< T > > >::operator()() , 以及 to_string_scientific().

◆ to_string_with_precision()

template<typename T, enable_if_t< is_floating_point< T >::value, int > = 0>
string neforce::to_string_with_precision ( T x,
int precision,
bool scientific = false )
nodiscardconstexpr

将浮点数转换为字符串(带精度控制)

模板参数
T浮点数类型
参数
x要转换的值
precision精度
scientific是否使用科学计数法
返回
字符串表示

在文件 to_string.hpp479 行定义.

引用了 to_string_with_precision().

被这些函数引用 to_string_with_precision().

◆ to_uint128()

uint128_t neforce::to_uint128 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为128位无符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的128位无符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp713 行定义.

引用了 neforce::basic_string_view< CharT, Traits >::data() , 以及 to_uint128().

被这些函数引用 operator""_u128(), neforce::uinteger128::parse(), to_uint128() , 以及 neforce::uinteger128::uinteger128().

◆ to_uint16()

uint16_t neforce::to_uint16 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为16位无符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的16位无符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp664 行定义.

引用了 neforce::numeric_traits< T, Dummy >::max(), to_uint16() , 以及 to_uint32().

被这些函数引用 to_uint16().

◆ to_uint32()

uint32_t neforce::to_uint32 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为32位无符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的32位无符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp627 行定义.

引用了 neforce::basic_string_view< CharT, Traits >::data() , 以及 to_uint32().

被这些函数引用 to_uint16(), to_uint32() , 以及 to_uint8().

◆ to_uint64()

uint64_t neforce::to_uint64 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为64位无符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的64位无符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp587 行定义.

引用了 neforce::basic_string_view< CharT, Traits >::data() , 以及 to_uint64().

被这些函数引用 to_uint64().

◆ to_uint8()

uint8_t neforce::to_uint8 ( const string_view sv,
size_t * idx = nullptr,
const int base = 10 )
nodiscardconstexpr

将字符串转换为8位无符号整数

参数
sv要转换的字符串视图
idx可选参数,存储转换结束位置索引
base进制基数(0表示自动检测)
返回
转换后的8位无符号整数
异常
typecast_exception转换失败时

在文件 to_numerics.hpp697 行定义.

引用了 neforce::numeric_traits< T, Dummy >::max(), to_uint32() , 以及 to_uint8().

被这些函数引用 to_uint8().