[libcxx-commits] [libcxx] Implement P1885R12: `<text_encoding>` header (PR #141312)

William Tran-Viet via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 23 20:48:56 PDT 2025


https://github.com/smallp-o-p updated https://github.com/llvm/llvm-project/pull/141312

>From 4ecef4f3d68fac70395e621a6a4e578f97769dcf Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Fri, 23 May 2025 22:08:36 -0400
Subject: [PATCH 1/3] Implement P1885R12

---
 libcxx/docs/FeatureTestMacroTable.rst         |    2 +-
 libcxx/docs/Status/Cxx2cPapers.csv            |    4 +-
 libcxx/include/CMakeLists.txt                 |    2 +
 libcxx/include/__locale                       |    9 +
 .../include/__text_encoding/text_encoding.h   | 1483 +++++++++++++++++
 libcxx/include/module.modulemap.in            |    7 +
 libcxx/include/text_encoding                  |   68 +
 libcxx/include/version                        |    2 +-
 libcxx/modules/std.compat.cppm.in             |    3 -
 libcxx/modules/std.cppm.in                    |    6 +-
 libcxx/modules/std/text_encoding.inc          |    9 +-
 libcxx/src/CMakeLists.txt                     |    1 +
 libcxx/src/locale.cpp                         |   13 +
 libcxx/src/text_encoding.cpp                  |   49 +
 .../test/libcxx/transitive_includes/cxx26.csv |   15 +
 .../text_encoding.version.compile.pass.cpp    |   63 +
 .../version.version.compile.pass.cpp          |   16 +-
 .../locale/locale.members/encoding.pass.cpp   |   56 +
 .../text_encoding.ctor/default.pass.cpp       |   39 +
 .../text_encoding.ctor/id.pass.cpp            |   56 +
 .../text_encoding.ctor/string_view.pass.cpp   |   73 +
 .../text_encoding.eq/equal.id.pass.cpp        |   69 +
 .../text_encoding.eq/equal.pass.cpp           |   66 +
 .../text_encoding.members/aliases.pass.cpp    |   37 +
 .../environment.pass.cpp                      |   83 +
 .../text_encoding.members/literal.pass.cpp    |   49 +
 .../text_encoding.aliases_view/begin.pass.cpp |   66 +
 .../text_encoding.aliases_view/empty.pass.cpp |   64 +
 .../text_encoding.aliases_view/front.pass.cpp |   66 +
 libcxx/test/support/test_text_encoding.h      | 1173 +++++++++++++
 .../generate_feature_test_macro_components.py |    1 -
 libcxx/utils/libcxx/header_information.py     |    3 +-
 32 files changed, 3624 insertions(+), 29 deletions(-)
 create mode 100644 libcxx/include/__text_encoding/text_encoding.h
 create mode 100644 libcxx/include/text_encoding
 create mode 100644 libcxx/src/text_encoding.cpp
 create mode 100644 libcxx/test/std/language.support/support.limits/support.limits.general/text_encoding.version.compile.pass.cpp
 create mode 100644 libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.ctor/default.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.ctor/id.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.ctor/string_view.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.id.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/environment.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/literal.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/begin.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/empty.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/front.pass.cpp
 create mode 100644 libcxx/test/support/test_text_encoding.h

diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index 9b57b7c8eeb52..93308e4078075 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -500,7 +500,7 @@ Status
     ---------------------------------------------------------- -----------------
     ``__cpp_lib_submdspan``                                    *unimplemented*
     ---------------------------------------------------------- -----------------
-    ``__cpp_lib_text_encoding``                                *unimplemented*
+    ``__cpp_lib_text_encoding``                                ``202306L``
     ---------------------------------------------------------- -----------------
     ``__cpp_lib_to_chars``                                     *unimplemented*
     ---------------------------------------------------------- -----------------
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index 3809446a57896..a7dfa75df7c87 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -13,7 +13,7 @@
 "`P2013R5 <https://wg21.link/P2013R5>`__","Freestanding Language: Optional ``::operator new``","2023-06 (Varna)","","",""
 "`P2363R5 <https://wg21.link/P2363R5>`__","Extending associative containers with the remaining heterogeneous overloads","2023-06 (Varna)","","",""
 "`P1901R2 <https://wg21.link/P1901R2>`__","Enabling the Use of ``weak_ptr`` as Keys in Unordered Associative Containers","2023-06 (Varna)","","",""
-"`P1885R12 <https://wg21.link/P1885R12>`__","Naming Text Encodings to Demystify Them","2023-06 (Varna)","","",""
+"`P1885R12 <https://wg21.link/P1885R12>`__","Naming Text Encodings to Demystify Them","2023-06 (Varna)","|Complete|","21",""
 "`P0792R14 <https://wg21.link/P0792R14>`__","``function_ref``: a type-erased callable reference","2023-06 (Varna)","","",""
 "`P2874R2 <https://wg21.link/P2874R2>`__","P2874R2: Mandating Annex D Require No More","2023-06 (Varna)","|Complete|","12",""
 "`P2757R3 <https://wg21.link/P2757R3>`__","Type-checking format args","2023-06 (Varna)","","",""
@@ -79,7 +79,7 @@
 "`P3136R1 <https://wg21.link/P3136R1>`__","Retiring niebloids","2024-11 (Wrocław)","|Complete|","14",""
 "`P3138R5 <https://wg21.link/P3138R5>`__","``views::cache_latest``","2024-11 (Wrocław)","","",""
 "`P3379R0 <https://wg21.link/P3379R0>`__","Constrain ``std::expected`` equality operators","2024-11 (Wrocław)","|Complete|","21",""
-"`P2862R1 <https://wg21.link/P2862R1>`__","``text_encoding::name()`` should never return null values","2024-11 (Wrocław)","","",""
+"`P2862R1 <https://wg21.link/P2862R1>`__","``text_encoding::name()`` should never return null values","2024-11 (Wrocław)","|Complete|","21",""
 "`P2897R7 <https://wg21.link/P2897R7>`__","``aligned_accessor``: An ``mdspan`` accessor expressing pointer over-alignment","2024-11 (Wrocław)","|Complete|","21",""
 "`P3355R1 <https://wg21.link/P3355R1>`__","Fix ``submdspan`` for C++26","2024-11 (Wrocław)","","",""
 "`P3222R0 <https://wg21.link/P3222R0>`__","Fix C++26 by adding transposed special cases for P2642 layouts","2024-11 (Wrocław)","","",""
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 43cefd5600646..ba61ee7c11e35 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -751,6 +751,7 @@ set(files
   __system_error/error_condition.h
   __system_error/system_error.h
   __system_error/throw_system_error.h
+  __text_encoding/text_encoding.h
   __thread/formatter.h
   __thread/id.h
   __thread/jthread.h
@@ -1062,6 +1063,7 @@ set(files
   strstream
   syncstream
   system_error
+  text_encoding
   tgmath.h
   thread
   tuple
diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index d6c6ef19627ff..4da3f38ac408f 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -31,6 +31,10 @@
 #  include <cstddef>
 #  include <cstring>
 
+#  if _LIBCPP_STD_VER >= 26
+#    include <__text_encoding/text_encoding.h>
+#  endif
+
 #  if _LIBCPP_HAS_WIDE_CHARACTERS
 #    include <cwchar>
 #  else
@@ -99,6 +103,11 @@ public:
 
   // locale operations:
   string name() const;
+  
+#  if _LIBCPP_STD_VER >= 26 && __CHAR_BIT__ == 8
+  text_encoding encoding() const; 
+#  endif // _LIBCPP_STD_VER >= 26
+
   bool operator==(const locale&) const;
 #  if _LIBCPP_STD_VER <= 17
   _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); }
diff --git a/libcxx/include/__text_encoding/text_encoding.h b/libcxx/include/__text_encoding/text_encoding.h
new file mode 100644
index 0000000000000..93d0ae2ab6b89
--- /dev/null
+++ b/libcxx/include/__text_encoding/text_encoding.h
@@ -0,0 +1,1483 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___TEXT_ENCODING_TEXT_ENCODING_H
+#define _LIBCPP___TEXT_ENCODING_TEXT_ENCODING_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_HAS_LOCALIZATION
+
+#include <__algorithm/copy_n.h>
+#include <__algorithm/lower_bound.h>
+#include <__algorithm/min.h>
+#include <__functional/hash.h>
+#include <__iterator/iterator_traits.h>
+#include <__locale_dir/locale_base_api.h>
+#include <__ranges/view_interface.h>
+#include <__string/char_traits.h>
+#include <__utility/unreachable.h>
+#include <cstdint>
+#include <string_view>
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if _LIBCPP_STD_VER >= 26
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+struct _LIBCPP_EXPORTED_FROM_ABI text_encoding {
+  static constexpr size_t max_name_length = 63;
+
+private:
+  struct __encoding_data {
+    using __id_rep _LIBCPP_NODEBUG = int_least32_t;
+    __id_rep __mib_rep;
+    const char* __name;
+
+    friend constexpr bool operator==(const __encoding_data& __e, const __encoding_data& __other) _NOEXCEPT {
+      return __e.__mib_rep == __other.__mib_rep || __comp_name(__e.__name, __other.__name);
+    }
+
+    friend constexpr bool operator<(const __encoding_data& __e, const __id_rep __i) _NOEXCEPT {
+      return __e.__mib_rep < __i;
+    }
+  };
+
+public:
+  enum class id : __encoding_data::__id_rep {
+    other                   = 1,
+    unknown                 = 2,
+    ASCII                   = 3,
+    ISOLatin1               = 4,
+    ISOLatin2               = 5,
+    ISOLatin3               = 6,
+    ISOLatin4               = 7,
+    ISOLatinCyrillic        = 8,
+    ISOLatinArabic          = 9,
+    ISOLatinGreek           = 10,
+    ISOLatinHebrew          = 11,
+    ISOLatin5               = 12,
+    ISOLatin6               = 13,
+    ISOTextComm             = 14,
+    HalfWidthKatakana       = 15,
+    JISEncoding             = 16,
+    ShiftJIS                = 17,
+    EUCPkdFmtJapanese       = 18,
+    EUCFixWidJapanese       = 19,
+    ISO4UnitedKingdom       = 20,
+    ISO11SwedishForNames    = 21,
+    ISO15Italian            = 22,
+    ISO17Spanish            = 23,
+    ISO21German             = 24,
+    ISO60DanishNorwegian    = 25,
+    ISO69French             = 26,
+    ISO10646UTF1            = 27,
+    ISO646basic1983         = 28,
+    INVARIANT               = 29,
+    ISO2IntlRefVersion      = 30,
+    NATSSEFI                = 31,
+    NATSSEFIADD             = 32,
+    NATSDANO                = 33,
+    NATSDANOADD             = 34,
+    ISO10Swedish            = 35,
+    KSC56011987             = 36,
+    ISO2022KR               = 37,
+    EUCKR                   = 38,
+    ISO2022JP               = 39,
+    ISO2022JP2              = 40,
+    ISO13JISC6220jp         = 41,
+    ISO14JISC6220ro         = 42,
+    ISO16Portuguese         = 43,
+    ISO18Greek7Old          = 44,
+    ISO19LatinGreek         = 45,
+    ISO25French             = 46,
+    ISO27LatinGreek1        = 47,
+    ISO5427Cyrillic         = 48,
+    ISO42JISC62261978       = 49,
+    ISO47BSViewdata         = 50,
+    ISO49INIS               = 51,
+    ISO50INIS8              = 52,
+    ISO51INISCyrillic       = 53,
+    ISO54271981             = 54,
+    ISO5428Greek            = 55,
+    ISO57GB1988             = 56,
+    ISO58GB231280           = 57,
+    ISO61Norwegian2         = 58,
+    ISO70VideotexSupp1      = 59,
+    ISO84Portuguese2        = 60,
+    ISO85Spanish2           = 61,
+    ISO86Hungarian          = 62,
+    ISO87JISX0208           = 63,
+    ISO88Greek7             = 64,
+    ISO89ASMO449            = 65,
+    ISO90                   = 66,
+    ISO91JISC62291984a      = 67,
+    ISO92JISC62991984b      = 68,
+    ISO93JIS62291984badd    = 69,
+    ISO94JIS62291984hand    = 70,
+    ISO95JIS62291984handadd = 71,
+    ISO96JISC62291984kana   = 72,
+    ISO2033                 = 73,
+    ISO99NAPLPS             = 74,
+    ISO102T617bit           = 75,
+    ISO103T618bit           = 76,
+    ISO111ECMACyrillic      = 77,
+    ISO121Canadian1         = 78,
+    ISO122Canadian2         = 79,
+    ISO123CSAZ24341985gr    = 80,
+    ISO88596E               = 81,
+    ISO88596I               = 82,
+    ISO128T101G2            = 83,
+    ISO88598E               = 84,
+    ISO88598I               = 85,
+    ISO139CSN369103         = 86,
+    ISO141JUSIB1002         = 87,
+    ISO143IECP271           = 88,
+    ISO146Serbian           = 89,
+    ISO147Macedonian        = 90,
+    ISO150                  = 91,
+    ISO151Cuba              = 92,
+    ISO6937Add              = 93,
+    ISO153GOST1976874       = 94,
+    ISO8859Supp             = 95,
+    ISO10367Box             = 96,
+    ISO158Lap               = 97,
+    ISO159JISX02121990      = 98,
+    ISO646Danish            = 99,
+    USDK                    = 100,
+    DKUS                    = 101,
+    KSC5636                 = 102,
+    Unicode11UTF7           = 103,
+    ISO2022CN               = 104,
+    ISO2022CNEXT            = 105,
+    UTF8                    = 106,
+    ISO885913               = 109,
+    ISO885914               = 110,
+    ISO885915               = 111,
+    ISO885916               = 112,
+    GBK                     = 113,
+    GB18030                 = 114,
+    OSDEBCDICDF0415         = 115,
+    OSDEBCDICDF03IRV        = 116,
+    OSDEBCDICDF041          = 117,
+    ISO115481               = 118,
+    KZ1048                  = 119,
+    UCS2                    = 1000,
+    UCS4                    = 1001,
+    UnicodeASCII            = 1002,
+    UnicodeLatin1           = 1003,
+    UnicodeJapanese         = 1004,
+    UnicodeIBM1261          = 1005,
+    UnicodeIBM1268          = 1006,
+    UnicodeIBM1276          = 1007,
+    UnicodeIBM1264          = 1008,
+    UnicodeIBM1265          = 1009,
+    Unicode11               = 1010,
+    SCSU                    = 1011,
+    UTF7                    = 1012,
+    UTF16BE                 = 1013,
+    UTF16LE                 = 1014,
+    UTF16                   = 1015,
+    CESU8                   = 1016,
+    UTF32                   = 1017,
+    UTF32BE                 = 1018,
+    UTF32LE                 = 1019,
+    BOCU1                   = 1020,
+    UTF7IMAP                = 1021,
+    Windows30Latin1         = 2000,
+    Windows31Latin1         = 2001,
+    Windows31Latin2         = 2002,
+    Windows31Latin5         = 2003,
+    HPRoman8                = 2004,
+    AdobeStandardEncoding   = 2005,
+    VenturaUS               = 2006,
+    VenturaInternational    = 2007,
+    DECMCS                  = 2008,
+    PC850Multilingual       = 2009,
+    PC8DanishNorwegian      = 2012,
+    PC862LatinHebrew        = 2013,
+    PC8Turkish              = 2014,
+    IBMSymbols              = 2015,
+    IBMThai                 = 2016,
+    HPLegal                 = 2017,
+    HPPiFont                = 2018,
+    HPMath8                 = 2019,
+    HPPSMath                = 2020,
+    HPDesktop               = 2021,
+    VenturaMath             = 2022,
+    MicrosoftPublishing     = 2023,
+    Windows31J              = 2024,
+    GB2312                  = 2025,
+    Big5                    = 2026,
+    Macintosh               = 2027,
+    IBM037                  = 2028,
+    IBM038                  = 2029,
+    IBM273                  = 2030,
+    IBM274                  = 2031,
+    IBM275                  = 2032,
+    IBM277                  = 2033,
+    IBM278                  = 2034,
+    IBM280                  = 2035,
+    IBM281                  = 2036,
+    IBM284                  = 2037,
+    IBM285                  = 2038,
+    IBM290                  = 2039,
+    IBM297                  = 2040,
+    IBM420                  = 2041,
+    IBM423                  = 2042,
+    IBM424                  = 2043,
+    PC8CodePage437          = 2011,
+    IBM500                  = 2044,
+    IBM851                  = 2045,
+    PCp852                  = 2010,
+    IBM855                  = 2046,
+    IBM857                  = 2047,
+    IBM860                  = 2048,
+    IBM861                  = 2049,
+    IBM863                  = 2050,
+    IBM864                  = 2051,
+    IBM865                  = 2052,
+    IBM868                  = 2053,
+    IBM869                  = 2054,
+    IBM870                  = 2055,
+    IBM871                  = 2056,
+    IBM880                  = 2057,
+    IBM891                  = 2058,
+    IBM903                  = 2059,
+    IBBM904                 = 2060,
+    IBM905                  = 2061,
+    IBM918                  = 2062,
+    IBM1026                 = 2063,
+    IBMEBCDICATDE           = 2064,
+    EBCDICATDEA             = 2065,
+    EBCDICCAFR              = 2066,
+    EBCDICDKNO              = 2067,
+    EBCDICDKNOA             = 2068,
+    EBCDICFISE              = 2069,
+    EBCDICFISEA             = 2070,
+    EBCDICFR                = 2071,
+    EBCDICIT                = 2072,
+    EBCDICPT                = 2073,
+    EBCDICES                = 2074,
+    EBCDICESA               = 2075,
+    EBCDICESS               = 2076,
+    EBCDICUK                = 2077,
+    EBCDICUS                = 2078,
+    Unknown8BiT             = 2079,
+    Mnemonic                = 2080,
+    Mnem                    = 2081,
+    VISCII                  = 2082,
+    VIQR                    = 2083,
+    KOI8R                   = 2084,
+    HZGB2312                = 2085,
+    IBM866                  = 2086,
+    PC775Baltic             = 2087,
+    KOI8U                   = 2088,
+    IBM00858                = 2089,
+    IBM00924                = 2090,
+    IBM01140                = 2091,
+    IBM01141                = 2092,
+    IBM01142                = 2093,
+    IBM01143                = 2094,
+    IBM01144                = 2095,
+    IBM01145                = 2096,
+    IBM01146                = 2097,
+    IBM01147                = 2098,
+    IBM01148                = 2099,
+    IBM01149                = 2100,
+    Big5HKSCS               = 2101,
+    IBM1047                 = 2102,
+    PTCP154                 = 2103,
+    Amiga1251               = 2104,
+    KOI7switched            = 2105,
+    BRF                     = 2106,
+    TSCII                   = 2107,
+    CP51932                 = 2108,
+    windows874              = 2109,
+    windows1250             = 2250,
+    windows1251             = 2251,
+    windows1252             = 2252,
+    windows1253             = 2253,
+    windows1254             = 2254,
+    windows1255             = 2255,
+    windows1256             = 2256,
+    windows1257             = 2257,
+    windows1258             = 2258,
+    TIS620                  = 2259,
+    CP50220                 = 2260,
+    reserved                = 3000
+  };
+
+  using enum id;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr text_encoding() = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit text_encoding(string_view __enc) _NOEXCEPT
+      : __encoding_rep_(__find_encoding_data(__enc)) {
+    __enc.copy(__name_, max_name_length, 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr text_encoding(id __i) _NOEXCEPT : __encoding_rep_(__find_encoding_data_by_id(__i)) {
+    if (__encoding_rep_->__name[0] != '\0')
+      std::copy_n(__encoding_rep_->__name, std::char_traits<char>::length(__encoding_rep_->__name), __name_);
+  }
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr id mib() const _NOEXCEPT { return id(__encoding_rep_->__mib_rep); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const char* name() const _NOEXCEPT { return __name_; }
+
+  // [text.encoding.aliases], class text_encoding::aliases_view
+  struct aliases_view : ranges::view_interface<aliases_view> {
+    constexpr aliases_view() = default;
+    constexpr aliases_view(const __encoding_data* __d) : __view_data_(__d) {}
+    struct __end_sentinel {};
+    struct __iterator {
+      using value_type        = const char*;
+      using reference         = const char*;
+      using difference_type   = ptrdiff_t;
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator() noexcept = default; 
+      
+      _LIBCPP_HIDE_FROM_ABI constexpr value_type operator*() const {
+        if (__can_dereference())
+          return __data_->__name;
+        std::unreachable();
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr value_type operator[](difference_type __n) const {
+        auto __it = *this;
+        return *(__it + __n);
+      }
+
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator __it, difference_type __n) {
+        __it += __n;
+        return __it;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, __iterator __it) {
+        __it += __n;
+        return __it;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(__iterator __it, difference_type __n) {
+        __it -= __n; 
+        return __it;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __iterator& __other) const 
+      {
+        if(__other.__mib_rep_ == __mib_rep_)
+          return __mib_rep_ - __other.__mib_rep_;
+        std::unreachable();
+      }
+
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(difference_type __n, __iterator& __it) {
+        __it -= __n; 
+        return __it;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() {
+        __data_++;
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) {
+        auto __old = *this;
+        __data_++;
+        return __old;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() {
+        __data_--;
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int) {
+        auto __old = *this;
+        __data_--;
+        return __old;
+      }
+
+      // Check if going past the encoding data list array and if the new index has the same id, if not then
+      // replace it with a sentinel "out-of-bounds" iterator.
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) {
+        if (__data_) [[__likely__]] {
+          if (__n > 0) {
+            if ((__data_ + __n) < std::end(__text_encoding_data) && __data_[__n - 1].__mib_rep == __mib_rep_)
+              __data_ += __n;
+            else
+              *this = __iterator{};
+          } else if (__n < 0) {
+            if ((__data_ + __n) > __text_encoding_data && __data_[__n].__mib_rep == __mib_rep_)
+              __data_ += __n;
+            else
+              *this = __iterator{};
+          }
+        }
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) { return operator+=(-__n); }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const __iterator& __it) const {
+        return __data_ == __it.__data_ && __it.__mib_rep_ == __mib_rep_;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(__end_sentinel) const { return !__can_dereference(); }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(__iterator __it) const { return __data_ <=> __it.__data_; }
+
+    private:
+      friend struct text_encoding;
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator(const __encoding_data* __enc_d) noexcept
+          : __data_(__enc_d), __mib_rep_(__enc_d ? __enc_d->__mib_rep : 0) {}
+
+      _LIBCPP_HIDE_FROM_ABI bool __can_dereference() const { return __data_ && __data_->__mib_rep == __mib_rep_; }
+
+      // default iterator is a sentinel
+      const __encoding_data* __data_       = nullptr;
+      __encoding_data::__id_rep __mib_rep_ = 0;
+    };
+
+    constexpr __iterator begin() const { return __iterator{__view_data_}; }
+    constexpr __end_sentinel end() const { return __end_sentinel{}; }
+
+  private:
+    const __encoding_data* __view_data_ = nullptr;
+  };
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr aliases_view aliases() const _NOEXCEPT {
+    auto __rep = __encoding_rep_ - 1;
+    if (__encoding_rep_->__name[0]) {
+      while (__rep > std::begin(__text_encoding_data) && (__rep--)->__mib_rep == __encoding_rep_->__mib_rep)
+        ;
+    } else {
+      __rep = nullptr;
+    }
+
+    return aliases_view(__rep);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const text_encoding& __a, const text_encoding& __b) _NOEXCEPT {
+    if (__a.mib() == id::other && __b.mib() == id::other)
+      return __comp_name(__a.__name_, __b.__name_);
+
+    return __a.mib() == __b.mib();
+  }
+
+  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const text_encoding& __encoding, id __i) _NOEXCEPT {
+    return __encoding.mib() == __i;
+  }
+
+#    if __CHAR_BIT__ == 8
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval text_encoding literal() _NOEXCEPT {
+#      ifdef __GNUC_EXECUTION_CHARSET_NAME
+    return text_encoding(__GNUC_EXECUTION_CHARSET_NAME);
+#      elif defined(__clang_literal_encoding__)
+    return text_encoding(__clang_literal_encoding__);
+#      elif defined(__clang__)
+    return text_encoding(id::UTF8);
+#      else
+    return {};
+#      endif
+  }
+
+  [[nodiscard]] static text_encoding environment();
+
+  template <id __i>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool environment_is() {
+    return environment() == __i;
+  }
+
+#    else
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval text_encoding literal() = delete;
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static text_encoding environment()       = delete;
+  template <id __i>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool environment_is() = delete;
+#    endif
+
+private:
+  _LIBCPP_HIDE_FROM_ABI static constexpr bool __comp_name(string_view __a, string_view __b) {
+    if (__a.empty() || __b.empty()) {
+      return false;
+    }
+
+    // map any non-alphanumeric character to 255, skip prefix 0s, else get tolower(__n)
+    auto __map_char = [](char __n, bool& __in_number) -> unsigned char {
+      auto __to_lower = [](char __n) -> char { return (__n >= 'A' && __n <= 'Z') ? __n + ('a' - 'A') : __n; };
+      if (__n == '0') {
+        return __in_number ? '0' : 255;
+      }
+      __in_number = __n >= '1' && __n <= '9';
+      return (__n >= '1' && __n <= '9') || (__n >= 'A' && __n <= 'Z') || (__n >= 'a' && __n <= 'z')
+               ? __to_lower(__n)
+               : 255;
+    };
+
+    auto __a_ptr = __a.begin(), __b_ptr = __b.begin();
+    bool __a_in_number = false, __b_in_number = false;
+
+    unsigned char __a_val = 255, __b_val = 255;
+    for (;; __a_ptr++, __b_ptr++) {
+      while ((__a_val = __map_char(*__a_ptr, __a_in_number)) == 255 && __a_ptr != __a.end())
+        __a_ptr++;
+      while ((__b_val = __map_char(*__b_ptr, __b_in_number)) == 255 && __b_ptr != __b.end())
+        __b_ptr++;
+
+      if (__a_ptr == __a.end())
+        return __b_ptr == __b.end();
+      if (__b_ptr == __b.end())
+        return false;
+      if (__a_val != __b_val)
+        return false;
+    }
+    return true;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI static constexpr const __encoding_data* __find_encoding_data(string_view __a) {
+    auto __data_ptr = __text_encoding_data + 2, __data_last = std::end(__text_encoding_data) - 1;
+
+    for (; __data_ptr != __data_last; __data_ptr++) {
+      if (__comp_name(__a, __data_ptr->__name)) {
+        const auto __found_id = __data_ptr->__mib_rep;
+        while (__data_ptr[-1].__mib_rep == __found_id)
+          __data_ptr--;
+        return __data_ptr;
+      }
+    }
+
+    return __text_encoding_data; // other
+  }
+
+  _LIBCPP_HIDE_FROM_ABI static constexpr const __encoding_data* __find_encoding_data_by_id(id __i) {
+    auto __found = std::lower_bound(
+        std::begin(__text_encoding_data), std::end(__text_encoding_data) - 1, __encoding_data::__id_rep(__i));
+    return __found != std::end(__text_encoding_data) - 1 ? __found : __text_encoding_data + 1; // unknown
+  }
+
+  _LIBCPP_HIDE_FROM_ABI static constexpr __encoding_data __text_encoding_data[] = {
+      {1, ""},
+      {2, ""},
+      {3, "ANSI_X3.4-1968"},
+      {3, "ANSI_X3.4-1986"},
+      {3, "IBM367"},
+      {3, "ISO646-US"},
+      {3, "ISO_646.irv:1991"},
+      {3, "cp367"},
+      {3, "csASCII"},
+      {3, "iso-ir-6"},
+      {3, "us"},
+      {4, "ISO-8859-1"},
+      {4, "ISO_8859-1:1987"},
+      {4, "CP819"},
+      {4, "IBM819"},
+      {4, "ISO_8859-1"},
+      {4, "csISOLatin1"},
+      {4, "iso-ir-100"},
+      {4, "l1"},
+      {4, "latin1"},
+      {5, "ISO-8859-2"},
+      {5, "ISO_8859-2:1987"},
+      {5, "ISO_8859-2"},
+      {5, "csISOLatin2"},
+      {5, "iso-ir-101"},
+      {5, "l2"},
+      {5, "latin2"},
+      {6, "ISO-8859-3"},
+      {6, "ISO_8859-3:1988"},
+      {6, "ISO_8859-3"},
+      {6, "csISOLatin3"},
+      {6, "iso-ir-109"},
+      {6, "l3"},
+      {6, "latin3"},
+      {7, "ISO-8859-4"},
+      {7, "ISO_8859-4:1988"},
+      {7, "ISO_8859-4"},
+      {7, "csISOLatin4"},
+      {7, "iso-ir-110"},
+      {7, "l4"},
+      {7, "latin4"},
+      {8, "ISO-8859-5"},
+      {8, "ISO_8859-5:1988"},
+      {8, "ISO_8859-5"},
+      {8, "csISOLatinCyrillic"},
+      {8, "cyrillic"},
+      {8, "iso-ir-144"},
+      {9, "ISO-8859-6"},
+      {9, "ISO_8859-6:1987"},
+      {9, "ASMO-708"},
+      {9, "ECMA-114"},
+      {9, "ISO_8859-6"},
+      {9, "arabic"},
+      {9, "csISOLatinArabic"},
+      {9, "iso-ir-127"},
+      {10, "ISO-8859-7"},
+      {10, "ISO_8859-7:1987"},
+      {10, "ECMA-118"},
+      {10, "ELOT_928"},
+      {10, "ISO_8859-7"},
+      {10, "csISOLatinGreek"},
+      {10, "greek"},
+      {10, "greek8"},
+      {10, "iso-ir-126"},
+      {11, "ISO-8859-8"},
+      {11, "ISO_8859-8:1988"},
+      {11, "ISO_8859-8"},
+      {11, "csISOLatinHebrew"},
+      {11, "hebrew"},
+      {11, "iso-ir-138"},
+      {12, "ISO-8859-9"},
+      {12, "ISO_8859-9:1989"},
+      {12, "ISO_8859-9"},
+      {12, "csISOLatin5"},
+      {12, "iso-ir-148"},
+      {12, "l5"},
+      {12, "latin5"},
+      {13, "ISO-8859-10"},
+      {13, "ISO_8859-10:1992"},
+      {13, "csISOLatin6"},
+      {13, "iso-ir-157"},
+      {13, "l6"},
+      {13, "latin6"},
+      {14, "ISO_6937-2-add"},
+      {14, "csISOTextComm"},
+      {14, "iso-ir-142"},
+      {15, "JIS_X0201"},
+      {15, "X0201"},
+      {15, "csHalfWidthKatakana"},
+      {16, "JIS_Encoding"},
+      {16, "csJISEncoding"},
+      {17, "Shift_JIS"},
+      {17, "MS_Kanji"},
+      {17, "csShiftJIS"},
+      {18, "EUC-JP"},
+      {18, "Extended_UNIX_Code_Packed_Format_for_Japanese"},
+      {18, "csEUCPkdFmtJapanese"},
+      {19, "Extended_UNIX_Code_Fixed_Width_for_Japanese"},
+      {19, "csEUCFixWidJapanese"},
+      {20, "BS_4730"},
+      {20, "ISO646-GB"},
+      {20, "csISO4UnitedKingdom"},
+      {20, "gb"},
+      {20, "iso-ir-4"},
+      {20, "uk"},
+      {21, "SEN_850200_C"},
+      {21, "ISO646-SE2"},
+      {21, "csISO11SwedishForNames"},
+      {21, "iso-ir-11"},
+      {21, "se2"},
+      {22, "IT"},
+      {22, "ISO646-IT"},
+      {22, "csISO15Italian"},
+      {22, "iso-ir-15"},
+      {23, "ES"},
+      {23, "ISO646-ES"},
+      {23, "csISO17Spanish"},
+      {23, "iso-ir-17"},
+      {24, "DIN_66003"},
+      {24, "ISO646-DE"},
+      {24, "csISO21German"},
+      {24, "de"},
+      {24, "iso-ir-21"},
+      {25, "NS_4551-1"},
+      {25, "ISO646-NO"},
+      {25, "csISO60DanishNorwegian"},
+      {25, "csISO60Norwegian1"},
+      {25, "iso-ir-60"},
+      {25, "no"},
+      {26, "NF_Z_62-010"},
+      {26, "ISO646-FR"},
+      {26, "csISO69French"},
+      {26, "fr"},
+      {26, "iso-ir-69"},
+      {27, "ISO-10646-UTF-1"},
+      {27, "csISO10646UTF1"},
+      {28, "ISO_646.basic:1983"},
+      {28, "csISO646basic1983"},
+      {28, "ref"},
+      {29, "INVARIANT"},
+      {29, "csINVARIANT"},
+      {30, "ISO_646.irv:1983"},
+      {30, "csISO2IntlRefVersion"},
+      {30, "irv"},
+      {30, "iso-ir-2"},
+      {31, "NATS-SEFI"},
+      {31, "csNATSSEFI"},
+      {31, "iso-ir-8-1"},
+      {32, "NATS-SEFI-ADD"},
+      {32, "csNATSSEFIADD"},
+      {32, "iso-ir-8-2"},
+      {33, "NATS-DANO"},
+      {33, "csNATSDANO"},
+      {33, "iso-ir-9-1"},
+      {34, "NATS-DANO-ADD"},
+      {34, "csNATSDANOADD"},
+      {34, "iso-ir-9-2"},
+      {35, "SEN_850200_B"},
+      {35, "FI"},
+      {35, "ISO646-FI"},
+      {35, "ISO646-SE"},
+      {35, "csISO10Swedish"},
+      {35, "iso-ir-10"},
+      {35, "se"},
+      {36, "KS_C_5601-1987"},
+      {36, "KSC_5601"},
+      {36, "KS_C_5601-1989"},
+      {36, "csKSC56011987"},
+      {36, "iso-ir-149"},
+      {36, "korean"},
+      {37, "ISO-2022-KR"},
+      {37, "csISO2022KR"},
+      {38, "EUC-KR"},
+      {38, "csEUCKR"},
+      {39, "ISO-2022-JP"},
+      {39, "csISO2022JP"},
+      {40, "ISO-2022-JP-2"},
+      {40, "csISO2022JP2"},
+      {41, "JIS_C6220-1969-jp"},
+      {41, "JIS_C6220-1969"},
+      {41, "csISO13JISC6220jp"},
+      {41, "iso-ir-13"},
+      {41, "katakana"},
+      {41, "x0201-7"},
+      {42, "JIS_C6220-1969-ro"},
+      {42, "ISO646-JP"},
+      {42, "csISO14JISC6220ro"},
+      {42, "iso-ir-14"},
+      {42, "jp"},
+      {43, "PT"},
+      {43, "ISO646-PT"},
+      {43, "csISO16Portuguese"},
+      {43, "iso-ir-16"},
+      {44, "greek7-old"},
+      {44, "csISO18Greek7Old"},
+      {44, "iso-ir-18"},
+      {45, "latin-greek"},
+      {45, "csISO19LatinGreek"},
+      {45, "iso-ir-19"},
+      {46, "NF_Z_62-010_(1973)"},
+      {46, "ISO646-FR1"},
+      {46, "csISO25French"},
+      {46, "iso-ir-25"},
+      {47, "Latin-greek-1"},
+      {47, "csISO27LatinGreek1"},
+      {47, "iso-ir-27"},
+      {48, "ISO_5427"},
+      {48, "csISO5427Cyrillic"},
+      {48, "iso-ir-37"},
+      {49, "JIS_C6226-1978"},
+      {49, "csISO42JISC62261978"},
+      {49, "iso-ir-42"},
+      {50, "BS_viewdata"},
+      {50, "csISO47BSViewdata"},
+      {50, "iso-ir-47"},
+      {51, "INIS"},
+      {51, "csISO49INIS"},
+      {51, "iso-ir-49"},
+      {52, "INIS-8"},
+      {52, "csISO50INIS8"},
+      {52, "iso-ir-50"},
+      {53, "INIS-cyrillic"},
+      {53, "csISO51INISCyrillic"},
+      {53, "iso-ir-51"},
+      {54, "ISO_5427:1981"},
+      {54, "ISO5427Cyrillic1981"},
+      {54, "csISO54271981"},
+      {54, "iso-ir-54"},
+      {55, "ISO_5428:1980"},
+      {55, "csISO5428Greek"},
+      {55, "iso-ir-55"},
+      {56, "GB_1988-80"},
+      {56, "ISO646-CN"},
+      {56, "cn"},
+      {56, "csISO57GB1988"},
+      {56, "iso-ir-57"},
+      {57, "GB_2312-80"},
+      {57, "chinese"},
+      {57, "csISO58GB231280"},
+      {57, "iso-ir-58"},
+      {58, "NS_4551-2"},
+      {58, "ISO646-NO2"},
+      {58, "csISO61Norwegian2"},
+      {58, "iso-ir-61"},
+      {58, "no2"},
+      {59, "videotex-suppl"},
+      {59, "csISO70VideotexSupp1"},
+      {59, "iso-ir-70"},
+      {60, "PT2"},
+      {60, "ISO646-PT2"},
+      {60, "csISO84Portuguese2"},
+      {60, "iso-ir-84"},
+      {61, "ES2"},
+      {61, "ISO646-ES2"},
+      {61, "csISO85Spanish2"},
+      {61, "iso-ir-85"},
+      {62, "MSZ_7795.3"},
+      {62, "ISO646-HU"},
+      {62, "csISO86Hungarian"},
+      {62, "hu"},
+      {62, "iso-ir-86"},
+      {63, "JIS_C6226-1983"},
+      {63, "JIS_X0208-1983"},
+      {63, "csISO87JISX0208"},
+      {63, "iso-ir-87"},
+      {63, "x0208"},
+      {64, "greek7"},
+      {64, "csISO88Greek7"},
+      {64, "iso-ir-88"},
+      {65, "ASMO_449"},
+      {65, "ISO_9036"},
+      {65, "arabic7"},
+      {65, "csISO89ASMO449"},
+      {65, "iso-ir-89"},
+      {66, "iso-ir-90"},
+      {66, "csISO90"},
+      {67, "JIS_C6229-1984-a"},
+      {67, "csISO91JISC62291984a"},
+      {67, "iso-ir-91"},
+      {67, "jp-ocr-a"},
+      {68, "JIS_C6229-1984-b"},
+      {68, "ISO646-JP-OCR-B"},
+      {68, "csISO92JISC62991984b"},
+      {68, "iso-ir-92"},
+      {68, "jp-ocr-b"},
+      {69, "JIS_C6229-1984-b-add"},
+      {69, "csISO93JIS62291984badd"},
+      {69, "iso-ir-93"},
+      {69, "jp-ocr-b-add"},
+      {70, "JIS_C6229-1984-hand"},
+      {70, "csISO94JIS62291984hand"},
+      {70, "iso-ir-94"},
+      {70, "jp-ocr-hand"},
+      {71, "JIS_C6229-1984-hand-add"},
+      {71, "csISO95JIS62291984handadd"},
+      {71, "iso-ir-95"},
+      {71, "jp-ocr-hand-add"},
+      {72, "JIS_C6229-1984-kana"},
+      {72, "csISO96JISC62291984kana"},
+      {72, "iso-ir-96"},
+      {73, "ISO_2033-1983"},
+      {73, "csISO2033"},
+      {73, "e13b"},
+      {73, "iso-ir-98"},
+      {74, "ANSI_X3.110-1983"},
+      {74, "CSA_T500-1983"},
+      {74, "NAPLPS"},
+      {74, "csISO99NAPLPS"},
+      {74, "iso-ir-99"},
+      {75, "T.61-7bit"},
+      {75, "csISO102T617bit"},
+      {75, "iso-ir-102"},
+      {76, "T.61-8bit"},
+      {76, "T.61"},
+      {76, "csISO103T618bit"},
+      {76, "iso-ir-103"},
+      {77, "ECMA-cyrillic"},
+      {77, "KOI8-E"},
+      {77, "csISO111ECMACyrillic"},
+      {77, "iso-ir-111"},
+      {78, "CSA_Z243.4-1985-1"},
+      {78, "ISO646-CA"},
+      {78, "ca"},
+      {78, "csISO121Canadian1"},
+      {78, "csa7-1"},
+      {78, "csa71"},
+      {78, "iso-ir-121"},
+      {79, "CSA_Z243.4-1985-2"},
+      {79, "ISO646-CA2"},
+      {79, "csISO122Canadian2"},
+      {79, "csa7-2"},
+      {79, "csa72"},
+      {79, "iso-ir-122"},
+      {80, "CSA_Z243.4-1985-gr"},
+      {80, "csISO123CSAZ24341985gr"},
+      {80, "iso-ir-123"},
+      {81, "ISO-8859-6-E"},
+      {81, "ISO_8859-6-E"},
+      {81, "csISO88596E"},
+      {82, "ISO-8859-6-I"},
+      {82, "ISO_8859-6-I"},
+      {82, "csISO88596I"},
+      {83, "T.101-G2"},
+      {83, "csISO128T101G2"},
+      {83, "iso-ir-128"},
+      {84, "ISO-8859-8-E"},
+      {84, "ISO_8859-8-E"},
+      {84, "csISO88598E"},
+      {85, "ISO-8859-8-I"},
+      {85, "ISO_8859-8-I"},
+      {85, "csISO88598I"},
+      {86, "CSN_369103"},
+      {86, "csISO139CSN369103"},
+      {86, "iso-ir-139"},
+      {87, "JUS_I.B1.002"},
+      {87, "ISO646-YU"},
+      {87, "csISO141JUSIB1002"},
+      {87, "iso-ir-141"},
+      {87, "js"},
+      {87, "yu"},
+      {88, "IEC_P27-1"},
+      {88, "csISO143IECP271"},
+      {88, "iso-ir-143"},
+      {89, "JUS_I.B1.003-serb"},
+      {89, "csISO146Serbian"},
+      {89, "iso-ir-146"},
+      {89, "serbian"},
+      {90, "JUS_I.B1.003-mac"},
+      {90, "csISO147Macedonian"},
+      {90, "iso-ir-147"},
+      {90, "macedonian"},
+      {91, "greek-ccitt"},
+      {91, "csISO150"},
+      {91, "csISO150GreekCCITT"},
+      {91, "iso-ir-150"},
+      {92, "NC_NC00-10:81"},
+      {92, "ISO646-CU"},
+      {92, "csISO151Cuba"},
+      {92, "cuba"},
+      {92, "iso-ir-151"},
+      {93, "ISO_6937-2-25"},
+      {93, "csISO6937Add"},
+      {93, "iso-ir-152"},
+      {94, "GOST_19768-74"},
+      {94, "ST_SEV_358-88"},
+      {94, "csISO153GOST1976874"},
+      {94, "iso-ir-153"},
+      {95, "ISO_8859-supp"},
+      {95, "csISO8859Supp"},
+      {95, "iso-ir-154"},
+      {95, "latin1-2-5"},
+      {96, "ISO_10367-box"},
+      {96, "csISO10367Box"},
+      {96, "iso-ir-155"},
+      {97, "latin-lap"},
+      {97, "csISO158Lap"},
+      {97, "iso-ir-158"},
+      {97, "lap"},
+      {98, "JIS_X0212-1990"},
+      {98, "csISO159JISX02121990"},
+      {98, "iso-ir-159"},
+      {98, "x0212"},
+      {99, "DS_2089"},
+      {99, "DS2089"},
+      {99, "ISO646-DK"},
+      {99, "csISO646Danish"},
+      {99, "dk"},
+      {100, "us-dk"},
+      {100, "csUSDK"},
+      {101, "dk-us"},
+      {101, "csDKUS"},
+      {102, "KSC5636"},
+      {102, "ISO646-KR"},
+      {102, "csKSC5636"},
+      {103, "UNICODE-1-1-UTF-7"},
+      {103, "csUnicode11UTF7"},
+      {104, "ISO-2022-CN"},
+      {104, "csISO2022CN"},
+      {105, "ISO-2022-CN-EXT"},
+      {105, "csISO2022CNEXT"},
+      {106, "UTF-8"},
+      {106, "csUTF8"},
+      {109, "ISO-8859-13"},
+      {109, "csISO885913"},
+      {110, "ISO-8859-14"},
+      {110, "ISO_8859-14"},
+      {110, "ISO_8859-14:1998"},
+      {110, "csISO885914"},
+      {110, "iso-celtic"},
+      {110, "iso-ir-199"},
+      {110, "l8"},
+      {110, "latin8"},
+      {111, "ISO-8859-15"},
+      {111, "ISO_8859-15"},
+      {111, "Latin-9"},
+      {111, "csISO885915"},
+      {112, "ISO-8859-16"},
+      {112, "ISO_8859-16"},
+      {112, "ISO_8859-16:2001"},
+      {112, "csISO885916"},
+      {112, "iso-ir-226"},
+      {112, "l10"},
+      {112, "latin10"},
+      {113, "GBK"},
+      {113, "CP936"},
+      {113, "MS936"},
+      {113, "csGBK"},
+      {113, "windows-936"},
+      {114, "GB18030"},
+      {114, "csGB18030"},
+      {115, "OSD_EBCDIC_DF04_15"},
+      {115, "csOSDEBCDICDF0415"},
+      {116, "OSD_EBCDIC_DF03_IRV"},
+      {116, "csOSDEBCDICDF03IRV"},
+      {117, "OSD_EBCDIC_DF04_1"},
+      {117, "csOSDEBCDICDF041"},
+      {118, "ISO-11548-1"},
+      {118, "ISO_11548-1"},
+      {118, "ISO_TR_11548-1"},
+      {118, "csISO115481"},
+      {119, "KZ-1048"},
+      {119, "RK1048"},
+      {119, "STRK1048-2002"},
+      {119, "csKZ1048"},
+      {1000, "ISO-10646-UCS-2"},
+      {1000, "csUnicode"},
+      {1001, "ISO-10646-UCS-4"},
+      {1001, "csUCS4"},
+      {1002, "ISO-10646-UCS-Basic"},
+      {1002, "csUnicodeASCII"},
+      {1003, "ISO-10646-Unicode-Latin1"},
+      {1003, "ISO-10646"},
+      {1003, "csUnicodeLatin1"},
+      {1004, "ISO-10646-J-1"},
+      {1004, "csUnicodeJapanese"},
+      {1005, "ISO-Unicode-IBM-1261"},
+      {1005, "csUnicodeIBM1261"},
+      {1006, "ISO-Unicode-IBM-1268"},
+      {1006, "csUnicodeIBM1268"},
+      {1007, "ISO-Unicode-IBM-1276"},
+      {1007, "csUnicodeIBM1276"},
+      {1008, "ISO-Unicode-IBM-1264"},
+      {1008, "csUnicodeIBM1264"},
+      {1009, "ISO-Unicode-IBM-1265"},
+      {1009, "csUnicodeIBM1265"},
+      {1010, "UNICODE-1-1"},
+      {1010, "csUnicode11"},
+      {1011, "SCSU"},
+      {1011, "csSCSU"},
+      {1012, "UTF-7"},
+      {1012, "csUTF7"},
+      {1013, "UTF-16BE"},
+      {1013, "csUTF16BE"},
+      {1014, "UTF-16LE"},
+      {1014, "csUTF16LE"},
+      {1015, "UTF-16"},
+      {1015, "csUTF16"},
+      {1016, "CESU-8"},
+      {1016, "csCESU-8"},
+      {1016, "csCESU8"},
+      {1017, "UTF-32"},
+      {1017, "csUTF32"},
+      {1018, "UTF-32BE"},
+      {1018, "csUTF32BE"},
+      {1019, "UTF-32LE"},
+      {1019, "csUTF32LE"},
+      {1020, "BOCU-1"},
+      {1020, "csBOCU-1"},
+      {1020, "csBOCU1"},
+      {1021, "UTF-7-IMAP"},
+      {1021, "csUTF7IMAP"},
+      {2000, "ISO-8859-1-Windows-3.0-Latin-1"},
+      {2000, "csWindows30Latin1"},
+      {2001, "ISO-8859-1-Windows-3.1-Latin-1"},
+      {2001, "csWindows31Latin1"},
+      {2002, "ISO-8859-2-Windows-Latin-2"},
+      {2002, "csWindows31Latin2"},
+      {2003, "ISO-8859-9-Windows-Latin-5"},
+      {2003, "csWindows31Latin5"},
+      {2004, "hp-roman8"},
+      {2004, "csHPRoman8"},
+      {2004, "r8"},
+      {2004, "roman8"},
+      {2005, "Adobe-Standard-Encoding"},
+      {2005, "csAdobeStandardEncoding"},
+      {2006, "Ventura-US"},
+      {2006, "csVenturaUS"},
+      {2007, "Ventura-International"},
+      {2007, "csVenturaInternational"},
+      {2008, "DEC-MCS"},
+      {2008, "csDECMCS"},
+      {2008, "dec"},
+      {2009, "IBM850"},
+      {2009, "850"},
+      {2009, "cp850"},
+      {2009, "csPC850Multilingual"},
+      {2010, "IBM852"},
+      {2010, "852"},
+      {2010, "cp852"},
+      {2010, "csPCp852"},
+      {2011, "IBM437"},
+      {2011, "437"},
+      {2011, "cp437"},
+      {2011, "csPC8CodePage437"},
+      {2012, "PC8-Danish-Norwegian"},
+      {2012, "csPC8DanishNorwegian"},
+      {2013, "IBM862"},
+      {2013, "862"},
+      {2013, "cp862"},
+      {2013, "csPC862LatinHebrew"},
+      {2014, "PC8-Turkish"},
+      {2014, "csPC8Turkish"},
+      {2015, "IBM-Symbols"},
+      {2015, "csIBMSymbols"},
+      {2016, "IBM-Thai"},
+      {2016, "csIBMThai"},
+      {2017, "HP-Legal"},
+      {2017, "csHPLegal"},
+      {2018, "HP-Pi-font"},
+      {2018, "csHPPiFont"},
+      {2019, "HP-Math8"},
+      {2019, "csHPMath8"},
+      {2020, "Adobe-Symbol-Encoding"},
+      {2020, "csHPPSMath"},
+      {2021, "HP-DeskTop"},
+      {2021, "csHPDesktop"},
+      {2022, "Ventura-Math"},
+      {2022, "csVenturaMath"},
+      {2023, "Microsoft-Publishing"},
+      {2023, "csMicrosoftPublishing"},
+      {2024, "Windows-31J"},
+      {2024, "csWindows31J"},
+      {2025, "GB2312"},
+      {2025, "csGB2312"},
+      {2026, "Big5"},
+      {2026, "csBig5"},
+      {2027, "macintosh"},
+      {2027, "csMacintosh"},
+      {2027, "mac"},
+      {2028, "IBM037"},
+      {2028, "cp037"},
+      {2028, "csIBM037"},
+      {2028, "ebcdic-cp-ca"},
+      {2028, "ebcdic-cp-nl"},
+      {2028, "ebcdic-cp-us"},
+      {2028, "ebcdic-cp-wt"},
+      {2029, "IBM038"},
+      {2029, "EBCDIC-INT"},
+      {2029, "cp038"},
+      {2029, "csIBM038"},
+      {2030, "IBM273"},
+      {2030, "CP273"},
+      {2030, "csIBM273"},
+      {2031, "IBM274"},
+      {2031, "CP274"},
+      {2031, "EBCDIC-BE"},
+      {2031, "csIBM274"},
+      {2032, "IBM275"},
+      {2032, "EBCDIC-BR"},
+      {2032, "cp275"},
+      {2032, "csIBM275"},
+      {2033, "IBM277"},
+      {2033, "EBCDIC-CP-DK"},
+      {2033, "EBCDIC-CP-NO"},
+      {2033, "csIBM277"},
+      {2034, "IBM278"},
+      {2034, "CP278"},
+      {2034, "csIBM278"},
+      {2034, "ebcdic-cp-fi"},
+      {2034, "ebcdic-cp-se"},
+      {2035, "IBM280"},
+      {2035, "CP280"},
+      {2035, "csIBM280"},
+      {2035, "ebcdic-cp-it"},
+      {2036, "IBM281"},
+      {2036, "EBCDIC-JP-E"},
+      {2036, "cp281"},
+      {2036, "csIBM281"},
+      {2037, "IBM284"},
+      {2037, "CP284"},
+      {2037, "csIBM284"},
+      {2037, "ebcdic-cp-es"},
+      {2038, "IBM285"},
+      {2038, "CP285"},
+      {2038, "csIBM285"},
+      {2038, "ebcdic-cp-gb"},
+      {2039, "IBM290"},
+      {2039, "EBCDIC-JP-kana"},
+      {2039, "cp290"},
+      {2039, "csIBM290"},
+      {2040, "IBM297"},
+      {2040, "cp297"},
+      {2040, "csIBM297"},
+      {2040, "ebcdic-cp-fr"},
+      {2041, "IBM420"},
+      {2041, "cp420"},
+      {2041, "csIBM420"},
+      {2041, "ebcdic-cp-ar1"},
+      {2042, "IBM423"},
+      {2042, "cp423"},
+      {2042, "csIBM423"},
+      {2042, "ebcdic-cp-gr"},
+      {2043, "IBM424"},
+      {2043, "cp424"},
+      {2043, "csIBM424"},
+      {2043, "ebcdic-cp-he"},
+      {2044, "IBM500"},
+      {2044, "CP500"},
+      {2044, "csIBM500"},
+      {2044, "ebcdic-cp-be"},
+      {2044, "ebcdic-cp-ch"},
+      {2045, "IBM851"},
+      {2045, "851"},
+      {2045, "cp851"},
+      {2045, "csIBM851"},
+      {2046, "IBM855"},
+      {2046, "855"},
+      {2046, "cp855"},
+      {2046, "csIBM855"},
+      {2047, "IBM857"},
+      {2047, "857"},
+      {2047, "cp857"},
+      {2047, "csIBM857"},
+      {2048, "IBM860"},
+      {2048, "860"},
+      {2048, "cp860"},
+      {2048, "csIBM860"},
+      {2049, "IBM861"},
+      {2049, "861"},
+      {2049, "cp-is"},
+      {2049, "cp861"},
+      {2049, "csIBM861"},
+      {2050, "IBM863"},
+      {2050, "863"},
+      {2050, "cp863"},
+      {2050, "csIBM863"},
+      {2051, "IBM864"},
+      {2051, "cp864"},
+      {2051, "csIBM864"},
+      {2052, "IBM865"},
+      {2052, "865"},
+      {2052, "cp865"},
+      {2052, "csIBM865"},
+      {2053, "IBM868"},
+      {2053, "CP868"},
+      {2053, "cp-ar"},
+      {2053, "csIBM868"},
+      {2054, "IBM869"},
+      {2054, "869"},
+      {2054, "cp-gr"},
+      {2054, "cp869"},
+      {2054, "csIBM869"},
+      {2055, "IBM870"},
+      {2055, "CP870"},
+      {2055, "csIBM870"},
+      {2055, "ebcdic-cp-roece"},
+      {2055, "ebcdic-cp-yu"},
+      {2056, "IBM871"},
+      {2056, "CP871"},
+      {2056, "csIBM871"},
+      {2056, "ebcdic-cp-is"},
+      {2057, "IBM880"},
+      {2057, "EBCDIC-Cyrillic"},
+      {2057, "cp880"},
+      {2057, "csIBM880"},
+      {2058, "IBM891"},
+      {2058, "cp891"},
+      {2058, "csIBM891"},
+      {2059, "IBM903"},
+      {2059, "cp903"},
+      {2059, "csIBM903"},
+      {2060, "IBM904"},
+      {2060, "904"},
+      {2060, "cp904"},
+      {2060, "csIBBM904"},
+      {2061, "IBM905"},
+      {2061, "CP905"},
+      {2061, "csIBM905"},
+      {2061, "ebcdic-cp-tr"},
+      {2062, "IBM918"},
+      {2062, "CP918"},
+      {2062, "csIBM918"},
+      {2062, "ebcdic-cp-ar2"},
+      {2063, "IBM1026"},
+      {2063, "CP1026"},
+      {2063, "csIBM1026"},
+      {2064, "EBCDIC-AT-DE"},
+      {2064, "csIBMEBCDICATDE"},
+      {2065, "EBCDIC-AT-DE-A"},
+      {2065, "csEBCDICATDEA"},
+      {2066, "EBCDIC-CA-FR"},
+      {2066, "csEBCDICCAFR"},
+      {2067, "EBCDIC-DK-NO"},
+      {2067, "csEBCDICDKNO"},
+      {2068, "EBCDIC-DK-NO-A"},
+      {2068, "csEBCDICDKNOA"},
+      {2069, "EBCDIC-FI-SE"},
+      {2069, "csEBCDICFISE"},
+      {2070, "EBCDIC-FI-SE-A"},
+      {2070, "csEBCDICFISEA"},
+      {2071, "EBCDIC-FR"},
+      {2071, "csEBCDICFR"},
+      {2072, "EBCDIC-IT"},
+      {2072, "csEBCDICIT"},
+      {2073, "EBCDIC-PT"},
+      {2073, "csEBCDICPT"},
+      {2074, "EBCDIC-ES"},
+      {2074, "csEBCDICES"},
+      {2075, "EBCDIC-ES-A"},
+      {2075, "csEBCDICESA"},
+      {2076, "EBCDIC-ES-S"},
+      {2076, "csEBCDICESS"},
+      {2077, "EBCDIC-UK"},
+      {2077, "csEBCDICUK"},
+      {2078, "EBCDIC-US"},
+      {2078, "csEBCDICUS"},
+      {2079, "UNKNOWN-8BIT"},
+      {2079, "csUnknown8BiT"},
+      {2080, "MNEMONIC"},
+      {2080, "csMnemonic"},
+      {2081, "MNEM"},
+      {2081, "csMnem"},
+      {2082, "VISCII"},
+      {2082, "csVISCII"},
+      {2083, "VIQR"},
+      {2083, "csVIQR"},
+      {2084, "KOI8-R"},
+      {2084, "csKOI8R"},
+      {2085, "HZ-GB-2312"},
+      {2086, "IBM866"},
+      {2086, "866"},
+      {2086, "cp866"},
+      {2086, "csIBM866"},
+      {2087, "IBM775"},
+      {2087, "cp775"},
+      {2087, "csPC775Baltic"},
+      {2088, "KOI8-U"},
+      {2088, "csKOI8U"},
+      {2089, "IBM00858"},
+      {2089, "CCSID00858"},
+      {2089, "CP00858"},
+      {2089, "PC-Multilingual-850+euro"},
+      {2089, "csIBM00858"},
+      {2090, "IBM00924"},
+      {2090, "CCSID00924"},
+      {2090, "CP00924"},
+      {2090, "csIBM00924"},
+      {2090, "ebcdic-Latin9--euro"},
+      {2091, "IBM01140"},
+      {2091, "CCSID01140"},
+      {2091, "CP01140"},
+      {2091, "csIBM01140"},
+      {2091, "ebcdic-us-37+euro"},
+      {2092, "IBM01141"},
+      {2092, "CCSID01141"},
+      {2092, "CP01141"},
+      {2092, "csIBM01141"},
+      {2092, "ebcdic-de-273+euro"},
+      {2093, "IBM01142"},
+      {2093, "CCSID01142"},
+      {2093, "CP01142"},
+      {2093, "csIBM01142"},
+      {2093, "ebcdic-dk-277+euro"},
+      {2093, "ebcdic-no-277+euro"},
+      {2094, "IBM01143"},
+      {2094, "CCSID01143"},
+      {2094, "CP01143"},
+      {2094, "csIBM01143"},
+      {2094, "ebcdic-fi-278+euro"},
+      {2094, "ebcdic-se-278+euro"},
+      {2095, "IBM01144"},
+      {2095, "CCSID01144"},
+      {2095, "CP01144"},
+      {2095, "csIBM01144"},
+      {2095, "ebcdic-it-280+euro"},
+      {2096, "IBM01145"},
+      {2096, "CCSID01145"},
+      {2096, "CP01145"},
+      {2096, "csIBM01145"},
+      {2096, "ebcdic-es-284+euro"},
+      {2097, "IBM01146"},
+      {2097, "CCSID01146"},
+      {2097, "CP01146"},
+      {2097, "csIBM01146"},
+      {2097, "ebcdic-gb-285+euro"},
+      {2098, "IBM01147"},
+      {2098, "CCSID01147"},
+      {2098, "CP01147"},
+      {2098, "csIBM01147"},
+      {2098, "ebcdic-fr-297+euro"},
+      {2099, "IBM01148"},
+      {2099, "CCSID01148"},
+      {2099, "CP01148"},
+      {2099, "csIBM01148"},
+      {2099, "ebcdic-international-500+euro"},
+      {2100, "IBM01149"},
+      {2100, "CCSID01149"},
+      {2100, "CP01149"},
+      {2100, "csIBM01149"},
+      {2100, "ebcdic-is-871+euro"},
+      {2101, "Big5-HKSCS"},
+      {2101, "csBig5HKSCS"},
+      {2102, "IBM1047"},
+      {2102, "IBM-1047"},
+      {2102, "csIBM1047"},
+      {2103, "PTCP154"},
+      {2103, "CP154"},
+      {2103, "Cyrillic-Asian"},
+      {2103, "PT154"},
+      {2103, "csPTCP154"},
+      {2104, "Amiga-1251"},
+      {2104, "Ami-1251"},
+      {2104, "Ami1251"},
+      {2104, "Amiga1251"},
+      {2104, "csAmiga1251"},
+      {2105, "KOI7-switched"},
+      {2105, "csKOI7switched"},
+      {2106, "BRF"},
+      {2106, "csBRF"},
+      {2107, "TSCII"},
+      {2107, "csTSCII"},
+      {2108, "CP51932"},
+      {2108, "csCP51932"},
+      {2109, "windows-874"},
+      {2109, "cswindows874"},
+      {2250, "windows-1250"},
+      {2250, "cswindows1250"},
+      {2251, "windows-1251"},
+      {2251, "cswindows1251"},
+      {2252, "windows-1252"},
+      {2252, "cswindows1252"},
+      {2253, "windows-1253"},
+      {2253, "cswindows1253"},
+      {2254, "windows-1254"},
+      {2254, "cswindows1254"},
+      {2255, "windows-1255"},
+      {2255, "cswindows1255"},
+      {2256, "windows-1256"},
+      {2256, "cswindows1256"},
+      {2257, "windows-1257"},
+      {2257, "cswindows1257"},
+      {2258, "windows-1258"},
+      {2258, "cswindows1258"},
+      {2259, "TIS-620"},
+      {2259, "ISO-8859-11"},
+      {2259, "csTIS620"},
+      {2260, "CP50220"},
+      {2260, "csCP50220"},
+      {0, nullptr} // sentinel
+  };
+
+  const __encoding_data* __encoding_rep_ = __text_encoding_data + 1;
+  char __name_[max_name_length + 1]      = {0};
+};
+
+template <>
+struct hash<text_encoding> {
+  size_t operator()(const text_encoding& __enc) const noexcept { return std::hash<text_encoding::id>()(__enc.mib()); }
+};
+
+namespace ranges {
+
+template <>
+inline constexpr bool enable_borrowed_range<text_encoding::aliases_view> = true;
+
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 26
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP_HAS_LOCALIZATION
+
+#endif // _LIBCPP___TEXT_ENCODING_TEXT_ENCODING_H
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 7f625cefed1c2..a347538620f4d 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2056,6 +2056,13 @@ module std [system] {
     export *
   }
 
+  module text_encoding {
+    module text_encoding { header "__text_encoding/text_encoding.h" }
+
+    header "text_encoding"
+    export *
+  }
+
   module thread {
     module formatter              { header "__thread/formatter.h" }
     module id                     { header "__thread/id.h" }
diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
new file mode 100644
index 0000000000000..579608e4f939d
--- /dev/null
+++ b/libcxx/include/text_encoding
@@ -0,0 +1,68 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_TEXT_ENCODING
+#define _LIBCPP_TEXT_ENCODING
+
+/* text_encoding synopsis 
+namespace std {
+
+struct text_encoding;
+
+// [text.encoding.hash], hash support
+template<class T> struct hash;
+template<> struct hash<text_encoding>;
+
+struct text_encoding 
+{
+    static constexpr size_t max_name_length = 63;
+
+    // [text.encoding.id], enumeration text_encoding​::​id
+    enum class id : int_least32_t {
+      see below
+    };
+    using enum id;
+
+    constexpr text_encoding() = default;
+    constexpr explicit text_encoding(string_view enc) noexcept;
+    constexpr text_encoding(id i) noexcept;
+
+    constexpr id mib() const noexcept;
+    constexpr const char* name() const noexcept;
+
+    // [text.encoding.aliases], class text_encoding​::​aliases_view
+    struct aliases_view;
+    constexpr aliases_view aliases() const noexcept;
+
+    friend constexpr bool operator==(const text_encoding& a,
+                                     const text_encoding& b) noexcept;
+    friend constexpr bool operator==(const text_encoding& encoding, id i) noexcept;
+
+    static consteval text_encoding literal() noexcept;
+    static text_encoding environment();
+    template<id i> static bool environment_is();
+
+  private:
+    id mib_ = id::unknown;                                              // exposition only
+    char name_[max_name_length + 1] = {0};                              // exposition only
+    static constexpr bool comp-name(string_view a, string_view b);      // exposition only
+};
+}
+
+*/
+
+#include <__config>
+
+#if _LIBCPP_STD_VER >= 26
+#    include <__text_encoding/text_encoding.h> 
+#endif // _LIBCPP_STD_VER >= 26
+
+#include <version> 
+
+#endif // _LIBCPP_TEXT_ENCODING 
diff --git a/libcxx/include/version b/libcxx/include/version
index 77d97b93adc6c..3079feac1ed54 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -592,7 +592,7 @@ __cpp_lib_void_t                                        201411L <type_traits>
 # undef  __cpp_lib_string_view
 # define __cpp_lib_string_view                          202403L
 // # define __cpp_lib_submdspan                            202306L
-// # define __cpp_lib_text_encoding                        202306L
+# define __cpp_lib_text_encoding                        202306L
 # undef  __cpp_lib_to_chars
 // # define __cpp_lib_to_chars                             202306L
 // # define __cpp_lib_to_string                            202306L
diff --git a/libcxx/modules/std.compat.cppm.in b/libcxx/modules/std.compat.cppm.in
index 95931447ccdc6..ce9b8bb5ec279 100644
--- a/libcxx/modules/std.compat.cppm.in
+++ b/libcxx/modules/std.compat.cppm.in
@@ -77,9 +77,6 @@ module;
 #  if __has_include(<stdfloat>)
 #    error "please update the header information for <stdfloat> in headers_not_available in utils/libcxx/header_information.py"
 #  endif // __has_include(<stdfloat>)
-#  if __has_include(<text_encoding>)
-#    error "please update the header information for <text_encoding> in headers_not_available in utils/libcxx/header_information.py"
-#  endif // __has_include(<text_encoding>)
 #endif // _WIN32
 
 export module std.compat;
diff --git a/libcxx/modules/std.cppm.in b/libcxx/modules/std.cppm.in
index 5c523691bff4e..6f396e9ccdd90 100644
--- a/libcxx/modules/std.cppm.in
+++ b/libcxx/modules/std.cppm.in
@@ -138,6 +138,9 @@ module;
 #  include <syncstream>
 #endif
 #include <system_error>
+#if _LIBCPP_HAS_LOCALIZATION
+#  include <text_encoding>
+#endif
 #include <thread>
 #include <tuple>
 #include <type_traits>
@@ -187,9 +190,6 @@ module;
 #  if __has_include(<stdfloat>)
 #    error "please update the header information for <stdfloat> in headers_not_available in utils/libcxx/header_information.py"
 #  endif // __has_include(<stdfloat>)
-#  if __has_include(<text_encoding>)
-#    error "please update the header information for <text_encoding> in headers_not_available in utils/libcxx/header_information.py"
-#  endif // __has_include(<text_encoding>)
 #endif // _WIN32
 
 export module std;
diff --git a/libcxx/modules/std/text_encoding.inc b/libcxx/modules/std/text_encoding.inc
index 6d5e3f1d68c60..23dd71965414c 100644
--- a/libcxx/modules/std/text_encoding.inc
+++ b/libcxx/modules/std/text_encoding.inc
@@ -8,12 +8,9 @@
 //===----------------------------------------------------------------------===//
 
 export namespace std {
-#if 0
-#  if _LIBCPP_STD_VER >= 23
+#if _LIBCPP_STD_VER >= 26
+  using ::std::hash;
   using std::text_encoding;
-
-  // hash support
-  using std::hash;
-#  endif // _LIBCPP_STD_VER >= 23
+  using ::std::ranges::enable_borrowed_range;
 #endif
 } // namespace std
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 4e9bf900af4c5..1a98812894896 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -92,6 +92,7 @@ if (LIBCXX_ENABLE_LOCALIZATION)
     ostream.cpp
     regex.cpp
     strstream.cpp
+    text_encoding.cpp
     )
 endif()
 
diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp
index d981d137cf1ba..6d8dababb84ce 100644
--- a/libcxx/src/locale.cpp
+++ b/libcxx/src/locale.cpp
@@ -558,6 +558,19 @@ locale::locale(const locale& other, const locale& one, category c)
 
 string locale::name() const { return __locale_->name(); }
 
+#  if _LIBCPP_STD_VER >= 26 && __CHAR_BIT__ == 8
+  text_encoding locale::encoding() const {
+    std::string __name = this->name();
+    if(__name.size() == 1){
+      if(__name[0] == 'C')
+        return std::text_encoding(text_encoding::id::ASCII);
+      if(__name[0] == '*')
+        return std::text_encoding();
+    }
+    return std::text_encoding(__name);
+  }
+#  endif // _LIBCPP_STD_VER >= 26
+
 void locale::__install_ctor(const locale& other, facet* f, long facet_id) {
   if (f)
     __locale_ = new __imp(*other.__locale_, f, facet_id);
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
new file mode 100644
index 0000000000000..42812aaed49c7
--- /dev/null
+++ b/libcxx/src/text_encoding.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <__config> 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#include <__locale_dir/locale_base_api.h>
+
+#include <text_encoding> 
+
+#if __has_include(<langinfo.h>)
+#  include <langinfo.h>
+#endif
+
+#if _LIBCPP_STD_VER >= 26 
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+#if __CHAR_BIT__ == 8
+
+text_encoding text_encoding::environment() {
+    auto __make_locale = [](const char* __name) {
+      text_encoding __enc{};
+      if (auto __loc = __locale::__newlocale(LC_CTYPE_MASK, __name, static_cast<locale_t>(0))) {
+        if (const char* __codeset = nl_langinfo_l(CODESET, __loc)) {
+          string_view __s(__codeset);
+          if (__s.size() < max_name_length)
+            __enc = text_encoding(__s);
+        }
+        __locale::__freelocale(__loc);
+      }
+      return __enc;
+    };
+
+    return __make_locale("");
+  }
+
+# endif  // __CHAR_BIT__ == 8
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER > 26
diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index ce8f0261f2b27..24e57ab696857 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -1065,6 +1065,21 @@ system_error string
 system_error string_view
 system_error tuple
 system_error version
+text_encoding cctype
+text_encoding clocale
+text_encoding compare
+text_encoding cstdint
+text_encoding cstdio
+text_encoding cstdlib
+text_encoding cstring
+text_encoding cwchar
+text_encoding cwctype
+text_encoding initializer_list
+text_encoding iosfwd
+text_encoding limits
+text_encoding stdexcept
+text_encoding string_view
+text_encoding version
 thread array
 thread atomic
 thread bitset
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/text_encoding.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/text_encoding.version.compile.pass.cpp
new file mode 100644
index 0000000000000..817b0f0d655db
--- /dev/null
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/text_encoding.version.compile.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// WARNING: This test was generated by generate_feature_test_macro_components.py
+// and should not be edited manually.
+
+// <text_encoding>
+
+// Test the feature test macros defined by <text_encoding>
+
+// clang-format off
+
+#include <text_encoding>
+#include "test_macros.h"
+
+#if TEST_STD_VER < 14
+
+#  ifdef __cpp_lib_text_encoding
+#    error "__cpp_lib_text_encoding should not be defined before c++26"
+#  endif
+
+#elif TEST_STD_VER == 14
+
+#  ifdef __cpp_lib_text_encoding
+#    error "__cpp_lib_text_encoding should not be defined before c++26"
+#  endif
+
+#elif TEST_STD_VER == 17
+
+#  ifdef __cpp_lib_text_encoding
+#    error "__cpp_lib_text_encoding should not be defined before c++26"
+#  endif
+
+#elif TEST_STD_VER == 20
+
+#  ifdef __cpp_lib_text_encoding
+#    error "__cpp_lib_text_encoding should not be defined before c++26"
+#  endif
+
+#elif TEST_STD_VER == 23
+
+#  ifdef __cpp_lib_text_encoding
+#    error "__cpp_lib_text_encoding should not be defined before c++26"
+#  endif
+
+#elif TEST_STD_VER > 23
+
+#  ifndef __cpp_lib_text_encoding
+#    error "__cpp_lib_text_encoding should be defined in c++26"
+#  endif
+#  if __cpp_lib_text_encoding != 202306L
+#    error "__cpp_lib_text_encoding should have the value 202306L in c++26"
+#  endif
+
+#endif // TEST_STD_VER > 23
+
+// clang-format on
+
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
index aa33a2788f1eb..ffcaeb4904b60 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
@@ -7852,17 +7852,11 @@
 #    endif
 #  endif
 
-#  if !defined(_LIBCPP_VERSION)
-#    ifndef __cpp_lib_text_encoding
-#      error "__cpp_lib_text_encoding should be defined in c++26"
-#    endif
-#    if __cpp_lib_text_encoding != 202306L
-#      error "__cpp_lib_text_encoding should have the value 202306L in c++26"
-#    endif
-#  else
-#    ifdef __cpp_lib_text_encoding
-#      error "__cpp_lib_text_encoding should not be defined because it is unimplemented in libc++!"
-#    endif
+#  ifndef __cpp_lib_text_encoding
+#    error "__cpp_lib_text_encoding should be defined in c++26"
+#  endif
+#  if __cpp_lib_text_encoding != 202306L
+#    error "__cpp_lib_text_encoding should have the value 202306L in c++26"
 #  endif
 
 #  ifndef __cpp_lib_three_way_comparison
diff --git a/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
new file mode 100644
index 0000000000000..7ebfb5a0b4f74
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
@@ -0,0 +1,56 @@
+
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// libc++ not built with C++26 yet
+// XFAIL: * 
+// REQUIRES: std-at-least-c++26
+// REQUIRES: locale.en_US.UTF-8
+// UNSUPPORTED: no-localization
+
+// class locale
+
+// text_encoding encoding() const
+
+// Concerns:
+// 1. Default locale returns a text_encoding representing "ASCII"
+// 2. Locale built with en_US.UTF-8 returns text_encoding representing "UTF-8"
+
+#include <cassert>
+#include <locale>
+#include <text_encoding>
+
+#include "test_macros.h"
+#include "platform_support.h"
+
+using id = std::text_encoding::id;
+
+int main() {
+
+  {
+    std::locale loc;
+
+    auto te = loc.encoding(); 
+    auto classicTE = std::text_encoding(id::ASCII);
+    assert(te == id::ASCII);
+    assert(te == classicTE);
+  }
+
+  {
+    std::locale utf8Locale(LOCALE_en_US_UTF_8);
+
+    auto te = utf8Locale.encoding();
+    auto utf8TE = std::text_encoding(id::UTF8);
+    assert(te == id::UTF8);
+    assert(te == utf8TE);
+  }
+
+  return 0; 
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/default.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/default.pass.cpp
new file mode 100644
index 0000000000000..62c30d7295491
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/default.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding::text_encoding() noexcept
+
+// Concerns:
+// 1. Default constructor must be nothrow
+// 2. Default constructing a text_encoding object makes it so that mib() == id::unknown, and its name is empty
+
+#include <cassert>
+#include <cstring>
+#include <text_encoding>
+#include <type_traits>
+
+int main(int, char**) {
+  {
+    static_assert(
+        std::is_nothrow_default_constructible<std::text_encoding>::value, "Must be nothrow default constructible");
+  }
+
+  {
+    auto te = std::text_encoding();
+    assert(te.mib() == std::text_encoding::id::unknown);
+    assert(strcmp(te.name(), "") == 0);
+  }
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/id.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/id.pass.cpp
new file mode 100644
index 0000000000000..6562971c73dbb
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/id.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding::text_encoding(id) noexcept
+
+// Concerns:
+// 1. text_encoding(id) must be nothrow
+// 2. Constructing an object with a valid id must set mib() and the name to the corresponding value.
+// 3. Constructing an object using id::unknown must set mib() to id::unknown and the name to an empty string.
+// 4. Constructing an object using id::other must set mib() to id::other and the name to an empty string.
+
+#include "test_text_encoding.h"
+#include <cassert>
+#include <string_view>
+#include <text_encoding>
+#include <type_traits>
+
+using te_id = std::text_encoding::id;
+
+constexpr void test_ctor(te_id i, te_id expect_id, std::string_view expect_name) {
+  auto te = std::text_encoding(i);
+  assert(te.mib() == expect_id);
+  assert(expect_name.compare(te.name()) == 0);
+}
+
+int main() {
+  {
+    static_assert(std::is_nothrow_constructible<std::text_encoding, std::text_encoding::id>::value,
+                  "Must be nothrow constructible with id");
+  }
+  
+  {
+    for (auto pair : unique_encoding_data){
+      test_ctor(te_id{pair.mib}, te_id{pair.mib}, pair.name);
+    }
+  }
+
+  {
+    for(int i = 2261; i < 2300; i++){ // test out of range id values
+      test_ctor(te_id{i}, te_id::unknown, "");
+    }
+  }
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/string_view.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/string_view.pass.cpp
new file mode 100644
index 0000000000000..b72adf0274cb2
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/string_view.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding::text_encoding(string_view) noexcept
+
+#include "test_macros.h"
+#include "test_text_encoding.h"
+#include <cassert>
+#include <cstring>
+#include <string_view>
+#include <text_encoding>
+#include <type_traits>
+
+constexpr void test_ctor(std::string_view str, std::string_view expect, std::text_encoding::id expect_id) {
+  auto te = std::text_encoding(str);
+  assert(te.mib() == expect_id);
+  assert(expect.compare(te.name()) == 0);
+}
+
+void test_correct_encoding_spellings() {
+  for (auto pair : unique_encoding_data) {
+    test_ctor(pair.name, pair.name, std::text_encoding::id{pair.mib});
+  }
+}
+
+int main() {
+  {
+    static_assert(std::is_nothrow_constructible<std::text_encoding, std::string_view>::value,
+                  "Must be nothrow constructible with string_view");
+  }
+
+  // happy paths
+  {
+    test_correct_encoding_spellings();
+  }
+
+  {
+    test_ctor("U_T_F-8", "U_T_F-8", std::text_encoding::UTF8);
+  }
+
+  {
+    test_ctor("utf8", "utf8", std::text_encoding::UTF8);
+  }
+
+  {
+    test_ctor("u.t.f-008", "u.t.f-008", std::text_encoding::UTF8);
+  }
+
+  {
+    test_ctor("utf-80", "utf-80", std::text_encoding::other);
+  }
+
+  {
+    test_ctor("iso885931988", "iso885931988", std::text_encoding::ISOLatin3);
+  }
+
+  {
+    test_ctor("iso00885931988", "iso00885931988", std::text_encoding::ISOLatin3);
+  }
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.id.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.id.pass.cpp
new file mode 100644
index 0000000000000..30ce1badec1d7
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.id.pass.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding operator==(const text_encoding&, id) _NOEXCEPT 
+
+// Concerns:
+// 1. operator==(const text_encoding&, id) must be noexcept
+// 2. operator==(const text_encoding&, id) returns true if mib() is equal to the id
+// 3. operator==(const text_encoding&, id) returns false if mib() is not equal to the id
+
+#include <cassert>
+#include <text_encoding>
+#include <type_traits>
+
+#include "test_macros.h"
+#include "test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+int main() {
+
+  { // 1
+    auto te = std::text_encoding();
+    ASSERT_NOEXCEPT(te == id::UTF8);
+  }
+
+  { // 2
+    auto te = std::text_encoding(id::UTF8);
+    assert(te == id::UTF8);
+  }
+
+  { // 2.0.1
+    constexpr auto te = std::text_encoding();
+    static_assert(te == id::unknown);
+  }
+
+  { // 2.1
+    auto te = std::text_encoding(id::other);
+    assert(te == id::other);
+  }
+
+  { // 2.1.1
+    constexpr auto te = std::text_encoding(id::other);
+    static_assert(te == id::other);
+  }
+
+  { // 3
+    auto te = std::text_encoding(id::UTF8);
+    assert(!(te == id::UTF16));
+  }
+
+  { // 3
+    constexpr auto te = std::text_encoding(id::UTF8);
+    static_assert(!(te == id::UTF16));
+  }
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.pass.cpp
new file mode 100644
index 0000000000000..81fdb0a681143
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding operator==(const text_encoding&, const text_encoding&) _NOEXCEPT 
+
+// Concerns:
+// 1. operator==(const text_encoding&, const text_encoding&) must be noexcept
+// 2. operator==(const text_encoding&, const text_encoding&) returns true if both text_encoding ids are equal
+// 3. operator==(const text_encoding&, const text_encoding&) for text_encodings with ids of "other" return true if the names are equal
+// 4. operator==(const text_encoding&, const text_encoding&) returns false when comparingtext_encodings with different ids
+// 5. operator==(const text_encoding&, const text_encoding&) for text_encodings with ids of "other" returns false if the names are not equal
+
+#include <cassert>
+#include <text_encoding>
+#include <type_traits>
+
+#include "test_macros.h"
+#include "test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+int main(){
+  
+  { // 1
+    auto te1 = std::text_encoding();
+    auto te2 = std::text_encoding();
+    ASSERT_NOEXCEPT(te1 == te2);
+  }
+
+  { // 2
+    auto te1 = std::text_encoding(id::UTF8);
+    auto te2 = std::text_encoding(id::UTF8);
+    assert(te1 == te2);
+  }
+
+  { // 3
+    auto other_te1 = std::text_encoding("foo");
+    auto other_te2 = std::text_encoding("foo");
+    assert(other_te1 == other_te2);
+  }
+
+  { // 4
+    auto te1 = std::text_encoding(id::UTF8);
+    auto te2 = std::text_encoding(id::UTF16);
+    assert(!(te1 == te2));
+  }
+
+  { // 5
+    auto other_te1 = std::text_encoding("foo");
+    auto other_te2 = std::text_encoding("bar");
+    assert(!(other_te1 == other_te2));
+  }
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases.pass.cpp
new file mode 100644
index 0000000000000..345438d6a1ecb
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding text_encoding::environment(); 
+
+// Concerns:
+// 1. Verify that text_encoding::aliases_view satisfies ranges::forward_range, copyable, view, 
+//    ranges::random_access_range and ranges::borrowed_range
+
+#include <concepts>
+#include <ranges>
+#include <text_encoding>
+#include <type_traits>
+
+#include "platform_support.h" 
+#include "test_macros.h"
+#include "test_text_encoding.h"
+
+int main(){
+  static_assert(std::ranges::forward_range<std::text_encoding::aliases_view>);
+  static_assert(std::copyable<std::text_encoding::aliases_view>);
+  static_assert(std::ranges::view<std::text_encoding::aliases_view>);
+  static_assert(std::ranges::random_access_range<std::text_encoding::aliases_view>);
+  static_assert(std::ranges::borrowed_range<std::text_encoding::aliases_view>);
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/environment.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/environment.pass.cpp
new file mode 100644
index 0000000000000..c0412d4d39ee1
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/environment.pass.cpp
@@ -0,0 +1,83 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+// REQUIRES: locale.en_US.UTF-8
+
+// UNSUPPORTED: no-localization
+// UNSUPPORTED: windows
+
+// libc++ is not built with C++26, and the implementation for this function is in a source file.
+// XFAIL: * 
+
+// class text_encoding
+
+// text_encoding text_encoding::environment(); 
+
+// Concerns:
+// 1. text_encoding::environment() returns the encoding for the "C" locale, which should be the default for any C++ program.
+// 2. text_encoding::environment() still returns the "C" locale encoding when the locale is set to "en_US.UTF-8".
+// 3. text_encoding::environment() is affected by changes to the "LANG" environment variable. 
+
+// The current implementation of text_encoding::environment() while conformant, 
+// is unfortunately affected by changes to the "LANG" environment variable.
+
+#include <cassert>
+#include <clocale>
+#include <cstdlib>
+#include <string_view>
+#include <text_encoding>
+
+#include "platform_support.h" 
+#include "test_macros.h"
+#include "test_text_encoding.h"
+
+int main() {
+
+  { // 1
+    auto te = std::text_encoding::environment(); 
+
+    assert(te == std::text_encoding::environment());
+    assert(te.mib() == std::text_encoding::id::ASCII);
+    assert(te == std::text_encoding::id::ASCII);
+    assert(std::string_view(te.name()) == "ANSI_X3.4-1968");
+    assert(te == std::text_encoding("ANSI_X3.4-1968"));
+
+    assert(std::text_encoding::environment_is<std::text_encoding::id::ASCII>());
+  }
+
+  { // 2
+    std::setlocale(LC_ALL, "en_US.UTF-8");
+
+    auto te = std::text_encoding::environment();
+
+    assert(te == std::text_encoding::environment());
+    assert(te.mib() == std::text_encoding::id::ASCII);
+    assert(std::string_view(te.name()) == "ANSI_X3.4-1968");
+    assert(te == std::text_encoding("ANSI_X3.4-1968"));
+
+    assert(std::text_encoding::environment_is<std::text_encoding::id::ASCII>());
+  }
+
+  { // 3
+    setenv("LANG", LOCALE_en_US_UTF_8, 1);
+    
+    auto te = std::text_encoding::environment();
+
+    assert(te == std::text_encoding::environment());
+    assert(te.mib() == std::text_encoding::id::UTF8);
+    assert(std::string_view(te.name()) == "UTF-8");
+    assert(te == std::text_encoding("UTF-8"));
+
+    assert(std::text_encoding::environment_is<std::text_encoding::id::UTF8>());
+  }
+  
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/literal.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/literal.pass.cpp
new file mode 100644
index 0000000000000..200f9630de580
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/literal.pass.cpp
@@ -0,0 +1,49 @@
+
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding text_encoding::literal() noexcept;
+
+// Concerns:
+// 1. text_encoding::literal() returns the proper encoding depending on the compiler, else unknown.
+
+#include <cassert>
+#include <text_encoding>
+#include <type_traits>
+#include <string_view>
+
+#include "test_macros.h"
+#include "test_text_encoding.h"
+
+int main() {
+#if __CHAR_BIT__ == 8
+ 
+  {
+    auto te = std::text_encoding::literal();
+#  ifdef __GNUC_EXECUTION_CHARSET_NAME
+    assert(std::string_view(te.name()) == std::string_view(__GNUC_EXECUTION_CHARSET_NAME));
+#  elif defined(__clang_literal_encoding__)
+    assert(std::string_view(te.name()) == std::string_view(__clang_literal_encoding__));
+#  elif defined(__clang__)
+    assert(std::string_view(te.name()) == "UTF-8");
+    assert(te.mib() == std::text_encoding::id::UTF8);
+#  else
+    assert(te.mib() = std::text_encoding::id::unknown);
+#  endif
+  }
+
+#endif // if __CHAR_BIT__ == 8
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/begin.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/begin.pass.cpp
new file mode 100644
index 0000000000000..61c148f854813
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/begin.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding text_encoding::environment(); 
+
+// Concerns:
+// 1. begin() of an aliases_view() from a single text_encoding object are the same.
+// 2. begin() of aliases_views of two text_encoding objects that represent the same ID but hold different names are the same.
+// 3. begin() of aliases_views of two text_encoding objects that represent different IDs are different.  
+
+#include <cassert>
+#include <cstdlib>
+#include <text_encoding>
+#include <ranges>
+
+#include "platform_support.h" 
+#include "test_macros.h"
+#include "test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+int main() {
+
+  {
+    auto te = std::text_encoding(id::UTF8);
+    auto view1 = te.aliases();
+    auto view2 = te.aliases();
+    
+    assert(std::ranges::begin(view1) == std::ranges::begin(view2)); 
+  }
+
+  {
+    auto te1 = std::text_encoding("ANSI_X3.4-1968");
+    auto te2 = std::text_encoding("ANSI_X3.4-1986");
+
+    auto view1 = te1.aliases(); 
+    auto view2 = te2.aliases();
+
+    assert(std::ranges::begin(view1) == std::ranges::begin(view2));
+  }
+
+  {
+    
+    auto te1 = std::text_encoding(id::UTF8);
+    auto te2 = std::text_encoding(id::ASCII);
+    
+    auto view1 = te1.aliases();
+    auto view2 = te2.aliases();
+
+    assert(!(std::ranges::begin(view1) == std::ranges::begin(view2)));
+  }
+
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/empty.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/empty.pass.cpp
new file mode 100644
index 0000000000000..253a060dc0961
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/empty.pass.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding text_encoding::environment(); 
+
+// Concerns:
+// 1. An alias_view of a text_encoding object for "other" is empty
+// 2. An alias_view of a text_encoding object for "unknown" is empty
+// 3. An alias_view of a text_encoding object for a known encoding e.g. "UTF-8" is not empty
+
+#include <cassert>
+#include <cstdlib>
+#include <ranges>
+#include <text_encoding>
+
+#include "platform_support.h" 
+#include "test_macros.h"
+#include "test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+int main(){
+
+  {
+    auto te = std::text_encoding(id::other);
+    auto empty_range = te.aliases();
+    
+    assert(std::ranges::empty(empty_range));
+    assert(empty_range.empty());
+    assert(!bool(empty_range));
+  }
+
+  {
+    auto te = std::text_encoding(id::unknown);
+    auto empty_range = te.aliases();
+
+    assert(std::ranges::empty(empty_range));
+    assert(empty_range.empty());
+    assert(!bool(empty_range));
+  }
+
+  {
+    auto te = std::text_encoding(id::UTF8);
+    auto range = te.aliases();
+
+    assert(!std::ranges::empty(range));
+    assert(!range.empty());
+    assert(bool(range));
+  }
+
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/front.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/front.pass.cpp
new file mode 100644
index 0000000000000..fb9f80247b1ac
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/front.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// class text_encoding
+
+// text_encoding text_encoding::environment(); 
+
+// Concerns:
+// 1. An aliases_view from a single text_encoding object returns the same front()
+// 2. An aliases_views of two text_encoding objects that represent the same ID but hold different names return the same front()
+// 3. An aliases_views of two text_encoding objects that represent different IDs return different front() 
+
+#include <cassert>
+#include <cstdlib>
+#include <text_encoding>
+
+#include "platform_support.h" 
+#include "test_macros.h"
+#include "test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+int main() {
+
+  {
+    auto te = std::text_encoding(id::UTF8);
+  
+    auto view1 = te.aliases();
+    auto view2 = te.aliases();
+  
+    assert(view1.front() == view2.front());
+  }
+
+  {
+    auto te1 = std::text_encoding("ANSI_X3.4-1968");
+    auto te2 = std::text_encoding("ANSI_X3.4-1986");
+
+    auto view1 = te1.aliases(); 
+    auto view2 = te2.aliases();
+
+    assert(view1.front() == view2.front());
+  }
+
+  {
+    
+    auto te1 = std::text_encoding(id::UTF8);
+    auto te2 = std::text_encoding(id::ASCII);
+    
+    auto view1 = te1.aliases();
+    auto view2 = te2.aliases();
+
+    assert(!(view1.front() == view2.front()));
+  }
+
+}
diff --git a/libcxx/test/support/test_text_encoding.h b/libcxx/test/support/test_text_encoding.h
new file mode 100644
index 0000000000000..460a259722f0d
--- /dev/null
+++ b/libcxx/test/support/test_text_encoding.h
@@ -0,0 +1,1173 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SUPPORT_TEST_TEXT_ENCODING_H
+#define SUPPORT_TEST_TEXT_ENCODING_H
+
+#include "test_macros.h"
+#include <cstdint>
+
+struct encoding_pair {
+  int_least32_t mib;
+  const char* name;
+};
+
+constexpr encoding_pair all_encoding_data[] = {
+    {1, ""},
+    {2, ""},
+    {3, "ANSI_X3.4-1968"},
+    {3, "ANSI_X3.4-1986"},
+    {3, "IBM367"},
+    {3, "ISO646-US"},
+    {3, "ISO_646.irv:1991"},
+    {3, "cp367"},
+    {3, "csASCII"},
+    {3, "iso-ir-6"},
+    {3, "us"},
+    {4, "ISO-8859-1"},
+    {4, "ISO_8859-1:1987"},
+    {4, "CP819"},
+    {4, "IBM819"},
+    {4, "ISO_8859-1"},
+    {4, "csISOLatin1"},
+    {4, "iso-ir-100"},
+    {4, "l1"},
+    {4, "latin1"},
+    {5, "ISO-8859-2"},
+    {5, "ISO_8859-2:1987"},
+    {5, "ISO_8859-2"},
+    {5, "csISOLatin2"},
+    {5, "iso-ir-101"},
+    {5, "l2"},
+    {5, "latin2"},
+    {6, "ISO-8859-3"},
+    {6, "ISO_8859-3:1988"},
+    {6, "ISO_8859-3"},
+    {6, "csISOLatin3"},
+    {6, "iso-ir-109"},
+    {6, "l3"},
+    {6, "latin3"},
+    {7, "ISO-8859-4"},
+    {7, "ISO_8859-4:1988"},
+    {7, "ISO_8859-4"},
+    {7, "csISOLatin4"},
+    {7, "iso-ir-110"},
+    {7, "l4"},
+    {7, "latin4"},
+    {8, "ISO-8859-5"},
+    {8, "ISO_8859-5:1988"},
+    {8, "ISO_8859-5"},
+    {8, "csISOLatinCyrillic"},
+    {8, "cyrillic"},
+    {8, "iso-ir-144"},
+    {9, "ISO-8859-6"},
+    {9, "ISO_8859-6:1987"},
+    {9, "ASMO-708"},
+    {9, "ECMA-114"},
+    {9, "ISO_8859-6"},
+    {9, "arabic"},
+    {9, "csISOLatinArabic"},
+    {9, "iso-ir-127"},
+    {10, "ISO-8859-7"},
+    {10, "ISO_8859-7:1987"},
+    {10, "ECMA-118"},
+    {10, "ELOT_928"},
+    {10, "ISO_8859-7"},
+    {10, "csISOLatinGreek"},
+    {10, "greek"},
+    {10, "greek8"},
+    {10, "iso-ir-126"},
+    {11, "ISO-8859-8"},
+    {11, "ISO_8859-8:1988"},
+    {11, "ISO_8859-8"},
+    {11, "csISOLatinHebrew"},
+    {11, "hebrew"},
+    {11, "iso-ir-138"},
+    {12, "ISO-8859-9"},
+    {12, "ISO_8859-9:1989"},
+    {12, "ISO_8859-9"},
+    {12, "csISOLatin5"},
+    {12, "iso-ir-148"},
+    {12, "l5"},
+    {12, "latin5"},
+    {13, "ISO-8859-10"},
+    {13, "ISO_8859-10:1992"},
+    {13, "csISOLatin6"},
+    {13, "iso-ir-157"},
+    {13, "l6"},
+    {13, "latin6"},
+    {14, "ISO_6937-2-add"},
+    {14, "csISOTextComm"},
+    {14, "iso-ir-142"},
+    {15, "JIS_X0201"},
+    {15, "X0201"},
+    {15, "csHalfWidthKatakana"},
+    {16, "JIS_Encoding"},
+    {16, "csJISEncoding"},
+    {17, "Shift_JIS"},
+    {17, "MS_Kanji"},
+    {17, "csShiftJIS"},
+    {18, "EUC-JP"},
+    {18, "Extended_UNIX_Code_Packed_Format_for_Japanese"},
+    {18, "csEUCPkdFmtJapanese"},
+    {19, "Extended_UNIX_Code_Fixed_Width_for_Japanese"},
+    {19, "csEUCFixWidJapanese"},
+    {20, "BS_4730"},
+    {20, "ISO646-GB"},
+    {20, "csISO4UnitedKingdom"},
+    {20, "gb"},
+    {20, "iso-ir-4"},
+    {20, "uk"},
+    {21, "SEN_850200_C"},
+    {21, "ISO646-SE2"},
+    {21, "csISO11SwedishForNames"},
+    {21, "iso-ir-11"},
+    {21, "se2"},
+    {22, "IT"},
+    {22, "ISO646-IT"},
+    {22, "csISO15Italian"},
+    {22, "iso-ir-15"},
+    {23, "ES"},
+    {23, "ISO646-ES"},
+    {23, "csISO17Spanish"},
+    {23, "iso-ir-17"},
+    {24, "DIN_66003"},
+    {24, "ISO646-DE"},
+    {24, "csISO21German"},
+    {24, "de"},
+    {24, "iso-ir-21"},
+    {25, "NS_4551-1"},
+    {25, "ISO646-NO"},
+    {25, "csISO60DanishNorwegian"},
+    {25, "csISO60Norwegian1"},
+    {25, "iso-ir-60"},
+    {25, "no"},
+    {26, "NF_Z_62-010"},
+    {26, "ISO646-FR"},
+    {26, "csISO69French"},
+    {26, "fr"},
+    {26, "iso-ir-69"},
+    {27, "ISO-10646-UTF-1"},
+    {27, "csISO10646UTF1"},
+    {28, "ISO_646.basic:1983"},
+    {28, "csISO646basic1983"},
+    {28, "ref"},
+    {29, "INVARIANT"},
+    {29, "csINVARIANT"},
+    {30, "ISO_646.irv:1983"},
+    {30, "csISO2IntlRefVersion"},
+    {30, "irv"},
+    {30, "iso-ir-2"},
+    {31, "NATS-SEFI"},
+    {31, "csNATSSEFI"},
+    {31, "iso-ir-8-1"},
+    {32, "NATS-SEFI-ADD"},
+    {32, "csNATSSEFIADD"},
+    {32, "iso-ir-8-2"},
+    {33, "NATS-DANO"},
+    {33, "csNATSDANO"},
+    {33, "iso-ir-9-1"},
+    {34, "NATS-DANO-ADD"},
+    {34, "csNATSDANOADD"},
+    {34, "iso-ir-9-2"},
+    {35, "SEN_850200_B"},
+    {35, "FI"},
+    {35, "ISO646-FI"},
+    {35, "ISO646-SE"},
+    {35, "csISO10Swedish"},
+    {35, "iso-ir-10"},
+    {35, "se"},
+    {36, "KS_C_5601-1987"},
+    {36, "KSC_5601"},
+    {36, "KS_C_5601-1989"},
+    {36, "csKSC56011987"},
+    {36, "iso-ir-149"},
+    {36, "korean"},
+    {37, "ISO-2022-KR"},
+    {37, "csISO2022KR"},
+    {38, "EUC-KR"},
+    {38, "csEUCKR"},
+    {39, "ISO-2022-JP"},
+    {39, "csISO2022JP"},
+    {40, "ISO-2022-JP-2"},
+    {40, "csISO2022JP2"},
+    {41, "JIS_C6220-1969-jp"},
+    {41, "JIS_C6220-1969"},
+    {41, "csISO13JISC6220jp"},
+    {41, "iso-ir-13"},
+    {41, "katakana"},
+    {41, "x0201-7"},
+    {42, "JIS_C6220-1969-ro"},
+    {42, "ISO646-JP"},
+    {42, "csISO14JISC6220ro"},
+    {42, "iso-ir-14"},
+    {42, "jp"},
+    {43, "PT"},
+    {43, "ISO646-PT"},
+    {43, "csISO16Portuguese"},
+    {43, "iso-ir-16"},
+    {44, "greek7-old"},
+    {44, "csISO18Greek7Old"},
+    {44, "iso-ir-18"},
+    {45, "latin-greek"},
+    {45, "csISO19LatinGreek"},
+    {45, "iso-ir-19"},
+    {46, "NF_Z_62-010_(1973)"},
+    {46, "ISO646-FR1"},
+    {46, "csISO25French"},
+    {46, "iso-ir-25"},
+    {47, "Latin-greek-1"},
+    {47, "csISO27LatinGreek1"},
+    {47, "iso-ir-27"},
+    {48, "ISO_5427"},
+    {48, "csISO5427Cyrillic"},
+    {48, "iso-ir-37"},
+    {49, "JIS_C6226-1978"},
+    {49, "csISO42JISC62261978"},
+    {49, "iso-ir-42"},
+    {50, "BS_viewdata"},
+    {50, "csISO47BSViewdata"},
+    {50, "iso-ir-47"},
+    {51, "INIS"},
+    {51, "csISO49INIS"},
+    {51, "iso-ir-49"},
+    {52, "INIS-8"},
+    {52, "csISO50INIS8"},
+    {52, "iso-ir-50"},
+    {53, "INIS-cyrillic"},
+    {53, "csISO51INISCyrillic"},
+    {53, "iso-ir-51"},
+    {54, "ISO_5427:1981"},
+    {54, "ISO5427Cyrillic1981"},
+    {54, "csISO54271981"},
+    {54, "iso-ir-54"},
+    {55, "ISO_5428:1980"},
+    {55, "csISO5428Greek"},
+    {55, "iso-ir-55"},
+    {56, "GB_1988-80"},
+    {56, "ISO646-CN"},
+    {56, "cn"},
+    {56, "csISO57GB1988"},
+    {56, "iso-ir-57"},
+    {57, "GB_2312-80"},
+    {57, "chinese"},
+    {57, "csISO58GB231280"},
+    {57, "iso-ir-58"},
+    {58, "NS_4551-2"},
+    {58, "ISO646-NO2"},
+    {58, "csISO61Norwegian2"},
+    {58, "iso-ir-61"},
+    {58, "no2"},
+    {59, "videotex-suppl"},
+    {59, "csISO70VideotexSupp1"},
+    {59, "iso-ir-70"},
+    {60, "PT2"},
+    {60, "ISO646-PT2"},
+    {60, "csISO84Portuguese2"},
+    {60, "iso-ir-84"},
+    {61, "ES2"},
+    {61, "ISO646-ES2"},
+    {61, "csISO85Spanish2"},
+    {61, "iso-ir-85"},
+    {62, "MSZ_7795.3"},
+    {62, "ISO646-HU"},
+    {62, "csISO86Hungarian"},
+    {62, "hu"},
+    {62, "iso-ir-86"},
+    {63, "JIS_C6226-1983"},
+    {63, "JIS_X0208-1983"},
+    {63, "csISO87JISX0208"},
+    {63, "iso-ir-87"},
+    {63, "x0208"},
+    {64, "greek7"},
+    {64, "csISO88Greek7"},
+    {64, "iso-ir-88"},
+    {65, "ASMO_449"},
+    {65, "ISO_9036"},
+    {65, "arabic7"},
+    {65, "csISO89ASMO449"},
+    {65, "iso-ir-89"},
+    {66, "iso-ir-90"},
+    {66, "csISO90"},
+    {67, "JIS_C6229-1984-a"},
+    {67, "csISO91JISC62291984a"},
+    {67, "iso-ir-91"},
+    {67, "jp-ocr-a"},
+    {68, "JIS_C6229-1984-b"},
+    {68, "ISO646-JP-OCR-B"},
+    {68, "csISO92JISC62991984b"},
+    {68, "iso-ir-92"},
+    {68, "jp-ocr-b"},
+    {69, "JIS_C6229-1984-b-add"},
+    {69, "csISO93JIS62291984badd"},
+    {69, "iso-ir-93"},
+    {69, "jp-ocr-b-add"},
+    {70, "JIS_C6229-1984-hand"},
+    {70, "csISO94JIS62291984hand"},
+    {70, "iso-ir-94"},
+    {70, "jp-ocr-hand"},
+    {71, "JIS_C6229-1984-hand-add"},
+    {71, "csISO95JIS62291984handadd"},
+    {71, "iso-ir-95"},
+    {71, "jp-ocr-hand-add"},
+    {72, "JIS_C6229-1984-kana"},
+    {72, "csISO96JISC62291984kana"},
+    {72, "iso-ir-96"},
+    {73, "ISO_2033-1983"},
+    {73, "csISO2033"},
+    {73, "e13b"},
+    {73, "iso-ir-98"},
+    {74, "ANSI_X3.110-1983"},
+    {74, "CSA_T500-1983"},
+    {74, "NAPLPS"},
+    {74, "csISO99NAPLPS"},
+    {74, "iso-ir-99"},
+    {75, "T.61-7bit"},
+    {75, "csISO102T617bit"},
+    {75, "iso-ir-102"},
+    {76, "T.61-8bit"},
+    {76, "T.61"},
+    {76, "csISO103T618bit"},
+    {76, "iso-ir-103"},
+    {77, "ECMA-cyrillic"},
+    {77, "KOI8-E"},
+    {77, "csISO111ECMACyrillic"},
+    {77, "iso-ir-111"},
+    {78, "CSA_Z243.4-1985-1"},
+    {78, "ISO646-CA"},
+    {78, "ca"},
+    {78, "csISO121Canadian1"},
+    {78, "csa7-1"},
+    {78, "csa71"},
+    {78, "iso-ir-121"},
+    {79, "CSA_Z243.4-1985-2"},
+    {79, "ISO646-CA2"},
+    {79, "csISO122Canadian2"},
+    {79, "csa7-2"},
+    {79, "csa72"},
+    {79, "iso-ir-122"},
+    {80, "CSA_Z243.4-1985-gr"},
+    {80, "csISO123CSAZ24341985gr"},
+    {80, "iso-ir-123"},
+    {81, "ISO-8859-6-E"},
+    {81, "ISO_8859-6-E"},
+    {81, "csISO88596E"},
+    {82, "ISO-8859-6-I"},
+    {82, "ISO_8859-6-I"},
+    {82, "csISO88596I"},
+    {83, "T.101-G2"},
+    {83, "csISO128T101G2"},
+    {83, "iso-ir-128"},
+    {84, "ISO-8859-8-E"},
+    {84, "ISO_8859-8-E"},
+    {84, "csISO88598E"},
+    {85, "ISO-8859-8-I"},
+    {85, "ISO_8859-8-I"},
+    {85, "csISO88598I"},
+    {86, "CSN_369103"},
+    {86, "csISO139CSN369103"},
+    {86, "iso-ir-139"},
+    {87, "JUS_I.B1.002"},
+    {87, "ISO646-YU"},
+    {87, "csISO141JUSIB1002"},
+    {87, "iso-ir-141"},
+    {87, "js"},
+    {87, "yu"},
+    {88, "IEC_P27-1"},
+    {88, "csISO143IECP271"},
+    {88, "iso-ir-143"},
+    {89, "JUS_I.B1.003-serb"},
+    {89, "csISO146Serbian"},
+    {89, "iso-ir-146"},
+    {89, "serbian"},
+    {90, "JUS_I.B1.003-mac"},
+    {90, "csISO147Macedonian"},
+    {90, "iso-ir-147"},
+    {90, "macedonian"},
+    {91, "greek-ccitt"},
+    {91, "csISO150"},
+    {91, "csISO150GreekCCITT"},
+    {91, "iso-ir-150"},
+    {92, "NC_NC00-10:81"},
+    {92, "ISO646-CU"},
+    {92, "csISO151Cuba"},
+    {92, "cuba"},
+    {92, "iso-ir-151"},
+    {93, "ISO_6937-2-25"},
+    {93, "csISO6937Add"},
+    {93, "iso-ir-152"},
+    {94, "GOST_19768-74"},
+    {94, "ST_SEV_358-88"},
+    {94, "csISO153GOST1976874"},
+    {94, "iso-ir-153"},
+    {95, "ISO_8859-supp"},
+    {95, "csISO8859Supp"},
+    {95, "iso-ir-154"},
+    {95, "latin1-2-5"},
+    {96, "ISO_10367-box"},
+    {96, "csISO10367Box"},
+    {96, "iso-ir-155"},
+    {97, "latin-lap"},
+    {97, "csISO158Lap"},
+    {97, "iso-ir-158"},
+    {97, "lap"},
+    {98, "JIS_X0212-1990"},
+    {98, "csISO159JISX02121990"},
+    {98, "iso-ir-159"},
+    {98, "x0212"},
+    {99, "DS_2089"},
+    {99, "DS2089"},
+    {99, "ISO646-DK"},
+    {99, "csISO646Danish"},
+    {99, "dk"},
+    {100, "us-dk"},
+    {100, "csUSDK"},
+    {101, "dk-us"},
+    {101, "csDKUS"},
+    {102, "KSC5636"},
+    {102, "ISO646-KR"},
+    {102, "csKSC5636"},
+    {103, "UNICODE-1-1-UTF-7"},
+    {103, "csUnicode11UTF7"},
+    {104, "ISO-2022-CN"},
+    {104, "csISO2022CN"},
+    {105, "ISO-2022-CN-EXT"},
+    {105, "csISO2022CNEXT"},
+    {106, "UTF-8"},
+    {106, "csUTF8"},
+    {109, "ISO-8859-13"},
+    {109, "csISO885913"},
+    {110, "ISO-8859-14"},
+    {110, "ISO_8859-14"},
+    {110, "ISO_8859-14:1998"},
+    {110, "csISO885914"},
+    {110, "iso-celtic"},
+    {110, "iso-ir-199"},
+    {110, "l8"},
+    {110, "latin8"},
+    {111, "ISO-8859-15"},
+    {111, "ISO_8859-15"},
+    {111, "Latin-9"},
+    {111, "csISO885915"},
+    {112, "ISO-8859-16"},
+    {112, "ISO_8859-16"},
+    {112, "ISO_8859-16:2001"},
+    {112, "csISO885916"},
+    {112, "iso-ir-226"},
+    {112, "l10"},
+    {112, "latin10"},
+    {113, "GBK"},
+    {113, "CP936"},
+    {113, "MS936"},
+    {113, "csGBK"},
+    {113, "windows-936"},
+    {114, "GB18030"},
+    {114, "csGB18030"},
+    {115, "OSD_EBCDIC_DF04_15"},
+    {115, "csOSDEBCDICDF0415"},
+    {116, "OSD_EBCDIC_DF03_IRV"},
+    {116, "csOSDEBCDICDF03IRV"},
+    {117, "OSD_EBCDIC_DF04_1"},
+    {117, "csOSDEBCDICDF041"},
+    {118, "ISO-11548-1"},
+    {118, "ISO_11548-1"},
+    {118, "ISO_TR_11548-1"},
+    {118, "csISO115481"},
+    {119, "KZ-1048"},
+    {119, "RK1048"},
+    {119, "STRK1048-2002"},
+    {119, "csKZ1048"},
+    {1000, "ISO-10646-UCS-2"},
+    {1000, "csUnicode"},
+    {1001, "ISO-10646-UCS-4"},
+    {1001, "csUCS4"},
+    {1002, "ISO-10646-UCS-Basic"},
+    {1002, "csUnicodeASCII"},
+    {1003, "ISO-10646-Unicode-Latin1"},
+    {1003, "ISO-10646"},
+    {1003, "csUnicodeLatin1"},
+    {1004, "ISO-10646-J-1"},
+    {1004, "csUnicodeJapanese"},
+    {1005, "ISO-Unicode-IBM-1261"},
+    {1005, "csUnicodeIBM1261"},
+    {1006, "ISO-Unicode-IBM-1268"},
+    {1006, "csUnicodeIBM1268"},
+    {1007, "ISO-Unicode-IBM-1276"},
+    {1007, "csUnicodeIBM1276"},
+    {1008, "ISO-Unicode-IBM-1264"},
+    {1008, "csUnicodeIBM1264"},
+    {1009, "ISO-Unicode-IBM-1265"},
+    {1009, "csUnicodeIBM1265"},
+    {1010, "UNICODE-1-1"},
+    {1010, "csUnicode11"},
+    {1011, "SCSU"},
+    {1011, "csSCSU"},
+    {1012, "UTF-7"},
+    {1012, "csUTF7"},
+    {1013, "UTF-16BE"},
+    {1013, "csUTF16BE"},
+    {1014, "UTF-16LE"},
+    {1014, "csUTF16LE"},
+    {1015, "UTF-16"},
+    {1015, "csUTF16"},
+    {1016, "CESU-8"},
+    {1016, "csCESU-8"},
+    {1016, "csCESU8"},
+    {1017, "UTF-32"},
+    {1017, "csUTF32"},
+    {1018, "UTF-32BE"},
+    {1018, "csUTF32BE"},
+    {1019, "UTF-32LE"},
+    {1019, "csUTF32LE"},
+    {1020, "BOCU-1"},
+    {1020, "csBOCU-1"},
+    {1020, "csBOCU1"},
+    {1021, "UTF-7-IMAP"},
+    {1021, "csUTF7IMAP"},
+    {2000, "ISO-8859-1-Windows-3.0-Latin-1"},
+    {2000, "csWindows30Latin1"},
+    {2001, "ISO-8859-1-Windows-3.1-Latin-1"},
+    {2001, "csWindows31Latin1"},
+    {2002, "ISO-8859-2-Windows-Latin-2"},
+    {2002, "csWindows31Latin2"},
+    {2003, "ISO-8859-9-Windows-Latin-5"},
+    {2003, "csWindows31Latin5"},
+    {2004, "hp-roman8"},
+    {2004, "csHPRoman8"},
+    {2004, "r8"},
+    {2004, "roman8"},
+    {2005, "Adobe-Standard-Encoding"},
+    {2005, "csAdobeStandardEncoding"},
+    {2006, "Ventura-US"},
+    {2006, "csVenturaUS"},
+    {2007, "Ventura-International"},
+    {2007, "csVenturaInternational"},
+    {2008, "DEC-MCS"},
+    {2008, "csDECMCS"},
+    {2008, "dec"},
+    {2009, "IBM850"},
+    {2009, "850"},
+    {2009, "cp850"},
+    {2009, "csPC850Multilingual"},
+    {2010, "IBM852"},
+    {2010, "852"},
+    {2010, "cp852"},
+    {2010, "csPCp852"},
+    {2011, "IBM437"},
+    {2011, "437"},
+    {2011, "cp437"},
+    {2011, "csPC8CodePage437"},
+    {2012, "PC8-Danish-Norwegian"},
+    {2012, "csPC8DanishNorwegian"},
+    {2013, "IBM862"},
+    {2013, "862"},
+    {2013, "cp862"},
+    {2013, "csPC862LatinHebrew"},
+    {2014, "PC8-Turkish"},
+    {2014, "csPC8Turkish"},
+    {2015, "IBM-Symbols"},
+    {2015, "csIBMSymbols"},
+    {2016, "IBM-Thai"},
+    {2016, "csIBMThai"},
+    {2017, "HP-Legal"},
+    {2017, "csHPLegal"},
+    {2018, "HP-Pi-font"},
+    {2018, "csHPPiFont"},
+    {2019, "HP-Math8"},
+    {2019, "csHPMath8"},
+    {2020, "Adobe-Symbol-Encoding"},
+    {2020, "csHPPSMath"},
+    {2021, "HP-DeskTop"},
+    {2021, "csHPDesktop"},
+    {2022, "Ventura-Math"},
+    {2022, "csVenturaMath"},
+    {2023, "Microsoft-Publishing"},
+    {2023, "csMicrosoftPublishing"},
+    {2024, "Windows-31J"},
+    {2024, "csWindows31J"},
+    {2025, "GB2312"},
+    {2025, "csGB2312"},
+    {2026, "Big5"},
+    {2026, "csBig5"},
+    {2027, "macintosh"},
+    {2027, "csMacintosh"},
+    {2027, "mac"},
+    {2028, "IBM037"},
+    {2028, "cp037"},
+    {2028, "csIBM037"},
+    {2028, "ebcdic-cp-ca"},
+    {2028, "ebcdic-cp-nl"},
+    {2028, "ebcdic-cp-us"},
+    {2028, "ebcdic-cp-wt"},
+    {2029, "IBM038"},
+    {2029, "EBCDIC-INT"},
+    {2029, "cp038"},
+    {2029, "csIBM038"},
+    {2030, "IBM273"},
+    {2030, "CP273"},
+    {2030, "csIBM273"},
+    {2031, "IBM274"},
+    {2031, "CP274"},
+    {2031, "EBCDIC-BE"},
+    {2031, "csIBM274"},
+    {2032, "IBM275"},
+    {2032, "EBCDIC-BR"},
+    {2032, "cp275"},
+    {2032, "csIBM275"},
+    {2033, "IBM277"},
+    {2033, "EBCDIC-CP-DK"},
+    {2033, "EBCDIC-CP-NO"},
+    {2033, "csIBM277"},
+    {2034, "IBM278"},
+    {2034, "CP278"},
+    {2034, "csIBM278"},
+    {2034, "ebcdic-cp-fi"},
+    {2034, "ebcdic-cp-se"},
+    {2035, "IBM280"},
+    {2035, "CP280"},
+    {2035, "csIBM280"},
+    {2035, "ebcdic-cp-it"},
+    {2036, "IBM281"},
+    {2036, "EBCDIC-JP-E"},
+    {2036, "cp281"},
+    {2036, "csIBM281"},
+    {2037, "IBM284"},
+    {2037, "CP284"},
+    {2037, "csIBM284"},
+    {2037, "ebcdic-cp-es"},
+    {2038, "IBM285"},
+    {2038, "CP285"},
+    {2038, "csIBM285"},
+    {2038, "ebcdic-cp-gb"},
+    {2039, "IBM290"},
+    {2039, "EBCDIC-JP-kana"},
+    {2039, "cp290"},
+    {2039, "csIBM290"},
+    {2040, "IBM297"},
+    {2040, "cp297"},
+    {2040, "csIBM297"},
+    {2040, "ebcdic-cp-fr"},
+    {2041, "IBM420"},
+    {2041, "cp420"},
+    {2041, "csIBM420"},
+    {2041, "ebcdic-cp-ar1"},
+    {2042, "IBM423"},
+    {2042, "cp423"},
+    {2042, "csIBM423"},
+    {2042, "ebcdic-cp-gr"},
+    {2043, "IBM424"},
+    {2043, "cp424"},
+    {2043, "csIBM424"},
+    {2043, "ebcdic-cp-he"},
+    {2044, "IBM500"},
+    {2044, "CP500"},
+    {2044, "csIBM500"},
+    {2044, "ebcdic-cp-be"},
+    {2044, "ebcdic-cp-ch"},
+    {2045, "IBM851"},
+    {2045, "851"},
+    {2045, "cp851"},
+    {2045, "csIBM851"},
+    {2046, "IBM855"},
+    {2046, "855"},
+    {2046, "cp855"},
+    {2046, "csIBM855"},
+    {2047, "IBM857"},
+    {2047, "857"},
+    {2047, "cp857"},
+    {2047, "csIBM857"},
+    {2048, "IBM860"},
+    {2048, "860"},
+    {2048, "cp860"},
+    {2048, "csIBM860"},
+    {2049, "IBM861"},
+    {2049, "861"},
+    {2049, "cp-is"},
+    {2049, "cp861"},
+    {2049, "csIBM861"},
+    {2050, "IBM863"},
+    {2050, "863"},
+    {2050, "cp863"},
+    {2050, "csIBM863"},
+    {2051, "IBM864"},
+    {2051, "cp864"},
+    {2051, "csIBM864"},
+    {2052, "IBM865"},
+    {2052, "865"},
+    {2052, "cp865"},
+    {2052, "csIBM865"},
+    {2053, "IBM868"},
+    {2053, "CP868"},
+    {2053, "cp-ar"},
+    {2053, "csIBM868"},
+    {2054, "IBM869"},
+    {2054, "869"},
+    {2054, "cp-gr"},
+    {2054, "cp869"},
+    {2054, "csIBM869"},
+    {2055, "IBM870"},
+    {2055, "CP870"},
+    {2055, "csIBM870"},
+    {2055, "ebcdic-cp-roece"},
+    {2055, "ebcdic-cp-yu"},
+    {2056, "IBM871"},
+    {2056, "CP871"},
+    {2056, "csIBM871"},
+    {2056, "ebcdic-cp-is"},
+    {2057, "IBM880"},
+    {2057, "EBCDIC-Cyrillic"},
+    {2057, "cp880"},
+    {2057, "csIBM880"},
+    {2058, "IBM891"},
+    {2058, "cp891"},
+    {2058, "csIBM891"},
+    {2059, "IBM903"},
+    {2059, "cp903"},
+    {2059, "csIBM903"},
+    {2060, "IBM904"},
+    {2060, "904"},
+    {2060, "cp904"},
+    {2060, "csIBBM904"},
+    {2061, "IBM905"},
+    {2061, "CP905"},
+    {2061, "csIBM905"},
+    {2061, "ebcdic-cp-tr"},
+    {2062, "IBM918"},
+    {2062, "CP918"},
+    {2062, "csIBM918"},
+    {2062, "ebcdic-cp-ar2"},
+    {2063, "IBM1026"},
+    {2063, "CP1026"},
+    {2063, "csIBM1026"},
+    {2064, "EBCDIC-AT-DE"},
+    {2064, "csIBMEBCDICATDE"},
+    {2065, "EBCDIC-AT-DE-A"},
+    {2065, "csEBCDICATDEA"},
+    {2066, "EBCDIC-CA-FR"},
+    {2066, "csEBCDICCAFR"},
+    {2067, "EBCDIC-DK-NO"},
+    {2067, "csEBCDICDKNO"},
+    {2068, "EBCDIC-DK-NO-A"},
+    {2068, "csEBCDICDKNOA"},
+    {2069, "EBCDIC-FI-SE"},
+    {2069, "csEBCDICFISE"},
+    {2070, "EBCDIC-FI-SE-A"},
+    {2070, "csEBCDICFISEA"},
+    {2071, "EBCDIC-FR"},
+    {2071, "csEBCDICFR"},
+    {2072, "EBCDIC-IT"},
+    {2072, "csEBCDICIT"},
+    {2073, "EBCDIC-PT"},
+    {2073, "csEBCDICPT"},
+    {2074, "EBCDIC-ES"},
+    {2074, "csEBCDICES"},
+    {2075, "EBCDIC-ES-A"},
+    {2075, "csEBCDICESA"},
+    {2076, "EBCDIC-ES-S"},
+    {2076, "csEBCDICESS"},
+    {2077, "EBCDIC-UK"},
+    {2077, "csEBCDICUK"},
+    {2078, "EBCDIC-US"},
+    {2078, "csEBCDICUS"},
+    {2079, "UNKNOWN-8BIT"},
+    {2079, "csUnknown8BiT"},
+    {2080, "MNEMONIC"},
+    {2080, "csMnemonic"},
+    {2081, "MNEM"},
+    {2081, "csMnem"},
+    {2082, "VISCII"},
+    {2082, "csVISCII"},
+    {2083, "VIQR"},
+    {2083, "csVIQR"},
+    {2084, "KOI8-R"},
+    {2084, "csKOI8R"},
+    {2085, "HZ-GB-2312"},
+    {2086, "IBM866"},
+    {2086, "866"},
+    {2086, "cp866"},
+    {2086, "csIBM866"},
+    {2087, "IBM775"},
+    {2087, "cp775"},
+    {2087, "csPC775Baltic"},
+    {2088, "KOI8-U"},
+    {2088, "csKOI8U"},
+    {2089, "IBM00858"},
+    {2089, "CCSID00858"},
+    {2089, "CP00858"},
+    {2089, "PC-Multilingual-850+euro"},
+    {2089, "csIBM00858"},
+    {2090, "IBM00924"},
+    {2090, "CCSID00924"},
+    {2090, "CP00924"},
+    {2090, "csIBM00924"},
+    {2090, "ebcdic-Latin9--euro"},
+    {2091, "IBM01140"},
+    {2091, "CCSID01140"},
+    {2091, "CP01140"},
+    {2091, "csIBM01140"},
+    {2091, "ebcdic-us-37+euro"},
+    {2092, "IBM01141"},
+    {2092, "CCSID01141"},
+    {2092, "CP01141"},
+    {2092, "csIBM01141"},
+    {2092, "ebcdic-de-273+euro"},
+    {2093, "IBM01142"},
+    {2093, "CCSID01142"},
+    {2093, "CP01142"},
+    {2093, "csIBM01142"},
+    {2093, "ebcdic-dk-277+euro"},
+    {2093, "ebcdic-no-277+euro"},
+    {2094, "IBM01143"},
+    {2094, "CCSID01143"},
+    {2094, "CP01143"},
+    {2094, "csIBM01143"},
+    {2094, "ebcdic-fi-278+euro"},
+    {2094, "ebcdic-se-278+euro"},
+    {2095, "IBM01144"},
+    {2095, "CCSID01144"},
+    {2095, "CP01144"},
+    {2095, "csIBM01144"},
+    {2095, "ebcdic-it-280+euro"},
+    {2096, "IBM01145"},
+    {2096, "CCSID01145"},
+    {2096, "CP01145"},
+    {2096, "csIBM01145"},
+    {2096, "ebcdic-es-284+euro"},
+    {2097, "IBM01146"},
+    {2097, "CCSID01146"},
+    {2097, "CP01146"},
+    {2097, "csIBM01146"},
+    {2097, "ebcdic-gb-285+euro"},
+    {2098, "IBM01147"},
+    {2098, "CCSID01147"},
+    {2098, "CP01147"},
+    {2098, "csIBM01147"},
+    {2098, "ebcdic-fr-297+euro"},
+    {2099, "IBM01148"},
+    {2099, "CCSID01148"},
+    {2099, "CP01148"},
+    {2099, "csIBM01148"},
+    {2099, "ebcdic-international-500+euro"},
+    {2100, "IBM01149"},
+    {2100, "CCSID01149"},
+    {2100, "CP01149"},
+    {2100, "csIBM01149"},
+    {2100, "ebcdic-is-871+euro"},
+    {2101, "Big5-HKSCS"},
+    {2101, "csBig5HKSCS"},
+    {2102, "IBM1047"},
+    {2102, "IBM-1047"},
+    {2102, "csIBM1047"},
+    {2103, "PTCP154"},
+    {2103, "CP154"},
+    {2103, "Cyrillic-Asian"},
+    {2103, "PT154"},
+    {2103, "csPTCP154"},
+    {2104, "Amiga-1251"},
+    {2104, "Ami-1251"},
+    {2104, "Ami1251"},
+    {2104, "Amiga1251"},
+    {2104, "csAmiga1251"},
+    {2105, "KOI7-switched"},
+    {2105, "csKOI7switched"},
+    {2106, "BRF"},
+    {2106, "csBRF"},
+    {2107, "TSCII"},
+    {2107, "csTSCII"},
+    {2108, "CP51932"},
+    {2108, "csCP51932"},
+    {2109, "windows-874"},
+    {2109, "cswindows874"},
+    {2250, "windows-1250"},
+    {2250, "cswindows1250"},
+    {2251, "windows-1251"},
+    {2251, "cswindows1251"},
+    {2252, "windows-1252"},
+    {2252, "cswindows1252"},
+    {2253, "windows-1253"},
+    {2253, "cswindows1253"},
+    {2254, "windows-1254"},
+    {2254, "cswindows1254"},
+    {2255, "windows-1255"},
+    {2255, "cswindows1255"},
+    {2256, "windows-1256"},
+    {2256, "cswindows1256"},
+    {2257, "windows-1257"},
+    {2257, "cswindows1257"},
+    {2258, "windows-1258"},
+    {2258, "cswindows1258"},
+    {2259, "TIS-620"},
+    {2259, "ISO-8859-11"},
+    {2259, "csTIS620"},
+    {2260, "CP50220"},
+    {2260, "csCP50220"},
+    {0, nullptr} // sentinel
+};
+
+constexpr encoding_pair unique_encoding_data[] = {
+    {3, "ANSI_X3.4-1968"},
+    {4, "ISO-8859-1"},
+    {5, "ISO-8859-2"},
+    {6, "ISO-8859-3"},
+    {7, "ISO-8859-4"},
+    {8, "ISO-8859-5"},
+    {9, "ISO-8859-6"},
+    {10, "ISO-8859-7"},
+    {11, "ISO-8859-8"},
+    {12, "ISO-8859-9"},
+    {13, "ISO-8859-10"},
+    {14, "ISO_6937-2-add"},
+    {15, "JIS_X0201"},
+    {16, "JIS_Encoding"},
+    {17, "Shift_JIS"},
+    {18, "EUC-JP"},
+    {19, "Extended_UNIX_Code_Fixed_Width_for_Japanese"},
+    {20, "BS_4730"},
+    {21, "SEN_850200_C"},
+    {22, "IT"},
+    {23, "ES"},
+    {24, "DIN_66003"},
+    {25, "NS_4551-1"},
+    {26, "NF_Z_62-010"},
+    {27, "ISO-10646-UTF-1"},
+    {28, "ISO_646.basic:1983"},
+    {29, "INVARIANT"},
+    {30, "ISO_646.irv:1983"},
+    {31, "NATS-SEFI"},
+    {32, "NATS-SEFI-ADD"},
+    {33, "NATS-DANO"},
+    {34, "NATS-DANO-ADD"},
+    {35, "SEN_850200_B"},
+    {36, "KS_C_5601-1987"},
+    {37, "ISO-2022-KR"},
+    {38, "EUC-KR"},
+    {39, "ISO-2022-JP"},
+    {40, "ISO-2022-JP-2"},
+    {41, "JIS_C6220-1969-jp"},
+    {42, "JIS_C6220-1969-ro"},
+    {43, "PT"},
+    {44, "greek7-old"},
+    {45, "latin-greek"},
+    {46, "NF_Z_62-010_(1973)"},
+    {47, "Latin-greek-1"},
+    {48, "ISO_5427"},
+    {49, "JIS_C6226-1978"},
+    {50, "BS_viewdata"},
+    {51, "INIS"},
+    {52, "INIS-8"},
+    {53, "INIS-cyrillic"},
+    {54, "ISO_5427:1981"},
+    {55, "ISO_5428:1980"},
+    {56, "GB_1988-80"},
+    {57, "GB_2312-80"},
+    {58, "NS_4551-2"},
+    {59, "videotex-suppl"},
+    {60, "PT2"},
+    {61, "ES2"},
+    {62, "MSZ_7795.3"},
+    {63, "JIS_C6226-1983"},
+    {64, "greek7"},
+    {65, "ASMO_449"},
+    {66, "iso-ir-90"},
+    {67, "JIS_C6229-1984-a"},
+    {68, "JIS_C6229-1984-b"},
+    {69, "JIS_C6229-1984-b-add"},
+    {70, "JIS_C6229-1984-hand"},
+    {71, "JIS_C6229-1984-hand-add"},
+    {72, "JIS_C6229-1984-kana"},
+    {73, "ISO_2033-1983"},
+    {74, "ANSI_X3.110-1983"},
+    {75, "T.61-7bit"},
+    {76, "T.61-8bit"},
+    {77, "ECMA-cyrillic"},
+    {78, "CSA_Z243.4-1985-1"},
+    {79, "CSA_Z243.4-1985-2"},
+    {80, "CSA_Z243.4-1985-gr"},
+    {81, "ISO-8859-6-E"},
+    {82, "ISO-8859-6-I"},
+    {83, "T.101-G2"},
+    {84, "ISO-8859-8-E"},
+    {85, "ISO-8859-8-I"},
+    {86, "CSN_369103"},
+    {87, "JUS_I.B1.002"},
+    {88, "IEC_P27-1"},
+    {89, "JUS_I.B1.003-serb"},
+    {90, "JUS_I.B1.003-mac"},
+    {91, "greek-ccitt"},
+    {92, "NC_NC00-10:81"},
+    {93, "ISO_6937-2-25"},
+    {94, "GOST_19768-74"},
+    {95, "ISO_8859-supp"},
+    {96, "ISO_10367-box"},
+    {97, "latin-lap"},
+    {98, "JIS_X0212-1990"},
+    {99, "DS_2089"},
+    {100, "us-dk"},
+    {101, "dk-us"},
+    {102, "KSC5636"},
+    {103, "UNICODE-1-1-UTF-7"},
+    {104, "ISO-2022-CN"},
+    {105, "ISO-2022-CN-EXT"},
+    {106, "UTF-8"},
+    {109, "ISO-8859-13"},
+    {110, "ISO-8859-14"},
+    {111, "ISO-8859-15"},
+    {112, "ISO-8859-16"},
+    {113, "GBK"},
+    {114, "GB18030"},
+    {115, "OSD_EBCDIC_DF04_15"},
+    {116, "OSD_EBCDIC_DF03_IRV"},
+    {117, "OSD_EBCDIC_DF04_1"},
+    {118, "ISO-11548-1"},
+    {119, "KZ-1048"},
+    {1000, "ISO-10646-UCS-2"},
+    {1001, "ISO-10646-UCS-4"},
+    {1002, "ISO-10646-UCS-Basic"},
+    {1003, "ISO-10646-Unicode-Latin1"},
+    {1004, "ISO-10646-J-1"},
+    {1005, "ISO-Unicode-IBM-1261"},
+    {1006, "ISO-Unicode-IBM-1268"},
+    {1007, "ISO-Unicode-IBM-1276"},
+    {1008, "ISO-Unicode-IBM-1264"},
+    {1009, "ISO-Unicode-IBM-1265"},
+    {1010, "UNICODE-1-1"},
+    {1011, "SCSU"},
+    {1012, "UTF-7"},
+    {1013, "UTF-16BE"},
+    {1014, "UTF-16LE"},
+    {1015, "UTF-16"},
+    {1016, "CESU-8"},
+    {1017, "UTF-32"},
+    {1018, "UTF-32BE"},
+    {1019, "UTF-32LE"},
+    {1020, "BOCU-1"},
+    {1021, "UTF-7-IMAP"},
+    {2000, "ISO-8859-1-Windows-3.0-Latin-1"},
+    {2001, "ISO-8859-1-Windows-3.1-Latin-1"},
+    {2002, "ISO-8859-2-Windows-Latin-2"},
+    {2003, "ISO-8859-9-Windows-Latin-5"},
+    {2004, "hp-roman8"},
+    {2005, "Adobe-Standard-Encoding"},
+    {2006, "Ventura-US"},
+    {2007, "Ventura-International"},
+    {2008, "DEC-MCS"},
+    {2009, "IBM850"},
+    {2010, "IBM852"},
+    {2011, "IBM437"},
+    {2012, "PC8-Danish-Norwegian"},
+    {2013, "IBM862"},
+    {2014, "PC8-Turkish"},
+    {2015, "IBM-Symbols"},
+    {2016, "IBM-Thai"},
+    {2017, "HP-Legal"},
+    {2018, "HP-Pi-font"},
+    {2019, "HP-Math8"},
+    {2020, "Adobe-Symbol-Encoding"},
+    {2021, "HP-DeskTop"},
+    {2022, "Ventura-Math"},
+    {2023, "Microsoft-Publishing"},
+    {2024, "Windows-31J"},
+    {2025, "GB2312"},
+    {2026, "Big5"},
+    {2027, "macintosh"},
+    {2028, "IBM037"},
+    {2029, "IBM038"},
+    {2030, "IBM273"},
+    {2031, "IBM274"},
+    {2032, "IBM275"},
+    {2033, "IBM277"},
+    {2034, "IBM278"},
+    {2035, "IBM280"},
+    {2036, "IBM281"},
+    {2037, "IBM284"},
+    {2038, "IBM285"},
+    {2039, "IBM290"},
+    {2040, "IBM297"},
+    {2041, "IBM420"},
+    {2042, "IBM423"},
+    {2043, "IBM424"},
+    {2044, "IBM500"},
+    {2045, "IBM851"},
+    {2046, "IBM855"},
+    {2047, "IBM857"},
+    {2048, "IBM860"},
+    {2049, "IBM861"},
+    {2050, "IBM863"},
+    {2051, "IBM864"},
+    {2052, "IBM865"},
+    {2053, "IBM868"},
+    {2054, "IBM869"},
+    {2055, "IBM870"},
+    {2056, "IBM871"},
+    {2057, "IBM880"},
+    {2058, "IBM891"},
+    {2059, "IBM903"},
+    {2060, "IBM904"},
+    {2061, "IBM905"},
+    {2062, "IBM918"},
+    {2063, "IBM1026"},
+    {2064, "EBCDIC-AT-DE"},
+    {2065, "EBCDIC-AT-DE-A"},
+    {2066, "EBCDIC-CA-FR"},
+    {2067, "EBCDIC-DK-NO"},
+    {2068, "EBCDIC-DK-NO-A"},
+    {2069, "EBCDIC-FI-SE"},
+    {2070, "EBCDIC-FI-SE-A"},
+    {2071, "EBCDIC-FR"},
+    {2072, "EBCDIC-IT"},
+    {2073, "EBCDIC-PT"},
+    {2074, "EBCDIC-ES"},
+    {2075, "EBCDIC-ES-A"},
+    {2076, "EBCDIC-ES-S"},
+    {2077, "EBCDIC-UK"},
+    {2078, "EBCDIC-US"},
+    {2079, "UNKNOWN-8BIT"},
+    {2080, "MNEMONIC"},
+    {2081, "MNEM"},
+    {2082, "VISCII"},
+    {2083, "VIQR"},
+    {2084, "KOI8-R"},
+    {2085, "HZ-GB-2312"},
+    {2086, "IBM866"},
+    {2087, "IBM775"},
+    {2088, "KOI8-U"},
+    {2089, "IBM00858"},
+    {2090, "IBM00924"},
+    {2091, "IBM01140"},
+    {2092, "IBM01141"},
+    {2093, "IBM01142"},
+    {2094, "IBM01143"},
+    {2095, "IBM01144"},
+    {2096, "IBM01145"},
+    {2097, "IBM01146"},
+    {2098, "IBM01147"},
+    {2099, "IBM01148"},
+    {2100, "IBM01149"},
+    {2101, "Big5-HKSCS"},
+    {2102, "IBM1047"},
+    {2103, "PTCP154"},
+    {2104, "Amiga-1251"},
+    {2105, "KOI7-switched"},
+    {2106, "BRF"},
+    {2107, "TSCII"},
+    {2108, "CP51932"},
+    {2109, "windows-874"},
+    {2250, "windows-1250"},
+    {2251, "windows-1251"},
+    {2252, "windows-1252"},
+    {2253, "windows-1253"},
+    {2254, "windows-1254"},
+    {2255, "windows-1255"},
+    {2256, "windows-1256"},
+    {2257, "windows-1257"},
+    {2258, "windows-1258"},
+    {2259, "TIS-620"},
+    {2260, "CP50220"},
+};
+
+#endif // SUPPORT_TEST_TEXT_ENCODING_H
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index 2b7f6fa8a48a9..fc3294c4bba76 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -1346,7 +1346,6 @@ def add_version_header(tc):
                 "c++26": 202306  # P1885R12 Naming Text Encodings to Demystify Them
             },
             "headers": ["text_encoding"],
-            "unimplemented": True,
         },
         {
             "name": "__cpp_lib_three_way_comparison",
diff --git a/libcxx/utils/libcxx/header_information.py b/libcxx/utils/libcxx/header_information.py
index a505d37b65b81..55b01f9eae44e 100644
--- a/libcxx/utils/libcxx/header_information.py
+++ b/libcxx/utils/libcxx/header_information.py
@@ -172,7 +172,6 @@ def __hash__(self) -> int:
     "spanstream",
     "stacktrace",
     "stdfloat",
-    "text_encoding",
 ]))
 
 header_restrictions = {
@@ -196,6 +195,7 @@ def __hash__(self) -> int:
     "streambuf": "_LIBCPP_HAS_LOCALIZATION",
     "strstream": "_LIBCPP_HAS_LOCALIZATION",
     "syncstream": "_LIBCPP_HAS_LOCALIZATION",
+    "text_encoding": "_LIBCPP_HAS_LOCALIZATION",
 }
 
 lit_header_restrictions = {
@@ -231,6 +231,7 @@ def __hash__(self) -> int:
     "streambuf": "// UNSUPPORTED: no-localization",
     "strstream": "// UNSUPPORTED: no-localization",
     "syncstream": "// UNSUPPORTED: no-localization",
+    "text_encoding": "// UNSUPPORTED: no-localization",
     "thread": "// UNSUPPORTED: no-threads, c++03",
     "wchar.h": "// UNSUPPORTED: no-wide-characters",
     "wctype.h": "// UNSUPPORTED: no-wide-characters",

>From 46758a78a3d4293911a90b5468c61258490ad4bf Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Fri, 23 May 2025 22:58:03 -0400
Subject: [PATCH 2/3] Clang-Format

---
 libcxx/include/__locale                       |  4 +-
 .../include/__text_encoding/text_encoding.h   | 47 +++++++++----------
 libcxx/include/text_encoding                  | 10 ++--
 libcxx/src/locale.cpp                         | 22 ++++-----
 libcxx/src/text_encoding.cpp                  | 36 +++++++-------
 .../text_encoding.ctor/id.pass.cpp            |  6 +--
 .../text_encoding.eq/equal.id.pass.cpp        |  3 +-
 .../text_encoding.eq/equal.pass.cpp           |  5 +-
 .../text_encoding.members/aliases.pass.cpp    |  8 ++--
 .../environment.pass.cpp                      | 17 ++++---
 .../text_encoding.members/literal.pass.cpp    |  2 +-
 .../text_encoding.aliases_view/begin.pass.cpp | 19 ++++----
 .../text_encoding.aliases_view/empty.pass.cpp | 16 +++----
 .../text_encoding.aliases_view/front.pass.cpp | 17 +++----
 14 files changed, 100 insertions(+), 112 deletions(-)

diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index 4da3f38ac408f..6f6091d08026f 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -103,9 +103,9 @@ public:
 
   // locale operations:
   string name() const;
-  
+
 #  if _LIBCPP_STD_VER >= 26 && __CHAR_BIT__ == 8
-  text_encoding encoding() const; 
+  text_encoding encoding() const;
 #  endif // _LIBCPP_STD_VER >= 26
 
   bool operator==(const locale&) const;
diff --git a/libcxx/include/__text_encoding/text_encoding.h b/libcxx/include/__text_encoding/text_encoding.h
index 93d0ae2ab6b89..5edc631f7acfd 100644
--- a/libcxx/include/__text_encoding/text_encoding.h
+++ b/libcxx/include/__text_encoding/text_encoding.h
@@ -18,22 +18,22 @@
 
 #if _LIBCPP_HAS_LOCALIZATION
 
-#include <__algorithm/copy_n.h>
-#include <__algorithm/lower_bound.h>
-#include <__algorithm/min.h>
-#include <__functional/hash.h>
-#include <__iterator/iterator_traits.h>
-#include <__locale_dir/locale_base_api.h>
-#include <__ranges/view_interface.h>
-#include <__string/char_traits.h>
-#include <__utility/unreachable.h>
-#include <cstdint>
-#include <string_view>
+#  include <__algorithm/copy_n.h>
+#  include <__algorithm/lower_bound.h>
+#  include <__algorithm/min.h>
+#  include <__functional/hash.h>
+#  include <__iterator/iterator_traits.h>
+#  include <__locale_dir/locale_base_api.h>
+#  include <__ranges/view_interface.h>
+#  include <__string/char_traits.h>
+#  include <__utility/unreachable.h>
+#  include <cstdint>
+#  include <string_view>
 
 _LIBCPP_PUSH_MACROS
-#include <__undef_macros>
+#  include <__undef_macros>
 
-#if _LIBCPP_STD_VER >= 26
+#  if _LIBCPP_STD_VER >= 26
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 struct _LIBCPP_EXPORTED_FROM_ABI text_encoding {
@@ -340,12 +340,12 @@ struct _LIBCPP_EXPORTED_FROM_ABI text_encoding {
     constexpr aliases_view(const __encoding_data* __d) : __view_data_(__d) {}
     struct __end_sentinel {};
     struct __iterator {
-      using value_type        = const char*;
-      using reference         = const char*;
-      using difference_type   = ptrdiff_t;
+      using value_type      = const char*;
+      using reference       = const char*;
+      using difference_type = ptrdiff_t;
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator() noexcept = default;
 
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator() noexcept = default; 
-      
       _LIBCPP_HIDE_FROM_ABI constexpr value_type operator*() const {
         if (__can_dereference())
           return __data_->__name;
@@ -368,19 +368,18 @@ struct _LIBCPP_EXPORTED_FROM_ABI text_encoding {
       }
 
       _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(__iterator __it, difference_type __n) {
-        __it -= __n; 
+        __it -= __n;
         return __it;
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __iterator& __other) const 
-      {
-        if(__other.__mib_rep_ == __mib_rep_)
+      _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __iterator& __other) const {
+        if (__other.__mib_rep_ == __mib_rep_)
           return __mib_rep_ - __other.__mib_rep_;
         std::unreachable();
       }
 
       _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(difference_type __n, __iterator& __it) {
-        __it -= __n; 
+        __it -= __n;
         return __it;
       }
 
@@ -1474,7 +1473,7 @@ inline constexpr bool enable_borrowed_range<text_encoding::aliases_view> = true;
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // _LIBCPP_STD_VER >= 26
+#  endif // _LIBCPP_STD_VER >= 26
 
 _LIBCPP_POP_MACROS
 
diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 579608e4f939d..b312e5ac1b9fb 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -10,7 +10,7 @@
 #ifndef _LIBCPP_TEXT_ENCODING
 #define _LIBCPP_TEXT_ENCODING
 
-/* text_encoding synopsis 
+/* text_encoding synopsis
 namespace std {
 
 struct text_encoding;
@@ -19,7 +19,7 @@ struct text_encoding;
 template<class T> struct hash;
 template<> struct hash<text_encoding>;
 
-struct text_encoding 
+struct text_encoding
 {
     static constexpr size_t max_name_length = 63;
 
@@ -60,9 +60,9 @@ struct text_encoding
 #include <__config>
 
 #if _LIBCPP_STD_VER >= 26
-#    include <__text_encoding/text_encoding.h> 
+#  include <__text_encoding/text_encoding.h>
 #endif // _LIBCPP_STD_VER >= 26
 
-#include <version> 
+#include <version>
 
-#endif // _LIBCPP_TEXT_ENCODING 
+#endif // _LIBCPP_TEXT_ENCODING
diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp
index 6d8dababb84ce..21c93e0939910 100644
--- a/libcxx/src/locale.cpp
+++ b/libcxx/src/locale.cpp
@@ -558,18 +558,18 @@ locale::locale(const locale& other, const locale& one, category c)
 
 string locale::name() const { return __locale_->name(); }
 
-#  if _LIBCPP_STD_VER >= 26 && __CHAR_BIT__ == 8
-  text_encoding locale::encoding() const {
-    std::string __name = this->name();
-    if(__name.size() == 1){
-      if(__name[0] == 'C')
-        return std::text_encoding(text_encoding::id::ASCII);
-      if(__name[0] == '*')
-        return std::text_encoding();
-    }
-    return std::text_encoding(__name);
+#if _LIBCPP_STD_VER >= 26 && __CHAR_BIT__ == 8
+text_encoding locale::encoding() const {
+  std::string __name = this->name();
+  if (__name.size() == 1) {
+    if (__name[0] == 'C')
+      return std::text_encoding(text_encoding::id::ASCII);
+    if (__name[0] == '*')
+      return std::text_encoding();
   }
-#  endif // _LIBCPP_STD_VER >= 26
+  return std::text_encoding(__name);
+}
+#endif // _LIBCPP_STD_VER >= 26
 
 void locale::__install_ctor(const locale& other, facet* f, long facet_id) {
   if (f)
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 42812aaed49c7..95b0020ba7690 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <__config> 
+#include <__config>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -14,35 +14,35 @@
 
 #include <__locale_dir/locale_base_api.h>
 
-#include <text_encoding> 
+#include <text_encoding>
 
 #if __has_include(<langinfo.h>)
 #  include <langinfo.h>
 #endif
 
-#if _LIBCPP_STD_VER >= 26 
+#if _LIBCPP_STD_VER >= 26
 
 _LIBCPP_BEGIN_NAMESPACE_STD
-#if __CHAR_BIT__ == 8
+#  if __CHAR_BIT__ == 8
 
 text_encoding text_encoding::environment() {
-    auto __make_locale = [](const char* __name) {
-      text_encoding __enc{};
-      if (auto __loc = __locale::__newlocale(LC_CTYPE_MASK, __name, static_cast<locale_t>(0))) {
-        if (const char* __codeset = nl_langinfo_l(CODESET, __loc)) {
-          string_view __s(__codeset);
-          if (__s.size() < max_name_length)
-            __enc = text_encoding(__s);
-        }
-        __locale::__freelocale(__loc);
+  auto __make_locale = [](const char* __name) {
+    text_encoding __enc{};
+    if (auto __loc = __locale::__newlocale(LC_CTYPE_MASK, __name, static_cast<locale_t>(0))) {
+      if (const char* __codeset = nl_langinfo_l(CODESET, __loc)) {
+        string_view __s(__codeset);
+        if (__s.size() < max_name_length)
+          __enc = text_encoding(__s);
       }
-      return __enc;
-    };
+      __locale::__freelocale(__loc);
+    }
+    return __enc;
+  };
 
-    return __make_locale("");
-  }
+  return __make_locale("");
+}
 
-# endif  // __CHAR_BIT__ == 8
+#  endif // __CHAR_BIT__ == 8
 
 _LIBCPP_END_NAMESPACE_STD
 
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/id.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/id.pass.cpp
index 6562971c73dbb..f01c3956e4736 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/id.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/id.pass.cpp
@@ -41,15 +41,15 @@ int main() {
     static_assert(std::is_nothrow_constructible<std::text_encoding, std::text_encoding::id>::value,
                   "Must be nothrow constructible with id");
   }
-  
+
   {
-    for (auto pair : unique_encoding_data){
+    for (auto pair : unique_encoding_data) {
       test_ctor(te_id{pair.mib}, te_id{pair.mib}, pair.name);
     }
   }
 
   {
-    for(int i = 2261; i < 2300; i++){ // test out of range id values
+    for (int i = 2261; i < 2300; i++) { // test out of range id values
       test_ctor(te_id{i}, te_id::unknown, "");
     }
   }
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.id.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.id.pass.cpp
index 30ce1badec1d7..bf0c75a3ebbb5 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.id.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.id.pass.cpp
@@ -14,7 +14,7 @@
 
 // class text_encoding
 
-// text_encoding operator==(const text_encoding&, id) _NOEXCEPT 
+// text_encoding operator==(const text_encoding&, id) _NOEXCEPT
 
 // Concerns:
 // 1. operator==(const text_encoding&, id) must be noexcept
@@ -31,7 +31,6 @@
 using id = std::text_encoding::id;
 
 int main() {
-
   { // 1
     auto te = std::text_encoding();
     ASSERT_NOEXCEPT(te == id::UTF8);
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.pass.cpp
index 81fdb0a681143..27cd9bdff08a5 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.pass.cpp
@@ -14,7 +14,7 @@
 
 // class text_encoding
 
-// text_encoding operator==(const text_encoding&, const text_encoding&) _NOEXCEPT 
+// text_encoding operator==(const text_encoding&, const text_encoding&) _NOEXCEPT
 
 // Concerns:
 // 1. operator==(const text_encoding&, const text_encoding&) must be noexcept
@@ -32,8 +32,7 @@
 
 using id = std::text_encoding::id;
 
-int main(){
-  
+int main() {
   { // 1
     auto te1 = std::text_encoding();
     auto te2 = std::text_encoding();
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases.pass.cpp
index 345438d6a1ecb..6b363ef7555e6 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases.pass.cpp
@@ -13,10 +13,10 @@
 
 // class text_encoding
 
-// text_encoding text_encoding::environment(); 
+// text_encoding text_encoding::environment();
 
 // Concerns:
-// 1. Verify that text_encoding::aliases_view satisfies ranges::forward_range, copyable, view, 
+// 1. Verify that text_encoding::aliases_view satisfies ranges::forward_range, copyable, view,
 //    ranges::random_access_range and ranges::borrowed_range
 
 #include <concepts>
@@ -24,11 +24,11 @@
 #include <text_encoding>
 #include <type_traits>
 
-#include "platform_support.h" 
+#include "platform_support.h"
 #include "test_macros.h"
 #include "test_text_encoding.h"
 
-int main(){
+int main() {
   static_assert(std::ranges::forward_range<std::text_encoding::aliases_view>);
   static_assert(std::copyable<std::text_encoding::aliases_view>);
   static_assert(std::ranges::view<std::text_encoding::aliases_view>);
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/environment.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/environment.pass.cpp
index c0412d4d39ee1..cba72e45f0666 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/environment.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/environment.pass.cpp
@@ -15,18 +15,18 @@
 // UNSUPPORTED: windows
 
 // libc++ is not built with C++26, and the implementation for this function is in a source file.
-// XFAIL: * 
+// XFAIL: *
 
 // class text_encoding
 
-// text_encoding text_encoding::environment(); 
+// text_encoding text_encoding::environment();
 
 // Concerns:
 // 1. text_encoding::environment() returns the encoding for the "C" locale, which should be the default for any C++ program.
 // 2. text_encoding::environment() still returns the "C" locale encoding when the locale is set to "en_US.UTF-8".
-// 3. text_encoding::environment() is affected by changes to the "LANG" environment variable. 
+// 3. text_encoding::environment() is affected by changes to the "LANG" environment variable.
 
-// The current implementation of text_encoding::environment() while conformant, 
+// The current implementation of text_encoding::environment() while conformant,
 // is unfortunately affected by changes to the "LANG" environment variable.
 
 #include <cassert>
@@ -35,14 +35,13 @@
 #include <string_view>
 #include <text_encoding>
 
-#include "platform_support.h" 
+#include "platform_support.h"
 #include "test_macros.h"
 #include "test_text_encoding.h"
 
 int main() {
-
   { // 1
-    auto te = std::text_encoding::environment(); 
+    auto te = std::text_encoding::environment();
 
     assert(te == std::text_encoding::environment());
     assert(te.mib() == std::text_encoding::id::ASCII);
@@ -68,7 +67,7 @@ int main() {
 
   { // 3
     setenv("LANG", LOCALE_en_US_UTF_8, 1);
-    
+
     auto te = std::text_encoding::environment();
 
     assert(te == std::text_encoding::environment());
@@ -78,6 +77,6 @@ int main() {
 
     assert(std::text_encoding::environment_is<std::text_encoding::id::UTF8>());
   }
-  
+
   return 0;
 }
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/literal.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/literal.pass.cpp
index 200f9630de580..4aa6d793000b3 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/literal.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/literal.pass.cpp
@@ -30,7 +30,7 @@
 
 int main() {
 #if __CHAR_BIT__ == 8
- 
+
   {
     auto te = std::text_encoding::literal();
 #  ifdef __GNUC_EXECUTION_CHARSET_NAME
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/begin.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/begin.pass.cpp
index 61c148f854813..ecb98403fc821 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/begin.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/begin.pass.cpp
@@ -14,53 +14,50 @@
 
 // class text_encoding
 
-// text_encoding text_encoding::environment(); 
+// text_encoding text_encoding::environment();
 
 // Concerns:
 // 1. begin() of an aliases_view() from a single text_encoding object are the same.
 // 2. begin() of aliases_views of two text_encoding objects that represent the same ID but hold different names are the same.
-// 3. begin() of aliases_views of two text_encoding objects that represent different IDs are different.  
+// 3. begin() of aliases_views of two text_encoding objects that represent different IDs are different.
 
 #include <cassert>
 #include <cstdlib>
 #include <text_encoding>
 #include <ranges>
 
-#include "platform_support.h" 
+#include "platform_support.h"
 #include "test_macros.h"
 #include "test_text_encoding.h"
 
 using id = std::text_encoding::id;
 
 int main() {
-
   {
-    auto te = std::text_encoding(id::UTF8);
+    auto te    = std::text_encoding(id::UTF8);
     auto view1 = te.aliases();
     auto view2 = te.aliases();
-    
-    assert(std::ranges::begin(view1) == std::ranges::begin(view2)); 
+
+    assert(std::ranges::begin(view1) == std::ranges::begin(view2));
   }
 
   {
     auto te1 = std::text_encoding("ANSI_X3.4-1968");
     auto te2 = std::text_encoding("ANSI_X3.4-1986");
 
-    auto view1 = te1.aliases(); 
+    auto view1 = te1.aliases();
     auto view2 = te2.aliases();
 
     assert(std::ranges::begin(view1) == std::ranges::begin(view2));
   }
 
   {
-    
     auto te1 = std::text_encoding(id::UTF8);
     auto te2 = std::text_encoding(id::ASCII);
-    
+
     auto view1 = te1.aliases();
     auto view2 = te2.aliases();
 
     assert(!(std::ranges::begin(view1) == std::ranges::begin(view2)));
   }
-
 }
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/empty.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/empty.pass.cpp
index 253a060dc0961..6105655351675 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/empty.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/empty.pass.cpp
@@ -14,7 +14,7 @@
 
 // class text_encoding
 
-// text_encoding text_encoding::environment(); 
+// text_encoding text_encoding::environment();
 
 // Concerns:
 // 1. An alias_view of a text_encoding object for "other" is empty
@@ -26,25 +26,24 @@
 #include <ranges>
 #include <text_encoding>
 
-#include "platform_support.h" 
+#include "platform_support.h"
 #include "test_macros.h"
 #include "test_text_encoding.h"
 
 using id = std::text_encoding::id;
 
-int main(){
-
+int main() {
   {
-    auto te = std::text_encoding(id::other);
+    auto te          = std::text_encoding(id::other);
     auto empty_range = te.aliases();
-    
+
     assert(std::ranges::empty(empty_range));
     assert(empty_range.empty());
     assert(!bool(empty_range));
   }
 
   {
-    auto te = std::text_encoding(id::unknown);
+    auto te          = std::text_encoding(id::unknown);
     auto empty_range = te.aliases();
 
     assert(std::ranges::empty(empty_range));
@@ -53,12 +52,11 @@ int main(){
   }
 
   {
-    auto te = std::text_encoding(id::UTF8);
+    auto te    = std::text_encoding(id::UTF8);
     auto range = te.aliases();
 
     assert(!std::ranges::empty(range));
     assert(!range.empty());
     assert(bool(range));
   }
-
 }
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/front.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/front.pass.cpp
index fb9f80247b1ac..9066e1e9f8da9 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/front.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/front.pass.cpp
@@ -14,31 +14,30 @@
 
 // class text_encoding
 
-// text_encoding text_encoding::environment(); 
+// text_encoding text_encoding::environment();
 
 // Concerns:
 // 1. An aliases_view from a single text_encoding object returns the same front()
 // 2. An aliases_views of two text_encoding objects that represent the same ID but hold different names return the same front()
-// 3. An aliases_views of two text_encoding objects that represent different IDs return different front() 
+// 3. An aliases_views of two text_encoding objects that represent different IDs return different front()
 
 #include <cassert>
 #include <cstdlib>
 #include <text_encoding>
 
-#include "platform_support.h" 
+#include "platform_support.h"
 #include "test_macros.h"
 #include "test_text_encoding.h"
 
 using id = std::text_encoding::id;
 
 int main() {
-
   {
     auto te = std::text_encoding(id::UTF8);
-  
+
     auto view1 = te.aliases();
     auto view2 = te.aliases();
-  
+
     assert(view1.front() == view2.front());
   }
 
@@ -46,21 +45,19 @@ int main() {
     auto te1 = std::text_encoding("ANSI_X3.4-1968");
     auto te2 = std::text_encoding("ANSI_X3.4-1986");
 
-    auto view1 = te1.aliases(); 
+    auto view1 = te1.aliases();
     auto view2 = te2.aliases();
 
     assert(view1.front() == view2.front());
   }
 
   {
-    
     auto te1 = std::text_encoding(id::UTF8);
     auto te2 = std::text_encoding(id::ASCII);
-    
+
     auto view1 = te1.aliases();
     auto view2 = te2.aliases();
 
     assert(!(view1.front() == view2.front()));
   }
-
 }

>From 38c97df18df0be1fc7859f7cef79ada14b4c928e Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Fri, 23 May 2025 23:20:55 -0400
Subject: [PATCH 3/3] Fix most causes of failing CI

---
 libcxx/include/text_encoding                     | 12 +++++++-----
 libcxx/test/libcxx/transitive_includes/cxx26.csv |  1 -
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index b312e5ac1b9fb..b41913a57bd72 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -23,7 +23,7 @@ struct text_encoding
 {
     static constexpr size_t max_name_length = 63;
 
-    // [text.encoding.id], enumeration text_encoding​::​id
+    // [text.encoding.id], enumeration text_encoding::id
     enum class id : int_least32_t {
       see below
     };
@@ -36,8 +36,8 @@ struct text_encoding
     constexpr id mib() const noexcept;
     constexpr const char* name() const noexcept;
 
-    // [text.encoding.aliases], class text_encoding​::​aliases_view
-    struct aliases_view;
+    // [text.encoding.aliases], class text_encoding::aliases_view
+    // struct aliases_view;
     constexpr aliases_view aliases() const noexcept;
 
     friend constexpr bool operator==(const text_encoding& a,
@@ -59,10 +59,12 @@ struct text_encoding
 
 #include <__config>
 
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
 #if _LIBCPP_STD_VER >= 26
 #  include <__text_encoding/text_encoding.h>
 #endif // _LIBCPP_STD_VER >= 26
 
-#include <version>
-
 #endif // _LIBCPP_TEXT_ENCODING
diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index 24e57ab696857..a795b872a6646 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -1066,7 +1066,6 @@ system_error string_view
 system_error tuple
 system_error version
 text_encoding cctype
-text_encoding clocale
 text_encoding compare
 text_encoding cstdint
 text_encoding cstdio



More information about the libcxx-commits mailing list