NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
neforce::locale类 参考

区域设置管理类 更多...

#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)
 拷贝构造函数
localeoperator= (const locale &other)
 拷贝赋值运算符
 locale (locale &&other) noexcept
 移动构造函数
localeoperator= (locale &&other) noexcept
 移动赋值运算符
const stringname () const noexcept
 获取规范 BCP-47 名称
const stringlanguage_code () const noexcept
 获取 ISO 639 语言代码
const stringscript_code () const noexcept
 获取 ISO 15924 文字代码
const stringcountry_code () const noexcept
 获取 ISO 3166 国家/地区代码
const stringvariant_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< stringui_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< stringavailable_locales ()
 获取所有可用 locale 列表
static vector< stringavailable_countries (const string &language)
 获取指定语言下的可用国家/地区
static bool is_valid_locale (const string &name)
 验证 locale 名称是否有效

详细描述

区域设置管理类

基于 ICU4C 提供跨平台的区域设置信息查询和格式化功能。 所有 locale 数据来自 CLDR(Unicode Common Locale Data Repository)。

使用场景:

  • 国际化/本地化应用程序
  • 格式化数字、货币、日期时间
  • 本地化字符串排序
  • 字符分类和大小写转换

在文件 locale.hpp66 行定义.

成员枚举类型说明

◆ collate_strength

字符串比较强度

枚举值
primary 

一级比较:仅基础字符

secondary 

二级比较:区分重音符号

tertiary 

三级比较:区分大小写

quaternary 

四级比较:区分标点

identical 

完全比较:逐码点比较

在文件 locale.hpp72 行定义.

◆ date_style

enum class neforce::locale::date_style : int8_t
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.hpp84 行定义.

◆ measurement_system

度量系统

枚举值
SI 

公制

US 

美制

UK 

英制

在文件 locale.hpp110 行定义.

◆ text_direction

文字方向

枚举值
LTR 

从左到右

RTL 

从右到左

在文件 locale.hpp120 行定义.

◆ time_style

enum class neforce::locale::time_style : int8_t
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.hpp97 行定义.

构造及析构函数说明

◆ locale() [1/3]

neforce::locale::locale ( const string & name)
explicit

从名称构造

参数
nameBCP-47 标签("en-US")或 POSIX 名("en_US.UTF-8")
异常
locale_exception名称无效时抛出

引用了 locale() , 以及 name().

◆ locale() [2/3]

neforce::locale::locale ( const locale & other)

拷贝构造函数

参数
other源 locale

引用了 locale().

◆ locale() [3/3]

neforce::locale::locale ( locale && other)
noexcept

移动构造函数

参数
other源 locale

引用了 locale().

成员函数说明

◆ available_countries()

vector< string > neforce::locale::available_countries ( const string & language)
staticnodiscard

获取指定语言下的可用国家/地区

参数
languageISO 639 语言代码
返回
国家/地区代码列表

◆ available_locales()

vector< string > neforce::locale::available_locales ( )
staticnodiscard

获取所有可用 locale 列表

返回
BCP-47 标签列表

◆ classic()

locale neforce::locale::classic ( )
staticnodiscard

获取经典(en-US-POSIX)locale

返回
经典 locale

引用了 classic() , 以及 locale().

被这些函数引用 classic().

◆ collation_key()

string neforce::locale::collation_key ( const string & s) const
nodiscard

生成排序键

参数
s源字符串
返回
可用于二进制比较的排序键

◆ compare()

int neforce::locale::compare ( const string & a,
const string & b,
collate_strength strength = collate_strength::tertiary ) const
nodiscard

比较两个字符串

参数
a第一个字符串
b第二个字符串
strength比较强度
返回
负数表示 a < b,0 表示相等,正数表示 a > b

引用了 tertiary.

◆ country_code()

const string & neforce::locale::country_code ( ) const
inlinenodiscardnoexcept

获取 ISO 3166 国家/地区代码

返回
地区代码,如 "US"、"CN"

在文件 locale.hpp290 行定义.

◆ direction()

text_direction neforce::locale::direction ( ) const
nodiscard

获取文字方向

返回
从左到右或从右到左

◆ display_name()

string neforce::locale::display_name ( const locale & display_locale) const
nodiscard

获取在该 locale 中的显示名

参数
display_locale显示所用的 locale,默认使用自身
返回
本地化显示名

引用了 locale().

◆ first_day_of_week()

int32_t neforce::locale::first_day_of_week ( ) const
nodiscard

获取一周首日

返回
1=周日, 2=周一, ..., 7=周六

◆ format_currency()

string neforce::locale::format_currency ( double value,
const string & iso_4217_code ) const
nodiscard

格式化货币金额

参数
value金额
iso_4217_codeISO 4217 货币代码(如 "USD"、"CNY"、"EUR")
返回
格式化的货币字符串

◆ format_datetime() [1/3]

string neforce::locale::format_datetime ( ) const
nodiscard

格式化当前日期时间

返回
格式化的日期时间字符串(中日期 + 中时间)

◆ format_datetime() [2/3]

string neforce::locale::format_datetime ( const datetime & dt,
const string & pattern ) const
nodiscard

使用 ICU 模式字符串格式化日期时间

