最終更新日時(UTC):
が更新

履歴 編集

function
<text_encoding>

std::text_encoding::コンストラクタ(C++26)

constexpr text_encoding() = default;                        // (1) C++26
constexpr explicit text_encoding(string_view enc) noexcept; // (2) C++26
constexpr text_encoding(id i) noexcept;                     // (3) C++26

概要

text_encodingオブジェクトを構築する。

  • (1) : デフォルトコンストラクタ。mib_id::unknownに初期化する
  • (2) : エンコーディング名から構築する。IANA登録名またはエイリアスに一致する場合は対応するMIB値が設定され、一致しない場合はid::otherが設定される
  • (3) : MIB列挙値から構築する

事前条件

  • (2) :
    • encは基本文字集合の要素のみで構成される通常リテラルエンコーディングの文字列を表す
    • enc.size() <= max_name_length
    • enc.contains('\0')false

事後条件

  • (2) :
    • 既知の登録済み文字エンコーディングのプライマリ名またはエイリアスaが存在し、comp-name(a, enc)trueとなる場合、mib_はその登録済みエンコーディングに対応するidの列挙子の値を持つ。そうでなければ、mib_ == id::other
    • enc.compare(name_) == 0
  • (3) :

例外

投げない。

#include <text_encoding>
#include <cassert>
#include <string_view>

int main() {
  using namespace std::string_view_literals;

  // (1) デフォルト構築
  std::text_encoding te1;
  assert(te1.mib() == std::text_encoding::id::unknown);

  // (2) エンコーディング名から構築
  std::text_encoding te2{"utf-8"};
  assert(te2.mib() == std::text_encoding::id::UTF8);
  assert(te2.name() == "utf-8"sv);

  // (2) 登録されていないエンコーディング名
  std::text_encoding te3{"WTF-8"};
  assert(te3.mib() == std::text_encoding::id::other);

  // (3) MIB値から構築
  std::text_encoding te4{std::text_encoding::id::ShiftJIS};
  assert(te4.mib() == std::text_encoding::id::ShiftJIS);
}

出力

バージョン

言語

  • C++26

処理系

参照