Namespaces
Variants

std::text_encoding:: text_encoding

From cppreference.net
constexpr text_encoding ( ) = default ;
(1) (自 C++26 起)
constexpr explicit text_encoding ( std:: string_view enc ) noexcept ;
(2) (自 C++26 起)
constexpr text_encoding ( std :: text_encoding :: id i ) noexcept ;
(3) (自 C++26 起)

构造一个新的文本编码对象。

1) 默认构造函数。构造一个具有 MIBenum std :: text_encoding :: id :: unknown 字符编码名称 为空的对象。
2) 构造一个具有 字符编码名称 enc 的对象。
enc 命名的 已注册字符编码 不是 NATS-DANO NATS-DANO-ADD ,则构造的对象将具有对应的 MIBenum 值,否则其 MIBenum 将为 std :: text_encoding :: id :: other
如果 enc. size ( ) > std :: text_encoding :: max_name_length || enc. contains ( ' \0 ' ) ,则行为未定义。
3) 使用 MIBenum i 构造对象。
如果 i std :: text_encoding :: id :: other std :: text_encoding :: id :: unknown ,则构造的对象将具有空的 字符编码名称 ,否则将具有 对应名称 之一。
如果 i 不是 std::text_encoding::id 的具名枚举项,则行为未定义。

参数

enc - 字符编码名称
i - MIBenum 值

示例

Compiler Explorer 上查看。

#include <text_encoding>
int main()
{
    constexpr std::text_encoding iso60 = std::text_encoding::ISO60DanishNorwegian;
    static_assert(iso60 == std::text_encoding("csISO60DanishNorwegian"));
    static_assert(iso60 == std::text_encoding("iso-ir-60"));
    static_assert(iso60 == std::text_encoding("NS_4551-1"));
}

外部链接

IANA字符集名称与MIBenum值注册表