|
NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
|
区域设置管理类 更多...
#include <locale.hpp>
类 | |
| struct | numeric_info |
| 数字格式信息 更多... | |
| struct | monetary_info |
| 货币格式信息 更多... | |
| struct | time_info |
| 时间格式信息 更多... | |
Public 类型 | |
| enum class | collate_strength : int32_t { primary = 0 , secondary = 1 , tertiary = 2 , quaternary = 3 , identical = 15 } |
| 字符串比较强度 更多... | |
| enum class | date_style : int8_t { none = -1 , full = 0 , long_fmt = 1 , medium = 2 , short_fmt = 3 , relative = 4 } |
| 日期格式化风格 更多... | |
| enum class | time_style : int8_t { none = -1 , full = 0 , long_fmt = 1 , medium = 2 , short_fmt = 3 , relative = 4 } |
| 时间格式化风格 更多... | |
| enum class | measurement_system : uint8_t { SI , US , UK } |
| 度量系统 更多... | |
| enum class | text_direction : uint8_t { LTR , RTL } |
| 文字方向 更多... | |
Public 成员函数 | |
| locale () | |
| 默认构造函数,创建 en-US-POSIX locale | |
| locale (const string &name) | |
| 从名称构造 | |
| ~locale () | |
| 析构函数 | |
| locale (const locale &other) | |
| 拷贝构造函数 | |
| locale & | operator= (const locale &other) |
| 拷贝赋值运算符 | |
| locale (locale &&other) noexcept | |
| 移动构造函数 | |
| locale & | operator= (locale &&other) noexcept |
| 移动赋值运算符 | |
| const string & | name () const noexcept |
| 获取规范 BCP-47 名称 | |
| const string & | language_code () const noexcept |
| 获取 ISO 639 语言代码 | |
| const string & | script_code () const noexcept |
| 获取 ISO 15924 文字代码 | |
| const string & | country_code () const noexcept |
| 获取 ISO 3166 国家/地区代码 | |
| const string & | variant_code () const noexcept |
| 获取变体代码 | |
| string | display_name (const locale &display_locale) const |
| 获取在该 locale 中的显示名 | |
| string | native_language_name () const |
| 获取本地语言名 | |
| string | native_country_name () const |
| 获取本地国家/地区名 | |
| text_direction | direction () const |
| 获取文字方向 | |
| measurement_system | measurement () const |
| 获取度量系统 | |
| int32_t | first_day_of_week () const |
| 获取一周首日 | |
| vector< string > | ui_languages () const |
| 获取 UI 语言回退链 | |
| int | compare (const string &a, const string &b, collate_strength strength=collate_strength::tertiary) const |
| 比较两个字符串 | |
| string | collation_key (const string &s) const |
| 生成排序键 | |
| string | to_multibyte (const u32string &ucs4) const |
| 将 UTF-32 字符串转换为 locale 编码的多字节字符串 | |
| u32string | to_ucs4 (const string &mb) const |
| 将 locale 编码的多字节字符串转换为 UTF-32 | |
| string | format_number (int64_t value) const |
| 格式化整数 | |
| string | format_number (double value, int32_t fraction_digits=2) const |
| 格式化浮点数 | |
| string | format_currency (double value, const string &iso_4217_code) const |
| 格式化货币金额 | |
| string | format_datetime (const datetime &dt, date_style ds=date_style::medium, time_style ts=time_style::medium) const |
| 格式化日期时间 | |
| string | format_datetime (const datetime &dt, const string &pattern) const |
| 使用 ICU 模式字符串格式化日期时间 | |
| string | format_datetime () const |
| 格式化当前日期时间 | |
| numeric_info | numeric () const |
| 获取数字格式信息 | |
| monetary_info | monetary () const |
| 获取货币格式信息 | |
| time_info | time () const |
| 获取时间格式信息 | |
| bool | operator== (const locale &o) const noexcept |
| 相等比较 | |
| bool | operator!= (const locale &o) const noexcept |
| 不等比较 | |
静态 Public 成员函数 | |
| static locale | classic () |
| 获取经典(en-US-POSIX)locale | |
| static locale | system () |
| 获取系统默认 locale | |
| static locale | from_name (const string &name) |
| 从名称构造 locale | |
| static bool | is_alpha (char32_t cp) noexcept |
| 是否为字母 | |
| static bool | is_digit (char32_t cp) noexcept |
| 是否为数字 | |
| static bool | is_alnum (char32_t cp) noexcept |
| 是否为字母或数字 | |
| static bool | is_space (char32_t cp) noexcept |
| 是否为空白字符(POSIX/C) | |
| static bool | is_upper (char32_t cp) noexcept |
| 是否为大写字母 | |
| static bool | is_lower (char32_t cp) noexcept |
| 是否为小写字母 | |
| static bool | is_punct (char32_t cp) noexcept |
| 是否为标点符号 | |
| static bool | is_print (char32_t cp) noexcept |
| 是否为可打印字符 | |
| static bool | is_titlecase (char32_t cp) noexcept |
| 是否为首字母大写 | |
| static bool | is_white_space (char32_t cp) noexcept |
| 是否为 Unicode 空白字符 | |
| static char32_t | to_upper (char32_t cp) noexcept |
| 转换为大写 | |
| static char32_t | to_lower (char32_t cp) noexcept |
| 转换为小写 | |
| static char32_t | to_titlecase (char32_t cp) noexcept |
| 转换为首字母大写 | |
| static vector< string > | available_locales () |
| 获取所有可用 locale 列表 | |
| static vector< string > | available_countries (const string &language) |
| 获取指定语言下的可用国家/地区 | |
| static bool | is_valid_locale (const string &name) |
| 验证 locale 名称是否有效 | |
区域设置管理类
基于 ICU4C 提供跨平台的区域设置信息查询和格式化功能。 所有 locale 数据来自 CLDR(Unicode Common Locale Data Repository)。
使用场景:
在文件 locale.hpp 第 66 行定义.
|
strong |
字符串比较强度
| 枚举值 | |
|---|---|
| primary | 一级比较:仅基础字符 |
| secondary | 二级比较:区分重音符号 |
| tertiary | 三级比较:区分大小写 |
| quaternary | 四级比较:区分标点 |
| identical | 完全比较:逐码点比较 |
在文件 locale.hpp 第 72 行定义.
|
strong |
日期格式化风格
| 枚举值 | |
|---|---|
| none | 不生成日期部分 |
| full | 完整格式:"Tuesday, April 15, 2025" |
| long_fmt | 长格式:"April 15, 2025" |
| medium | 中格式:"Apr 15, 2025" |
| short_fmt | 短格式:"4/15/25" |
| relative | 相对时间:"yesterday", "3 hours ago" |
在文件 locale.hpp 第 84 行定义.
|
strong |
|
strong |
|
strong |
时间格式化风格
| 枚举值 | |
|---|---|
| none | 不生成时间部分 |
| full | 完整格式:"3:45:30 PM Pacific Standard Time" |
| long_fmt | 长格式:"3:45:30 PM PST" |
| medium | 中格式:"3:45:30 PM" |
| short_fmt | 短格式:"3:45 PM" |
| relative | 相对时间:"5 minutes ago" |
在文件 locale.hpp 第 97 行定义.
|
explicit |
| neforce::locale::locale | ( | const locale & | other | ) |
|
noexcept |
获取指定语言下的可用国家/地区
| language | ISO 639 语言代码 |
获取所有可用 locale 列表
|
staticnodiscard |
生成排序键
| s | 源字符串 |
|
nodiscard |
|
inlinenodiscardnoexcept |
|
nodiscard |
获取文字方向
|
nodiscard |
获取一周首日
|
nodiscard |
格式化货币金额
| value | 金额 |
| iso_4217_code | ISO 4217 货币代码(如 "USD"、"CNY"、"EUR") |
|
nodiscard |
格式化当前日期时间
|
nodiscard |
使用 ICU 模式字符串格式化日期时间
| dt | 日期时间对象 |
| pattern | ICU 日期格式模式(如 "yyyy-MM-dd HH:mm:ss") |
ICU 模式语法与 SimpleDateFormat 兼容。
|
nodiscard |
格式化浮点数
| value | 浮点数值 |
| fraction_digits | 小数位数,-1 使用默认值 |
格式化整数
| value | 整数值 |
被这些函数引用 neforce::formatter< T, enable_if_t< is_floating_point_v< T > > >::operator()(), neforce::formatter< T, enable_if_t< is_standard_integral_v< T > &&is_signed_v< T > > >::operator()() , 以及 neforce::formatter< T, enable_if_t< is_standard_integral_v< T > &&is_unsigned_v< T > > >::operator()().
从名称构造 locale
| name | BCP-47 或 POSIX 名称 |
引用了 from_name(), locale() , 以及 name().
被这些函数引用 from_name().
|
staticnodiscard |
|
inlinenodiscardnoexcept |
|
nodiscard |
获取度量系统
|
nodiscard |
获取货币格式信息
|
inlinenodiscardnoexcept |
获取规范 BCP-47 名称
在文件 locale.hpp 第 272 行定义.
引用了 name().
被这些函数引用 from_name(), is_valid_locale(), locale() , 以及 name().
|
nodiscard |
获取本地国家/地区名
|
nodiscard |
获取本地语言名
|
nodiscard |
获取数字格式信息
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
staticnodiscard |
|
nodiscard |
获取时间格式信息
获取 UI 语言回退链
示例:"zh-Hans-CN" → {"zh-Hans-CN", "zh-Hans", "zh-CN", "zh"} 用于查找最优翻译资源。
|
inlinenodiscardnoexcept |