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

字符串格式化功能 更多...

struct  neforce::format_options
 格式选项 更多...
struct  neforce::formatter< Number, Dummy >
 格式化器主模板 更多...
struct  neforce::formatter< T, enable_if_t< is_floating_point_v< T > > >
 浮点数类型的格式化器特化 更多...
struct  neforce::formatter< T, enable_if_t< is_standard_integral_v< T > &&is_signed_v< T > > >
 有符号整数类型的格式化器特化 更多...
struct  neforce::formatter< T, enable_if_t< is_standard_integral_v< T > &&is_unsigned_v< T > > >
 无符号整数类型的格式化器特化 更多...
struct  neforce::formatter< char >
 单个字符的格式化器特化 更多...
struct  neforce::formatter< bool >
 布尔类型的格式化器特化 更多...
struct  neforce::formatter< string >
 字符串类型的格式化器特化 更多...
struct  neforce::formatter< string_view >
 字符串视图的格式化器特化 更多...
struct  neforce::formatter< const char * >
 C风格字符串的格式化器特化 更多...
struct  neforce::formatter< nullptr_t >
 nullptr_t 格式化器 更多...
struct  neforce::formatter< T *, enable_if_t<!is_cstring_v< T * > > >
 指针格式化器 更多...
struct  neforce::formatter< char * >
 非const C风格字符串的格式化器特化 更多...
struct  neforce::formatter< datetime >
 datetime 格式化器特化 更多...

枚举

enum class  neforce::format_align {
  format_align::DEFAULT , format_align::LEFT , format_align::RIGHT , format_align::CENTER ,
  format_align::NUMERIC
}
 对齐方式枚举 更多...
enum class  neforce::format_type : uint8_t {
  format_type::DEFAULT , format_type::DECIMAL , format_type::BINARY , format_type::OCTAL ,
  format_type::HEX , format_type::SCIENTIFIC , format_type::FIXED , format_type::GENERAL ,
  format_type::CHAR
}
 数值类型格式枚举 更多...

函数

template<typename... Args, enable_if_t<(sizeof...(Args) > 0), int > = 0>
constexpr string neforce::format (const string_view fmt, Args &&... args)
 格式化字符串
template<size_t N, typename... Args, enable_if_t<(sizeof...(Args) > 0), int > = 0>
constexpr string neforce::format (const char(&fmt)[N], Args &&... args)
 格式化字符串
constexpr string neforce::format_named (const string_view fmt, const std::initializer_list< pair< const char *, string_view > > params)
 命名参数格式化
template<typename... Args, enable_if_t<(sizeof...(Args) > 0), int > = 0>
string neforce::format (const locale &loc, const string_view fmt, Args &&... args)
 locale 感知的格式化

详细描述

字符串格式化功能

枚举类型说明

◆ format_align

enum class neforce::format_align
strong

对齐方式枚举

枚举值
DEFAULT 

默认(数字右对齐,其他左对齐)

LEFT 

左对齐 '<'

RIGHT 

右对齐 '>'

CENTER 

居中 '^'

NUMERIC 

符号感知填充 '='

在文件 format.hpp27 行定义.

◆ format_type

enum class neforce::format_type : uint8_t
strong

数值类型格式枚举

枚举值
DEFAULT 

默认(由类型决定)

DECIMAL 

十进制 'd' / 'f' / 'g'

BINARY 

二进制 'b'

OCTAL 

八进制 'o'

HEX 

十六进制 'x' / 'X'

SCIENTIFIC 

科学计数法 'e' / 'E'

FIXED 

固定小数 'f'

GENERAL 

通用浮点 'g' / 'G'

CHAR 

字符 'c'

在文件 format.hpp39 行定义.

函数说明

◆ format() [1/3]

template<size_t N, typename... Args, enable_if_t<(sizeof...(Args) > 0), int > = 0>
string neforce::format ( const char(&) fmt[N],
Args &&... args )
nodiscardconstexpr

格式化字符串

模板参数
N格式字符串长度
Args参数类型
参数
fmt格式字符串字面量
args要格式化的参数
返回
格式化后的字符串
异常
value_exception如果格式错误

在编译期验证格式字符串中花括号的平衡性。 用法:format("Hello, {}!", name)

在文件 format.hpp828 行定义.

引用了 format() , 以及 forward().

◆ format() [2/3]

template<typename... Args, enable_if_t<(sizeof...(Args) > 0), int > = 0>
string neforce::format ( const locale & loc,
const string_view fmt,
Args &&... args )
nodiscard

locale 感知的格式化

模板参数
Args参数类型
参数
loclocale 对象
fmt格式字符串
args要格式化的参数
返回
格式化后的字符串

格式选项中的 loc 指针将被设置为 &loc,所有 formatter 特化 均可通过 opts.loc 访问 locale 以进行本地化格式化。

在文件 format.hpp901 行定义.

引用了 format(), forward(), neforce::format_options::loc, neforce::basic_string< CharT, Traits, Alloc >::reserve() , 以及 neforce::basic_string_view< CharT, Traits >::size().

◆ format() [3/3]

template<typename... Args, enable_if_t<(sizeof...(Args) > 0), int > = 0>
string neforce::format ( const string_view fmt,
Args &&... args )
nodiscardconstexpr

◆ format_named()

string neforce::format_named ( const string_view fmt,
const std::initializer_list< pair< const char *, string_view > > params )
nodiscardconstexpr

命名参数格式化

参数
fmt格式字符串,使用 {name} 标记命名占位符
params命名参数列表
返回
格式化后的字符串

将格式字符串中的 {name} 替换为 params 中的对应值。 不支持格式选项,仅做纯文本替换。 用法:format_named("{greeting}, {name}!", {{"greeting", "Hello"}, {"name", "World"}})

在文件 format.hpp843 行定义.

引用了 format_named(), neforce::basic_string< CharT, Traits, Alloc >::reserve(), neforce::basic_string_view< CharT, Traits >::size() , 以及 neforce::basic_string_view< CharT, Traits >::view().

被这些函数引用 format_named().