参数
dt日期时间对象
patternICU 日期格式模式(如 "yyyy-MM-dd HH:mm:ss")
返回
格式化的字符串

ICU 模式语法与 SimpleDateFormat 兼容。

◆ format_datetime() [3/3]

string neforce::locale::format_datetime ( const datetime & dt,
date_style ds = date_style::medium,
time_style ts = time_style::medium ) const
nodiscard

格式化日期时间

参数
dt日期时间对象
ds日期风格
ts时间风格
返回
格式化的日期时间字符串

引用了 medium.

◆ format_number() [1/2]

string neforce::locale::format_number ( double value,
int32_t fraction_digits = 2 ) const
nodiscard

格式化浮点数

参数
value浮点数值
fraction_digits小数位数,-1 使用默认值
返回
格式化的字符串

◆ format_number() [2/2]

◆ from_name()

locale neforce::locale::from_name ( const string & name)
staticnodiscard

从名称构造 locale

参数
nameBCP-47 或 POSIX 名称
返回
locale 对象

引用了 from_name(), locale() , 以及 name().

被这些函数引用 from_name().

◆ is_valid_locale()

bool neforce::locale::is_valid_locale ( const string & name)
staticnodiscard

验证 locale 名称是否有效

参数
nameBCP-47 或 POSIX 名称
返回
是否可构造为有效 locale

引用了 name().

◆ language_code()

const string & neforce::locale::language_code ( ) const
inlinenodiscardnoexcept

获取 ISO 639 语言代码

返回
语言代码,如 "en"、"zh"

在文件 locale.hpp278 行定义.

◆ measurement()

measurement_system neforce::locale::measurement ( ) const
nodiscard

获取度量系统

返回
度量系统

◆ monetary()

monetary_info neforce::locale::monetary ( ) const
nodiscard

获取货币格式信息

返回
货币格式信息

◆ name()

const string & neforce::locale::name ( ) const
inlinenodiscardnoexcept

获取规范 BCP-47 名称

返回
BCP-47 标签,如 "en-US"

在文件 locale.hpp272 行定义.

引用了 name().

被这些函数引用 from_name(), is_valid_locale(), locale() , 以及 name().

◆ native_country_name()

string neforce::locale::native_country_name ( ) const
nodiscard

获取本地国家/地区名

返回
以该语言自身显示的地区名,如 "United States"、"中国"

◆ native_language_name()

string neforce::locale::native_language_name ( ) const
nodiscard

获取本地语言名

返回
以该语言自身显示的语言名,如 "English"、"中文"

◆ numeric()

numeric_info neforce::locale::numeric ( ) const
nodiscard

获取数字格式信息

返回
数字格式信息

◆ operator!=()

bool neforce::locale::operator!= ( const locale & o) const
inlinenodiscardnoexcept

不等比较

参数
o另一个 locale
返回
BCP-47 规范名称不同返回 true

在文件 locale.hpp491 行定义.

引用了 locale().

◆ operator=() [1/2]

locale & neforce::locale::operator= ( const locale & other)

拷贝赋值运算符

参数
other源 locale
返回
自身引用

引用了 locale().

◆ operator=() [2/2]

locale & neforce::locale::operator= ( locale && other)
noexcept

移动赋值运算符

参数
other源 locale
返回
自身引用

引用了 locale().

◆ operator==()

bool neforce::locale::operator== ( const locale & o) const
inlinenodiscardnoexcept

相等比较

参数
o另一个 locale
返回
BCP-47 规范名称相同返回 true

在文件 locale.hpp484 行定义.

引用了 locale().

◆ script_code()

const string & neforce::locale::script_code ( ) const
inlinenodiscardnoexcept

获取 ISO 15924 文字代码

返回
文字代码,如 "Latn"、"Hans"

在文件 locale.hpp284 行定义.

◆ system()

locale neforce::locale::system ( )
staticnodiscard

获取系统默认 locale

返回
系统 locale

引用了 locale() , 以及 system().

被这些函数引用 system().

◆ time()

time_info neforce::locale::time ( ) const
nodiscard

获取时间格式信息

返回
时间格式信息

◆ to_multibyte()

string neforce::locale::to_multibyte ( const u32string & ucs4) const
nodiscard

将 UTF-32 字符串转换为 locale 编码的多字节字符串

参数
ucs4UTF-32 字符串
返回
多字节字符串
异常
locale_exception转换失败时抛出

◆ to_ucs4()

u32string neforce::locale::to_ucs4 ( const string & mb) const
nodiscard

将 locale 编码的多字节字符串转换为 UTF-32

参数
mb多字节字符串
返回
UTF-32 字符串
异常
locale_exception转换失败时抛出

◆ ui_languages()

vector< string > neforce::locale::ui_languages ( ) const
nodiscard

获取 UI 语言回退链

返回
BCP-47 标签列表,按优先级降序

示例:"zh-Hans-CN" → {"zh-Hans-CN", "zh-Hans", "zh-CN", "zh"} 用于查找最优翻译资源。

◆ variant_code()

const string & neforce::locale::variant_code ( ) const
inlinenodiscardnoexcept

获取变体代码

返回
变体代码,如 "POSIX"、"1996"

在文件 locale.hpp296 行定义.


该类的文档由以下文件生成: