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

William Tran-Viet via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 31 19:32:31 PDT 2026


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

>From 3309926c7636acca750d9e5aa74219ba552d1136 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 01/58] Implement P1885R12

---
 libcxx/docs/FeatureTestMacroTable.rst         |    2 +-
 libcxx/docs/Status/Cxx2cIssues.csv            |    2 +-
 libcxx/docs/Status/Cxx2cPapers.csv            |    4 +-
 libcxx/include/CMakeLists.txt                 |    2 +
 libcxx/include/__configuration/availability.h |    5 +-
 libcxx/include/__locale_dir/locale_base_api.h |    9 +-
 .../include/__locale_dir/support/bsd_like.h   |    8 +-
 libcxx/include/__locale_dir/support/linux.h   |   11 +-
 libcxx/include/__text_encoding/te_impl.h      | 1441 +++++++++++++++++
 libcxx/include/module.modulemap.in            |    7 +
 libcxx/include/text_encoding                  |  142 ++
 libcxx/include/version                        |    2 +-
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |    1 +
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |    1 +
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |    1 +
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |    1 +
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |    1 +
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |    1 +
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |    1 +
 ...xxabi.v1.stable.noexceptions.nonew.abilist |    1 +
 libcxx/modules/std.compat.cppm.in             |    3 -
 libcxx/modules/std.cppm.in                    |    4 +-
 libcxx/modules/std/text_encoding.inc          |   11 +-
 libcxx/src/CMakeLists.txt                     |    1 +
 libcxx/src/text_encoding.cpp                  |  256 +++
 .../test/libcxx/transitive_includes/cxx03.csv |   33 +
 .../test/libcxx/transitive_includes/cxx11.csv |   33 +
 .../test/libcxx/transitive_includes/cxx14.csv |   34 +
 .../test/libcxx/transitive_includes/cxx17.csv |   33 +
 .../test/libcxx/transitive_includes/cxx20.csv |   33 +
 .../test/libcxx/transitive_includes/cxx23.csv |   13 +
 .../test/libcxx/transitive_includes/cxx26.csv |   13 +
 .../text_encoding/environment.pass.cpp        |   38 +
 .../text_encoding.ctor/assert.id.pass.cpp     |   34 +
 .../assert.string_view.pass.cpp               |   37 +
 .../environment.nodiscard.verify.cpp          |   30 +
 .../nodiscard.verify.cpp                      |   31 +
 .../text_encoding.version.compile.pass.cpp    |   62 +
 .../version.version.compile.pass.cpp          |   16 +-
 .../get_long_double_fr_FR.pass.cpp            |    5 +
 .../put_long_double_fr_FR.pass.cpp            |    5 +
 .../locale/locale.members/encoding.pass.cpp   |   53 +
 .../text_encoding/test_text_encoding.h        |  282 ++++
 .../text_encoding.ctor/default.pass.cpp       |   41 +
 .../text_encoding.ctor/id.pass.cpp            |   84 +
 .../text_encoding.ctor/string_view.pass.cpp   |   98 ++
 .../text_encoding.eq/equal.id.pass.cpp        |   74 +
 .../text_encoding.eq/equal.pass.cpp           |   64 +
 .../text_encoding.hash/enabled_hash.pass.cpp  |   24 +
 .../text_encoding.hash/hash.pass.cpp          |   58 +
 .../aliases_view.compile.pass.cpp             |   23 +
 .../environment.pass.cpp                      |   50 +
 .../text_encoding.members/literal.pass.cpp    |   36 +
 .../text_encoding.aliases_view/begin.pass.cpp |   63 +
 .../text_encoding.aliases_view/empty.pass.cpp |   76 +
 .../text_encoding.aliases_view/end.pass.cpp   |   34 +
 .../text_encoding.aliases_view/front.pass.cpp |   63 +
 .../iterator.pass.cpp                         |  103 ++
 .../trivially_copyable.compile.pass.cpp       |   16 +
 libcxx/test/support/platform_support.h        |    1 +
 .../generate_feature_test_macro_components.py |    1 -
 libcxx/utils/libcxx/header_information.py     |    1 -
 .../libcxx/test/features/availability.py      |    8 +
 63 files changed, 3587 insertions(+), 34 deletions(-)
 create mode 100644 libcxx/include/__text_encoding/te_impl.h
 create mode 100644 libcxx/include/text_encoding
 create mode 100644 libcxx/src/text_encoding.cpp
 create mode 100644 libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp
 create mode 100644 libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp
 create mode 100644 libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
 create mode 100644 libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.nodiscard.verify.cpp
 create mode 100644 libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/nodiscard.verify.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/test_text_encoding.h
 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.hash/enabled_hash.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.hash/hash.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases_view.compile.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/end.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/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/trivially_copyable.compile.pass.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index d2b76cb96e866..13dac625c7502 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -524,7 +524,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/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index 101a708b7b2de..f066eca24f3d3 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -56,7 +56,7 @@
 "`LWG4035 <https://wg21.link/LWG4035>`__","``single_view`` should provide ``empty``","2024-03 (Tokyo)","|Complete|","19","`#105328 <https://github.com/llvm/llvm-project/issues/105328>`__",""
 "`LWG4036 <https://wg21.link/LWG4036>`__","``__alignof_is_defined`` is only implicitly specified in C++ and not yet deprecated","2024-03 (Tokyo)","","","`#105329 <https://github.com/llvm/llvm-project/issues/105329>`__",""
 "`LWG4037 <https://wg21.link/LWG4037>`__","Static data members of ``ctype_base`` are not yet required to be usable in constant expressions","2024-03 (Tokyo)","","","`#105330 <https://github.com/llvm/llvm-project/issues/105330>`__",""
-"`LWG4038 <https://wg21.link/LWG4038>`__","``std::text_encoding::aliases_view`` should have constexpr iterators","2024-03 (Tokyo)","","","`#105332 <https://github.com/llvm/llvm-project/issues/105332>`__",""
+"`LWG4038 <https://wg21.link/LWG4038>`__","``std::text_encoding::aliases_view`` should have constexpr iterators","2024-03 (Tokyo)","|Complete|","","`#105332 <https://github.com/llvm/llvm-project/issues/105332>`__",""
 "`LWG4043 <https://wg21.link/LWG4043>`__","""ASCII"" is not a registered character encoding","2024-03 (Tokyo)","|Nothing To Do|","","`#105335 <https://github.com/llvm/llvm-project/issues/105335>`__",""
 "`LWG4045 <https://wg21.link/LWG4045>`__","``tuple`` can create dangling references from ``tuple-like``","2024-03 (Tokyo)","","","`#105337 <https://github.com/llvm/llvm-project/issues/105337>`__",""
 "`LWG4053 <https://wg21.link/LWG4053>`__","Unary call to ``std::views::repeat`` does not decay the argument","2024-03 (Tokyo)","|Complete|","19","`#105338 <https://github.com/llvm/llvm-project/issues/105338>`__",""
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index 29642fc53cac6..77e488654099a 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)","","","`#105370 <https://github.com/llvm/llvm-project/issues/105370>`__",""
 "`P2363R5 <https://wg21.link/P2363R5>`__","Extending associative containers with the remaining heterogeneous overloads","2023-06 (Varna)","","","`#105371 <https://github.com/llvm/llvm-project/issues/105371>`__",""
 "`P1901R2 <https://wg21.link/P1901R2>`__","Enabling the Use of ``weak_ptr`` as Keys in Unordered Associative Containers","2023-06 (Varna)","","","`#105372 <https://github.com/llvm/llvm-project/issues/105372>`__",""
-"`P1885R12 <https://wg21.link/P1885R12>`__","Naming Text Encodings to Demystify Them","2023-06 (Varna)","","","`#105373 <https://github.com/llvm/llvm-project/issues/105373>`__",""
+"`P1885R12 <https://wg21.link/P1885R12>`__","Naming Text Encodings to Demystify Them","2023-06 (Varna)","|Partial|","22","`#105373 <https://github.com/llvm/llvm-project/issues/105373>`__","locale::encoding() is not yet implemented."
 "`P0792R14 <https://wg21.link/P0792R14>`__","``function_ref``: a type-erased callable reference","2023-06 (Varna)","","","`#105376 <https://github.com/llvm/llvm-project/issues/105376>`__",""
 "`P2874R2 <https://wg21.link/P2874R2>`__","P2874R2: Mandating Annex D Require No More","2023-06 (Varna)","|Complete|","12","`#105377 <https://github.com/llvm/llvm-project/issues/105377>`__",""
 "`P2757R3 <https://wg21.link/P2757R3>`__","Type-checking format args","2023-06 (Varna)","","","`#105378 <https://github.com/llvm/llvm-project/issues/105378>`__",""
@@ -79,7 +79,7 @@
 "`P3136R1 <https://wg21.link/P3136R1>`__","Retiring niebloids","2024-11 (Wrocław)","|Complete|","14","`#118133 <https://github.com/llvm/llvm-project/issues/118133>`__",""
 "`P3138R5 <https://wg21.link/P3138R5>`__","``views::cache_latest``","2024-11 (Wrocław)","","","`#118134 <https://github.com/llvm/llvm-project/issues/118134>`__",""
 "`P3379R0 <https://wg21.link/P3379R0>`__","Constrain ``std::expected`` equality operators","2024-11 (Wrocław)","|Complete|","21","`#118135 <https://github.com/llvm/llvm-project/issues/118135>`__",""
-"`P2862R1 <https://wg21.link/P2862R1>`__","``text_encoding::name()`` should never return null values","2024-11 (Wrocław)","","","`#118371 <https://github.com/llvm/llvm-project/issues/118371>`__",""
+"`P2862R1 <https://wg21.link/P2862R1>`__","``text_encoding::name()`` should never return null values","2024-11 (Wrocław)","|Complete|","22","`#118371 <https://github.com/llvm/llvm-project/issues/118371>`__",""
 "`P2897R7 <https://wg21.link/P2897R7>`__","``aligned_accessor``: An ``mdspan`` accessor expressing pointer over-alignment","2024-11 (Wrocław)","|Complete|","21","`#118372 <https://github.com/llvm/llvm-project/issues/118372>`__",""
 "`P3355R2 <https://wg21.link/P3355R2>`__","Fix ``submdspan`` for C++26","2024-11 (Wrocław)","","","`#118373 <https://github.com/llvm/llvm-project/issues/118373>`__",""
 "`P3222R0 <https://wg21.link/P3222R0>`__","Fix C++26 by adding transposed special cases for P2642 layouts","2024-11 (Wrocław)","","","`#118374 <https://github.com/llvm/llvm-project/issues/118374>`__",""
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index dc6c262fad17e..5d52ea5e53677 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -779,6 +779,7 @@ set(files
   __system_error/error_condition.h
   __system_error/system_error.h
   __system_error/throw_system_error.h
+  __text_encoding/te_impl.h
   __thread/formatter.h
   __thread/id.h
   __thread/jthread.h
@@ -1086,6 +1087,7 @@ set(files
   strstream
   syncstream
   system_error
+  text_encoding
   tgmath.h
   thread
   tuple
diff --git a/libcxx/include/__configuration/availability.h b/libcxx/include/__configuration/availability.h
index f70e1b2034772..cd79036b9db68 100644
--- a/libcxx/include/__configuration/availability.h
+++ b/libcxx/include/__configuration/availability.h
@@ -71,7 +71,6 @@
 // clang-format off
 
 // LLVM 22
-// TODO: Fill this in
 #  define _LIBCPP_INTRODUCED_IN_LLVM_22 0
 #  define _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE __attribute__((unavailable))
 
@@ -295,6 +294,10 @@
 #define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE _LIBCPP_INTRODUCED_IN_LLVM_21
 // No attribute, since we've had bad_function_call::what() in the headers before
 
+// Controls whether the internal implementation for text_encoding::environment() -> te_impl::__environment() is available
+#define _LIBCPP_AVAILABILITY_HAS_TE_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_22
+#define _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE
+
 // Only define a bunch of symbols in the dylib if we need to be compatible with LLVM 7 headers or older
 #  if defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_AVAILABILITY_MINIMUM_HEADER_VERSION < 8
 #    define _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8
diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index 0474c1db359de..56826c8e636f1 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -139,6 +139,7 @@
 #    include <__cstddef/size_t.h>
 #    include <__utility/forward.h>
 #    include <ctype.h>
+#    include <langinfo.h>
 #    include <string.h>
 #    include <time.h>
 #    if _LIBCPP_HAS_WIDE_CHARACTERS
@@ -157,6 +158,7 @@ namespace __locale {
 #    define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
 #    define _LIBCPP_ALL_MASK LC_ALL_MASK
 #    define _LIBCPP_LC_ALL LC_ALL
+#    define _LIBCPP_NL_CODESET CODESET
 
 using __locale_t _LIBCPP_NODEBUG = locale_t;
 
@@ -268,7 +270,12 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps,
   return __libcpp_mbsrtowcs_l(__dest, __src, __len, __ps, __loc);
 }
 #      endif // _LIBCPP_HAS_WIDE_CHARACTERS
-#    endif   // _LIBCPP_BUILDING_LIBRARY
+
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+  return ::nl_langinfo_l(__item, __loc);
+}
+
+#    endif // _LIBCPP_BUILDING_LIBRARY
 
 _LIBCPP_DIAGNOSTIC_PUSH
 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
diff --git a/libcxx/include/__locale_dir/support/bsd_like.h b/libcxx/include/__locale_dir/support/bsd_like.h
index 6f533b4e1eab1..c3c1aadefa1e8 100644
--- a/libcxx/include/__locale_dir/support/bsd_like.h
+++ b/libcxx/include/__locale_dir/support/bsd_like.h
@@ -15,6 +15,7 @@
 #include <__utility/forward.h>
 #include <clocale> // std::lconv
 #include <ctype.h>
+#include <langinfo.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -46,6 +47,7 @@ namespace __locale {
 #define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
 #define _LIBCPP_ALL_MASK LC_ALL_MASK
 #define _LIBCPP_LC_ALL LC_ALL
+#define _LIBCPP_NL_CODESET CODESET
 
 using __locale_t _LIBCPP_NODEBUG = ::locale_t;
 #if defined(_LIBCPP_BUILDING_LIBRARY)
@@ -180,7 +182,11 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps,
   return ::mbsrtowcs_l(__dest, __src, __len, __ps, __loc);
 }
 #  endif // _LIBCPP_HAS_WIDE_CHARACTERS
-#endif   // _LIBCPP_BUILDING_LIBRARY
+
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+  return ::nl_langinfo_l(__item, __loc);
+}
+#endif // _LIBCPP_BUILDING_LIBRARY
 
 _LIBCPP_DIAGNOSTIC_PUSH
 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
diff --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index 1a589be49bf1d..96bda017cee43 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -17,6 +17,7 @@
 #include <cstdio>
 #include <cstdlib>
 #include <ctype.h>
+#include <langinfo.h>
 #include <stdarg.h>
 #include <string.h>
 #include <time.h>
@@ -57,6 +58,7 @@ struct __locale_guard {
 #define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
 #define _LIBCPP_ALL_MASK LC_ALL_MASK
 #define _LIBCPP_LC_ALL LC_ALL
+#define _LIBCPP_NL_CODESET CODESET
 
 using __locale_t _LIBCPP_NODEBUG = ::locale_t;
 
@@ -211,7 +213,14 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps,
   return std::mbsrtowcs(__dest, __src, __len, __ps);
 }
 #  endif // _LIBCPP_HAS_WIDE_CHARACTERS
-#endif   // _LIBCPP_BUILDING_LIBRARY
+
+// TODO: Android has langinfo.h but not nl_langinfo_l
+#  ifndef __ANDROID__
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+  return ::nl_langinfo_l(__item, __loc);
+}
+#  endif
+#endif // _LIBCPP_BUILDING_LIBRARY
 
 #ifndef _LIBCPP_COMPILER_GCC // GCC complains that this can't be always_inline due to C-style varargs
 _LIBCPP_HIDE_FROM_ABI
diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
new file mode 100644
index 0000000000000..2192735b027fa
--- /dev/null
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -0,0 +1,1441 @@
+// -*- 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_TE_IMPL_H
+#define _LIBCPP__TEXT_ENCODING_TE_IMPL_H
+
+#include <__algorithm/copy_n.h>
+#include <__algorithm/find.h>
+#include <__algorithm/lower_bound.h>
+#include <__config>
+#include <__cstddef/ptrdiff_t.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/view_interface.h>
+#include <cstdint>
+#include <string_view>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+struct __te_impl {
+private:
+  friend struct text_encoding;
+  enum class __id : int_least32_t {
+    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,
+    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,
+    IBM904                  = 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
+  };
+
+  using enum __id;
+  static constexpr size_t __max_name_length_ = 63;
+
+  struct __te_data {
+    const char* __name_;
+    int_least32_t __mib_rep_;
+    uint16_t __name_size_;
+    uint16_t __to_end_;
+    // The encoding data knows the end of its range to simplify iterator implementation.
+
+    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_data& __e, const __te_data& __other) noexcept {
+      return __e.__mib_rep_ == __other.__mib_rep_ ||
+             __comp_name(string_view(__e.__name_, __e.__name_size_), string_view(__other.__name_, __e.__name_size_));
+    }
+
+    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __te_data& __e, const int_least32_t __i) noexcept {
+      return __e.__mib_rep_ < __i;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_data& __e, std::string_view __name) noexcept {
+      return __comp_name(__name, string_view(__e.__name_, __e.__name_size_));
+    }
+  }; // __te_data
+
+  _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_in) -> char {
+        return (__n_in >= 'A' && __n_in <= 'Z') ? __n_in + ('a' - 'A') : __n_in;
+      };
+      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_ptr != __a.end() && (__a_val = __map_char(*__a_ptr, __a_in_number)) == 255)
+        __a_ptr++;
+      while (__b_ptr != __b.end() && (__b_val = __map_char(*__b_ptr, __b_in_number)) == 255)
+        __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 __te_data* __find_encoding_data(string_view __a) {
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+        __a.size() <= __max_name_length_ && !__a.contains('\0'), "invalid string passed to text_encoding(string_view)");
+    const __te_data* __data_first = __text_encoding_data + 2;
+    const __te_data* __data_last  = std::end(__text_encoding_data);
+
+    auto* __found_data = std::find(__data_first, __data_last, __a);
+
+    if (__found_data == __data_last) {
+      return __text_encoding_data; // other
+    }
+
+    while (__found_data[-1].__mib_rep_ == __found_data->__mib_rep_) {
+      __found_data--;
+    }
+
+    return __found_data;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI static constexpr const __te_data* __find_encoding_data_by_id(__id __i) {
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+        ((__i >= __id::other && __i <= __id::CP50220) && ((int_least32_t(__i) != 33) && (int_least32_t(__i) != 34))),
+        "invalid text_encoding::id passed to text_encoding(id)");
+    auto __found =
+        std::lower_bound(std::begin(__text_encoding_data), std::end(__text_encoding_data), int_least32_t(__i));
+
+    return __found != std::end(__text_encoding_data)
+             ? __found
+             : __text_encoding_data + 1; // unknown, should be unreachable
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr __te_impl() = default;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __te_impl(string_view __enc) noexcept
+      : __encoding_rep_(__find_encoding_data(__enc)) {
+    __enc.copy(__name_, __max_name_length_, 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr __te_impl(__id __i) noexcept : __encoding_rep_(__find_encoding_data_by_id(__i)) {
+    if (__encoding_rep_->__name_[0] != '\0')
+      std::copy_n(__encoding_rep_->__name_, __encoding_rep_->__name_size_, __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> {
+    struct __iterator {
+      using iterator_concept  = random_access_iterator_tag;
+      using iterator_category = random_access_iterator_tag;
+      using value_type        = const char*;
+      using reference         = const char*;
+      using difference_type   = ptrdiff_t;
+
+      constexpr __iterator() noexcept = default;
+
+      _LIBCPP_HIDE_FROM_ABI constexpr value_type operator*() const { return __data_->__name_; }
+
+      _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 {
+        return __data_ - __other.__data_;
+      }
+
+      _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;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) {
+        __data_ += __n;
+        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_; }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(__iterator __it) const { return __data_ <=> __it.__data_; }
+
+    private:
+      friend struct __aliases_view;
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator(const __te_data* __enc_d) noexcept : __data_(__enc_d) {}
+
+      const __te_data* __data_;
+    }; // __iterator
+
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const { return __iterator{__view_data_}; }
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const {
+      return __iterator{__view_data_ + __view_data_->__to_end_};
+    }
+
+  private:
+    friend struct __te_impl;
+
+    _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view(const __te_data* __d) : __view_data_(__d) {}
+    const __te_data* __view_data_;
+  };
+
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view __aliases() const {
+    return __aliases_view(__encoding_rep_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_impl& __a, const __te_impl& __b) noexcept {
+    return __a.__mib() == __id::other && __b.__mib() == __id::other
+             ? __comp_name(__a.__name_, __b.__name_)
+             : __a.__mib() == __b.__mib();
+  }
+
+  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_impl& __encoding, const __id __i) noexcept {
+    return __encoding.__mib() == __i;
+  }
+
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static consteval __te_impl __literal() noexcept {
+    // TODO: Remove this branch once we have __GNUC_EXECUTION_CHARSET_NAME or __clang_literal_encoding__ unconditionally
+#  ifdef __GNUC_EXECUTION_CHARSET_NAME
+    return __te_impl(__GNUC_EXECUTION_CHARSET_NAME);
+#  elif defined(__clang_literal_encoding__)
+    return __te_impl(__clang_literal_encoding__);
+#  else
+    return __te_impl();
+#  endif
+  }
+
+#  if _LIBCPP_HAS_LOCALIZATION
+  _LIBCPP_HIDDEN static __te_impl __get_locale_encoding(const char* __name);
+  _LIBCPP_HIDDEN static __te_impl __get_env_encoding();
+#    if defined(_LIBCPP_WIN32API)
+  _LIBCPP_HIDDEN static __id __get_win32_acp();
+#    endif
+
+  [[__nodiscard__]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment();
+
+  template <__id _Id>
+  [[__nodiscard__]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool __environment_is() {
+    return __environment() == _Id;
+  }
+
+#  endif
+
+  const __te_data* __encoding_rep_     = __text_encoding_data + 1;
+  char __name_[__max_name_length_ + 1] = {0};
+
+  _LIBCPP_HIDE_FROM_ABI static constexpr __te_data __text_encoding_data[] = {
+      {"", 1, 0, 0}, // other
+      {"", 2, 0, 0}, // unknown
+      {"US-ASCII", 3, 8, 11},
+      {"iso-ir-6", 3, 8, 10},
+      {"ANSI_X3.4-1968", 3, 14, 9},
+      {"ANSI_X3.4-1986", 3, 14, 8},
+      {"ISO_646.irv:1991", 3, 16, 7},
+      {"ISO646-US", 3, 9, 6},
+      {"us", 3, 2, 5},
+      {"IBM367", 3, 6, 4},
+      {"cp367", 3, 5, 3},
+      {"csASCII", 3, 7, 2},
+      {"ASCII", 3, 5, 1},
+      {"ISO_8859-1:1987", 4, 15, 9},
+      {"iso-ir-100", 4, 10, 8},
+      {"ISO_8859-1", 4, 10, 7},
+      {"ISO-8859-1", 4, 10, 6},
+      {"latin1", 4, 6, 5},
+      {"l1", 4, 2, 4},
+      {"IBM819", 4, 6, 3},
+      {"CP819", 4, 5, 2},
+      {"csISOLatin1", 4, 11, 1},
+      {"ISO_8859-2:1987", 5, 15, 7},
+      {"iso-ir-101", 5, 10, 6},
+      {"ISO_8859-2", 5, 10, 5},
+      {"ISO-8859-2", 5, 10, 4},
+      {"latin2", 5, 6, 3},
+      {"l2", 5, 2, 2},
+      {"csISOLatin2", 5, 11, 1},
+      {"ISO_8859-3:1988", 6, 15, 7},
+      {"iso-ir-109", 6, 10, 6},
+      {"ISO_8859-3", 6, 10, 5},
+      {"ISO-8859-3", 6, 10, 4},
+      {"latin3", 6, 6, 3},
+      {"l3", 6, 2, 2},
+      {"csISOLatin3", 6, 11, 1},
+      {"ISO_8859-4:1988", 7, 15, 7},
+      {"iso-ir-110", 7, 10, 6},
+      {"ISO_8859-4", 7, 10, 5},
+      {"ISO-8859-4", 7, 10, 4},
+      {"latin4", 7, 6, 3},
+      {"l4", 7, 2, 2},
+      {"csISOLatin4", 7, 11, 1},
+      {"ISO_8859-5:1988", 8, 15, 6},
+      {"iso-ir-144", 8, 10, 5},
+      {"ISO_8859-5", 8, 10, 4},
+      {"ISO-8859-5", 8, 10, 3},
+      {"cyrillic", 8, 8, 2},
+      {"csISOLatinCyrillic", 8, 18, 1},
+      {"ISO_8859-6:1987", 9, 15, 8},
+      {"iso-ir-127", 9, 10, 7},
+      {"ISO_8859-6", 9, 10, 6},
+      {"ISO-8859-6", 9, 10, 5},
+      {"ECMA-114", 9, 8, 4},
+      {"ASMO-708", 9, 8, 3},
+      {"arabic", 9, 6, 2},
+      {"csISOLatinArabic", 9, 16, 1},
+      {"ISO_8859-7:1987", 10, 15, 9},
+      {"iso-ir-126", 10, 10, 8},
+      {"ISO_8859-7", 10, 10, 7},
+      {"ISO-8859-7", 10, 10, 6},
+      {"ELOT_928", 10, 8, 5},
+      {"ECMA-118", 10, 8, 4},
+      {"greek", 10, 5, 3},
+      {"greek8", 10, 6, 2},
+      {"csISOLatinGreek", 10, 15, 1},
+      {"ISO_8859-8:1988", 11, 15, 6},
+      {"iso-ir-138", 11, 10, 5},
+      {"ISO_8859-8", 11, 10, 4},
+      {"ISO-8859-8", 11, 10, 3},
+      {"hebrew", 11, 6, 2},
+      {"csISOLatinHebrew", 11, 16, 1},
+      {"ISO_8859-9:1989", 12, 15, 7},
+      {"iso-ir-148", 12, 10, 6},
+      {"ISO_8859-9", 12, 10, 5},
+      {"ISO-8859-9", 12, 10, 4},
+      {"latin5", 12, 6, 3},
+      {"l5", 12, 2, 2},
+      {"csISOLatin5", 12, 11, 1},
+      {"ISO-8859-10", 13, 11, 6},
+      {"iso-ir-157", 13, 10, 5},
+      {"l6", 13, 2, 4},
+      {"ISO_8859-10:1992", 13, 16, 3},
+      {"csISOLatin6", 13, 11, 2},
+      {"latin6", 13, 6, 1},
+      {"ISO_6937-2-add", 14, 14, 3},
+      {"iso-ir-142", 14, 10, 2},
+      {"csISOTextComm", 14, 13, 1},
+      {"JIS_X0201", 15, 9, 3},
+      {"X0201", 15, 5, 2},
+      {"csHalfWidthKatakana", 15, 19, 1},
+      {"JIS_Encoding", 16, 12, 2},
+      {"csJISEncoding", 16, 13, 1},
+      {"Shift_JIS", 17, 9, 3},
+      {"MS_Kanji", 17, 8, 2},
+      {"csShiftJIS", 17, 10, 1},
+      {"Extended_UNIX_Code_Packed_Format_for_Japanese", 18, 45, 3},
+      {"csEUCPkdFmtJapanese", 18, 19, 2},
+      {"EUC-JP", 18, 6, 1},
+      {"Extended_UNIX_Code_Fixed_Width_for_Japanese", 19, 43, 2},
+      {"csEUCFixWidJapanese", 19, 19, 1},
+      {"BS_4730", 20, 7, 6},
+      {"iso-ir-4", 20, 8, 5},
+      {"ISO646-GB", 20, 9, 4},
+      {"gb", 20, 2, 3},
+      {"uk", 20, 2, 2},
+      {"csISO4UnitedKingdom", 20, 19, 1},
+      {"SEN_850200_C", 21, 12, 5},
+      {"iso-ir-11", 21, 9, 4},
+      {"ISO646-SE2", 21, 10, 3},
+      {"se2", 21, 3, 2},
+      {"csISO11SwedishForNames", 21, 22, 1},
+      {"IT", 22, 2, 4},
+      {"iso-ir-15", 22, 9, 3},
+      {"ISO646-IT", 22, 9, 2},
+      {"csISO15Italian", 22, 14, 1},
+      {"ES", 23, 2, 4},
+      {"iso-ir-17", 23, 9, 3},
+      {"ISO646-ES", 23, 9, 2},
+      {"csISO17Spanish", 23, 14, 1},
+      {"DIN_66003", 24, 9, 5},
+      {"iso-ir-21", 24, 9, 4},
+      {"de", 24, 2, 3},
+      {"ISO646-DE", 24, 9, 2},
+      {"csISO21German", 24, 13, 1},
+      {"NS_4551-1", 25, 9, 6},
+      {"iso-ir-60", 25, 9, 5},
+      {"ISO646-NO", 25, 9, 4},
+      {"no", 25, 2, 3},
+      {"csISO60DanishNorwegian", 25, 22, 2},
+      {"csISO60Norwegian1", 25, 17, 1},
+      {"NF_Z_62-010", 26, 11, 5},
+      {"iso-ir-69", 26, 9, 4},
+      {"ISO646-FR", 26, 9, 3},
+      {"fr", 26, 2, 2},
+      {"csISO69French", 26, 13, 1},
+      {"ISO-10646-UTF-1", 27, 15, 2},
+      {"csISO10646UTF1", 27, 14, 1},
+      {"ISO_646.basic:1983", 28, 18, 3},
+      {"ref", 28, 3, 2},
+      {"csISO646basic1983", 28, 17, 1},
+      {"INVARIANT", 29, 9, 2},
+      {"csINVARIANT", 29, 11, 1},
+      {"ISO_646.irv:1983", 30, 16, 4},
+      {"iso-ir-2", 30, 8, 3},
+      {"irv", 30, 3, 2},
+      {"csISO2IntlRefVersion", 30, 20, 1},
+      {"NATS-SEFI", 31, 9, 3},
+      {"iso-ir-8-1", 31, 10, 2},
+      {"csNATSSEFI", 31, 10, 1},
+      {"NATS-SEFI-ADD", 32, 13, 3},
+      {"iso-ir-8-2", 32, 10, 2},
+      {"csNATSSEFIADD", 32, 13, 1},
+      {"SEN_850200_B", 35, 12, 7},
+      {"iso-ir-10", 35, 9, 6},
+      {"FI", 35, 2, 5},
+      {"ISO646-FI", 35, 9, 4},
+      {"ISO646-SE", 35, 9, 3},
+      {"se", 35, 2, 2},
+      {"csISO10Swedish", 35, 14, 1},
+      {"KS_C_5601-1987", 36, 14, 6},
+      {"iso-ir-149", 36, 10, 5},
+      {"KS_C_5601-1989", 36, 14, 4},
+      {"KSC_5601", 36, 8, 3},
+      {"korean", 36, 6, 2},
+      {"csKSC56011987", 36, 13, 1},
+      {"ISO-2022-KR", 37, 11, 2},
+      {"csISO2022KR", 37, 11, 1},
+      {"EUC-KR", 38, 6, 2},
+      {"csEUCKR", 38, 7, 1},
+      {"ISO-2022-JP", 39, 11, 2},
+      {"csISO2022JP", 39, 11, 1},
+      {"ISO-2022-JP-2", 40, 13, 2},
+      {"csISO2022JP2", 40, 12, 1},
+      {"JIS_C6220-1969-jp", 41, 17, 6},
+      {"JIS_C6220-1969", 41, 14, 5},
+      {"iso-ir-13", 41, 9, 4},
+      {"katakana", 41, 8, 3},
+      {"x0201-7", 41, 7, 2},
+      {"csISO13JISC6220jp", 41, 17, 1},
+      {"JIS_C6220-1969-ro", 42, 17, 5},
+      {"iso-ir-14", 42, 9, 4},
+      {"jp", 42, 2, 3},
+      {"ISO646-JP", 42, 9, 2},
+      {"csISO14JISC6220ro", 42, 17, 1},
+      {"PT", 43, 2, 4},
+      {"iso-ir-16", 43, 9, 3},
+      {"ISO646-PT", 43, 9, 2},
+      {"csISO16Portuguese", 43, 17, 1},
+      {"greek7-old", 44, 10, 3},
+      {"iso-ir-18", 44, 9, 2},
+      {"csISO18Greek7Old", 44, 16, 1},
+      {"latin-greek", 45, 11, 3},
+      {"iso-ir-19", 45, 9, 2},
+      {"csISO19LatinGreek", 45, 17, 1},
+      {"NF_Z_62-010_(1973)", 46, 18, 4},
+      {"iso-ir-25", 46, 9, 3},
+      {"ISO646-FR1", 46, 10, 2},
+      {"csISO25French", 46, 13, 1},
+      {"Latin-greek-1", 47, 13, 3},
+      {"iso-ir-27", 47, 9, 2},
+      {"csISO27LatinGreek1", 47, 18, 1},
+      {"ISO_5427", 48, 8, 3},
+      {"iso-ir-37", 48, 9, 2},
+      {"csISO5427Cyrillic", 48, 17, 1},
+      {"JIS_C6226-1978", 49, 14, 3},
+      {"iso-ir-42", 49, 9, 2},
+      {"csISO42JISC62261978", 49, 19, 1},
+      {"BS_viewdata", 50, 11, 3},
+      {"iso-ir-47", 50, 9, 2},
+      {"csISO47BSViewdata", 50, 17, 1},
+      {"INIS", 51, 4, 3},
+      {"iso-ir-49", 51, 9, 2},
+      {"csISO49INIS", 51, 11, 1},
+      {"INIS-8", 52, 6, 3},
+      {"iso-ir-50", 52, 9, 2},
+      {"csISO50INIS8", 52, 12, 1},
+      {"INIS-cyrillic", 53, 13, 3},
+      {"iso-ir-51", 53, 9, 2},
+      {"csISO51INISCyrillic", 53, 19, 1},
+      {"ISO_5427:1981", 54, 13, 4},
+      {"iso-ir-54", 54, 9, 3},
+      {"ISO5427Cyrillic1981", 54, 19, 2},
+      {"csISO54271981", 54, 13, 1},
+      {"ISO_5428:1980", 55, 13, 3},
+      {"iso-ir-55", 55, 9, 2},
+      {"csISO5428Greek", 55, 14, 1},
+      {"GB_1988-80", 56, 10, 5},
+      {"iso-ir-57", 56, 9, 4},
+      {"cn", 56, 2, 3},
+      {"ISO646-CN", 56, 9, 2},
+      {"csISO57GB1988", 56, 13, 1},
+      {"GB_2312-80", 57, 10, 4},
+      {"iso-ir-58", 57, 9, 3},
+      {"chinese", 57, 7, 2},
+      {"csISO58GB231280", 57, 15, 1},
+      {"NS_4551-2", 58, 9, 5},
+      {"ISO646-NO2", 58, 10, 4},
+      {"iso-ir-61", 58, 9, 3},
+      {"no2", 58, 3, 2},
+      {"csISO61Norwegian2", 58, 17, 1},
+      {"videotex-suppl", 59, 14, 3},
+      {"iso-ir-70", 59, 9, 2},
+      {"csISO70VideotexSupp1", 59, 20, 1},
+      {"PT2", 60, 3, 4},
+      {"iso-ir-84", 60, 9, 3},
+      {"ISO646-PT2", 60, 10, 2},
+      {"csISO84Portuguese2", 60, 18, 1},
+      {"ES2", 61, 3, 4},
+      {"iso-ir-85", 61, 9, 3},
+      {"ISO646-ES2", 61, 10, 2},
+      {"csISO85Spanish2", 61, 15, 1},
+      {"MSZ_7795.3", 62, 10, 5},
+      {"iso-ir-86", 62, 9, 4},
+      {"ISO646-HU", 62, 9, 3},
+      {"hu", 62, 2, 2},
+      {"csISO86Hungarian", 62, 16, 1},
+      {"JIS_C6226-1983", 63, 14, 5},
+      {"iso-ir-87", 63, 9, 4},
+      {"x0208", 63, 5, 3},
+      {"JIS_X0208-1983", 63, 14, 2},
+      {"csISO87JISX0208", 63, 15, 1},
+      {"greek7", 64, 6, 3},
+      {"iso-ir-88", 64, 9, 2},
+      {"csISO88Greek7", 64, 13, 1},
+      {"ASMO_449", 65, 8, 5},
+      {"ISO_9036", 65, 8, 4},
+      {"arabic7", 65, 7, 3},
+      {"iso-ir-89", 65, 9, 2},
+      {"csISO89ASMO449", 65, 14, 1},
+      {"iso-ir-90", 66, 9, 2},
+      {"csISO90", 66, 7, 1},
+      {"JIS_C6229-1984-a", 67, 16, 4},
+      {"iso-ir-91", 67, 9, 3},
+      {"jp-ocr-a", 67, 8, 2},
+      {"csISO91JISC62291984a", 67, 20, 1},
+      {"JIS_C6229-1984-b", 68, 16, 5},
+      {"iso-ir-92", 68, 9, 4},
+      {"ISO646-JP-OCR-B", 68, 15, 3},
+      {"jp-ocr-b", 68, 8, 2},
+      {"csISO92JISC62991984b", 68, 20, 1},
+      {"JIS_C6229-1984-b-add", 69, 20, 4},
+      {"iso-ir-93", 69, 9, 3},
+      {"jp-ocr-b-add", 69, 12, 2},
+      {"csISO93JIS62291984badd", 69, 22, 1},
+      {"JIS_C6229-1984-hand", 70, 19, 4},
+      {"iso-ir-94", 70, 9, 3},
+      {"jp-ocr-hand", 70, 11, 2},
+      {"csISO94JIS62291984hand", 70, 22, 1},
+      {"JIS_C6229-1984-hand-add", 71, 23, 4},
+      {"iso-ir-95", 71, 9, 3},
+      {"jp-ocr-hand-add", 71, 15, 2},
+      {"csISO95JIS62291984handadd", 71, 25, 1},
+      {"JIS_C6229-1984-kana", 72, 19, 3},
+      {"iso-ir-96", 72, 9, 2},
+      {"csISO96JISC62291984kana", 72, 23, 1},
+      {"ISO_2033-1983", 73, 13, 4},
+      {"iso-ir-98", 73, 9, 3},
+      {"e13b", 73, 4, 2},
+      {"csISO2033", 73, 9, 1},
+      {"ANSI_X3.110-1983", 74, 16, 5},
+      {"iso-ir-99", 74, 9, 4},
+      {"CSA_T500-1983", 74, 13, 3},
+      {"NAPLPS", 74, 6, 2},
+      {"csISO99NAPLPS", 74, 13, 1},
+      {"T.61-7bit", 75, 9, 3},
+      {"iso-ir-102", 75, 10, 2},
+      {"csISO102T617bit", 75, 15, 1},
+      {"T.61-8bit", 76, 9, 4},
+      {"T.61", 76, 4, 3},
+      {"iso-ir-103", 76, 10, 2},
+      {"csISO103T618bit", 76, 15, 1},
+      {"ECMA-cyrillic", 77, 13, 4},
+      {"iso-ir-111", 77, 10, 3},
+      {"KOI8-E", 77, 6, 2},
+      {"csISO111ECMACyrillic", 77, 20, 1},
+      {"CSA_Z243.4-1985-1", 78, 17, 7},
+      {"iso-ir-121", 78, 10, 6},
+      {"ISO646-CA", 78, 9, 5},
+      {"csa7-1", 78, 6, 4},
+      {"csa71", 78, 5, 3},
+      {"ca", 78, 2, 2},
+      {"csISO121Canadian1", 78, 17, 1},
+      {"CSA_Z243.4-1985-2", 79, 17, 6},
+      {"iso-ir-122", 79, 10, 5},
+      {"ISO646-CA2", 79, 10, 4},
+      {"csa7-2", 79, 6, 3},
+      {"csa72", 79, 5, 2},
+      {"csISO122Canadian2", 79, 17, 1},
+      {"CSA_Z243.4-1985-gr", 80, 18, 3},
+      {"iso-ir-123", 80, 10, 2},
+      {"csISO123CSAZ24341985gr", 80, 22, 1},
+      {"ISO_8859-6-E", 81, 12, 3},
+      {"csISO88596E", 81, 11, 2},
+      {"ISO-8859-6-E", 81, 12, 1},
+      {"ISO_8859-6-I", 82, 12, 3},
+      {"csISO88596I", 82, 11, 2},
+      {"ISO-8859-6-I", 82, 12, 1},
+      {"T.101-G2", 83, 8, 3},
+      {"iso-ir-128", 83, 10, 2},
+      {"csISO128T101G2", 83, 14, 1},
+      {"ISO_8859-8-E", 84, 12, 3},
+      {"csISO88598E", 84, 11, 2},
+      {"ISO-8859-8-E", 84, 12, 1},
+      {"ISO_8859-8-I", 85, 12, 3},
+      {"csISO88598I", 85, 11, 2},
+      {"ISO-8859-8-I", 85, 12, 1},
+      {"CSN_369103", 86, 10, 3},
+      {"iso-ir-139", 86, 10, 2},
+      {"csISO139CSN369103", 86, 17, 1},
+      {"JUS_I.B1.002", 87, 12, 6},
+      {"iso-ir-141", 87, 10, 5},
+      {"ISO646-YU", 87, 9, 4},
+      {"js", 87, 2, 3},
+      {"yu", 87, 2, 2},
+      {"csISO141JUSIB1002", 87, 17, 1},
+      {"IEC_P27-1", 88, 9, 3},
+      {"iso-ir-143", 88, 10, 2},
+      {"csISO143IECP271", 88, 15, 1},
+      {"JUS_I.B1.003-serb", 89, 17, 4},
+      {"iso-ir-146", 89, 10, 3},
+      {"serbian", 89, 7, 2},
+      {"csISO146Serbian", 89, 15, 1},
+      {"JUS_I.B1.003-mac", 90, 16, 4},
+      {"macedonian", 90, 10, 3},
+      {"iso-ir-147", 90, 10, 2},
+      {"csISO147Macedonian", 90, 18, 1},
+      {"greek-ccitt", 91, 11, 4},
+      {"iso-ir-150", 91, 10, 3},
+      {"csISO150", 91, 8, 2},
+      {"csISO150GreekCCITT", 91, 18, 1},
+      {"NC_NC00-10:81", 92, 13, 5},
+      {"cuba", 92, 4, 4},
+      {"iso-ir-151", 92, 10, 3},
+      {"ISO646-CU", 92, 9, 2},
+      {"csISO151Cuba", 92, 12, 1},
+      {"ISO_6937-2-25", 93, 13, 3},
+      {"iso-ir-152", 93, 10, 2},
+      {"csISO6937Add", 93, 12, 1},
+      {"GOST_19768-74", 94, 13, 4},
+      {"ST_SEV_358-88", 94, 13, 3},
+      {"iso-ir-153", 94, 10, 2},
+      {"csISO153GOST1976874", 94, 19, 1},
+      {"ISO_8859-supp", 95, 13, 4},
+      {"iso-ir-154", 95, 10, 3},
+      {"latin1-2-5", 95, 10, 2},
+      {"csISO8859Supp", 95, 13, 1},
+      {"ISO_10367-box", 96, 13, 3},
+      {"iso-ir-155", 96, 10, 2},
+      {"csISO10367Box", 96, 13, 1},
+      {"latin-lap", 97, 9, 4},
+      {"lap", 97, 3, 3},
+      {"iso-ir-158", 97, 10, 2},
+      {"csISO158Lap", 97, 11, 1},
+      {"JIS_X0212-1990", 98, 14, 4},
+      {"x0212", 98, 5, 3},
+      {"iso-ir-159", 98, 10, 2},
+      {"csISO159JISX02121990", 98, 20, 1},
+      {"DS_2089", 99, 7, 5},
+      {"DS2089", 99, 6, 4},
+      {"ISO646-DK", 99, 9, 3},
+      {"dk", 99, 2, 2},
+      {"csISO646Danish", 99, 14, 1},
+      {"us-dk", 100, 5, 2},
+      {"csUSDK", 100, 6, 1},
+      {"dk-us", 101, 5, 2},
+      {"csDKUS", 101, 6, 1},
+      {"KSC5636", 102, 7, 3},
+      {"ISO646-KR", 102, 9, 2},
+      {"csKSC5636", 102, 9, 1},
+      {"UNICODE-1-1-UTF-7", 103, 17, 2},
+      {"csUnicode11UTF7", 103, 15, 1},
+      {"ISO-2022-CN", 104, 11, 2},
+      {"csISO2022CN", 104, 11, 1},
+      {"ISO-2022-CN-EXT", 105, 15, 2},
+      {"csISO2022CNEXT", 105, 14, 1},
+      {"UTF-8", 106, 5, 2},
+      {"csUTF8", 106, 6, 1},
+      {"ISO-8859-13", 109, 11, 2},
+      {"csISO885913", 109, 11, 1},
+      {"ISO-8859-14", 110, 11, 8},
+      {"iso-ir-199", 110, 10, 7},
+      {"ISO_8859-14:1998", 110, 16, 6},
+      {"ISO_8859-14", 110, 11, 5},
+      {"latin8", 110, 6, 4},
+      {"iso-celtic", 110, 10, 3},
+      {"l8", 110, 2, 2},
+      {"csISO885914", 110, 11, 1},
+      {"ISO-8859-15", 111, 11, 4},
+      {"ISO_8859-15", 111, 11, 3},
+      {"Latin-9", 111, 7, 2},
+      {"csISO885915", 111, 11, 1},
+      {"ISO-8859-16", 112, 11, 7},
+      {"iso-ir-226", 112, 10, 6},
+      {"ISO_8859-16:2001", 112, 16, 5},
+      {"ISO_8859-16", 112, 11, 4},
+      {"latin10", 112, 7, 3},
+      {"l10", 112, 3, 2},
+      {"csISO885916", 112, 11, 1},
+      {"GBK", 113, 3, 5},
+      {"CP936", 113, 5, 4},
+      {"MS936", 113, 5, 3},
+      {"windows-936", 113, 11, 2},
+      {"csGBK", 113, 5, 1},
+      {"GB18030", 114, 7, 2},
+      {"csGB18030", 114, 9, 1},
+      {"OSD_EBCDIC_DF04_15", 115, 18, 2},
+      {"csOSDEBCDICDF0415", 115, 17, 1},
+      {"OSD_EBCDIC_DF03_IRV", 116, 19, 2},
+      {"csOSDEBCDICDF03IRV", 116, 18, 1},
+      {"OSD_EBCDIC_DF04_1", 117, 17, 2},
+      {"csOSDEBCDICDF041", 117, 16, 1},
+      {"ISO-11548-1", 118, 11, 4},
+      {"ISO_11548-1", 118, 11, 3},
+      {"ISO_TR_11548-1", 118, 14, 2},
+      {"csISO115481", 118, 11, 1},
+      {"KZ-1048", 119, 7, 4},
+      {"STRK1048-2002", 119, 13, 3},
+      {"RK1048", 119, 6, 2},
+      {"csKZ1048", 119, 8, 1},
+      {"ISO-10646-UCS-2", 1000, 15, 2},
+      {"csUnicode", 1000, 9, 1},
+      {"ISO-10646-UCS-4", 1001, 15, 2},
+      {"csUCS4", 1001, 6, 1},
+      {"ISO-10646-UCS-Basic", 1002, 19, 2},
+      {"csUnicodeASCII", 1002, 14, 1},
+      {"ISO-10646-Unicode-Latin1", 1003, 24, 3},
+      {"csUnicodeLatin1", 1003, 15, 2},
+      {"ISO-10646", 1003, 9, 1},
+      {"ISO-10646-J-1", 1004, 13, 2},
+      {"csUnicodeJapanese", 1004, 17, 1},
+      {"ISO-Unicode-IBM-1261", 1005, 20, 2},
+      {"csUnicodeIBM1261", 1005, 16, 1},
+      {"ISO-Unicode-IBM-1268", 1006, 20, 2},
+      {"csUnicodeIBM1268", 1006, 16, 1},
+      {"ISO-Unicode-IBM-1276", 1007, 20, 2},
+      {"csUnicodeIBM1276", 1007, 16, 1},
+      {"ISO-Unicode-IBM-1264", 1008, 20, 2},
+      {"csUnicodeIBM1264", 1008, 16, 1},
+      {"ISO-Unicode-IBM-1265", 1009, 20, 2},
+      {"csUnicodeIBM1265", 1009, 16, 1},
+      {"UNICODE-1-1", 1010, 11, 2},
+      {"csUnicode11", 1010, 11, 1},
+      {"SCSU", 1011, 4, 2},
+      {"csSCSU", 1011, 6, 1},
+      {"UTF-7", 1012, 5, 2},
+      {"csUTF7", 1012, 6, 1},
+      {"UTF-16BE", 1013, 8, 2},
+      {"csUTF16BE", 1013, 9, 1},
+      {"UTF-16LE", 1014, 8, 2},
+      {"csUTF16LE", 1014, 9, 1},
+      {"UTF-16", 1015, 6, 2},
+      {"csUTF16", 1015, 7, 1},
+      {"CESU-8", 1016, 6, 3},
+      {"csCESU8", 1016, 7, 2},
+      {"csCESU-8", 1016, 8, 1},
+      {"UTF-32", 1017, 6, 2},
+      {"csUTF32", 1017, 7, 1},
+      {"UTF-32BE", 1018, 8, 2},
+      {"csUTF32BE", 1018, 9, 1},
+      {"UTF-32LE", 1019, 8, 2},
+      {"csUTF32LE", 1019, 9, 1},
+      {"BOCU-1", 1020, 6, 3},
+      {"csBOCU1", 1020, 7, 2},
+      {"csBOCU-1", 1020, 8, 1},
+      {"UTF-7-IMAP", 1021, 10, 2},
+      {"csUTF7IMAP", 1021, 10, 1},
+      {"ISO-8859-1-Windows-3.0-Latin-1", 2000, 30, 2},
+      {"csWindows30Latin1", 2000, 17, 1},
+      {"ISO-8859-1-Windows-3.1-Latin-1", 2001, 30, 2},
+      {"csWindows31Latin1", 2001, 17, 1},
+      {"ISO-8859-2-Windows-Latin-2", 2002, 26, 2},
+      {"csWindows31Latin2", 2002, 17, 1},
+      {"ISO-8859-9-Windows-Latin-5", 2003, 26, 2},
+      {"csWindows31Latin5", 2003, 17, 1},
+      {"hp-roman8", 2004, 9, 4},
+      {"roman8", 2004, 6, 3},
+      {"r8", 2004, 2, 2},
+      {"csHPRoman8", 2004, 10, 1},
+      {"Adobe-Standard-Encoding", 2005, 23, 2},
+      {"csAdobeStandardEncoding", 2005, 23, 1},
+      {"Ventura-US", 2006, 10, 2},
+      {"csVenturaUS", 2006, 11, 1},
+      {"Ventura-International", 2007, 21, 2},
+      {"csVenturaInternational", 2007, 22, 1},
+      {"DEC-MCS", 2008, 7, 3},
+      {"dec", 2008, 3, 2},
+      {"csDECMCS", 2008, 8, 1},
+      {"IBM850", 2009, 6, 4},
+      {"cp850", 2009, 5, 3},
+      {"850", 2009, 3, 2},
+      {"csPC850Multilingual", 2009, 19, 1},
+      {"IBM852", 2010, 6, 4},
+      {"cp852", 2010, 5, 3},
+      {"852", 2010, 3, 2},
+      {"csPCp852", 2010, 8, 1},
+      {"IBM437", 2011, 6, 4},
+      {"cp437", 2011, 5, 3},
+      {"437", 2011, 3, 2},
+      {"csPC8CodePage437", 2011, 16, 1},
+      {"PC8-Danish-Norwegian", 2012, 20, 2},
+      {"csPC8DanishNorwegian", 2012, 20, 1},
+      {"IBM862", 2013, 6, 4},
+      {"cp862", 2013, 5, 3},
+      {"862", 2013, 3, 2},
+      {"csPC862LatinHebrew", 2013, 18, 1},
+      {"PC8-Turkish", 2014, 11, 2},
+      {"csPC8Turkish", 2014, 12, 1},
+      {"IBM-Symbols", 2015, 11, 2},
+      {"csIBMSymbols", 2015, 12, 1},
+      {"IBM-Thai", 2016, 8, 2},
+      {"csIBMThai", 2016, 9, 1},
+      {"HP-Legal", 2017, 8, 2},
+      {"csHPLegal", 2017, 9, 1},
+      {"HP-Pi-font", 2018, 10, 2},
+      {"csHPPiFont", 2018, 10, 1},
+      {"HP-Math8", 2019, 8, 2},
+      {"csHPMath8", 2019, 9, 1},
+      {"Adobe-Symbol-Encoding", 2020, 21, 2},
+      {"csHPPSMath", 2020, 10, 1},
+      {"HP-DeskTop", 2021, 10, 2},
+      {"csHPDesktop", 2021, 11, 1},
+      {"Ventura-Math", 2022, 12, 2},
+      {"csVenturaMath", 2022, 13, 1},
+      {"Microsoft-Publishing", 2023, 20, 2},
+      {"csMicrosoftPublishing", 2023, 21, 1},
+      {"Windows-31J", 2024, 11, 2},
+      {"csWindows31J", 2024, 12, 1},
+      {"GB2312", 2025, 6, 2},
+      {"csGB2312", 2025, 8, 1},
+      {"Big5", 2026, 4, 2},
+      {"csBig5", 2026, 6, 1},
+      {"macintosh", 2027, 9, 3},
+      {"mac", 2027, 3, 2},
+      {"csMacintosh", 2027, 11, 1},
+      {"IBM037", 2028, 6, 7},
+      {"cp037", 2028, 5, 6},
+      {"ebcdic-cp-us", 2028, 12, 5},
+      {"ebcdic-cp-ca", 2028, 12, 4},
+      {"ebcdic-cp-wt", 2028, 12, 3},
+      {"ebcdic-cp-nl", 2028, 12, 2},
+      {"csIBM037", 2028, 8, 1},
+      {"IBM038", 2029, 6, 4},
+      {"EBCDIC-INT", 2029, 10, 3},
+      {"cp038", 2029, 5, 2},
+      {"csIBM038", 2029, 8, 1},
+      {"IBM273", 2030, 6, 3},
+      {"CP273", 2030, 5, 2},
+      {"csIBM273", 2030, 8, 1},
+      {"IBM274", 2031, 6, 4},
+      {"EBCDIC-BE", 2031, 9, 3},
+      {"CP274", 2031, 5, 2},
+      {"csIBM274", 2031, 8, 1},
+      {"IBM275", 2032, 6, 4},
+      {"EBCDIC-BR", 2032, 9, 3},
+      {"cp275", 2032, 5, 2},
+      {"csIBM275", 2032, 8, 1},
+      {"IBM277", 2033, 6, 4},
+      {"EBCDIC-CP-DK", 2033, 12, 3},
+      {"EBCDIC-CP-NO", 2033, 12, 2},
+      {"csIBM277", 2033, 8, 1},
+      {"IBM278", 2034, 6, 5},
+      {"CP278", 2034, 5, 4},
+      {"ebcdic-cp-fi", 2034, 12, 3},
+      {"ebcdic-cp-se", 2034, 12, 2},
+      {"csIBM278", 2034, 8, 1},
+      {"IBM280", 2035, 6, 4},
+      {"CP280", 2035, 5, 3},
+      {"ebcdic-cp-it", 2035, 12, 2},
+      {"csIBM280", 2035, 8, 1},
+      {"IBM281", 2036, 6, 4},
+      {"EBCDIC-JP-E", 2036, 11, 3},
+      {"cp281", 2036, 5, 2},
+      {"csIBM281", 2036, 8, 1},
+      {"IBM284", 2037, 6, 4},
+      {"CP284", 2037, 5, 3},
+      {"ebcdic-cp-es", 2037, 12, 2},
+      {"csIBM284", 2037, 8, 1},
+      {"IBM285", 2038, 6, 4},
+      {"CP285", 2038, 5, 3},
+      {"ebcdic-cp-gb", 2038, 12, 2},
+      {"csIBM285", 2038, 8, 1},
+      {"IBM290", 2039, 6, 4},
+      {"cp290", 2039, 5, 3},
+      {"EBCDIC-JP-kana", 2039, 14, 2},
+      {"csIBM290", 2039, 8, 1},
+      {"IBM297", 2040, 6, 4},
+      {"cp297", 2040, 5, 3},
+      {"ebcdic-cp-fr", 2040, 12, 2},
+      {"csIBM297", 2040, 8, 1},
+      {"IBM420", 2041, 6, 4},
+      {"cp420", 2041, 5, 3},
+      {"ebcdic-cp-ar1", 2041, 13, 2},
+      {"csIBM420", 2041, 8, 1},
+      {"IBM423", 2042, 6, 4},
+      {"cp423", 2042, 5, 3},
+      {"ebcdic-cp-gr", 2042, 12, 2},
+      {"csIBM423", 2042, 8, 1},
+      {"IBM424", 2043, 6, 4},
+      {"cp424", 2043, 5, 3},
+      {"ebcdic-cp-he", 2043, 12, 2},
+      {"csIBM424", 2043, 8, 1},
+      {"IBM500", 2044, 6, 5},
+      {"CP500", 2044, 5, 4},
+      {"ebcdic-cp-be", 2044, 12, 3},
+      {"ebcdic-cp-ch", 2044, 12, 2},
+      {"csIBM500", 2044, 8, 1},
+      {"IBM851", 2045, 6, 4},
+      {"cp851", 2045, 5, 3},
+      {"851", 2045, 3, 2},
+      {"csIBM851", 2045, 8, 1},
+      {"IBM855", 2046, 6, 4},
+      {"cp855", 2046, 5, 3},
+      {"855", 2046, 3, 2},
+      {"csIBM855", 2046, 8, 1},
+      {"IBM857", 2047, 6, 4},
+      {"cp857", 2047, 5, 3},
+      {"857", 2047, 3, 2},
+      {"csIBM857", 2047, 8, 1},
+      {"IBM860", 2048, 6, 4},
+      {"cp860", 2048, 5, 3},
+      {"860", 2048, 3, 2},
+      {"csIBM860", 2048, 8, 1},
+      {"IBM861", 2049, 6, 5},
+      {"cp861", 2049, 5, 4},
+      {"861", 2049, 3, 3},
+      {"cp-is", 2049, 5, 2},
+      {"csIBM861", 2049, 8, 1},
+      {"IBM863", 2050, 6, 4},
+      {"cp863", 2050, 5, 3},
+      {"863", 2050, 3, 2},
+      {"csIBM863", 2050, 8, 1},
+      {"IBM864", 2051, 6, 3},
+      {"cp864", 2051, 5, 2},
+      {"csIBM864", 2051, 8, 1},
+      {"IBM865", 2052, 6, 4},
+      {"cp865", 2052, 5, 3},
+      {"865", 2052, 3, 2},
+      {"csIBM865", 2052, 8, 1},
+      {"IBM868", 2053, 6, 4},
+      {"CP868", 2053, 5, 3},
+      {"cp-ar", 2053, 5, 2},
+      {"csIBM868", 2053, 8, 1},
+      {"IBM869", 2054, 6, 5},
+      {"cp869", 2054, 5, 4},
+      {"869", 2054, 3, 3},
+      {"cp-gr", 2054, 5, 2},
+      {"csIBM869", 2054, 8, 1},
+      {"IBM870", 2055, 6, 5},
+      {"CP870", 2055, 5, 4},
+      {"ebcdic-cp-roece", 2055, 15, 3},
+      {"ebcdic-cp-yu", 2055, 12, 2},
+      {"csIBM870", 2055, 8, 1},
+      {"IBM871", 2056, 6, 4},
+      {"CP871", 2056, 5, 3},
+      {"ebcdic-cp-is", 2056, 12, 2},
+      {"csIBM871", 2056, 8, 1},
+      {"IBM880", 2057, 6, 4},
+      {"cp880", 2057, 5, 3},
+      {"EBCDIC-Cyrillic", 2057, 15, 2},
+      {"csIBM880", 2057, 8, 1},
+      {"IBM891", 2058, 6, 3},
+      {"cp891", 2058, 5, 2},
+      {"csIBM891", 2058, 8, 1},
+      {"IBM903", 2059, 6, 3},
+      {"cp903", 2059, 5, 2},
+      {"csIBM903", 2059, 8, 1},
+      {"IBM904", 2060, 6, 4},
+      {"cp904", 2060, 5, 3},
+      {"904", 2060, 3, 2},
+      {"csIBBM904", 2060, 9, 1},
+      {"IBM905", 2061, 6, 4},
+      {"CP905", 2061, 5, 3},
+      {"ebcdic-cp-tr", 2061, 12, 2},
+      {"csIBM905", 2061, 8, 1},
+      {"IBM918", 2062, 6, 4},
+      {"CP918", 2062, 5, 3},
+      {"ebcdic-cp-ar2", 2062, 13, 2},
+      {"csIBM918", 2062, 8, 1},
+      {"IBM1026", 2063, 7, 3},
+      {"CP1026", 2063, 6, 2},
+      {"csIBM1026", 2063, 9, 1},
+      {"EBCDIC-AT-DE", 2064, 12, 2},
+      {"csIBMEBCDICATDE", 2064, 15, 1},
+      {"EBCDIC-AT-DE-A", 2065, 14, 2},
+      {"csEBCDICATDEA", 2065, 13, 1},
+      {"EBCDIC-CA-FR", 2066, 12, 2},
+      {"csEBCDICCAFR", 2066, 12, 1},
+      {"EBCDIC-DK-NO", 2067, 12, 2},
+      {"csEBCDICDKNO", 2067, 12, 1},
+      {"EBCDIC-DK-NO-A", 2068, 14, 2},
+      {"csEBCDICDKNOA", 2068, 13, 1},
+      {"EBCDIC-FI-SE", 2069, 12, 2},
+      {"csEBCDICFISE", 2069, 12, 1},
+      {"EBCDIC-FI-SE-A", 2070, 14, 2},
+      {"csEBCDICFISEA", 2070, 13, 1},
+      {"EBCDIC-FR", 2071, 9, 2},
+      {"csEBCDICFR", 2071, 10, 1},
+      {"EBCDIC-IT", 2072, 9, 2},
+      {"csEBCDICIT", 2072, 10, 1},
+      {"EBCDIC-PT", 2073, 9, 2},
+      {"csEBCDICPT", 2073, 10, 1},
+      {"EBCDIC-ES", 2074, 9, 2},
+      {"csEBCDICES", 2074, 10, 1},
+      {"EBCDIC-ES-A", 2075, 11, 2},
+      {"csEBCDICESA", 2075, 11, 1},
+      {"EBCDIC-ES-S", 2076, 11, 2},
+      {"csEBCDICESS", 2076, 11, 1},
+      {"EBCDIC-UK", 2077, 9, 2},
+      {"csEBCDICUK", 2077, 10, 1},
+      {"EBCDIC-US", 2078, 9, 2},
+      {"csEBCDICUS", 2078, 10, 1},
+      {"UNKNOWN-8BIT", 2079, 12, 2},
+      {"csUnknown8BiT", 2079, 13, 1},
+      {"MNEMONIC", 2080, 8, 2},
+      {"csMnemonic", 2080, 10, 1},
+      {"MNEM", 2081, 4, 2},
+      {"csMnem", 2081, 6, 1},
+      {"VISCII", 2082, 6, 2},
+      {"csVISCII", 2082, 8, 1},
+      {"VIQR", 2083, 4, 2},
+      {"csVIQR", 2083, 6, 1},
+      {"KOI8-R", 2084, 6, 2},
+      {"csKOI8R", 2084, 7, 1},
+      {"HZ-GB-2312", 2085, 10, 1},
+      {"IBM866", 2086, 6, 4},
+      {"cp866", 2086, 5, 3},
+      {"866", 2086, 3, 2},
+      {"csIBM866", 2086, 8, 1},
+      {"IBM775", 2087, 6, 3},
+      {"cp775", 2087, 5, 2},
+      {"csPC775Baltic", 2087, 13, 1},
+      {"KOI8-U", 2088, 6, 2},
+      {"csKOI8U", 2088, 7, 1},
+      {"IBM00858", 2089, 8, 5},
+      {"CCSID00858", 2089, 10, 4},
+      {"CP00858", 2089, 7, 3},
+      {"PC-Multilingual-850+euro", 2089, 24, 2},
+      {"csIBM00858", 2089, 10, 1},
+      {"IBM00924", 2090, 8, 5},
+      {"CCSID00924", 2090, 10, 4},
+      {"CP00924", 2090, 7, 3},
+      {"ebcdic-Latin9--euro", 2090, 19, 2},
+      {"csIBM00924", 2090, 10, 1},
+      {"IBM01140", 2091, 8, 5},
+      {"CCSID01140", 2091, 10, 4},
+      {"CP01140", 2091, 7, 3},
+      {"ebcdic-us-37+euro", 2091, 17, 2},
+      {"csIBM01140", 2091, 10, 1},
+      {"IBM01141", 2092, 8, 5},
+      {"CCSID01141", 2092, 10, 4},
+      {"CP01141", 2092, 7, 3},
+      {"ebcdic-de-273+euro", 2092, 18, 2},
+      {"csIBM01141", 2092, 10, 1},
+      {"IBM01142", 2093, 8, 6},
+      {"CCSID01142", 2093, 10, 5},
+      {"CP01142", 2093, 7, 4},
+      {"ebcdic-dk-277+euro", 2093, 18, 3},
+      {"ebcdic-no-277+euro", 2093, 18, 2},
+      {"csIBM01142", 2093, 10, 1},
+      {"IBM01143", 2094, 8, 6},
+      {"CCSID01143", 2094, 10, 5},
+      {"CP01143", 2094, 7, 4},
+      {"ebcdic-fi-278+euro", 2094, 18, 3},
+      {"ebcdic-se-278+euro", 2094, 18, 2},
+      {"csIBM01143", 2094, 10, 1},
+      {"IBM01144", 2095, 8, 5},
+      {"CCSID01144", 2095, 10, 4},
+      {"CP01144", 2095, 7, 3},
+      {"ebcdic-it-280+euro", 2095, 18, 2},
+      {"csIBM01144", 2095, 10, 1},
+      {"IBM01145", 2096, 8, 5},
+      {"CCSID01145", 2096, 10, 4},
+      {"CP01145", 2096, 7, 3},
+      {"ebcdic-es-284+euro", 2096, 18, 2},
+      {"csIBM01145", 2096, 10, 1},
+      {"IBM01146", 2097, 8, 5},
+      {"CCSID01146", 2097, 10, 4},
+      {"CP01146", 2097, 7, 3},
+      {"ebcdic-gb-285+euro", 2097, 18, 2},
+      {"csIBM01146", 2097, 10, 1},
+      {"IBM01147", 2098, 8, 5},
+      {"CCSID01147", 2098, 10, 4},
+      {"CP01147", 2098, 7, 3},
+      {"ebcdic-fr-297+euro", 2098, 18, 2},
+      {"csIBM01147", 2098, 10, 1},
+      {"IBM01148", 2099, 8, 5},
+      {"CCSID01148", 2099, 10, 4},
+      {"CP01148", 2099, 7, 3},
+      {"ebcdic-international-500+euro", 2099, 29, 2},
+      {"csIBM01148", 2099, 10, 1},
+      {"IBM01149", 2100, 8, 5},
+      {"CCSID01149", 2100, 10, 4},
+      {"CP01149", 2100, 7, 3},
+      {"ebcdic-is-871+euro", 2100, 18, 2},
+      {"csIBM01149", 2100, 10, 1},
+      {"Big5-HKSCS", 2101, 10, 2},
+      {"csBig5HKSCS", 2101, 11, 1},
+      {"IBM1047", 2102, 7, 3},
+      {"IBM-1047", 2102, 8, 2},
+      {"csIBM1047", 2102, 9, 1},
+      {"PTCP154", 2103, 7, 5},
+      {"csPTCP154", 2103, 9, 4},
+      {"PT154", 2103, 5, 3},
+      {"CP154", 2103, 5, 2},
+      {"Cyrillic-Asian", 2103, 14, 1},
+      {"Amiga-1251", 2104, 10, 5},
+      {"Ami1251", 2104, 7, 4},
+      {"Amiga1251", 2104, 9, 3},
+      {"Ami-1251", 2104, 8, 2},
+      {"csAmiga1251", 2104, 11, 1},
+      {"KOI7-switched", 2105, 13, 2},
+      {"csKOI7switched", 2105, 14, 1},
+      {"BRF", 2106, 3, 2},
+      {"csBRF", 2106, 5, 1},
+      {"TSCII", 2107, 5, 2},
+      {"csTSCII", 2107, 7, 1},
+      {"CP51932", 2108, 7, 2},
+      {"csCP51932", 2108, 9, 1},
+      {"windows-874", 2109, 11, 2},
+      {"cswindows874", 2109, 12, 1},
+      {"windows-1250", 2250, 12, 2},
+      {"cswindows1250", 2250, 13, 1},
+      {"windows-1251", 2251, 12, 2},
+      {"cswindows1251", 2251, 13, 1},
+      {"windows-1252", 2252, 12, 2},
+      {"cswindows1252", 2252, 13, 1},
+      {"windows-1253", 2253, 12, 2},
+      {"cswindows1253", 2253, 13, 1},
+      {"windows-1254", 2254, 12, 2},
+      {"cswindows1254", 2254, 13, 1},
+      {"windows-1255", 2255, 12, 2},
+      {"cswindows1255", 2255, 13, 1},
+      {"windows-1256", 2256, 12, 2},
+      {"cswindows1256", 2256, 13, 1},
+      {"windows-1257", 2257, 12, 2},
+      {"cswindows1257", 2257, 13, 1},
+      {"windows-1258", 2258, 12, 2},
+      {"cswindows1258", 2258, 13, 1},
+      {"TIS-620", 2259, 7, 3},
+      {"csTIS620", 2259, 8, 2},
+      {"ISO-8859-11", 2259, 11, 1},
+      {"CP50220", 2260, 7, 2},
+      {"csCP50220", 2260, 9, 1}};
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP__TEXT_ENCODING_TE_IMPL_H
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index b622680a4920b..953f10f996f55 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2099,6 +2099,13 @@ module std [system] {
     export *
   }
 
+  module text_encoding {
+    module text_encoding { header "__text_encoding/te_impl.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..45962b3cc7438
--- /dev/null
+++ b/libcxx/include/text_encoding
@@ -0,0 +1,142 @@
+// -*- 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
+};
+}
+
+*/
+
+#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
+#  include <__cxx03/__config>
+#else
+
+#  include <__config>
+#  include <__functional/hash.h>
+#  include <__ranges/enable_borrowed_range.h>
+#  include <__text_encoding/te_impl.h>
+#  include <string_view>
+#  include <version>
+
+#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#    pragma GCC system_header
+#  endif
+
+#  if _LIBCPP_STD_VER >= 26
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+struct text_encoding {
+private:
+  __te_impl __impl_;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit text_encoding(__te_impl&& __imp) : __impl_(__imp) {}
+
+public:
+  static constexpr auto max_name_length = __te_impl::__max_name_length_;
+  using id                              = __te_impl::__id;
+  using aliases_view                    = __te_impl::__aliases_view;
+  using enum id;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr text_encoding() = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit text_encoding(string_view __enc) noexcept : __impl_(__enc) {}
+  _LIBCPP_HIDE_FROM_ABI constexpr text_encoding(id __i) noexcept : __impl_(__i) {}
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr id mib() const noexcept { return __impl_.__mib(); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const char* name() const noexcept { return __impl_.__name(); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr aliases_view aliases() const { return __impl_.__aliases(); }
+
+  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const text_encoding& __a, const text_encoding& __b) noexcept {
+    return __a.__impl_ == __b.__impl_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const text_encoding& __enc, const id __i) noexcept {
+    return __enc.__impl_ == __i;
+  }
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval text_encoding literal() noexcept {
+    return text_encoding(__te_impl::__literal());
+  }
+#    if _LIBCPP_HAS_LOCALIZATION && !defined(__ANDROID__)
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static text_encoding environment() {
+    return text_encoding(__te_impl::__environment());
+  };
+
+  template <id _Id>
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool environment_is() {
+    return __te_impl::__environment_is<_Id>();
+  }
+#    else
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static text_encoding environment() = delete;
+
+  template <id _Id>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool environment_is() = delete;
+#    endif
+};
+
+template <>
+struct hash<text_encoding> {
+  size_t operator()(const text_encoding& __enc) const noexcept {
+    return std::hash<std::text_encoding::id>()(__enc.mib());
+  }
+};
+
+template <>
+inline constexpr bool ranges::enable_borrowed_range<text_encoding::aliases_view> = true;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#  endif // _LIBCPP_STD_VER >= 26
+
+#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
+
+#endif // _LIBCPP_TEXT_ENCODING
diff --git a/libcxx/include/version b/libcxx/include/version
index 7d77677a012ce..f64da3a604dc7 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -619,7 +619,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/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist
index da1e340b1d4aa..4180bc584a3f3 100644
--- a/libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -1921,6 +1921,7 @@
 {'is_defined': True, 'name': '__ZNSt3__19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
+{'is_defined': True, 'name': '__ZNSt3__19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
index abbcc5c14b544..562ab477169a7 100644
--- a/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -1558,6 +1558,7 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt6__ndk19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
index 1224f51e17687..0785d602473e3 100644
--- a/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -850,6 +850,7 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_f', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_fNS_12chars_formatE', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_fNS_12chars_formatEi', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
+{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD0Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD1Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD2Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
index 934505b18a64b..6730f90d8c32f 100644
--- a/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -850,6 +850,7 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_f', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_fNS_12chars_formatE', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_fNS_12chars_formatEi', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
+{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD0Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD1Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD2Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
index 6c437f9adea48..0bbf013474c0c 100644
--- a/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -1558,6 +1558,7 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt6__ndk19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist
index 017b6d33c4262..f60e7be8b442a 100644
--- a/libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -1571,6 +1571,7 @@
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
index 363fa42975b8e..ebfcebde7f5c6 100644
--- a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -1570,6 +1570,7 @@
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist
index cf4668a2dea21..55fe24a03ce00 100644
--- a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist
@@ -1541,6 +1541,7 @@
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
diff --git a/libcxx/modules/std.compat.cppm.in b/libcxx/modules/std.compat.cppm.in
index dd7385bf33a42..ab08125c4c4e4 100644
--- a/libcxx/modules/std.compat.cppm.in
+++ b/libcxx/modules/std.compat.cppm.in
@@ -75,9 +75,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 984b18321923c..08a39f64bc1e3 100644
--- a/libcxx/modules/std.cppm.in
+++ b/libcxx/modules/std.cppm.in
@@ -110,6 +110,7 @@ module;
 #include <strstream>
 #include <syncstream>
 #include <system_error>
+#include <text_encoding>
 #include <thread>
 #include <tuple>
 #include <type_traits>
@@ -159,9 +160,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..8ad1e7bfced43 100644
--- a/libcxx/modules/std/text_encoding.inc
+++ b/libcxx/modules/std/text_encoding.inc
@@ -8,12 +8,11 @@
 //===----------------------------------------------------------------------===//
 
 export namespace std {
-#if 0
-#  if _LIBCPP_STD_VER >= 23
-  using std::text_encoding;
-
-  // hash support
+#if _LIBCPP_STD_VER >= 26
   using std::hash;
-#  endif // _LIBCPP_STD_VER >= 23
+  namespace ranges {
+    using std::ranges::enable_borrowed_range;
+  }
+  using std::text_encoding;
 #endif
 } // namespace std
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index ebd6141902ef7..18fc4282d5430 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/text_encoding.cpp b/libcxx/src/text_encoding.cpp
new file mode 100644
index 0000000000000..8c5a1889c4799
--- /dev/null
+++ b/libcxx/src/text_encoding.cpp
@@ -0,0 +1,256 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+#include <__text_encoding/te_impl.h>
+
+#if defined(_LIBCPP_WIN32API)
+#  include <windows.h>
+#else
+#  include <__locale_dir/locale_base_api.h>
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if defined(_LIBCPP_WIN32API)
+_LIBCPP_HIDDEN __te_impl::__id __te_impl::__get_win32_acp() {
+  switch (GetACP()) {
+  case 037:
+    return __te_impl::__id::IBM037;
+  case 437:
+    return __te_impl::__id::PC8CodePage437;
+  case 500:
+    return __te_impl::__id::IBM500;
+  case 708:
+    return __te_impl::__id::ISOLatinArabic;
+  case 709:
+    return __te_impl::__id::ISO89ASMO449;
+  case 775:
+    return __te_impl::__id::PC775Baltic;
+  case 850:
+    return __te_impl::__id::PC850Multilingual;
+  case 852:
+    return __te_impl::__id::PCp852;
+  case 855:
+    return __te_impl::__id::IBM855;
+  case 857:
+    return __te_impl::__id::IBM857;
+  case 858:
+    return __te_impl::__id::IBM00858;
+  case 860:
+    return __te_impl::__id::IBM860;
+  case 861:
+    return __te_impl::__id::IBM861;
+  case 862:
+    return __te_impl::__id::PC862LatinHebrew;
+  case 863:
+    return __te_impl::__id::IBM863;
+  case 864:
+    return __te_impl::__id::IBM864;
+  case 865:
+    return __te_impl::__id::IBM865;
+  case 866:
+    return __te_impl::__id::IBM866;
+  case 869:
+    return __te_impl::__id::IBM869;
+  case 870:
+    return __te_impl::__id::IBM870;
+  case 874:
+    return __te_impl::__id::windows874;
+  case 932:
+    return __te_impl::__id::ShiftJIS;
+  case 936:
+    return __te_impl::__id::GB2312;
+  case 949:
+    return __te_impl::__id::KSC56011987;
+  case 950:
+    return __te_impl::__id::Big5;
+  case 1026:
+    return __te_impl::__id::IBM1026;
+  case 1047:
+    return __te_impl::__id::IBM1047;
+  case 1140:
+    return __te_impl::__id::IBM01140;
+  case 1141:
+    return __te_impl::__id::IBM01141;
+  case 1142:
+    return __te_impl::__id::IBM01142;
+  case 1143:
+    return __te_impl::__id::IBM01143;
+  case 1144:
+    return __te_impl::__id::IBM01144;
+  case 1145:
+    return __te_impl::__id::IBM01145;
+  case 1146:
+    return __te_impl::__id::IBM01146;
+  case 1147:
+    return __te_impl::__id::IBM01147;
+  case 1148:
+    return __te_impl::__id::IBM01148;
+  case 1149:
+    return __te_impl::__id::IBM01149;
+  case 1200:
+    return __te_impl::__id::UTF16LE;
+  case 1201:
+    return __te_impl::__id::UTF16BE;
+  case 1250:
+    return __te_impl::__id::windows1250;
+  case 1251:
+    return __te_impl::__id::windows1251;
+  case 1252:
+    return __te_impl::__id::windows1252;
+  case 1253:
+    return __te_impl::__id::windows1253;
+  case 1254:
+    return __te_impl::__id::windows1254;
+  case 1255:
+    return __te_impl::__id::windows1255;
+  case 1256:
+    return __te_impl::__id::windows1256;
+  case 1257:
+    return __te_impl::__id::windows1257;
+  case 1258:
+    return __te_impl::__id::windows1258;
+  case 10000:
+    return __te_impl::__id::Macintosh;
+  case 12000:
+    return __te_impl::__id::UTF32LE;
+  case 12001:
+    return __te_impl::__id::UTF32BE;
+  case 20127:
+    return __te_impl::__id::ASCII;
+  case 20273:
+    return __te_impl::__id::IBM273;
+  case 20277:
+    return __te_impl::__id::IBM277;
+  case 20278:
+    return __te_impl::__id::IBM278;
+  case 20280:
+    return __te_impl::__id::IBM280;
+  case 20284:
+    return __te_impl::__id::IBM284;
+  case 20285:
+    return __te_impl::__id::IBM285;
+  case 20290:
+    return __te_impl::__id::IBM290;
+  case 20297:
+    return __te_impl::__id::IBM297;
+  case 20420:
+    return __te_impl::__id::IBM420;
+  case 20423:
+    return __te_impl::__id::IBM423;
+  case 20424:
+    return __te_impl::__id::IBM424;
+  case 20838:
+    return __te_impl::__id::IBMThai;
+  case 20866:
+    return __te_impl::__id::KOI8R;
+  case 20871:
+    return __te_impl::__id::IBM871;
+  case 20880:
+    return __te_impl::__id::IBM880;
+  case 20905:
+    return __te_impl::__id::IBM905;
+  case 20924:
+    return __te_impl::__id::IBM00924;
+  case 20932:
+    return __te_impl::__id::EUCPkdFmtJapanese;
+  case 21866:
+    return __te_impl::__id::KOI8U;
+  case 28591:
+    return __te_impl::__id::ISOLatin1;
+  case 28592:
+    return __te_impl::__id::ISOLatin2;
+  case 28593:
+    return __te_impl::__id::ISOLatin3;
+  case 28594:
+    return __te_impl::__id::ISOLatin4;
+  case 28595:
+    return __te_impl::__id::ISOLatin5;
+  case 28596:
+    return __te_impl::__id::ISOLatin6;
+  case 28597:
+    return __te_impl::__id::ISOLatinGreek;
+  case 28598:
+    return __te_impl::__id::ISOLatinHebrew;
+  case 28599:
+    return __te_impl::__id::Windows31Latin5;
+  case 28603:
+    return __te_impl::__id::ISO885913;
+  case 28605:
+    return __te_impl::__id::ISO885915;
+  case 38598:
+    return __te_impl::__id::ISO88598I;
+  case 50220:
+  case 50221:
+  case 50222:
+    return __te_impl::__id::ISO2022JP;
+  case 51932:
+    return __te_impl::__id::EUCPkdFmtJapanese;
+  case 51936:
+    return __te_impl::__id::GB2312;
+  case 51949:
+    return __te_impl::__id::EUCKR;
+  case 52936:
+    return __te_impl::__id::HZGB2312;
+  case 54936:
+    return __te_impl::__id::GB18030;
+  case 65000:
+    return __te_impl::__id::UTF7;
+  case 65001:
+    return __te_impl::__id::UTF8;
+  default:
+    return __te_impl::__id::other;
+  }
+}
+#endif // _LIBCPP_WIN32API
+
+#if !defined(__ANDROID__) && !defined(_LIBCPP_WIN32API)
+_LIBCPP_HIDDEN __te_impl __te_impl::__get_locale_encoding(const char* __name) {
+  __te_impl __e;
+
+  __locale::__locale_t __l = __locale::__newlocale(_LIBCPP_CTYPE_MASK, __name, static_cast<__locale::__locale_t>(0));
+
+  if (!__l) {
+    return __e;
+  }
+
+  const char* __codeset = __locale::__nl_langinfo_l(_LIBCPP_NL_CODESET, __l);
+
+  if (!__codeset) {
+    return __e;
+  }
+
+  string_view __codeset_sv(__codeset);
+
+  if (__codeset_sv.size() <= __te_impl::__max_name_length_) {
+    __e = __te_impl(__codeset_sv);
+  }
+
+  __locale::__freelocale(__l);
+
+  return __e;
+}
+
+#else
+_LIBCPP_HIDDEN __te_impl __te_impl::__get_locale_encoding(const char* __name [[maybe_unused]]) { return __te_impl(); }
+#endif
+
+_LIBCPP_HIDDEN __te_impl __te_impl::__get_env_encoding() {
+#if defined(_LIBCPP_WIN32API)
+  return __te_impl(__get_win32_acp());
+#else
+  return __get_locale_encoding("");
+#endif // _LIBCPP_WIN32API
+}
+
+_LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI __te_impl __te_impl::__environment() {
+  return __te_impl::__get_env_encoding();
+}
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index c0031543e47bc..7d8aad95f3b8c 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -2282,6 +2282,39 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
+text_encoding algorithm
+text_encoding atomic
+text_encoding bit
+text_encoding cctype
+text_encoding climits
+text_encoding cmath
+text_encoding compare
+text_encoding concepts
+text_encoding cstddef
+text_encoding cstdint
+text_encoding cstdio
+text_encoding cstdlib
+text_encoding cstring
+text_encoding ctime
+text_encoding cwchar
+text_encoding cwctype
+text_encoding exception
+text_encoding initializer_list
+text_encoding iosfwd
+text_encoding iterator
+text_encoding limits
+text_encoding memory
+text_encoding new
+text_encoding optional
+text_encoding ratio
+text_encoding stdexcept
+text_encoding string_view
+text_encoding tuple
+text_encoding type_traits
+text_encoding typeinfo
+text_encoding utility
+text_encoding variant
+text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv
index c0031543e47bc..7d8aad95f3b8c 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -2282,6 +2282,39 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
+text_encoding algorithm
+text_encoding atomic
+text_encoding bit
+text_encoding cctype
+text_encoding climits
+text_encoding cmath
+text_encoding compare
+text_encoding concepts
+text_encoding cstddef
+text_encoding cstdint
+text_encoding cstdio
+text_encoding cstdlib
+text_encoding cstring
+text_encoding ctime
+text_encoding cwchar
+text_encoding cwctype
+text_encoding exception
+text_encoding initializer_list
+text_encoding iosfwd
+text_encoding iterator
+text_encoding limits
+text_encoding memory
+text_encoding new
+text_encoding optional
+text_encoding ratio
+text_encoding stdexcept
+text_encoding string_view
+text_encoding tuple
+text_encoding type_traits
+text_encoding typeinfo
+text_encoding utility
+text_encoding variant
+text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv
index c2eb5b44e8d7a..bbdb10a75993d 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -2328,6 +2328,40 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
+text_encoding algorithm
+text_encoding atomic
+text_encoding bit
+text_encoding cctype
+text_encoding climits
+text_encoding cmath
+text_encoding compare
+text_encoding concepts
+text_encoding cstddef
+text_encoding cstdint
+text_encoding cstdio
+text_encoding cstdlib
+text_encoding cstring
+text_encoding ctime
+text_encoding cwchar
+text_encoding cwctype
+text_encoding exception
+text_encoding execution
+text_encoding initializer_list
+text_encoding iosfwd
+text_encoding iterator
+text_encoding limits
+text_encoding memory
+text_encoding new
+text_encoding optional
+text_encoding ratio
+text_encoding stdexcept
+text_encoding string_view
+text_encoding tuple
+text_encoding type_traits
+text_encoding typeinfo
+text_encoding utility
+text_encoding variant
+text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv
index 332cb62f35b5f..53b8325423fa9 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx17.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv
@@ -2335,6 +2335,39 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
+text_encoding algorithm
+text_encoding atomic
+text_encoding bit
+text_encoding cctype
+text_encoding climits
+text_encoding cmath
+text_encoding compare
+text_encoding concepts
+text_encoding cstddef
+text_encoding cstdint
+text_encoding cstdio
+text_encoding cstdlib
+text_encoding cstring
+text_encoding ctime
+text_encoding cwchar
+text_encoding cwctype
+text_encoding exception
+text_encoding initializer_list
+text_encoding iosfwd
+text_encoding iterator
+text_encoding limits
+text_encoding memory
+text_encoding new
+text_encoding optional
+text_encoding ratio
+text_encoding stdexcept
+text_encoding string_view
+text_encoding tuple
+text_encoding type_traits
+text_encoding typeinfo
+text_encoding utility
+text_encoding variant
+text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv
index 55c79acff5a8f..f15b13738dd8a 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx20.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv
@@ -2365,6 +2365,39 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
+text_encoding algorithm
+text_encoding atomic
+text_encoding bit
+text_encoding cctype
+text_encoding climits
+text_encoding cmath
+text_encoding compare
+text_encoding concepts
+text_encoding cstddef
+text_encoding cstdint
+text_encoding cstdio
+text_encoding cstdlib
+text_encoding cstring
+text_encoding ctime
+text_encoding cwchar
+text_encoding cwctype
+text_encoding exception
+text_encoding initializer_list
+text_encoding iosfwd
+text_encoding iterator
+text_encoding limits
+text_encoding memory
+text_encoding new
+text_encoding optional
+text_encoding ratio
+text_encoding stdexcept
+text_encoding string_view
+text_encoding tuple
+text_encoding type_traits
+text_encoding typeinfo
+text_encoding utility
+text_encoding variant
+text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv
index c5cc61f06678c..4714f5f9ca0ba 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx23.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv
@@ -1069,6 +1069,19 @@ system_error string
 system_error string_view
 system_error tuple
 system_error version
+text_encoding cctype
+text_encoding compare
+text_encoding cstdint
+text_encoding cstdio
+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/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index c11fb5ac10016..f79e0f5ef60ec 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -1048,6 +1048,19 @@ system_error string
 system_error string_view
 system_error tuple
 system_error version
+text_encoding cctype
+text_encoding compare
+text_encoding cstdint
+text_encoding cstdio
+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/libcxx/utilities/text_encoding/environment.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp
new file mode 100644
index 0000000000000..03909f474a246
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.fr_CA.ISO8859-1
+
+// UNSUPPORTED: no-localization
+// UNSUPPORTED: android
+// UNSUPPORTED: windows
+// UNSUPPORTED: availability-te-environment-missing
+
+#include <algorithm>
+#include <cassert>
+#include <cstdlib>
+#include <text_encoding>
+
+#include "platform_support.h" // locale name macros
+
+int main(int, char**) {
+  // text_encoding::environment() is (unfortunately) affected by changes to the "LANG" environment variable on POSIX systems.
+  {
+    setenv("LANG", LOCALE_fr_CA_ISO8859_1, 1);
+
+    auto te = std::text_encoding::environment();
+
+    assert(std::text_encoding::environment_is<std::text_encoding::id::ISOLatin1>());
+    assert(te == std::text_encoding::environment());
+    assert(te.mib() == std::text_encoding::id::ISOLatin1);
+    assert(std::ranges::contains(te.aliases(), std::string_view("ISO_8859-1")));
+  }
+}
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp
new file mode 100644
index 0000000000000..e1c966902a343
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+// REQUIRES: libcpp-hardening-mode={{extensive|debug}}
+
+// <text_encoding>
+
+// text_encoding text_encoding(id)
+
+#include <climits>
+#include <text_encoding>
+
+#include "check_assertion.h"
+
+int main(int, char**) {
+  // Make sure that text_encoding(id) asserts when the input id not in range of allowed values
+
+  TEST_LIBCPP_ASSERT_FAILURE(
+      std::text_encoding(std::text_encoding::id(33)), "invalid text_encoding::id passed to text_encoding(id)");
+  TEST_LIBCPP_ASSERT_FAILURE(
+      std::text_encoding(std::text_encoding::id(34)), "invalid text_encoding::id passed to text_encoding(id)");
+  TEST_LIBCPP_ASSERT_FAILURE(
+      std::text_encoding(std::text_encoding::id(-1)), "invalid text_encoding::id passed to text_encoding(id)");
+  TEST_LIBCPP_ASSERT_FAILURE(
+      std::text_encoding(std::text_encoding::id(INT_MAX)), "invalid text_encoding::id passed to text_encoding(id)");
+
+  return 0;
+}
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
new file mode 100644
index 0000000000000..75bee493bbf68
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+// REQUIRES: libcpp-hardening-mode={{extensive|debug}}
+
+// <text_encoding>
+
+// text_encoding text_encoding(string_view)
+
+#include <string_view>
+#include <text_encoding>
+
+#include "check_assertion.h"
+
+int main(int, char**) {
+  char str[std::text_encoding::max_name_length + 2] =
+      "HELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELL";
+  std::string_view view(str);
+
+  // text_encoding(string_view) asserts if its input size() > max_name_length
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(view), "invalid string passed to text_encoding(string_view)");
+
+  // text_encoding(string_view) asserts if its input contains a null terminator
+  char str2[std::text_encoding::max_name_length] = "HELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELL";
+  std::string_view view2(str2);
+  str2[3] = '\0';
+
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(view2), "invalid string passed to text_encoding(string_view)");
+
+  return 0;
+}
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.nodiscard.verify.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.nodiscard.verify.cpp
new file mode 100644
index 0000000000000..97dc5c713f7a4
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.nodiscard.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+// UNSUPPORTED: android
+// UNSUPPORTED: availability-te-environment-missing
+
+// <text_encoding>
+
+// text_encoding text_encoding::environment()
+
+// Split from the general [[nodiscard]] tests to accomodate no-localization builds.
+
+#include <text_encoding>
+
+int main(int, char**) {
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::text_encoding::environment();
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::text_encoding::environment_is<std::text_encoding::UTF8>();
+
+  return 0;
+}
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/nodiscard.verify.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/nodiscard.verify.cpp
new file mode 100644
index 0000000000000..8c9324c4f4b7c
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/nodiscard.verify.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// UNSUPPORTED: no-localization
+
+// <text_encoding>
+
+#include <text_encoding>
+
+int main(int, char**) {
+  std::text_encoding te = std::text_encoding();
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  te.mib();
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  te.name();
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  te.aliases();
+
+  // Clang does not emit a nodiscard warning for consteval functions with [[nodiscard]]: See issue #141536
+  // expected-warning at +1 {{expression result unused}}
+  std::text_encoding::literal();
+
+  return 0;
+}
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..1678e8840af8d
--- /dev/null
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/text_encoding.version.compile.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 f442b22c6d752..767479b30cef3 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
@@ -8035,17 +8035,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/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_fr_FR.pass.cpp b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_fr_FR.pass.cpp
index 002fc4b1ec7ef..5b0b31f4b7e98 100644
--- a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_fr_FR.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_fr_FR.pass.cpp
@@ -31,6 +31,11 @@
 #include "platform_support.h" // locale name macros
 #include "test_macros.h"
 
+// glibc <langinfo.h> has a THOUSANDS_SEP macro already defined
+#ifdef THOUSANDS_SEP
+#  undef THOUSANDS_SEP
+#endif
+
 #ifdef _AIX
 // the AIX libc expects U202F as LC_MONETARY thousands_sep
 #  define THOUSANDS_SEP L"\u202F"
diff --git a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.put/locale.money.put.members/put_long_double_fr_FR.pass.cpp b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.put/locale.money.put.members/put_long_double_fr_FR.pass.cpp
index 733eea94fd9bd..171a3ab9f75d4 100644
--- a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.put/locale.money.put.members/put_long_double_fr_FR.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.put/locale.money.put.members/put_long_double_fr_FR.pass.cpp
@@ -32,6 +32,11 @@
 #include "platform_support.h" // locale name macros
 #include "test_macros.h"
 
+// glibc <langinfo.h> has a THOUSANDS_SEP macro already defined
+#ifdef THOUSANDS_SEP
+#  undef THOUSANDS_SEP
+#endif
+
 #ifdef _AIX
 // the AIX libc expects U202F as LC_MONETARY thousands_sep
 #  define THOUSANDS_SEP L"\u202F"
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..e77ad12eb2267
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// 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: android
+
+// class locale
+
+// text_encoding encoding() const
+
+#include <cassert>
+#include <locale>
+#include <text_encoding>
+
+#include "test_macros.h"
+#include "platform_support.h"
+
+using id = std::text_encoding::id;
+
+int main(int, char**) {
+// FIXME: enable once locale::encoding() is implemented
+#if false
+  {
+    // 1. Default locale returns a text_encoding representing "ASCII"
+    std::locale loc;
+
+    auto te        = loc.encoding();
+    auto classicTE = std::text_encoding(id::ASCII);
+    assert(te == id::ASCII);
+    assert(te == classicTE);
+  }
+
+  {
+    // 2. Locale built with en_US.UTF-8 returns text_encoding representing "UTF-8"
+    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);
+  }
+#endif
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/text_encoding/test_text_encoding.h b/libcxx/test/std/utilities/text_encoding/test_text_encoding.h
new file mode 100644
index 0000000000000..1458f6ab7d907
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/test_text_encoding.h
@@ -0,0 +1,282 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <string_view>
+
+struct encoding_data {
+  std::string_view name;
+  int mib;
+  int size;
+};
+
+constexpr encoding_data unique_encoding_data[]{
+    {"US-ASCII", 3, 8},
+    {"ISO_8859-1:1987", 4, 15},
+    {"ISO_8859-2:1987", 5, 15},
+    {"ISO_8859-3:1988", 6, 15},
+    {"ISO_8859-4:1988", 7, 15},
+    {"ISO_8859-5:1988", 8, 15},
+    {"ISO_8859-6:1987", 9, 15},
+    {"ISO_8859-7:1987", 10, 15},
+    {"ISO_8859-8:1988", 11, 15},
+    {"ISO_8859-9:1989", 12, 15},
+    {"ISO-8859-10", 13, 11},
+    {"ISO_6937-2-add", 14, 14},
+    {"JIS_X0201", 15, 9},
+    {"JIS_Encoding", 16, 12},
+    {"Shift_JIS", 17, 9},
+    {"Extended_UNIX_Code_Packed_Format_for_Japanese", 18, 45},
+    {"Extended_UNIX_Code_Fixed_Width_for_Japanese", 19, 43},
+    {"BS_4730", 20, 7},
+    {"SEN_850200_C", 21, 12},
+    {"IT", 22, 2},
+    {"ES", 23, 2},
+    {"DIN_66003", 24, 9},
+    {"NS_4551-1", 25, 9},
+    {"NF_Z_62-010", 26, 11},
+    {"ISO-10646-UTF-1", 27, 15},
+    {"ISO_646.basic:1983", 28, 18},
+    {"INVARIANT", 29, 9},
+    {"ISO_646.irv:1983", 30, 16},
+    {"NATS-SEFI", 31, 9},
+    {"NATS-SEFI-ADD", 32, 13},
+    {"SEN_850200_B", 35, 12},
+    {"KS_C_5601-1987", 36, 14},
+    {"ISO-2022-KR", 37, 11},
+    {"EUC-KR", 38, 6},
+    {"ISO-2022-JP", 39, 11},
+    {"ISO-2022-JP-2", 40, 13},
+    {"JIS_C6220-1969-jp", 41, 17},
+    {"JIS_C6220-1969-ro", 42, 17},
+    {"PT", 43, 2},
+    {"greek7-old", 44, 10},
+    {"latin-greek", 45, 11},
+    {"NF_Z_62-010_(1973)", 46, 18},
+    {"Latin-greek-1", 47, 13},
+    {"ISO_5427", 48, 8},
+    {"JIS_C6226-1978", 49, 14},
+    {"BS_viewdata", 50, 11},
+    {"INIS", 51, 4},
+    {"INIS-8", 52, 6},
+    {"INIS-cyrillic", 53, 13},
+    {"ISO_5427:1981", 54, 13},
+    {"ISO_5428:1980", 55, 13},
+    {"GB_1988-80", 56, 10},
+    {"GB_2312-80", 57, 10},
+    {"NS_4551-2", 58, 9},
+    {"videotex-suppl", 59, 14},
+    {"PT2", 60, 3},
+    {"ES2", 61, 3},
+    {"MSZ_7795.3", 62, 10},
+    {"JIS_C6226-1983", 63, 14},
+    {"greek7", 64, 6},
+    {"ASMO_449", 65, 8},
+    {"iso-ir-90", 66, 9},
+    {"JIS_C6229-1984-a", 67, 16},
+    {"JIS_C6229-1984-b", 68, 16},
+    {"JIS_C6229-1984-b-add", 69, 20},
+    {"JIS_C6229-1984-hand", 70, 19},
+    {"JIS_C6229-1984-hand-add", 71, 23},
+    {"JIS_C6229-1984-kana", 72, 19},
+    {"ISO_2033-1983", 73, 13},
+    {"ANSI_X3.110-1983", 74, 16},
+    {"T.61-7bit", 75, 9},
+    {"T.61-8bit", 76, 9},
+    {"ECMA-cyrillic", 77, 13},
+    {"CSA_Z243.4-1985-1", 78, 17},
+    {"CSA_Z243.4-1985-2", 79, 17},
+    {"CSA_Z243.4-1985-gr", 80, 18},
+    {"ISO_8859-6-E", 81, 12},
+    {"ISO_8859-6-I", 82, 12},
+    {"T.101-G2", 83, 8},
+    {"ISO_8859-8-E", 84, 12},
+    {"ISO_8859-8-I", 85, 12},
+    {"CSN_369103", 86, 10},
+    {"JUS_I.B1.002", 87, 12},
+    {"IEC_P27-1", 88, 9},
+    {"JUS_I.B1.003-serb", 89, 17},
+    {"JUS_I.B1.003-mac", 90, 16},
+    {"greek-ccitt", 91, 11},
+    {"NC_NC00-10:81", 92, 13},
+    {"ISO_6937-2-25", 93, 13},
+    {"GOST_19768-74", 94, 13},
+    {"ISO_8859-supp", 95, 13},
+    {"ISO_10367-box", 96, 13},
+    {"latin-lap", 97, 9},
+    {"JIS_X0212-1990", 98, 14},
+    {"DS_2089", 99, 7},
+    {"us-dk", 100, 5},
+    {"dk-us", 101, 5},
+    {"KSC5636", 102, 7},
+    {"UNICODE-1-1-UTF-7", 103, 17},
+    {"ISO-2022-CN", 104, 11},
+    {"ISO-2022-CN-EXT", 105, 15},
+    {"UTF-8", 106, 5},
+    {"ISO-8859-13", 109, 11},
+    {"ISO-8859-14", 110, 11},
+    {"ISO-8859-15", 111, 11},
+    {"ISO-8859-16", 112, 11},
+    {"GBK", 113, 3},
+    {"GB18030", 114, 7},
+    {"OSD_EBCDIC_DF04_15", 115, 18},
+    {"OSD_EBCDIC_DF03_IRV", 116, 19},
+    {"OSD_EBCDIC_DF04_1", 117, 17},
+    {"ISO-11548-1", 118, 11},
+    {"KZ-1048", 119, 7},
+    {"ISO-10646-UCS-2", 1000, 15},
+    {"ISO-10646-UCS-4", 1001, 15},
+    {"ISO-10646-UCS-Basic", 1002, 19},
+    {"ISO-10646-Unicode-Latin1", 1003, 24},
+    {"ISO-10646-J-1", 1004, 13},
+    {"ISO-Unicode-IBM-1261", 1005, 20},
+    {"ISO-Unicode-IBM-1268", 1006, 20},
+    {"ISO-Unicode-IBM-1276", 1007, 20},
+    {"ISO-Unicode-IBM-1264", 1008, 20},
+    {"ISO-Unicode-IBM-1265", 1009, 20},
+    {"UNICODE-1-1", 1010, 11},
+    {"SCSU", 1011, 4},
+    {"UTF-7", 1012, 5},
+    {"UTF-16BE", 1013, 8},
+    {"UTF-16LE", 1014, 8},
+    {"UTF-16", 1015, 6},
+    {"CESU-8", 1016, 6},
+    {"UTF-32", 1017, 6},
+    {"UTF-32BE", 1018, 8},
+    {"UTF-32LE", 1019, 8},
+    {"BOCU-1", 1020, 6},
+    {"UTF-7-IMAP", 1021, 10},
+    {"ISO-8859-1-Windows-3.0-Latin-1", 2000, 30},
+    {"ISO-8859-1-Windows-3.1-Latin-1", 2001, 30},
+    {"ISO-8859-2-Windows-Latin-2", 2002, 26},
+    {"ISO-8859-9-Windows-Latin-5", 2003, 26},
+    {"hp-roman8", 2004, 9},
+    {"Adobe-Standard-Encoding", 2005, 23},
+    {"Ventura-US", 2006, 10},
+    {"Ventura-International", 2007, 21},
+    {"DEC-MCS", 2008, 7},
+    {"IBM850", 2009, 6},
+    {"IBM852", 2010, 6},
+    {"IBM437", 2011, 6},
+    {"PC8-Danish-Norwegian", 2012, 20},
+    {"IBM862", 2013, 6},
+    {"PC8-Turkish", 2014, 11},
+    {"IBM-Symbols", 2015, 11},
+    {"IBM-Thai", 2016, 8},
+    {"HP-Legal", 2017, 8},
+    {"HP-Pi-font", 2018, 10},
+    {"HP-Math8", 2019, 8},
+    {"Adobe-Symbol-Encoding", 2020, 21},
+    {"HP-DeskTop", 2021, 10},
+    {"Ventura-Math", 2022, 12},
+    {"Microsoft-Publishing", 2023, 20},
+    {"Windows-31J", 2024, 11},
+    {"GB2312", 2025, 6},
+    {"Big5", 2026, 4},
+    {"macintosh", 2027, 9},
+    {"IBM037", 2028, 6},
+    {"IBM038", 2029, 6},
+    {"IBM273", 2030, 6},
+    {"IBM274", 2031, 6},
+    {"IBM275", 2032, 6},
+    {"IBM277", 2033, 6},
+    {"IBM278", 2034, 6},
+    {"IBM280", 2035, 6},
+    {"IBM281", 2036, 6},
+    {"IBM284", 2037, 6},
+    {"IBM285", 2038, 6},
+    {"IBM290", 2039, 6},
+    {"IBM297", 2040, 6},
+    {"IBM420", 2041, 6},
+    {"IBM423", 2042, 6},
+    {"IBM424", 2043, 6},
+    {"IBM500", 2044, 6},
+    {"IBM851", 2045, 6},
+    {"IBM855", 2046, 6},
+    {"IBM857", 2047, 6},
+    {"IBM860", 2048, 6},
+    {"IBM861", 2049, 6},
+    {"IBM863", 2050, 6},
+    {"IBM864", 2051, 6},
+    {"IBM865", 2052, 6},
+    {"IBM868", 2053, 6},
+    {"IBM869", 2054, 6},
+    {"IBM870", 2055, 6},
+    {"IBM871", 2056, 6},
+    {"IBM880", 2057, 6},
+    {"IBM891", 2058, 6},
+    {"IBM903", 2059, 6},
+    {"IBM904", 2060, 6},
+    {"IBM905", 2061, 6},
+    {"IBM918", 2062, 6},
+    {"IBM1026", 2063, 7},
+    {"EBCDIC-AT-DE", 2064, 12},
+    {"EBCDIC-AT-DE-A", 2065, 14},
+    {"EBCDIC-CA-FR", 2066, 12},
+    {"EBCDIC-DK-NO", 2067, 12},
+    {"EBCDIC-DK-NO-A", 2068, 14},
+    {"EBCDIC-FI-SE", 2069, 12},
+    {"EBCDIC-FI-SE-A", 2070, 14},
+    {"EBCDIC-FR", 2071, 9},
+    {"EBCDIC-IT", 2072, 9},
+    {"EBCDIC-PT", 2073, 9},
+    {"EBCDIC-ES", 2074, 9},
+    {"EBCDIC-ES-A", 2075, 11},
+    {"EBCDIC-ES-S", 2076, 11},
+    {"EBCDIC-UK", 2077, 9},
+    {"EBCDIC-US", 2078, 9},
+    {"UNKNOWN-8BIT", 2079, 12},
+    {"MNEMONIC", 2080, 8},
+    {"MNEM", 2081, 4},
+    {"VISCII", 2082, 6},
+    {"VIQR", 2083, 4},
+    {"KOI8-R", 2084, 6},
+    {"HZ-GB-2312", 2085, 10},
+    {"IBM866", 2086, 6},
+    {"IBM775", 2087, 6},
+    {"KOI8-U", 2088, 6},
+    {"IBM00858", 2089, 8},
+    {"IBM00924", 2090, 8},
+    {"IBM01140", 2091, 8},
+    {"IBM01141", 2092, 8},
+    {"IBM01142", 2093, 8},
+    {"IBM01143", 2094, 8},
+    {"IBM01144", 2095, 8},
+    {"IBM01145", 2096, 8},
+    {"IBM01146", 2097, 8},
+    {"IBM01147", 2098, 8},
+    {"IBM01148", 2099, 8},
+    {"IBM01149", 2100, 8},
+    {"Big5-HKSCS", 2101, 10},
+    {"IBM1047", 2102, 7},
+    {"PTCP154", 2103, 7},
+    {"Amiga-1251", 2104, 10},
+    {"KOI7-switched", 2105, 13},
+    {"BRF", 2106, 3},
+    {"TSCII", 2107, 5},
+    {"CP51932", 2108, 7},
+    {"windows-874", 2109, 11},
+    {"windows-1250", 2250, 12},
+    {"windows-1251", 2251, 12},
+    {"windows-1252", 2252, 12},
+    {"windows-1253", 2253, 12},
+    {"windows-1254", 2254, 12},
+    {"windows-1255", 2255, 12},
+    {"windows-1256", 2256, 12},
+    {"windows-1257", 2257, 12},
+    {"windows-1258", 2258, 12},
+    {"TIS-620", 2259, 7},
+    {"CP50220", 2260, 7},
+};
+
+constexpr std::string_view other_names[]{
+    "graah", "oops", "libcxx", "foobar", "barbaz", "1234567", "llvm-project", "utf-81", "utf-9", "CA-ASCII"};
+
+#endif // SUPPORT_TEST_TEXT_ENCODING_H
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..d84b36d86d88f
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/default.pass.cpp
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::text_encoding() noexcept
+
+#include <cassert>
+#include <text_encoding>
+#include <type_traits>
+
+constexpr bool test() {
+  std::text_encoding te = std::text_encoding();
+  assert(te.mib() == std::text_encoding::unknown);
+  assert(std::string_view("") == te.name());
+
+  return true;
+}
+
+int main(int, char**) {
+  // 1. Default constructor must be nothrow
+  {
+    static_assert(
+        std::is_nothrow_default_constructible<std::text_encoding>::value, "Must be nothrow default constructible");
+  }
+
+  // 2. Default constructing a text_encoding object makes it so that mib() == id::unknown, and its name is empty
+  {
+    test();
+    static_assert(test());
+  }
+
+  return 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..aadae652d5b91
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/id.pass.cpp
@@ -0,0 +1,84 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::text_encoding(id) noexcept
+
+#include <algorithm>
+#include <cassert>
+#include <ranges>
+#include <text_encoding>
+#include <type_traits>
+
+#include "../test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+constexpr void id_ctor(id i, id expect_id, std::string_view expect_name) {
+  std::text_encoding te = std::text_encoding(i);
+
+  assert(te.mib() == expect_id);
+  assert(expect_name == te.name());
+  assert(std::ranges::contains(te.aliases(), expect_name));
+}
+
+constexpr void id_ctors() {
+  for (auto pair : unique_encoding_data) {
+    id_ctor(id(pair.mib), id(pair.mib), pair.name);
+  }
+}
+
+constexpr void test_unknown_other() {
+  {
+    std::text_encoding te = std::text_encoding(id::other);
+
+    assert(te.mib() == id::other);
+    assert(std::string_view("") == te.name());
+    assert(std::ranges::empty(te.aliases()));
+  }
+
+  {
+    std::text_encoding te = std::text_encoding(id::unknown);
+
+    assert(te.mib() == id::unknown);
+    assert(std::string_view("") == te.name());
+    assert(std::ranges::empty(te.aliases()));
+  }
+}
+
+constexpr bool test() {
+  {
+    // 2. Constructing an object with a valid id must set mib() and the name to the corresponding value.
+    id_ctors();
+  }
+
+  {
+    // 3. Constructing an object using id::unknown or id::other must set mib() to id::unknown or id::other, respectively, and the name to an empty string.
+    test_unknown_other();
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  {
+    // 1. text_encoding(id) must be nothrow
+    static_assert(std::is_nothrow_constructible<std::text_encoding, std::text_encoding::id>::value,
+                  "Must be nothrow constructible with id");
+  }
+
+  {
+    test();
+    static_assert(test());
+  }
+
+  return 0;
+}
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..8b92d5fa7fba8
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.ctor/string_view.pass.cpp
@@ -0,0 +1,98 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=30000000
+// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-ops-limit): -fconstexpr-ops-limit=99000000
+
+// <text_encoding>
+
+// text_encoding::text_encoding(string_view) noexcept
+
+#include <cassert>
+#include <string_view>
+#include <text_encoding>
+#include <type_traits>
+
+#include "../test_text_encoding.h"
+
+constexpr void test_ctor(std::string_view str, std::string_view expect, std::text_encoding::id expect_id) {
+  std::text_encoding te = std::text_encoding(str);
+
+  assert(te.mib() == expect_id);
+  assert(te.name() == expect);
+}
+
+constexpr void test_primary_encoding_spellings() {
+  for (auto& data : unique_encoding_data) {
+    std::text_encoding te = std::text_encoding(data.name);
+
+    assert(te.mib() == std::text_encoding::id(data.mib));
+    assert(te.name() == data.name);
+  }
+}
+
+constexpr void test_others() {
+  for (auto& name : other_names) {
+    std::text_encoding te = std::text_encoding(name);
+
+    assert(te.mib() == std::text_encoding::other);
+    assert(te.name() == name);
+  }
+}
+
+constexpr bool test() {
+  // happy paths
+  {
+    test_primary_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);
+  }
+
+  {
+    test_others();
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  {
+    static_assert(std::is_nothrow_constructible<std::text_encoding, std::string_view>::value,
+                  "Must be nothrow constructible with string_view");
+  }
+
+  {
+    test();
+    static_assert(test());
+  }
+
+  return 0;
+}
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..3dd8b4322e82e
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.id.pass.cpp
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// bool text_encoding::operator==(const text_encoding&, id) noexcept
+
+#include <cassert>
+#include <text_encoding>
+
+#include "test_macros.h"
+#include "../test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+constexpr void test_primary_encodings() {
+  for (auto& data : unique_encoding_data) {
+    std::text_encoding te = std::text_encoding(id(data.mib));
+    assert(te == id(data.mib));
+  }
+}
+
+constexpr bool test() {
+  // 1. operator==(const text_encoding&, id) must be noexcept
+  {
+    std::text_encoding te = std::text_encoding();
+    ASSERT_NOEXCEPT(te == id::UTF8);
+  }
+
+  // 2. operator==(const text_encoding&, id) returns true if mib() is equal to the id
+  {
+    assert(std::text_encoding(id::UTF8) == id::UTF8);
+  }
+
+  // 2.1
+  {
+    assert(std::text_encoding() == id::unknown);
+  }
+
+  // 2.1.1
+  {
+    assert(std::text_encoding(id::unknown) == id::unknown);
+  }
+
+  // 2.2
+  {
+    assert(std::text_encoding(id::other) == id::other);
+  }
+
+  // 3. operator==(const text_encoding&, id) returns false if mib() is not equal to the id
+  {
+    assert(!(std::text_encoding(id::UTF8) == id::UTF16));
+  }
+
+  {
+    test_primary_encodings();
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}
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..eefbf02bc5bcf
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.eq/equal.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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// bool text_encoding::operator==(const text_encoding&, const text_encoding&) noexcept
+
+#include <cassert>
+#include <text_encoding>
+
+#include "test_macros.h"
+
+using id = std::text_encoding::id;
+
+constexpr bool test() {
+  // 1. operator==(const text_encoding&, const text_encoding&) must be noexcept
+  {
+    ASSERT_NOEXCEPT(std::text_encoding() == std::text_encoding());
+  }
+
+  // 2. operator==(const text_encoding&, const text_encoding&) returns true if both text_encoding ids are equal
+  {
+    std::text_encoding te1 = std::text_encoding(id::UTF8);
+    std::text_encoding te2 = std::text_encoding(id::UTF8);
+    assert(te1 == te2);
+  }
+
+  // 3. operator==(const text_encoding&, const text_encoding&) for text_encodings with ids of "other" return true if the names are equal
+  {
+    std::text_encoding other_te1 = std::text_encoding("foo");
+    std::text_encoding other_te2 = std::text_encoding("foo");
+    assert(other_te1 == other_te2);
+  }
+
+  // 4. operator==(const text_encoding&, const text_encoding&) returns false when comparingtext_encodings with different ids
+  {
+    std::text_encoding te1 = std::text_encoding(id::UTF8);
+    std::text_encoding te2 = std::text_encoding(id::UTF16);
+    assert(!(te1 == te2));
+  }
+
+  // 5. operator==(const text_encoding&, const text_encoding&) for text_encodings with ids of "other" returns false if the names are not equal
+  {
+    std::text_encoding other_te1 = std::text_encoding("foo");
+    std::text_encoding other_te2 = std::text_encoding("bar");
+    assert(!(other_te1 == other_te2));
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.hash/enabled_hash.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.hash/enabled_hash.pass.cpp
new file mode 100644
index 0000000000000..981cb4f061268
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.hash/enabled_hash.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// template <> struct hash<text_encoding>
+
+#include <text_encoding>
+
+#include "poisoned_hash_helper.h"
+#include "test_macros.h"
+
+int main(int, char**) {
+  test_library_hash_specializations_available();
+
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.hash/hash.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.hash/hash.pass.cpp
new file mode 100644
index 0000000000000..1171e2dab882b
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.hash/hash.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// template <> struct hash<text_encoding>
+
+#include <cassert>
+#include <cstdint>
+#include <text_encoding>
+#include <type_traits>
+
+void test_te_hash() {
+  using T = std::text_encoding;
+  using H = std::hash<T>;
+
+  {
+    const T te(T::ASCII);
+    const H h{};
+    assert(h(te) == h(te));
+    static_assert(std::is_same_v<decltype(h(te)), std::size_t>);
+  }
+
+  {
+    const T te1(T::ASCII);
+    const T te2(T::UTF8);
+    const H h{};
+
+    assert(h(te1) != h(te2));
+  }
+
+  {
+    const T te1(T::unknown);
+    const T te2(T::unknown);
+    const H h{};
+    assert(h(te1) == h(te2));
+  }
+
+  {
+    const T te1(T::other);
+    const T te2(T::other);
+    const H h{};
+    assert(h(te1) == h(te2));
+  }
+}
+
+int main(int, char**) {
+  test_te_hash();
+
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases_view.compile.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases_view.compile.pass.cpp
new file mode 100644
index 0000000000000..711ad99476e77
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases_view.compile.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::aliases_view;
+
+#include <concepts>
+#include <text_encoding>
+
+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>);
+static_assert(std::same_as<std::ranges::range_value_t<std::text_encoding::aliases_view>, const char*>);
+static_assert(std::same_as<std::ranges::range_reference_t<std::text_encoding::aliases_view>, const char*>);
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..a527581ec1e34
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/environment.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+// REQUIRES: locale.en_US.UTF-8
+
+// UNSUPPORTED: no-localization
+// UNSUPPORTED: android
+// UNSUPPORTED: availability-te-environment-missing
+
+// <text_encoding>
+
+// text_encoding text_encoding::environment();
+
+#include <cassert>
+#include <clocale>
+#include <text_encoding>
+
+#include "../test_text_encoding.h"
+#include "platform_support.h"
+
+int main(int, char**) {
+  std::text_encoding te = std::text_encoding::environment();
+  // 1. Depending on the platform's default, verify that environment() returns the corresponding text encoding.
+  {
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
+    assert(te.mib() == std::text_encoding::ASCII);
+    assert(std::text_encoding::environment_is<std::text_encoding::ASCII>());
+#elif defined(_WIN32)
+    assert(te.mib() == std::text_encoding::windows1252);
+    assert(std::text_encoding::environment_is<std::text_encoding::windows1252>());
+#endif
+  }
+
+  // 2. text_encoding::environment() still returns the default locale encoding when the locale is set to "en_US.UTF-8".
+  {
+    std::setlocale(LC_ALL, LOCALE_en_US_UTF_8);
+
+    std::text_encoding te2 = std::text_encoding::environment();
+    assert(te2 != std::text_encoding::UTF8);
+    assert(te == te2);
+  }
+
+  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..84390e7d9c5fe
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/literal.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding text_encoding::literal() noexcept;
+
+#include <cassert>
+#include <text_encoding>
+
+constexpr bool test() {
+  std::text_encoding 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__));
+#else
+  assert(te.mib() = std::text_encoding::id::unknown);
+#endif
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}
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..8664eeb6213ab
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/begin.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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::aliases_view::begin()
+
+#include <cassert>
+#include <ranges>
+#include <text_encoding>
+
+constexpr bool test() {
+  // 1. begin() of an aliases_view from a single text_encoding object are the same.
+  {
+    std::text_encoding te = std::text_encoding(std::text_encoding::UTF8);
+
+    std::text_encoding::aliases_view view1 = te.aliases();
+    std::text_encoding::aliases_view view2 = te.aliases();
+
+    assert(std::ranges::begin(view1) == std::ranges::begin(view2));
+    assert(view1.begin() == view2.begin());
+  }
+
+  // 2. begin() of aliases_views of two text_encoding objects that represent the same ID but hold different names are the same.
+  {
+    std::text_encoding te1 = std::text_encoding("ANSI_X3.4-1968");
+    std::text_encoding te2 = std::text_encoding("ANSI_X3.4-1986");
+
+    std::text_encoding::aliases_view view1 = te1.aliases();
+    std::text_encoding::aliases_view view2 = te2.aliases();
+
+    assert(view1.begin() == view2.begin());
+    assert(std::ranges::begin(view1) == std::ranges::begin(view2));
+  }
+
+  // 3. begin() of aliases_views of two text_encoding objects that represent different IDs are different.
+  {
+    std::text_encoding te1 = std::text_encoding(std::text_encoding::UTF8);
+    std::text_encoding te2 = std::text_encoding(std::text_encoding::ASCII);
+
+    std::text_encoding::aliases_view view1 = te1.aliases();
+    std::text_encoding::aliases_view view2 = te2.aliases();
+
+    assert(!(view1.begin() == view2.begin()));
+    assert(!(std::ranges::begin(view1) == std::ranges::begin(view2)));
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}
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..525d448054436
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/empty.pass.cpp
@@ -0,0 +1,76 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=9000000
+
+// <text_encoding>
+
+// text_encoding::aliases_view
+
+#include <cassert>
+#include <ranges>
+#include <text_encoding>
+
+#include "../../test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+constexpr void test_other_unknown() {
+  {
+    std::text_encoding te_other = std::text_encoding(id::other);
+
+    std::text_encoding::aliases_view other_range = te_other.aliases();
+
+    assert(std::ranges::empty(other_range));
+    assert(other_range.empty());
+    assert(!bool(other_range));
+  }
+
+  {
+    std::text_encoding te_unknown = std::text_encoding(id::unknown);
+
+    std::text_encoding::aliases_view unknown_range = te_unknown.aliases();
+    assert(std::ranges::empty(unknown_range));
+    assert(unknown_range.empty());
+    assert(!bool(unknown_range));
+  }
+}
+
+constexpr void test_primary_encodings() {
+  for (auto& data : unique_encoding_data) {
+    std::text_encoding te = std::text_encoding(id(data.mib));
+
+    std::text_encoding::aliases_view range = te.aliases();
+
+    assert(!std::ranges::empty(range));
+    assert(!range.empty());
+    assert(bool(range));
+  }
+}
+
+constexpr bool test() {
+  // 1. An alias_view of a text_encoding object for "other" and "unknown" are empty
+  {
+    test_other_unknown();
+  }
+
+  // 2. An alias_view of a text_encoding object for a known encoding e.g. "UTF-8" is not empty
+  {
+    test_primary_encodings();
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/end.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/end.pass.cpp
new file mode 100644
index 0000000000000..b19069dd54b77
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/end.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::aliases_view::end()
+
+#include <cassert>
+#include <text_encoding>
+
+constexpr bool test() {
+  std::text_encoding a_other = std::text_encoding("foobar");
+
+  std::text_encoding::aliases_view other_aliases = a_other.aliases();
+
+  // 1. begin() of an aliases_view of "other" is equal to end()
+  assert(other_aliases.begin() == other_aliases.end());
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}
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..27970fdfd5976
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/front.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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::aliases_view::front()
+
+#include <cassert>
+#include <ranges>
+#include <string_view>
+#include <text_encoding>
+
+using id = std::text_encoding::id;
+
+constexpr bool test() {
+  // 1. An aliases_view from a single text_encoding object returns the same front()
+  {
+    std::text_encoding te = std::text_encoding(id::UTF8);
+
+    std::text_encoding::aliases_view view1 = te.aliases();
+    std::text_encoding::aliases_view view2 = te.aliases();
+
+    assert(std::string_view(view1.front()) == std::string_view(view2.front()));
+  }
+
+  // 2. An aliases_views of two text_encoding objects that represent the same ID but hold different names return the same front()
+  {
+    std::text_encoding te1 = std::text_encoding("US-ASCII");
+    std::text_encoding te2 = std::text_encoding("ANSI_X3.4-1986");
+
+    std::text_encoding::aliases_view view1 = te1.aliases();
+    std::text_encoding::aliases_view view2 = te2.aliases();
+
+    assert(std::string_view(view1.front()) == std::string_view(view2.front()));
+  }
+
+  // 3. An aliases_views of two text_encoding objects that represent different IDs return different front()
+  {
+    std::text_encoding te1 = std::text_encoding(id::UTF8);
+    std::text_encoding te2 = std::text_encoding(id::ASCII);
+
+    std::text_encoding::aliases_view view1 = te1.aliases();
+    std::text_encoding::aliases_view view2 = te2.aliases();
+
+    assert(!(std::string_view(view1.front()) == std::string_view(view2.front())));
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
new file mode 100644
index 0000000000000..63e714c68abd3
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
@@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::aliases_view::iterator (implementation-defined)
+
+#include <cassert>
+#include <compare>
+#include <string_view>
+#include <text_encoding>
+#include <utility>
+
+constexpr bool test() {
+  // Test iterator operators.
+  std::text_encoding te = std::text_encoding(std::text_encoding::ASCII); // 11 aliases
+
+  auto i = te.aliases().begin();
+  auto j = te.aliases().begin();
+  auto k = te.aliases().end();
+
+  static_assert(std::three_way_comparable<decltype(i), std::strong_ordering>);
+
+  {
+    assert(i == j);
+    assert(i != k);
+    assert((i <=> j) == std::strong_ordering::equal);
+    assert(std::string_view(*i) == std::string_view(*j));
+  }
+  {
+    assert(std::string_view(i[0]) == std::string_view(j[0]));
+    assert(std::string_view(i[1]) != std::string_view(j[3]));
+  }
+  {
+    i++;
+    assert(i > j);
+    assert((i <=> j) == std::strong_ordering::greater);
+    assert(std::string_view(*i) != std::string_view(*j));
+  }
+  {
+    i--;
+    assert(i == te.aliases().begin());
+    assert(i == j);
+    assert(i != k);
+    assert(std::string_view(*i) == std::string_view(*j));
+  }
+  {
+    i++;
+    j++;
+    assert(i != te.aliases().begin());
+    assert(i == j);
+    assert(i != k);
+    assert(std::string_view(*i) == std::string_view(*j));
+  }
+  {
+    auto temp = i + 2;
+    assert(i != temp);
+    assert(std::string_view(*temp) != std::string_view(*j));
+    auto temp2 = temp - 2;
+    assert(std::string_view(*temp2) == std::string_view(*j));
+  }
+  {
+    assert(i - j == 0);
+    assert(k - i > 0);
+  }
+  {
+    auto temp = ++i;
+    assert(temp == i);
+    auto temp2 = j++;
+    assert(temp2 == j - 1);
+    assert(i == j);
+  }
+  {
+    i += 2;
+    j += 3;
+
+    auto tempi = i;
+    auto tempj = j;
+    assert(i != j);
+    assert((i <=> j) == std::strong_ordering::less);
+    i -= 2;
+    j -= 3;
+    assert(i == j);
+    assert(i != tempi && (tempi - i) == 2);
+    assert(j != tempj && (tempj - j) == 3);
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/text_encoding/trivially_copyable.compile.pass.cpp b/libcxx/test/std/utilities/text_encoding/trivially_copyable.compile.pass.cpp
new file mode 100644
index 0000000000000..c16e60523c4d4
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/trivially_copyable.compile.pass.cpp
@@ -0,0 +1,16 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+#include <text_encoding>
+#include <type_traits>
+
+static_assert(std::is_trivially_copyable_v<std::text_encoding>);
diff --git a/libcxx/test/support/platform_support.h b/libcxx/test/support/platform_support.h
index b66fdff9b0491..f78aa39efd0d2 100644
--- a/libcxx/test/support/platform_support.h
+++ b/libcxx/test/support/platform_support.h
@@ -33,6 +33,7 @@
 #define LOCALE_ru_RU_UTF_8     "ru_RU.UTF-8"
 #define LOCALE_zh_CN_UTF_8     "zh_CN.UTF-8"
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string>
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index 88431c76a00f5..581578db7d69f 100644
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -1395,7 +1395,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 d06271a7908cc..ad011374a14a4 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 = {
diff --git a/libcxx/utils/libcxx/test/features/availability.py b/libcxx/utils/libcxx/test/features/availability.py
index 39c6cf45a1708..cf491e27dcef7 100644
--- a/libcxx/utils/libcxx/test/features/availability.py
+++ b/libcxx/utils/libcxx/test/features/availability.py
@@ -196,4 +196,12 @@
             cfg.available_features,
         ),
     ),
+    # Tests that require std::text_encoding::environment() in the built library
+    Feature(
+        name="availability-te-environment-missing",
+        when=lambda cfg: BooleanExpression.evaluate(
+            "!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-22)",
+            cfg.available_features,
+        ),
+    ),
 ]

>From 560706a7dc5d4f556a9ff162483fdc9012f2a716 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Sat, 7 Feb 2026 16:25:23 -0500
Subject: [PATCH 02/58] Retarget to LLVM 23

---
 libcxx/docs/Status/Cxx2cIssues.csv                | 2 +-
 libcxx/docs/Status/Cxx2cPapers.csv                | 4 ++--
 libcxx/include/__configuration/availability.h     | 9 +++++++--
 libcxx/utils/libcxx/test/features/availability.py | 2 +-
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index f066eca24f3d3..847760b8b8f08 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -56,7 +56,7 @@
 "`LWG4035 <https://wg21.link/LWG4035>`__","``single_view`` should provide ``empty``","2024-03 (Tokyo)","|Complete|","19","`#105328 <https://github.com/llvm/llvm-project/issues/105328>`__",""
 "`LWG4036 <https://wg21.link/LWG4036>`__","``__alignof_is_defined`` is only implicitly specified in C++ and not yet deprecated","2024-03 (Tokyo)","","","`#105329 <https://github.com/llvm/llvm-project/issues/105329>`__",""
 "`LWG4037 <https://wg21.link/LWG4037>`__","Static data members of ``ctype_base`` are not yet required to be usable in constant expressions","2024-03 (Tokyo)","","","`#105330 <https://github.com/llvm/llvm-project/issues/105330>`__",""
-"`LWG4038 <https://wg21.link/LWG4038>`__","``std::text_encoding::aliases_view`` should have constexpr iterators","2024-03 (Tokyo)","|Complete|","","`#105332 <https://github.com/llvm/llvm-project/issues/105332>`__",""
+"`LWG4038 <https://wg21.link/LWG4038>`__","``std::text_encoding::aliases_view`` should have constexpr iterators","2024-03 (Tokyo)","|Complete|","23","`#105332 <https://github.com/llvm/llvm-project/issues/105332>`__",""
 "`LWG4043 <https://wg21.link/LWG4043>`__","""ASCII"" is not a registered character encoding","2024-03 (Tokyo)","|Nothing To Do|","","`#105335 <https://github.com/llvm/llvm-project/issues/105335>`__",""
 "`LWG4045 <https://wg21.link/LWG4045>`__","``tuple`` can create dangling references from ``tuple-like``","2024-03 (Tokyo)","","","`#105337 <https://github.com/llvm/llvm-project/issues/105337>`__",""
 "`LWG4053 <https://wg21.link/LWG4053>`__","Unary call to ``std::views::repeat`` does not decay the argument","2024-03 (Tokyo)","|Complete|","19","`#105338 <https://github.com/llvm/llvm-project/issues/105338>`__",""
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index 77e488654099a..5cccf8c6d6163 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)","","","`#105370 <https://github.com/llvm/llvm-project/issues/105370>`__",""
 "`P2363R5 <https://wg21.link/P2363R5>`__","Extending associative containers with the remaining heterogeneous overloads","2023-06 (Varna)","","","`#105371 <https://github.com/llvm/llvm-project/issues/105371>`__",""
 "`P1901R2 <https://wg21.link/P1901R2>`__","Enabling the Use of ``weak_ptr`` as Keys in Unordered Associative Containers","2023-06 (Varna)","","","`#105372 <https://github.com/llvm/llvm-project/issues/105372>`__",""
-"`P1885R12 <https://wg21.link/P1885R12>`__","Naming Text Encodings to Demystify Them","2023-06 (Varna)","|Partial|","22","`#105373 <https://github.com/llvm/llvm-project/issues/105373>`__","locale::encoding() is not yet implemented."
+"`P1885R12 <https://wg21.link/P1885R12>`__","Naming Text Encodings to Demystify Them","2023-06 (Varna)","|Partial|","23","`#105373 <https://github.com/llvm/llvm-project/issues/105373>`__","locale::encoding() is not yet implemented."
 "`P0792R14 <https://wg21.link/P0792R14>`__","``function_ref``: a type-erased callable reference","2023-06 (Varna)","","","`#105376 <https://github.com/llvm/llvm-project/issues/105376>`__",""
 "`P2874R2 <https://wg21.link/P2874R2>`__","P2874R2: Mandating Annex D Require No More","2023-06 (Varna)","|Complete|","12","`#105377 <https://github.com/llvm/llvm-project/issues/105377>`__",""
 "`P2757R3 <https://wg21.link/P2757R3>`__","Type-checking format args","2023-06 (Varna)","","","`#105378 <https://github.com/llvm/llvm-project/issues/105378>`__",""
@@ -79,7 +79,7 @@
 "`P3136R1 <https://wg21.link/P3136R1>`__","Retiring niebloids","2024-11 (Wrocław)","|Complete|","14","`#118133 <https://github.com/llvm/llvm-project/issues/118133>`__",""
 "`P3138R5 <https://wg21.link/P3138R5>`__","``views::cache_latest``","2024-11 (Wrocław)","","","`#118134 <https://github.com/llvm/llvm-project/issues/118134>`__",""
 "`P3379R0 <https://wg21.link/P3379R0>`__","Constrain ``std::expected`` equality operators","2024-11 (Wrocław)","|Complete|","21","`#118135 <https://github.com/llvm/llvm-project/issues/118135>`__",""
-"`P2862R1 <https://wg21.link/P2862R1>`__","``text_encoding::name()`` should never return null values","2024-11 (Wrocław)","|Complete|","22","`#118371 <https://github.com/llvm/llvm-project/issues/118371>`__",""
+"`P2862R1 <https://wg21.link/P2862R1>`__","``text_encoding::name()`` should never return null values","2024-11 (Wrocław)","|Complete|","23","`#118371 <https://github.com/llvm/llvm-project/issues/118371>`__",""
 "`P2897R7 <https://wg21.link/P2897R7>`__","``aligned_accessor``: An ``mdspan`` accessor expressing pointer over-alignment","2024-11 (Wrocław)","|Complete|","21","`#118372 <https://github.com/llvm/llvm-project/issues/118372>`__",""
 "`P3355R2 <https://wg21.link/P3355R2>`__","Fix ``submdspan`` for C++26","2024-11 (Wrocław)","","","`#118373 <https://github.com/llvm/llvm-project/issues/118373>`__",""
 "`P3222R0 <https://wg21.link/P3222R0>`__","Fix C++26 by adding transposed special cases for P2642 layouts","2024-11 (Wrocław)","","","`#118374 <https://github.com/llvm/llvm-project/issues/118374>`__",""
diff --git a/libcxx/include/__configuration/availability.h b/libcxx/include/__configuration/availability.h
index cd79036b9db68..37b329bb0bf6c 100644
--- a/libcxx/include/__configuration/availability.h
+++ b/libcxx/include/__configuration/availability.h
@@ -38,6 +38,8 @@
 // When availability annotations are disabled, we take for granted that features introduced
 // in all versions of the library are available.
 #if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
+#  define _LIBCPP_INTRODUCED_IN_LLVM_23 1
+#  define _LIBCPP_INTRODUCED_IN_LLVM_23_ATTRIBUTE /* nothing */
 
 #  define _LIBCPP_INTRODUCED_IN_LLVM_22 1
 #  define _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE /* nothing */
@@ -70,6 +72,9 @@
 
 // clang-format off
 
+#  define _LIBCPP_INTRODUCED_IN_LLVM_23 0
+#  define _LIBCPP_INTRODUCED_IN_LLVM_23_ATTRIBUTE __attribute__((unavailable))
+
 // LLVM 22
 #  define _LIBCPP_INTRODUCED_IN_LLVM_22 0
 #  define _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE __attribute__((unavailable))
@@ -295,8 +300,8 @@
 // No attribute, since we've had bad_function_call::what() in the headers before
 
 // Controls whether the internal implementation for text_encoding::environment() -> te_impl::__environment() is available
-#define _LIBCPP_AVAILABILITY_HAS_TE_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_22
-#define _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE
+#define _LIBCPP_AVAILABILITY_HAS_TE_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_23
+#define _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_23_ATTRIBUTE
 
 // Only define a bunch of symbols in the dylib if we need to be compatible with LLVM 7 headers or older
 #  if defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_AVAILABILITY_MINIMUM_HEADER_VERSION < 8
diff --git a/libcxx/utils/libcxx/test/features/availability.py b/libcxx/utils/libcxx/test/features/availability.py
index cf491e27dcef7..8a6694cf6ae1c 100644
--- a/libcxx/utils/libcxx/test/features/availability.py
+++ b/libcxx/utils/libcxx/test/features/availability.py
@@ -200,7 +200,7 @@
     Feature(
         name="availability-te-environment-missing",
         when=lambda cfg: BooleanExpression.evaluate(
-            "!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-22)",
+            "!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-23)",
             cfg.available_features,
         ),
     ),

>From df749f528913b81bef60c642b72619b349fe4bfc Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Sat, 7 Feb 2026 16:26:07 -0500
Subject: [PATCH 03/58] Improve struct size, 72 bytes -> 66 bytes on 64bit
 system

---
 libcxx/include/__text_encoding/te_impl.h      | 88 ++++++++++---------
 .../text_encoding.ctor/assert.id.pass.cpp     | 18 ++--
 .../assert.string_view.pass.cpp               |  4 +-
 3 files changed, 57 insertions(+), 53 deletions(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index 2192735b027fa..9ecfd3c244d81 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -295,6 +295,9 @@ struct __te_impl {
     CP50220                 = 2260
   };
 
+  static constexpr int __NATS_DANO_     = 33;
+  static constexpr int __NATS_DANO_ADD_ = 34;
+
   using enum __id;
   static constexpr size_t __max_name_length_ = 63;
 
@@ -310,11 +313,11 @@ struct __te_impl {
              __comp_name(string_view(__e.__name_, __e.__name_size_), string_view(__other.__name_, __e.__name_size_));
     }
 
-    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __te_data& __e, const int_least32_t __i) noexcept {
-      return __e.__mib_rep_ < __i;
+    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __te_data& __e, __id __i) noexcept {
+      return __e.__mib_rep_ < int_least32_t(__i);
     }
 
-    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_data& __e, std::string_view __name) noexcept {
+    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_data& __e, string_view __name) noexcept {
       return __comp_name(__name, string_view(__e.__name_, __e.__name_size_));
     }
   }; // __te_data
@@ -326,16 +329,19 @@ struct __te_impl {
 
     // 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_in) -> char {
-        return (__n_in >= 'A' && __n_in <= 'Z') ? __n_in + ('a' - 'A') : __n_in;
-      };
       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;
+
+      if ((__n >= '1' && __n <= '9') || (__n >= 'a' && __n <= 'z')) {
+        return __n;
+      }
+      if (__n >= 'A' && __n <= 'Z') {
+        return __n + ('a' - 'A'); // tolower
+      }
+
+      return 255;
     };
 
     auto __a_ptr = __a.begin(), __b_ptr = __b.begin();
@@ -358,51 +364,52 @@ struct __te_impl {
     return true;
   }
 
-  _LIBCPP_HIDE_FROM_ABI static constexpr const __te_data* __find_encoding_data(string_view __a) {
-    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
-        __a.size() <= __max_name_length_ && !__a.contains('\0'), "invalid string passed to text_encoding(string_view)");
-    const __te_data* __data_first = __text_encoding_data + 2;
-    const __te_data* __data_last  = std::end(__text_encoding_data);
+  _LIBCPP_HIDE_FROM_ABI static constexpr unsigned short __find_data_idx(string_view __a) {
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__a.size() <= __max_name_length_, "input string_view must have size <= 63");
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__a.contains('\0'), "input string_view must not contain '\\0'");
 
-    auto* __found_data = std::find(__data_first, __data_last, __a);
+    auto* __found = std::find(__text_encoding_data + 2, std::end(__text_encoding_data), __a);
 
-    if (__found_data == __data_last) {
-      return __text_encoding_data; // other
+    if (__found == std::end(__text_encoding_data)) {
+      return 0u; // other
     }
 
-    while (__found_data[-1].__mib_rep_ == __found_data->__mib_rep_) {
-      __found_data--;
+    while (__found[-1].__mib_rep_ == __found->__mib_rep_) {
+      __found--;
     }
 
-    return __found_data;
+    return __found - __text_encoding_data;
   }
 
-  _LIBCPP_HIDE_FROM_ABI static constexpr const __te_data* __find_encoding_data_by_id(__id __i) {
-    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
-        ((__i >= __id::other && __i <= __id::CP50220) && ((int_least32_t(__i) != 33) && (int_least32_t(__i) != 34))),
-        "invalid text_encoding::id passed to text_encoding(id)");
-    auto __found =
-        std::lower_bound(std::begin(__text_encoding_data), std::end(__text_encoding_data), int_least32_t(__i));
+  _LIBCPP_HIDE_FROM_ABI static constexpr unsigned short __find_data_idx_by_id(__id __i) {
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__i >= __id::other, "invalid text_encoding::id passed");
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__i <= __id::CP50220, "invalid text_encoding::id passed");
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(int_least32_t(__i) != __NATS_DANO_, "Mib for NATS-DANO used");
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(int_least32_t(__i) != __NATS_DANO_ADD_, "Mib for NATS-DANO-ADD used");
+    auto __found = std::lower_bound(std::begin(__text_encoding_data), std::end(__text_encoding_data), __i);
 
-    return __found != std::end(__text_encoding_data)
-             ? __found
-             : __text_encoding_data + 1; // unknown, should be unreachable
+    if (__found == std::end(__text_encoding_data)) {
+      return 1u;
+    }
+
+    return __found - __text_encoding_data;
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr __te_impl() = default;
 
   _LIBCPP_HIDE_FROM_ABI constexpr explicit __te_impl(string_view __enc) noexcept
-      : __encoding_rep_(__find_encoding_data(__enc)) {
+      : __encoding_idx_(__find_data_idx(__enc)) {
     __enc.copy(__name_, __max_name_length_, 0);
   }
 
-  _LIBCPP_HIDE_FROM_ABI constexpr __te_impl(__id __i) noexcept : __encoding_rep_(__find_encoding_data_by_id(__i)) {
-    if (__encoding_rep_->__name_[0] != '\0')
-      std::copy_n(__encoding_rep_->__name_, __encoding_rep_->__name_size_, __name_);
+  _LIBCPP_HIDE_FROM_ABI constexpr __te_impl(__id __i) noexcept : __encoding_idx_(__find_data_idx_by_id(__i)) {
+    if (__text_encoding_data[__encoding_idx_].__name_[0] != '\0')
+      std::copy_n(
+          __text_encoding_data[__encoding_idx_].__name_, __text_encoding_data[__encoding_idx_].__name_size_, __name_);
   }
 
   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __id __mib() const noexcept {
-    return __id(__encoding_rep_->__mib_rep_);
+    return __id(__text_encoding_data[__encoding_idx_].__mib_rep_);
   }
   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr const char* __name() const noexcept { return __name_; }
 
@@ -475,7 +482,7 @@ struct __te_impl {
         return *this;
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) { return operator+=(-__n); }
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) { return (*this += -__n); }
 
       _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const __iterator& __it) const { return __data_ == __it.__data_; }
 
@@ -499,10 +506,10 @@ struct __te_impl {
 
     _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view(const __te_data* __d) : __view_data_(__d) {}
     const __te_data* __view_data_;
-  };
+  }; // __aliases_view
 
   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view __aliases() const {
-    return __aliases_view(__encoding_rep_);
+    return __aliases_view(&__text_encoding_data[__encoding_idx_]);
   }
 
   _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_impl& __a, const __te_impl& __b) noexcept {
@@ -511,7 +518,7 @@ struct __te_impl {
              : __a.__mib() == __b.__mib();
   }
 
-  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_impl& __encoding, const __id __i) noexcept {
+  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_impl& __encoding, __id __i) noexcept {
     return __encoding.__mib() == __i;
   }
 
@@ -541,9 +548,8 @@ struct __te_impl {
   }
 
 #  endif
-
-  const __te_data* __encoding_rep_     = __text_encoding_data + 1;
-  char __name_[__max_name_length_ + 1] = {0};
+  unsigned short __encoding_idx_{1u};
+  char __name_[__max_name_length_ + 1]{};
 
   _LIBCPP_HIDE_FROM_ABI static constexpr __te_data __text_encoding_data[] = {
       {"", 1, 0, 0}, // other
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp
index e1c966902a343..a2884b941dcf2 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp
@@ -19,16 +19,14 @@
 #include "check_assertion.h"
 
 int main(int, char**) {
-  // Make sure that text_encoding(id) asserts when the input id not in range of allowed values
-
-  TEST_LIBCPP_ASSERT_FAILURE(
-      std::text_encoding(std::text_encoding::id(33)), "invalid text_encoding::id passed to text_encoding(id)");
-  TEST_LIBCPP_ASSERT_FAILURE(
-      std::text_encoding(std::text_encoding::id(34)), "invalid text_encoding::id passed to text_encoding(id)");
-  TEST_LIBCPP_ASSERT_FAILURE(
-      std::text_encoding(std::text_encoding::id(-1)), "invalid text_encoding::id passed to text_encoding(id)");
-  TEST_LIBCPP_ASSERT_FAILURE(
-      std::text_encoding(std::text_encoding::id(INT_MAX)), "invalid text_encoding::id passed to text_encoding(id)");
+  // Make sure that text_encoding(id) asserts when the input id not in the range of allowed values
+
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::text_encoding::id(33)), "Mib for NATS-DANO used");
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::text_encoding::id(34)), "Mib for NATS-DANO-ADD used");
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::text_encoding::id(-1)), "invalid text_encoding::id passed");
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::text_encoding::id(INT_MAX)), "invalid text_encoding::id passed");
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::text_encoding::id(int(std::text_encoding::id::CP50220) + 1)),
+                             "invalid text_encoding::id passed");
 
   return 0;
 }
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
index 75bee493bbf68..3d50bdd4832f3 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
@@ -24,14 +24,14 @@ int main(int, char**) {
   std::string_view view(str);
 
   // text_encoding(string_view) asserts if its input size() > max_name_length
-  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(view), "invalid string passed to text_encoding(string_view)");
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(view), "input string_view must have size <= 63");
 
   // text_encoding(string_view) asserts if its input contains a null terminator
   char str2[std::text_encoding::max_name_length] = "HELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELL";
   std::string_view view2(str2);
   str2[3] = '\0';
 
-  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(view2), "invalid string passed to text_encoding(string_view)");
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(view2), "input string_view must not contain '\\0'");
 
   return 0;
 }

>From 01fc9905f47b05ebe988f16392d718eebf830b6b Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Sat, 7 Feb 2026 16:51:29 -0500
Subject: [PATCH 04/58] Update locale for AIX, picolibc

---
 libcxx/include/__locale_dir/support/aix.h    | 6 ++++++
 libcxx/include/__locale_dir/support/newlib.h | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/libcxx/include/__locale_dir/support/aix.h b/libcxx/include/__locale_dir/support/aix.h
index a216e28393799..86c44adea3846 100644
--- a/libcxx/include/__locale_dir/support/aix.h
+++ b/libcxx/include/__locale_dir/support/aix.h
@@ -17,6 +17,7 @@
 #include <cstdio>
 #include <cstdlib>
 #include <ctype.h>
+#include <langinfo.h>
 #include <string.h>
 #include <time.h>
 #if _LIBCPP_HAS_WIDE_CHARACTERS
@@ -56,6 +57,7 @@ struct __locale_guard {
 #define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
 #define _LIBCPP_ALL_MASK LC_ALL_MASK
 #define _LIBCPP_LC_ALL LC_ALL
+#define _LIBCPP_NL_CODESET CODESET
 
 // Get MB_CUE_MAX before __locale_t is defined because it uses a defferent definition in <sys/localedef.h>.
 inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_cur_max() { return MB_CUR_MAX; }
@@ -79,6 +81,10 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
   __locale_guard __current(__loc);
   return std::localeconv();
 }
+
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+  return ::nl_langinfo_l(__item, __loc);
+}
 #endif // _LIBCPP_BUILDING_LIBRARY
 
 // The following structure is a quick-and-dirty workaround for routines that AIX
diff --git a/libcxx/include/__locale_dir/support/newlib.h b/libcxx/include/__locale_dir/support/newlib.h
index 05c8a449cfb05..1e2a3310f74da 100644
--- a/libcxx/include/__locale_dir/support/newlib.h
+++ b/libcxx/include/__locale_dir/support/newlib.h
@@ -16,6 +16,7 @@
 #include <cstdio>
 #include <cstdlib>
 #include <ctype.h>
+#include <langinfo.h>
 #include <stdarg.h>
 #include <string.h>
 #include <time.h>
@@ -56,6 +57,7 @@ struct __locale_guard {
 #define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
 #define _LIBCPP_ALL_MASK LC_ALL_MASK
 #define _LIBCPP_LC_ALL LC_ALL
+#define _LIBCPP_NL_CODESET CODESET
 
 using __locale_t _LIBCPP_NODEBUG = ::locale_t;
 
@@ -76,6 +78,10 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
   __locale_guard __current(__loc);
   return std::localeconv();
 }
+
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+  return ::nl_langinfo_l(__item, __loc);
+}
 #endif // _LIBCPP_BUILDING_LIBRARY
 
 //

>From 0c3d432b9eee551b60f8af0b818e9b268c46fe6f Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 9 Feb 2026 22:31:02 -0500
Subject: [PATCH 05/58] Reduce __te_data struct size from 16B -> 6B, reduces
 data table size from 14144 Bytes -> 8620 Bytes

---
 libcxx/include/__iterator/wrap_iter.h    |    1 +
 libcxx/include/__text_encoding/te_impl.h | 1897 +++++++++++-----------
 2 files changed, 972 insertions(+), 926 deletions(-)

diff --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h
index 128aeab3ac7cd..a1c8235a46c29 100644
--- a/libcxx/include/__iterator/wrap_iter.h
+++ b/libcxx/include/__iterator/wrap_iter.h
@@ -119,6 +119,7 @@ class __wrap_iter {
   friend struct array;
   template <class _Tp, class>
   friend struct __optional_iterator;
+  friend struct __te_impl;
 };
 
 template <class _Iter1>
diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index 9ecfd3c244d81..4c20847b6bc89 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -10,8 +10,7 @@
 #ifndef _LIBCPP__TEXT_ENCODING_TE_IMPL_H
 #define _LIBCPP__TEXT_ENCODING_TE_IMPL_H
 
-#include <__algorithm/copy_n.h>
-#include <__algorithm/find.h>
+#include <__algorithm/find_if.h>
 #include <__algorithm/lower_bound.h>
 #include <__config>
 #include <__cstddef/ptrdiff_t.h>
@@ -300,27 +299,23 @@ struct __te_impl {
 
   using enum __id;
   static constexpr size_t __max_name_length_ = 63;
-
   struct __te_data {
-    const char* __name_;
-    int_least32_t __mib_rep_;
-    uint16_t __name_size_;
-    uint16_t __to_end_;
-    // The encoding data knows the end of its range to simplify iterator implementation.
-
-    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_data& __e, const __te_data& __other) noexcept {
-      return __e.__mib_rep_ == __other.__mib_rep_ ||
-             __comp_name(string_view(__e.__name_, __e.__name_size_), string_view(__other.__name_, __e.__name_size_));
+    unsigned short __first_alias_index_;
+    unsigned short __mib_rep_;
+    unsigned char __num_aliases_;
+
+    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __te_data& __enc, __id __i) noexcept {
+      return __enc.__mib_rep_ < static_cast<unsigned short>(__i);
     }
 
-    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __te_data& __e, __id __i) noexcept {
-      return __e.__mib_rep_ < int_least32_t(__i);
+    _LIBCPP_HIDE_FROM_ABI constexpr const char* const* __aliases_begin() const {
+      return &__aliases_table[__first_alias_index_];
     }
 
-    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_data& __e, string_view __name) noexcept {
-      return __comp_name(__name, string_view(__e.__name_, __e.__name_size_));
+    _LIBCPP_HIDE_FROM_ABI constexpr const char* const* __aliases_end() const {
+      return &__aliases_table[__first_alias_index_ + __num_aliases_];
     }
-  }; // __te_data
+  };
 
   _LIBCPP_HIDE_FROM_ABI static constexpr bool __comp_name(string_view __a, string_view __b) {
     if (__a.empty() || __b.empty()) {
@@ -368,17 +363,19 @@ struct __te_impl {
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__a.size() <= __max_name_length_, "input string_view must have size <= 63");
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__a.contains('\0'), "input string_view must not contain '\\0'");
 
-    auto* __found = std::find(__text_encoding_data + 2, std::end(__text_encoding_data), __a);
+    auto __pred = [&__a](const __te_data& __entry) -> bool {
+      // Search slice of alias table that corresponds to the current MIB
+      return std::find_if(__entry.__aliases_begin(), __entry.__aliases_end(), [&__a](const char* __alias) {
+               return __comp_name(__a, __alias);
+             }) != __entry.__aliases_end();
+    };
 
-    if (__found == std::end(__text_encoding_data)) {
+    const __te_data* __found = std::find_if(__entries + 2, std::end(__entries), __pred);
+    if (__found == std::end(__entries)) {
       return 0u; // other
     }
 
-    while (__found[-1].__mib_rep_ == __found->__mib_rep_) {
-      __found--;
-    }
-
-    return __found - __text_encoding_data;
+    return __found - __entries;
   }
 
   _LIBCPP_HIDE_FROM_ABI static constexpr unsigned short __find_data_idx_by_id(__id __i) {
@@ -386,13 +383,13 @@ struct __te_impl {
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__i <= __id::CP50220, "invalid text_encoding::id passed");
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(int_least32_t(__i) != __NATS_DANO_, "Mib for NATS-DANO used");
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(int_least32_t(__i) != __NATS_DANO_ADD_, "Mib for NATS-DANO-ADD used");
-    auto __found = std::lower_bound(std::begin(__text_encoding_data), std::end(__text_encoding_data), __i);
+    auto __found = std::lower_bound(std::begin(__entries), std::end(__entries), __i);
 
-    if (__found == std::end(__text_encoding_data)) {
-      return 1u;
+    if (__found == std::end(__entries)) {
+      return 1u; // unknown
     }
 
-    return __found - __text_encoding_data;
+    return __found - __entries;
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr __te_impl() = default;
@@ -403,14 +400,16 @@ struct __te_impl {
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr __te_impl(__id __i) noexcept : __encoding_idx_(__find_data_idx_by_id(__i)) {
-    if (__text_encoding_data[__encoding_idx_].__name_[0] != '\0')
-      std::copy_n(
-          __text_encoding_data[__encoding_idx_].__name_, __text_encoding_data[__encoding_idx_].__name_size_, __name_);
+    const char* __alias = __aliases_table[__entries[__encoding_idx_].__first_alias_index_];
+    if (__alias[0] != '\0') {
+      string_view(__alias).copy(__name_, __max_name_length_);
+    }
   }
 
   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __id __mib() const noexcept {
-    return __id(__text_encoding_data[__encoding_idx_].__mib_rep_);
+    return __id(__entries[__encoding_idx_].__mib_rep_);
   }
+
   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr const char* __name() const noexcept { return __name_; }
 
   // [text.encoding.aliases], class text_encoding::aliases_view
@@ -424,13 +423,15 @@ struct __te_impl {
 
       constexpr __iterator() noexcept = default;
 
-      _LIBCPP_HIDE_FROM_ABI constexpr value_type operator*() const { return __data_->__name_; }
+      _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const { return *__data_; }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr value_type operator[](difference_type __n) const {
+      _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const {
         auto __it = *this;
         return *(__it + __n);
       }
 
+      _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator->() const { return __data_; }
+
       _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator __it, difference_type __n) {
         __it += __n;
         return __it;
@@ -491,15 +492,13 @@ struct __te_impl {
     private:
       friend struct __aliases_view;
 
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator(const __te_data* __enc_d) noexcept : __data_(__enc_d) {}
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator(const char* const* __enc_d) noexcept : __data_(__enc_d) {}
 
-      const __te_data* __data_;
+      const char* const* __data_;
     }; // __iterator
 
-    _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const { return __iterator{__view_data_}; }
-    _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const {
-      return __iterator{__view_data_ + __view_data_->__to_end_};
-    }
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const { return __iterator{__view_data_->__aliases_begin()}; }
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const { return __iterator{__view_data_->__aliases_end()}; }
 
   private:
     friend struct __te_impl;
@@ -509,7 +508,7 @@ struct __te_impl {
   }; // __aliases_view
 
   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view __aliases() const {
-    return __aliases_view(&__text_encoding_data[__encoding_idx_]);
+    return __aliases_view(&__entries[__encoding_idx_]);
   }
 
   _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_impl& __a, const __te_impl& __b) noexcept {
@@ -551,891 +550,937 @@ struct __te_impl {
   unsigned short __encoding_idx_{1u};
   char __name_[__max_name_length_ + 1]{};
 
-  _LIBCPP_HIDE_FROM_ABI static constexpr __te_data __text_encoding_data[] = {
-      {"", 1, 0, 0}, // other
-      {"", 2, 0, 0}, // unknown
-      {"US-ASCII", 3, 8, 11},
-      {"iso-ir-6", 3, 8, 10},
-      {"ANSI_X3.4-1968", 3, 14, 9},
-      {"ANSI_X3.4-1986", 3, 14, 8},
-      {"ISO_646.irv:1991", 3, 16, 7},
-      {"ISO646-US", 3, 9, 6},
-      {"us", 3, 2, 5},
-      {"IBM367", 3, 6, 4},
-      {"cp367", 3, 5, 3},
-      {"csASCII", 3, 7, 2},
-      {"ASCII", 3, 5, 1},
-      {"ISO_8859-1:1987", 4, 15, 9},
-      {"iso-ir-100", 4, 10, 8},
-      {"ISO_8859-1", 4, 10, 7},
-      {"ISO-8859-1", 4, 10, 6},
-      {"latin1", 4, 6, 5},
-      {"l1", 4, 2, 4},
-      {"IBM819", 4, 6, 3},
-      {"CP819", 4, 5, 2},
-      {"csISOLatin1", 4, 11, 1},
-      {"ISO_8859-2:1987", 5, 15, 7},
-      {"iso-ir-101", 5, 10, 6},
-      {"ISO_8859-2", 5, 10, 5},
-      {"ISO-8859-2", 5, 10, 4},
-      {"latin2", 5, 6, 3},
-      {"l2", 5, 2, 2},
-      {"csISOLatin2", 5, 11, 1},
-      {"ISO_8859-3:1988", 6, 15, 7},
-      {"iso-ir-109", 6, 10, 6},
-      {"ISO_8859-3", 6, 10, 5},
-      {"ISO-8859-3", 6, 10, 4},
-      {"latin3", 6, 6, 3},
-      {"l3", 6, 2, 2},
-      {"csISOLatin3", 6, 11, 1},
-      {"ISO_8859-4:1988", 7, 15, 7},
-      {"iso-ir-110", 7, 10, 6},
-      {"ISO_8859-4", 7, 10, 5},
-      {"ISO-8859-4", 7, 10, 4},
-      {"latin4", 7, 6, 3},
-      {"l4", 7, 2, 2},
-      {"csISOLatin4", 7, 11, 1},
-      {"ISO_8859-5:1988", 8, 15, 6},
-      {"iso-ir-144", 8, 10, 5},
-      {"ISO_8859-5", 8, 10, 4},
-      {"ISO-8859-5", 8, 10, 3},
-      {"cyrillic", 8, 8, 2},
-      {"csISOLatinCyrillic", 8, 18, 1},
-      {"ISO_8859-6:1987", 9, 15, 8},
-      {"iso-ir-127", 9, 10, 7},
-      {"ISO_8859-6", 9, 10, 6},
-      {"ISO-8859-6", 9, 10, 5},
-      {"ECMA-114", 9, 8, 4},
-      {"ASMO-708", 9, 8, 3},
-      {"arabic", 9, 6, 2},
-      {"csISOLatinArabic", 9, 16, 1},
-      {"ISO_8859-7:1987", 10, 15, 9},
-      {"iso-ir-126", 10, 10, 8},
-      {"ISO_8859-7", 10, 10, 7},
-      {"ISO-8859-7", 10, 10, 6},
-      {"ELOT_928", 10, 8, 5},
-      {"ECMA-118", 10, 8, 4},
-      {"greek", 10, 5, 3},
-      {"greek8", 10, 6, 2},
-      {"csISOLatinGreek", 10, 15, 1},
-      {"ISO_8859-8:1988", 11, 15, 6},
-      {"iso-ir-138", 11, 10, 5},
-      {"ISO_8859-8", 11, 10, 4},
-      {"ISO-8859-8", 11, 10, 3},
-      {"hebrew", 11, 6, 2},
-      {"csISOLatinHebrew", 11, 16, 1},
-      {"ISO_8859-9:1989", 12, 15, 7},
-      {"iso-ir-148", 12, 10, 6},
-      {"ISO_8859-9", 12, 10, 5},
-      {"ISO-8859-9", 12, 10, 4},
-      {"latin5", 12, 6, 3},
-      {"l5", 12, 2, 2},
-      {"csISOLatin5", 12, 11, 1},
-      {"ISO-8859-10", 13, 11, 6},
-      {"iso-ir-157", 13, 10, 5},
-      {"l6", 13, 2, 4},
-      {"ISO_8859-10:1992", 13, 16, 3},
-      {"csISOLatin6", 13, 11, 2},
-      {"latin6", 13, 6, 1},
-      {"ISO_6937-2-add", 14, 14, 3},
-      {"iso-ir-142", 14, 10, 2},
-      {"csISOTextComm", 14, 13, 1},
-      {"JIS_X0201", 15, 9, 3},
-      {"X0201", 15, 5, 2},
-      {"csHalfWidthKatakana", 15, 19, 1},
-      {"JIS_Encoding", 16, 12, 2},
-      {"csJISEncoding", 16, 13, 1},
-      {"Shift_JIS", 17, 9, 3},
-      {"MS_Kanji", 17, 8, 2},
-      {"csShiftJIS", 17, 10, 1},
-      {"Extended_UNIX_Code_Packed_Format_for_Japanese", 18, 45, 3},
-      {"csEUCPkdFmtJapanese", 18, 19, 2},
-      {"EUC-JP", 18, 6, 1},
-      {"Extended_UNIX_Code_Fixed_Width_for_Japanese", 19, 43, 2},
-      {"csEUCFixWidJapanese", 19, 19, 1},
-      {"BS_4730", 20, 7, 6},
-      {"iso-ir-4", 20, 8, 5},
-      {"ISO646-GB", 20, 9, 4},
-      {"gb", 20, 2, 3},
-      {"uk", 20, 2, 2},
-      {"csISO4UnitedKingdom", 20, 19, 1},
-      {"SEN_850200_C", 21, 12, 5},
-      {"iso-ir-11", 21, 9, 4},
-      {"ISO646-SE2", 21, 10, 3},
-      {"se2", 21, 3, 2},
-      {"csISO11SwedishForNames", 21, 22, 1},
-      {"IT", 22, 2, 4},
-      {"iso-ir-15", 22, 9, 3},
-      {"ISO646-IT", 22, 9, 2},
-      {"csISO15Italian", 22, 14, 1},
-      {"ES", 23, 2, 4},
-      {"iso-ir-17", 23, 9, 3},
-      {"ISO646-ES", 23, 9, 2},
-      {"csISO17Spanish", 23, 14, 1},
-      {"DIN_66003", 24, 9, 5},
-      {"iso-ir-21", 24, 9, 4},
-      {"de", 24, 2, 3},
-      {"ISO646-DE", 24, 9, 2},
-      {"csISO21German", 24, 13, 1},
-      {"NS_4551-1", 25, 9, 6},
-      {"iso-ir-60", 25, 9, 5},
-      {"ISO646-NO", 25, 9, 4},
-      {"no", 25, 2, 3},
-      {"csISO60DanishNorwegian", 25, 22, 2},
-      {"csISO60Norwegian1", 25, 17, 1},
-      {"NF_Z_62-010", 26, 11, 5},
-      {"iso-ir-69", 26, 9, 4},
-      {"ISO646-FR", 26, 9, 3},
-      {"fr", 26, 2, 2},
-      {"csISO69French", 26, 13, 1},
-      {"ISO-10646-UTF-1", 27, 15, 2},
-      {"csISO10646UTF1", 27, 14, 1},
-      {"ISO_646.basic:1983", 28, 18, 3},
-      {"ref", 28, 3, 2},
-      {"csISO646basic1983", 28, 17, 1},
-      {"INVARIANT", 29, 9, 2},
-      {"csINVARIANT", 29, 11, 1},
-      {"ISO_646.irv:1983", 30, 16, 4},
-      {"iso-ir-2", 30, 8, 3},
-      {"irv", 30, 3, 2},
-      {"csISO2IntlRefVersion", 30, 20, 1},
-      {"NATS-SEFI", 31, 9, 3},
-      {"iso-ir-8-1", 31, 10, 2},
-      {"csNATSSEFI", 31, 10, 1},
-      {"NATS-SEFI-ADD", 32, 13, 3},
-      {"iso-ir-8-2", 32, 10, 2},
-      {"csNATSSEFIADD", 32, 13, 1},
-      {"SEN_850200_B", 35, 12, 7},
-      {"iso-ir-10", 35, 9, 6},
-      {"FI", 35, 2, 5},
-      {"ISO646-FI", 35, 9, 4},
-      {"ISO646-SE", 35, 9, 3},
-      {"se", 35, 2, 2},
-      {"csISO10Swedish", 35, 14, 1},
-      {"KS_C_5601-1987", 36, 14, 6},
-      {"iso-ir-149", 36, 10, 5},
-      {"KS_C_5601-1989", 36, 14, 4},
-      {"KSC_5601", 36, 8, 3},
-      {"korean", 36, 6, 2},
-      {"csKSC56011987", 36, 13, 1},
-      {"ISO-2022-KR", 37, 11, 2},
-      {"csISO2022KR", 37, 11, 1},
-      {"EUC-KR", 38, 6, 2},
-      {"csEUCKR", 38, 7, 1},
-      {"ISO-2022-JP", 39, 11, 2},
-      {"csISO2022JP", 39, 11, 1},
-      {"ISO-2022-JP-2", 40, 13, 2},
-      {"csISO2022JP2", 40, 12, 1},
-      {"JIS_C6220-1969-jp", 41, 17, 6},
-      {"JIS_C6220-1969", 41, 14, 5},
-      {"iso-ir-13", 41, 9, 4},
-      {"katakana", 41, 8, 3},
-      {"x0201-7", 41, 7, 2},
-      {"csISO13JISC6220jp", 41, 17, 1},
-      {"JIS_C6220-1969-ro", 42, 17, 5},
-      {"iso-ir-14", 42, 9, 4},
-      {"jp", 42, 2, 3},
-      {"ISO646-JP", 42, 9, 2},
-      {"csISO14JISC6220ro", 42, 17, 1},
-      {"PT", 43, 2, 4},
-      {"iso-ir-16", 43, 9, 3},
-      {"ISO646-PT", 43, 9, 2},
-      {"csISO16Portuguese", 43, 17, 1},
-      {"greek7-old", 44, 10, 3},
-      {"iso-ir-18", 44, 9, 2},
-      {"csISO18Greek7Old", 44, 16, 1},
-      {"latin-greek", 45, 11, 3},
-      {"iso-ir-19", 45, 9, 2},
-      {"csISO19LatinGreek", 45, 17, 1},
-      {"NF_Z_62-010_(1973)", 46, 18, 4},
-      {"iso-ir-25", 46, 9, 3},
-      {"ISO646-FR1", 46, 10, 2},
-      {"csISO25French", 46, 13, 1},
-      {"Latin-greek-1", 47, 13, 3},
-      {"iso-ir-27", 47, 9, 2},
-      {"csISO27LatinGreek1", 47, 18, 1},
-      {"ISO_5427", 48, 8, 3},
-      {"iso-ir-37", 48, 9, 2},
-      {"csISO5427Cyrillic", 48, 17, 1},
-      {"JIS_C6226-1978", 49, 14, 3},
-      {"iso-ir-42", 49, 9, 2},
-      {"csISO42JISC62261978", 49, 19, 1},
-      {"BS_viewdata", 50, 11, 3},
-      {"iso-ir-47", 50, 9, 2},
-      {"csISO47BSViewdata", 50, 17, 1},
-      {"INIS", 51, 4, 3},
-      {"iso-ir-49", 51, 9, 2},
-      {"csISO49INIS", 51, 11, 1},
-      {"INIS-8", 52, 6, 3},
-      {"iso-ir-50", 52, 9, 2},
-      {"csISO50INIS8", 52, 12, 1},
-      {"INIS-cyrillic", 53, 13, 3},
-      {"iso-ir-51", 53, 9, 2},
-      {"csISO51INISCyrillic", 53, 19, 1},
-      {"ISO_5427:1981", 54, 13, 4},
-      {"iso-ir-54", 54, 9, 3},
-      {"ISO5427Cyrillic1981", 54, 19, 2},
-      {"csISO54271981", 54, 13, 1},
-      {"ISO_5428:1980", 55, 13, 3},
-      {"iso-ir-55", 55, 9, 2},
-      {"csISO5428Greek", 55, 14, 1},
-      {"GB_1988-80", 56, 10, 5},
-      {"iso-ir-57", 56, 9, 4},
-      {"cn", 56, 2, 3},
-      {"ISO646-CN", 56, 9, 2},
-      {"csISO57GB1988", 56, 13, 1},
-      {"GB_2312-80", 57, 10, 4},
-      {"iso-ir-58", 57, 9, 3},
-      {"chinese", 57, 7, 2},
-      {"csISO58GB231280", 57, 15, 1},
-      {"NS_4551-2", 58, 9, 5},
-      {"ISO646-NO2", 58, 10, 4},
-      {"iso-ir-61", 58, 9, 3},
-      {"no2", 58, 3, 2},
-      {"csISO61Norwegian2", 58, 17, 1},
-      {"videotex-suppl", 59, 14, 3},
-      {"iso-ir-70", 59, 9, 2},
-      {"csISO70VideotexSupp1", 59, 20, 1},
-      {"PT2", 60, 3, 4},
-      {"iso-ir-84", 60, 9, 3},
-      {"ISO646-PT2", 60, 10, 2},
-      {"csISO84Portuguese2", 60, 18, 1},
-      {"ES2", 61, 3, 4},
-      {"iso-ir-85", 61, 9, 3},
-      {"ISO646-ES2", 61, 10, 2},
-      {"csISO85Spanish2", 61, 15, 1},
-      {"MSZ_7795.3", 62, 10, 5},
-      {"iso-ir-86", 62, 9, 4},
-      {"ISO646-HU", 62, 9, 3},
-      {"hu", 62, 2, 2},
-      {"csISO86Hungarian", 62, 16, 1},
-      {"JIS_C6226-1983", 63, 14, 5},
-      {"iso-ir-87", 63, 9, 4},
-      {"x0208", 63, 5, 3},
-      {"JIS_X0208-1983", 63, 14, 2},
-      {"csISO87JISX0208", 63, 15, 1},
-      {"greek7", 64, 6, 3},
-      {"iso-ir-88", 64, 9, 2},
-      {"csISO88Greek7", 64, 13, 1},
-      {"ASMO_449", 65, 8, 5},
-      {"ISO_9036", 65, 8, 4},
-      {"arabic7", 65, 7, 3},
-      {"iso-ir-89", 65, 9, 2},
-      {"csISO89ASMO449", 65, 14, 1},
-      {"iso-ir-90", 66, 9, 2},
-      {"csISO90", 66, 7, 1},
-      {"JIS_C6229-1984-a", 67, 16, 4},
-      {"iso-ir-91", 67, 9, 3},
-      {"jp-ocr-a", 67, 8, 2},
-      {"csISO91JISC62291984a", 67, 20, 1},
-      {"JIS_C6229-1984-b", 68, 16, 5},
-      {"iso-ir-92", 68, 9, 4},
-      {"ISO646-JP-OCR-B", 68, 15, 3},
-      {"jp-ocr-b", 68, 8, 2},
-      {"csISO92JISC62991984b", 68, 20, 1},
-      {"JIS_C6229-1984-b-add", 69, 20, 4},
-      {"iso-ir-93", 69, 9, 3},
-      {"jp-ocr-b-add", 69, 12, 2},
-      {"csISO93JIS62291984badd", 69, 22, 1},
-      {"JIS_C6229-1984-hand", 70, 19, 4},
-      {"iso-ir-94", 70, 9, 3},
-      {"jp-ocr-hand", 70, 11, 2},
-      {"csISO94JIS62291984hand", 70, 22, 1},
-      {"JIS_C6229-1984-hand-add", 71, 23, 4},
-      {"iso-ir-95", 71, 9, 3},
-      {"jp-ocr-hand-add", 71, 15, 2},
-      {"csISO95JIS62291984handadd", 71, 25, 1},
-      {"JIS_C6229-1984-kana", 72, 19, 3},
-      {"iso-ir-96", 72, 9, 2},
-      {"csISO96JISC62291984kana", 72, 23, 1},
-      {"ISO_2033-1983", 73, 13, 4},
-      {"iso-ir-98", 73, 9, 3},
-      {"e13b", 73, 4, 2},
-      {"csISO2033", 73, 9, 1},
-      {"ANSI_X3.110-1983", 74, 16, 5},
-      {"iso-ir-99", 74, 9, 4},
-      {"CSA_T500-1983", 74, 13, 3},
-      {"NAPLPS", 74, 6, 2},
-      {"csISO99NAPLPS", 74, 13, 1},
-      {"T.61-7bit", 75, 9, 3},
-      {"iso-ir-102", 75, 10, 2},
-      {"csISO102T617bit", 75, 15, 1},
-      {"T.61-8bit", 76, 9, 4},
-      {"T.61", 76, 4, 3},
-      {"iso-ir-103", 76, 10, 2},
-      {"csISO103T618bit", 76, 15, 1},
-      {"ECMA-cyrillic", 77, 13, 4},
-      {"iso-ir-111", 77, 10, 3},
-      {"KOI8-E", 77, 6, 2},
-      {"csISO111ECMACyrillic", 77, 20, 1},
-      {"CSA_Z243.4-1985-1", 78, 17, 7},
-      {"iso-ir-121", 78, 10, 6},
-      {"ISO646-CA", 78, 9, 5},
-      {"csa7-1", 78, 6, 4},
-      {"csa71", 78, 5, 3},
-      {"ca", 78, 2, 2},
-      {"csISO121Canadian1", 78, 17, 1},
-      {"CSA_Z243.4-1985-2", 79, 17, 6},
-      {"iso-ir-122", 79, 10, 5},
-      {"ISO646-CA2", 79, 10, 4},
-      {"csa7-2", 79, 6, 3},
-      {"csa72", 79, 5, 2},
-      {"csISO122Canadian2", 79, 17, 1},
-      {"CSA_Z243.4-1985-gr", 80, 18, 3},
-      {"iso-ir-123", 80, 10, 2},
-      {"csISO123CSAZ24341985gr", 80, 22, 1},
-      {"ISO_8859-6-E", 81, 12, 3},
-      {"csISO88596E", 81, 11, 2},
-      {"ISO-8859-6-E", 81, 12, 1},
-      {"ISO_8859-6-I", 82, 12, 3},
-      {"csISO88596I", 82, 11, 2},
-      {"ISO-8859-6-I", 82, 12, 1},
-      {"T.101-G2", 83, 8, 3},
-      {"iso-ir-128", 83, 10, 2},
-      {"csISO128T101G2", 83, 14, 1},
-      {"ISO_8859-8-E", 84, 12, 3},
-      {"csISO88598E", 84, 11, 2},
-      {"ISO-8859-8-E", 84, 12, 1},
-      {"ISO_8859-8-I", 85, 12, 3},
-      {"csISO88598I", 85, 11, 2},
-      {"ISO-8859-8-I", 85, 12, 1},
-      {"CSN_369103", 86, 10, 3},
-      {"iso-ir-139", 86, 10, 2},
-      {"csISO139CSN369103", 86, 17, 1},
-      {"JUS_I.B1.002", 87, 12, 6},
-      {"iso-ir-141", 87, 10, 5},
-      {"ISO646-YU", 87, 9, 4},
-      {"js", 87, 2, 3},
-      {"yu", 87, 2, 2},
-      {"csISO141JUSIB1002", 87, 17, 1},
-      {"IEC_P27-1", 88, 9, 3},
-      {"iso-ir-143", 88, 10, 2},
-      {"csISO143IECP271", 88, 15, 1},
-      {"JUS_I.B1.003-serb", 89, 17, 4},
-      {"iso-ir-146", 89, 10, 3},
-      {"serbian", 89, 7, 2},
-      {"csISO146Serbian", 89, 15, 1},
-      {"JUS_I.B1.003-mac", 90, 16, 4},
-      {"macedonian", 90, 10, 3},
-      {"iso-ir-147", 90, 10, 2},
-      {"csISO147Macedonian", 90, 18, 1},
-      {"greek-ccitt", 91, 11, 4},
-      {"iso-ir-150", 91, 10, 3},
-      {"csISO150", 91, 8, 2},
-      {"csISO150GreekCCITT", 91, 18, 1},
-      {"NC_NC00-10:81", 92, 13, 5},
-      {"cuba", 92, 4, 4},
-      {"iso-ir-151", 92, 10, 3},
-      {"ISO646-CU", 92, 9, 2},
-      {"csISO151Cuba", 92, 12, 1},
-      {"ISO_6937-2-25", 93, 13, 3},
-      {"iso-ir-152", 93, 10, 2},
-      {"csISO6937Add", 93, 12, 1},
-      {"GOST_19768-74", 94, 13, 4},
-      {"ST_SEV_358-88", 94, 13, 3},
-      {"iso-ir-153", 94, 10, 2},
-      {"csISO153GOST1976874", 94, 19, 1},
-      {"ISO_8859-supp", 95, 13, 4},
-      {"iso-ir-154", 95, 10, 3},
-      {"latin1-2-5", 95, 10, 2},
-      {"csISO8859Supp", 95, 13, 1},
-      {"ISO_10367-box", 96, 13, 3},
-      {"iso-ir-155", 96, 10, 2},
-      {"csISO10367Box", 96, 13, 1},
-      {"latin-lap", 97, 9, 4},
-      {"lap", 97, 3, 3},
-      {"iso-ir-158", 97, 10, 2},
-      {"csISO158Lap", 97, 11, 1},
-      {"JIS_X0212-1990", 98, 14, 4},
-      {"x0212", 98, 5, 3},
-      {"iso-ir-159", 98, 10, 2},
-      {"csISO159JISX02121990", 98, 20, 1},
-      {"DS_2089", 99, 7, 5},
-      {"DS2089", 99, 6, 4},
-      {"ISO646-DK", 99, 9, 3},
-      {"dk", 99, 2, 2},
-      {"csISO646Danish", 99, 14, 1},
-      {"us-dk", 100, 5, 2},
-      {"csUSDK", 100, 6, 1},
-      {"dk-us", 101, 5, 2},
-      {"csDKUS", 101, 6, 1},
-      {"KSC5636", 102, 7, 3},
-      {"ISO646-KR", 102, 9, 2},
-      {"csKSC5636", 102, 9, 1},
-      {"UNICODE-1-1-UTF-7", 103, 17, 2},
-      {"csUnicode11UTF7", 103, 15, 1},
-      {"ISO-2022-CN", 104, 11, 2},
-      {"csISO2022CN", 104, 11, 1},
-      {"ISO-2022-CN-EXT", 105, 15, 2},
-      {"csISO2022CNEXT", 105, 14, 1},
-      {"UTF-8", 106, 5, 2},
-      {"csUTF8", 106, 6, 1},
-      {"ISO-8859-13", 109, 11, 2},
-      {"csISO885913", 109, 11, 1},
-      {"ISO-8859-14", 110, 11, 8},
-      {"iso-ir-199", 110, 10, 7},
-      {"ISO_8859-14:1998", 110, 16, 6},
-      {"ISO_8859-14", 110, 11, 5},
-      {"latin8", 110, 6, 4},
-      {"iso-celtic", 110, 10, 3},
-      {"l8", 110, 2, 2},
-      {"csISO885914", 110, 11, 1},
-      {"ISO-8859-15", 111, 11, 4},
-      {"ISO_8859-15", 111, 11, 3},
-      {"Latin-9", 111, 7, 2},
-      {"csISO885915", 111, 11, 1},
-      {"ISO-8859-16", 112, 11, 7},
-      {"iso-ir-226", 112, 10, 6},
-      {"ISO_8859-16:2001", 112, 16, 5},
-      {"ISO_8859-16", 112, 11, 4},
-      {"latin10", 112, 7, 3},
-      {"l10", 112, 3, 2},
-      {"csISO885916", 112, 11, 1},
-      {"GBK", 113, 3, 5},
-      {"CP936", 113, 5, 4},
-      {"MS936", 113, 5, 3},
-      {"windows-936", 113, 11, 2},
-      {"csGBK", 113, 5, 1},
-      {"GB18030", 114, 7, 2},
-      {"csGB18030", 114, 9, 1},
-      {"OSD_EBCDIC_DF04_15", 115, 18, 2},
-      {"csOSDEBCDICDF0415", 115, 17, 1},
-      {"OSD_EBCDIC_DF03_IRV", 116, 19, 2},
-      {"csOSDEBCDICDF03IRV", 116, 18, 1},
-      {"OSD_EBCDIC_DF04_1", 117, 17, 2},
-      {"csOSDEBCDICDF041", 117, 16, 1},
-      {"ISO-11548-1", 118, 11, 4},
-      {"ISO_11548-1", 118, 11, 3},
-      {"ISO_TR_11548-1", 118, 14, 2},
-      {"csISO115481", 118, 11, 1},
-      {"KZ-1048", 119, 7, 4},
-      {"STRK1048-2002", 119, 13, 3},
-      {"RK1048", 119, 6, 2},
-      {"csKZ1048", 119, 8, 1},
-      {"ISO-10646-UCS-2", 1000, 15, 2},
-      {"csUnicode", 1000, 9, 1},
-      {"ISO-10646-UCS-4", 1001, 15, 2},
-      {"csUCS4", 1001, 6, 1},
-      {"ISO-10646-UCS-Basic", 1002, 19, 2},
-      {"csUnicodeASCII", 1002, 14, 1},
-      {"ISO-10646-Unicode-Latin1", 1003, 24, 3},
-      {"csUnicodeLatin1", 1003, 15, 2},
-      {"ISO-10646", 1003, 9, 1},
-      {"ISO-10646-J-1", 1004, 13, 2},
-      {"csUnicodeJapanese", 1004, 17, 1},
-      {"ISO-Unicode-IBM-1261", 1005, 20, 2},
-      {"csUnicodeIBM1261", 1005, 16, 1},
-      {"ISO-Unicode-IBM-1268", 1006, 20, 2},
-      {"csUnicodeIBM1268", 1006, 16, 1},
-      {"ISO-Unicode-IBM-1276", 1007, 20, 2},
-      {"csUnicodeIBM1276", 1007, 16, 1},
-      {"ISO-Unicode-IBM-1264", 1008, 20, 2},
-      {"csUnicodeIBM1264", 1008, 16, 1},
-      {"ISO-Unicode-IBM-1265", 1009, 20, 2},
-      {"csUnicodeIBM1265", 1009, 16, 1},
-      {"UNICODE-1-1", 1010, 11, 2},
-      {"csUnicode11", 1010, 11, 1},
-      {"SCSU", 1011, 4, 2},
-      {"csSCSU", 1011, 6, 1},
-      {"UTF-7", 1012, 5, 2},
-      {"csUTF7", 1012, 6, 1},
-      {"UTF-16BE", 1013, 8, 2},
-      {"csUTF16BE", 1013, 9, 1},
-      {"UTF-16LE", 1014, 8, 2},
-      {"csUTF16LE", 1014, 9, 1},
-      {"UTF-16", 1015, 6, 2},
-      {"csUTF16", 1015, 7, 1},
-      {"CESU-8", 1016, 6, 3},
-      {"csCESU8", 1016, 7, 2},
-      {"csCESU-8", 1016, 8, 1},
-      {"UTF-32", 1017, 6, 2},
-      {"csUTF32", 1017, 7, 1},
-      {"UTF-32BE", 1018, 8, 2},
-      {"csUTF32BE", 1018, 9, 1},
-      {"UTF-32LE", 1019, 8, 2},
-      {"csUTF32LE", 1019, 9, 1},
-      {"BOCU-1", 1020, 6, 3},
-      {"csBOCU1", 1020, 7, 2},
-      {"csBOCU-1", 1020, 8, 1},
-      {"UTF-7-IMAP", 1021, 10, 2},
-      {"csUTF7IMAP", 1021, 10, 1},
-      {"ISO-8859-1-Windows-3.0-Latin-1", 2000, 30, 2},
-      {"csWindows30Latin1", 2000, 17, 1},
-      {"ISO-8859-1-Windows-3.1-Latin-1", 2001, 30, 2},
-      {"csWindows31Latin1", 2001, 17, 1},
-      {"ISO-8859-2-Windows-Latin-2", 2002, 26, 2},
-      {"csWindows31Latin2", 2002, 17, 1},
-      {"ISO-8859-9-Windows-Latin-5", 2003, 26, 2},
-      {"csWindows31Latin5", 2003, 17, 1},
-      {"hp-roman8", 2004, 9, 4},
-      {"roman8", 2004, 6, 3},
-      {"r8", 2004, 2, 2},
-      {"csHPRoman8", 2004, 10, 1},
-      {"Adobe-Standard-Encoding", 2005, 23, 2},
-      {"csAdobeStandardEncoding", 2005, 23, 1},
-      {"Ventura-US", 2006, 10, 2},
-      {"csVenturaUS", 2006, 11, 1},
-      {"Ventura-International", 2007, 21, 2},
-      {"csVenturaInternational", 2007, 22, 1},
-      {"DEC-MCS", 2008, 7, 3},
-      {"dec", 2008, 3, 2},
-      {"csDECMCS", 2008, 8, 1},
-      {"IBM850", 2009, 6, 4},
-      {"cp850", 2009, 5, 3},
-      {"850", 2009, 3, 2},
-      {"csPC850Multilingual", 2009, 19, 1},
-      {"IBM852", 2010, 6, 4},
-      {"cp852", 2010, 5, 3},
-      {"852", 2010, 3, 2},
-      {"csPCp852", 2010, 8, 1},
-      {"IBM437", 2011, 6, 4},
-      {"cp437", 2011, 5, 3},
-      {"437", 2011, 3, 2},
-      {"csPC8CodePage437", 2011, 16, 1},
-      {"PC8-Danish-Norwegian", 2012, 20, 2},
-      {"csPC8DanishNorwegian", 2012, 20, 1},
-      {"IBM862", 2013, 6, 4},
-      {"cp862", 2013, 5, 3},
-      {"862", 2013, 3, 2},
-      {"csPC862LatinHebrew", 2013, 18, 1},
-      {"PC8-Turkish", 2014, 11, 2},
-      {"csPC8Turkish", 2014, 12, 1},
-      {"IBM-Symbols", 2015, 11, 2},
-      {"csIBMSymbols", 2015, 12, 1},
-      {"IBM-Thai", 2016, 8, 2},
-      {"csIBMThai", 2016, 9, 1},
-      {"HP-Legal", 2017, 8, 2},
-      {"csHPLegal", 2017, 9, 1},
-      {"HP-Pi-font", 2018, 10, 2},
-      {"csHPPiFont", 2018, 10, 1},
-      {"HP-Math8", 2019, 8, 2},
-      {"csHPMath8", 2019, 9, 1},
-      {"Adobe-Symbol-Encoding", 2020, 21, 2},
-      {"csHPPSMath", 2020, 10, 1},
-      {"HP-DeskTop", 2021, 10, 2},
-      {"csHPDesktop", 2021, 11, 1},
-      {"Ventura-Math", 2022, 12, 2},
-      {"csVenturaMath", 2022, 13, 1},
-      {"Microsoft-Publishing", 2023, 20, 2},
-      {"csMicrosoftPublishing", 2023, 21, 1},
-      {"Windows-31J", 2024, 11, 2},
-      {"csWindows31J", 2024, 12, 1},
-      {"GB2312", 2025, 6, 2},
-      {"csGB2312", 2025, 8, 1},
-      {"Big5", 2026, 4, 2},
-      {"csBig5", 2026, 6, 1},
-      {"macintosh", 2027, 9, 3},
-      {"mac", 2027, 3, 2},
-      {"csMacintosh", 2027, 11, 1},
-      {"IBM037", 2028, 6, 7},
-      {"cp037", 2028, 5, 6},
-      {"ebcdic-cp-us", 2028, 12, 5},
-      {"ebcdic-cp-ca", 2028, 12, 4},
-      {"ebcdic-cp-wt", 2028, 12, 3},
-      {"ebcdic-cp-nl", 2028, 12, 2},
-      {"csIBM037", 2028, 8, 1},
-      {"IBM038", 2029, 6, 4},
-      {"EBCDIC-INT", 2029, 10, 3},
-      {"cp038", 2029, 5, 2},
-      {"csIBM038", 2029, 8, 1},
-      {"IBM273", 2030, 6, 3},
-      {"CP273", 2030, 5, 2},
-      {"csIBM273", 2030, 8, 1},
-      {"IBM274", 2031, 6, 4},
-      {"EBCDIC-BE", 2031, 9, 3},
-      {"CP274", 2031, 5, 2},
-      {"csIBM274", 2031, 8, 1},
-      {"IBM275", 2032, 6, 4},
-      {"EBCDIC-BR", 2032, 9, 3},
-      {"cp275", 2032, 5, 2},
-      {"csIBM275", 2032, 8, 1},
-      {"IBM277", 2033, 6, 4},
-      {"EBCDIC-CP-DK", 2033, 12, 3},
-      {"EBCDIC-CP-NO", 2033, 12, 2},
-      {"csIBM277", 2033, 8, 1},
-      {"IBM278", 2034, 6, 5},
-      {"CP278", 2034, 5, 4},
-      {"ebcdic-cp-fi", 2034, 12, 3},
-      {"ebcdic-cp-se", 2034, 12, 2},
-      {"csIBM278", 2034, 8, 1},
-      {"IBM280", 2035, 6, 4},
-      {"CP280", 2035, 5, 3},
-      {"ebcdic-cp-it", 2035, 12, 2},
-      {"csIBM280", 2035, 8, 1},
-      {"IBM281", 2036, 6, 4},
-      {"EBCDIC-JP-E", 2036, 11, 3},
-      {"cp281", 2036, 5, 2},
-      {"csIBM281", 2036, 8, 1},
-      {"IBM284", 2037, 6, 4},
-      {"CP284", 2037, 5, 3},
-      {"ebcdic-cp-es", 2037, 12, 2},
-      {"csIBM284", 2037, 8, 1},
-      {"IBM285", 2038, 6, 4},
-      {"CP285", 2038, 5, 3},
-      {"ebcdic-cp-gb", 2038, 12, 2},
-      {"csIBM285", 2038, 8, 1},
-      {"IBM290", 2039, 6, 4},
-      {"cp290", 2039, 5, 3},
-      {"EBCDIC-JP-kana", 2039, 14, 2},
-      {"csIBM290", 2039, 8, 1},
-      {"IBM297", 2040, 6, 4},
-      {"cp297", 2040, 5, 3},
-      {"ebcdic-cp-fr", 2040, 12, 2},
-      {"csIBM297", 2040, 8, 1},
-      {"IBM420", 2041, 6, 4},
-      {"cp420", 2041, 5, 3},
-      {"ebcdic-cp-ar1", 2041, 13, 2},
-      {"csIBM420", 2041, 8, 1},
-      {"IBM423", 2042, 6, 4},
-      {"cp423", 2042, 5, 3},
-      {"ebcdic-cp-gr", 2042, 12, 2},
-      {"csIBM423", 2042, 8, 1},
-      {"IBM424", 2043, 6, 4},
-      {"cp424", 2043, 5, 3},
-      {"ebcdic-cp-he", 2043, 12, 2},
-      {"csIBM424", 2043, 8, 1},
-      {"IBM500", 2044, 6, 5},
-      {"CP500", 2044, 5, 4},
-      {"ebcdic-cp-be", 2044, 12, 3},
-      {"ebcdic-cp-ch", 2044, 12, 2},
-      {"csIBM500", 2044, 8, 1},
-      {"IBM851", 2045, 6, 4},
-      {"cp851", 2045, 5, 3},
-      {"851", 2045, 3, 2},
-      {"csIBM851", 2045, 8, 1},
-      {"IBM855", 2046, 6, 4},
-      {"cp855", 2046, 5, 3},
-      {"855", 2046, 3, 2},
-      {"csIBM855", 2046, 8, 1},
-      {"IBM857", 2047, 6, 4},
-      {"cp857", 2047, 5, 3},
-      {"857", 2047, 3, 2},
-      {"csIBM857", 2047, 8, 1},
-      {"IBM860", 2048, 6, 4},
-      {"cp860", 2048, 5, 3},
-      {"860", 2048, 3, 2},
-      {"csIBM860", 2048, 8, 1},
-      {"IBM861", 2049, 6, 5},
-      {"cp861", 2049, 5, 4},
-      {"861", 2049, 3, 3},
-      {"cp-is", 2049, 5, 2},
-      {"csIBM861", 2049, 8, 1},
-      {"IBM863", 2050, 6, 4},
-      {"cp863", 2050, 5, 3},
-      {"863", 2050, 3, 2},
-      {"csIBM863", 2050, 8, 1},
-      {"IBM864", 2051, 6, 3},
-      {"cp864", 2051, 5, 2},
-      {"csIBM864", 2051, 8, 1},
-      {"IBM865", 2052, 6, 4},
-      {"cp865", 2052, 5, 3},
-      {"865", 2052, 3, 2},
-      {"csIBM865", 2052, 8, 1},
-      {"IBM868", 2053, 6, 4},
-      {"CP868", 2053, 5, 3},
-      {"cp-ar", 2053, 5, 2},
-      {"csIBM868", 2053, 8, 1},
-      {"IBM869", 2054, 6, 5},
-      {"cp869", 2054, 5, 4},
-      {"869", 2054, 3, 3},
-      {"cp-gr", 2054, 5, 2},
-      {"csIBM869", 2054, 8, 1},
-      {"IBM870", 2055, 6, 5},
-      {"CP870", 2055, 5, 4},
-      {"ebcdic-cp-roece", 2055, 15, 3},
-      {"ebcdic-cp-yu", 2055, 12, 2},
-      {"csIBM870", 2055, 8, 1},
-      {"IBM871", 2056, 6, 4},
-      {"CP871", 2056, 5, 3},
-      {"ebcdic-cp-is", 2056, 12, 2},
-      {"csIBM871", 2056, 8, 1},
-      {"IBM880", 2057, 6, 4},
-      {"cp880", 2057, 5, 3},
-      {"EBCDIC-Cyrillic", 2057, 15, 2},
-      {"csIBM880", 2057, 8, 1},
-      {"IBM891", 2058, 6, 3},
-      {"cp891", 2058, 5, 2},
-      {"csIBM891", 2058, 8, 1},
-      {"IBM903", 2059, 6, 3},
-      {"cp903", 2059, 5, 2},
-      {"csIBM903", 2059, 8, 1},
-      {"IBM904", 2060, 6, 4},
-      {"cp904", 2060, 5, 3},
-      {"904", 2060, 3, 2},
-      {"csIBBM904", 2060, 9, 1},
-      {"IBM905", 2061, 6, 4},
-      {"CP905", 2061, 5, 3},
-      {"ebcdic-cp-tr", 2061, 12, 2},
-      {"csIBM905", 2061, 8, 1},
-      {"IBM918", 2062, 6, 4},
-      {"CP918", 2062, 5, 3},
-      {"ebcdic-cp-ar2", 2062, 13, 2},
-      {"csIBM918", 2062, 8, 1},
-      {"IBM1026", 2063, 7, 3},
-      {"CP1026", 2063, 6, 2},
-      {"csIBM1026", 2063, 9, 1},
-      {"EBCDIC-AT-DE", 2064, 12, 2},
-      {"csIBMEBCDICATDE", 2064, 15, 1},
-      {"EBCDIC-AT-DE-A", 2065, 14, 2},
-      {"csEBCDICATDEA", 2065, 13, 1},
-      {"EBCDIC-CA-FR", 2066, 12, 2},
-      {"csEBCDICCAFR", 2066, 12, 1},
-      {"EBCDIC-DK-NO", 2067, 12, 2},
-      {"csEBCDICDKNO", 2067, 12, 1},
-      {"EBCDIC-DK-NO-A", 2068, 14, 2},
-      {"csEBCDICDKNOA", 2068, 13, 1},
-      {"EBCDIC-FI-SE", 2069, 12, 2},
-      {"csEBCDICFISE", 2069, 12, 1},
-      {"EBCDIC-FI-SE-A", 2070, 14, 2},
-      {"csEBCDICFISEA", 2070, 13, 1},
-      {"EBCDIC-FR", 2071, 9, 2},
-      {"csEBCDICFR", 2071, 10, 1},
-      {"EBCDIC-IT", 2072, 9, 2},
-      {"csEBCDICIT", 2072, 10, 1},
-      {"EBCDIC-PT", 2073, 9, 2},
-      {"csEBCDICPT", 2073, 10, 1},
-      {"EBCDIC-ES", 2074, 9, 2},
-      {"csEBCDICES", 2074, 10, 1},
-      {"EBCDIC-ES-A", 2075, 11, 2},
-      {"csEBCDICESA", 2075, 11, 1},
-      {"EBCDIC-ES-S", 2076, 11, 2},
-      {"csEBCDICESS", 2076, 11, 1},
-      {"EBCDIC-UK", 2077, 9, 2},
-      {"csEBCDICUK", 2077, 10, 1},
-      {"EBCDIC-US", 2078, 9, 2},
-      {"csEBCDICUS", 2078, 10, 1},
-      {"UNKNOWN-8BIT", 2079, 12, 2},
-      {"csUnknown8BiT", 2079, 13, 1},
-      {"MNEMONIC", 2080, 8, 2},
-      {"csMnemonic", 2080, 10, 1},
-      {"MNEM", 2081, 4, 2},
-      {"csMnem", 2081, 6, 1},
-      {"VISCII", 2082, 6, 2},
-      {"csVISCII", 2082, 8, 1},
-      {"VIQR", 2083, 4, 2},
-      {"csVIQR", 2083, 6, 1},
-      {"KOI8-R", 2084, 6, 2},
-      {"csKOI8R", 2084, 7, 1},
-      {"HZ-GB-2312", 2085, 10, 1},
-      {"IBM866", 2086, 6, 4},
-      {"cp866", 2086, 5, 3},
-      {"866", 2086, 3, 2},
-      {"csIBM866", 2086, 8, 1},
-      {"IBM775", 2087, 6, 3},
-      {"cp775", 2087, 5, 2},
-      {"csPC775Baltic", 2087, 13, 1},
-      {"KOI8-U", 2088, 6, 2},
-      {"csKOI8U", 2088, 7, 1},
-      {"IBM00858", 2089, 8, 5},
-      {"CCSID00858", 2089, 10, 4},
-      {"CP00858", 2089, 7, 3},
-      {"PC-Multilingual-850+euro", 2089, 24, 2},
-      {"csIBM00858", 2089, 10, 1},
-      {"IBM00924", 2090, 8, 5},
-      {"CCSID00924", 2090, 10, 4},
-      {"CP00924", 2090, 7, 3},
-      {"ebcdic-Latin9--euro", 2090, 19, 2},
-      {"csIBM00924", 2090, 10, 1},
-      {"IBM01140", 2091, 8, 5},
-      {"CCSID01140", 2091, 10, 4},
-      {"CP01140", 2091, 7, 3},
-      {"ebcdic-us-37+euro", 2091, 17, 2},
-      {"csIBM01140", 2091, 10, 1},
-      {"IBM01141", 2092, 8, 5},
-      {"CCSID01141", 2092, 10, 4},
-      {"CP01141", 2092, 7, 3},
-      {"ebcdic-de-273+euro", 2092, 18, 2},
-      {"csIBM01141", 2092, 10, 1},
-      {"IBM01142", 2093, 8, 6},
-      {"CCSID01142", 2093, 10, 5},
-      {"CP01142", 2093, 7, 4},
-      {"ebcdic-dk-277+euro", 2093, 18, 3},
-      {"ebcdic-no-277+euro", 2093, 18, 2},
-      {"csIBM01142", 2093, 10, 1},
-      {"IBM01143", 2094, 8, 6},
-      {"CCSID01143", 2094, 10, 5},
-      {"CP01143", 2094, 7, 4},
-      {"ebcdic-fi-278+euro", 2094, 18, 3},
-      {"ebcdic-se-278+euro", 2094, 18, 2},
-      {"csIBM01143", 2094, 10, 1},
-      {"IBM01144", 2095, 8, 5},
-      {"CCSID01144", 2095, 10, 4},
-      {"CP01144", 2095, 7, 3},
-      {"ebcdic-it-280+euro", 2095, 18, 2},
-      {"csIBM01144", 2095, 10, 1},
-      {"IBM01145", 2096, 8, 5},
-      {"CCSID01145", 2096, 10, 4},
-      {"CP01145", 2096, 7, 3},
-      {"ebcdic-es-284+euro", 2096, 18, 2},
-      {"csIBM01145", 2096, 10, 1},
-      {"IBM01146", 2097, 8, 5},
-      {"CCSID01146", 2097, 10, 4},
-      {"CP01146", 2097, 7, 3},
-      {"ebcdic-gb-285+euro", 2097, 18, 2},
-      {"csIBM01146", 2097, 10, 1},
-      {"IBM01147", 2098, 8, 5},
-      {"CCSID01147", 2098, 10, 4},
-      {"CP01147", 2098, 7, 3},
-      {"ebcdic-fr-297+euro", 2098, 18, 2},
-      {"csIBM01147", 2098, 10, 1},
-      {"IBM01148", 2099, 8, 5},
-      {"CCSID01148", 2099, 10, 4},
-      {"CP01148", 2099, 7, 3},
-      {"ebcdic-international-500+euro", 2099, 29, 2},
-      {"csIBM01148", 2099, 10, 1},
-      {"IBM01149", 2100, 8, 5},
-      {"CCSID01149", 2100, 10, 4},
-      {"CP01149", 2100, 7, 3},
-      {"ebcdic-is-871+euro", 2100, 18, 2},
-      {"csIBM01149", 2100, 10, 1},
-      {"Big5-HKSCS", 2101, 10, 2},
-      {"csBig5HKSCS", 2101, 11, 1},
-      {"IBM1047", 2102, 7, 3},
-      {"IBM-1047", 2102, 8, 2},
-      {"csIBM1047", 2102, 9, 1},
-      {"PTCP154", 2103, 7, 5},
-      {"csPTCP154", 2103, 9, 4},
-      {"PT154", 2103, 5, 3},
-      {"CP154", 2103, 5, 2},
-      {"Cyrillic-Asian", 2103, 14, 1},
-      {"Amiga-1251", 2104, 10, 5},
-      {"Ami1251", 2104, 7, 4},
-      {"Amiga1251", 2104, 9, 3},
-      {"Ami-1251", 2104, 8, 2},
-      {"csAmiga1251", 2104, 11, 1},
-      {"KOI7-switched", 2105, 13, 2},
-      {"csKOI7switched", 2105, 14, 1},
-      {"BRF", 2106, 3, 2},
-      {"csBRF", 2106, 5, 1},
-      {"TSCII", 2107, 5, 2},
-      {"csTSCII", 2107, 7, 1},
-      {"CP51932", 2108, 7, 2},
-      {"csCP51932", 2108, 9, 1},
-      {"windows-874", 2109, 11, 2},
-      {"cswindows874", 2109, 12, 1},
-      {"windows-1250", 2250, 12, 2},
-      {"cswindows1250", 2250, 13, 1},
-      {"windows-1251", 2251, 12, 2},
-      {"cswindows1251", 2251, 13, 1},
-      {"windows-1252", 2252, 12, 2},
-      {"cswindows1252", 2252, 13, 1},
-      {"windows-1253", 2253, 12, 2},
-      {"cswindows1253", 2253, 13, 1},
-      {"windows-1254", 2254, 12, 2},
-      {"cswindows1254", 2254, 13, 1},
-      {"windows-1255", 2255, 12, 2},
-      {"cswindows1255", 2255, 13, 1},
-      {"windows-1256", 2256, 12, 2},
-      {"cswindows1256", 2256, 13, 1},
-      {"windows-1257", 2257, 12, 2},
-      {"cswindows1257", 2257, 13, 1},
-      {"windows-1258", 2258, 12, 2},
-      {"cswindows1258", 2258, 13, 1},
-      {"TIS-620", 2259, 7, 3},
-      {"csTIS620", 2259, 8, 2},
-      {"ISO-8859-11", 2259, 11, 1},
-      {"CP50220", 2260, 7, 2},
-      {"csCP50220", 2260, 9, 1}};
+  // Structuring the text encoding data and the table in this manner has a few benefits:
+  // Smaller footprint: We only need 6 bytes for the information we need.
+  // Smaller total table: We only need one entry per Mib.
+  // Easier aliases_view: We know the begin, and end of each range of aliases, which makes iterator
+  // implementation simple.
+
+  static constexpr __te_data __entries[] = {
+      {0, 1, 0},      {1, 2, 0},      {2, 3, 11},     {13, 4, 9},     {22, 5, 7},     {29, 6, 7},     {36, 7, 7},
+      {43, 8, 6},     {49, 9, 8},     {57, 10, 9},    {66, 11, 6},    {72, 12, 7},    {79, 13, 6},    {85, 14, 3},
+      {88, 15, 3},    {91, 16, 2},    {93, 17, 3},    {96, 18, 3},    {99, 19, 2},    {101, 20, 6},   {107, 21, 5},
+      {112, 22, 4},   {116, 23, 4},   {120, 24, 5},   {125, 25, 6},   {131, 26, 5},   {136, 27, 2},   {138, 28, 3},
+      {141, 29, 2},   {143, 30, 4},   {147, 31, 3},   {150, 32, 3},   {153, 35, 7},   {160, 36, 6},   {166, 37, 2},
+      {168, 38, 2},   {170, 39, 2},   {172, 40, 2},   {174, 41, 6},   {180, 42, 5},   {185, 43, 4},   {189, 44, 3},
+      {192, 45, 3},   {195, 46, 4},   {199, 47, 3},   {202, 48, 3},   {205, 49, 3},   {208, 50, 3},   {211, 51, 3},
+      {214, 52, 3},   {217, 53, 3},   {220, 54, 4},   {224, 55, 3},   {227, 56, 5},   {232, 57, 4},   {236, 58, 5},
+      {241, 59, 3},   {244, 60, 4},   {248, 61, 4},   {252, 62, 5},   {257, 63, 5},   {262, 64, 3},   {265, 65, 5},
+      {270, 66, 2},   {272, 67, 4},   {276, 68, 5},   {281, 69, 4},   {285, 70, 4},   {289, 71, 4},   {293, 72, 3},
+      {296, 73, 4},   {300, 74, 5},   {305, 75, 3},   {308, 76, 4},   {312, 77, 4},   {316, 78, 7},   {323, 79, 6},
+      {329, 80, 3},   {332, 81, 3},   {335, 82, 3},   {338, 83, 3},   {341, 84, 3},   {344, 85, 3},   {347, 86, 3},
+      {350, 87, 6},   {356, 88, 3},   {359, 89, 4},   {363, 90, 4},   {367, 91, 4},   {371, 92, 5},   {376, 93, 3},
+      {379, 94, 4},   {383, 95, 4},   {387, 96, 3},   {390, 97, 4},   {394, 98, 4},   {398, 99, 5},   {403, 100, 2},
+      {405, 101, 2},  {407, 102, 3},  {410, 103, 2},  {412, 104, 2},  {414, 105, 2},  {416, 106, 2},  {418, 109, 2},
+      {420, 110, 8},  {428, 111, 4},  {432, 112, 7},  {439, 113, 5},  {444, 114, 2},  {446, 115, 2},  {448, 116, 2},
+      {450, 117, 2},  {452, 118, 4},  {456, 119, 4},  {460, 1000, 2}, {462, 1001, 2}, {464, 1002, 2}, {466, 1003, 3},
+      {469, 1004, 2}, {471, 1005, 2}, {473, 1006, 2}, {475, 1007, 2}, {477, 1008, 2}, {479, 1009, 2}, {481, 1010, 2},
+      {483, 1011, 2}, {485, 1012, 2}, {487, 1013, 2}, {489, 1014, 2}, {491, 1015, 2}, {493, 1016, 3}, {496, 1017, 2},
+      {498, 1018, 2}, {500, 1019, 2}, {502, 1020, 3}, {505, 1021, 2}, {507, 2000, 2}, {509, 2001, 2}, {511, 2002, 2},
+      {513, 2003, 2}, {515, 2004, 4}, {519, 2005, 2}, {521, 2006, 2}, {523, 2007, 2}, {525, 2008, 3}, {528, 2009, 4},
+      {532, 2010, 4}, {536, 2011, 4}, {540, 2012, 2}, {542, 2013, 4}, {546, 2014, 2}, {548, 2015, 2}, {550, 2016, 2},
+      {552, 2017, 2}, {554, 2018, 2}, {556, 2019, 2}, {558, 2020, 2}, {560, 2021, 2}, {562, 2022, 2}, {564, 2023, 2},
+      {566, 2024, 2}, {568, 2025, 2}, {570, 2026, 2}, {572, 2027, 3}, {575, 2028, 7}, {582, 2029, 4}, {586, 2030, 3},
+      {589, 2031, 4}, {593, 2032, 4}, {597, 2033, 4}, {601, 2034, 5}, {606, 2035, 4}, {610, 2036, 4}, {614, 2037, 4},
+      {618, 2038, 4}, {622, 2039, 4}, {626, 2040, 4}, {630, 2041, 4}, {634, 2042, 4}, {638, 2043, 4}, {642, 2044, 5},
+      {647, 2045, 4}, {651, 2046, 4}, {655, 2047, 4}, {659, 2048, 4}, {663, 2049, 5}, {668, 2050, 4}, {672, 2051, 3},
+      {675, 2052, 4}, {679, 2053, 4}, {683, 2054, 5}, {688, 2055, 5}, {693, 2056, 4}, {697, 2057, 4}, {701, 2058, 3},
+      {704, 2059, 3}, {707, 2060, 4}, {711, 2061, 4}, {715, 2062, 4}, {719, 2063, 3}, {722, 2064, 2}, {724, 2065, 2},
+      {726, 2066, 2}, {728, 2067, 2}, {730, 2068, 2}, {732, 2069, 2}, {734, 2070, 2}, {736, 2071, 2}, {738, 2072, 2},
+      {740, 2073, 2}, {742, 2074, 2}, {744, 2075, 2}, {746, 2076, 2}, {748, 2077, 2}, {750, 2078, 2}, {752, 2079, 2},
+      {754, 2080, 2}, {756, 2081, 2}, {758, 2082, 2}, {760, 2083, 2}, {762, 2084, 2}, {764, 2085, 1}, {765, 2086, 4},
+      {769, 2087, 3}, {772, 2088, 2}, {774, 2089, 5}, {779, 2090, 5}, {784, 2091, 5}, {789, 2092, 5}, {794, 2093, 6},
+      {800, 2094, 6}, {806, 2095, 5}, {811, 2096, 5}, {816, 2097, 5}, {821, 2098, 5}, {826, 2099, 5}, {831, 2100, 5},
+      {836, 2101, 2}, {838, 2102, 3}, {841, 2103, 5}, {846, 2104, 5}, {851, 2105, 2}, {853, 2106, 2}, {855, 2107, 2},
+      {857, 2108, 2}, {859, 2109, 2}, {861, 2250, 2}, {863, 2251, 2}, {865, 2252, 2}, {867, 2253, 2}, {869, 2254, 2},
+      {871, 2255, 2}, {873, 2256, 2}, {875, 2257, 2}, {877, 2258, 2}, {879, 2259, 3}, {882, 2260, 2}};
+
+  static constexpr char const* __aliases_table[] = {
+      "",
+      "",
+      "US-ASCII",
+      "iso-ir-6",
+      "ANSI_X3.4-1968",
+      "ANSI_X3.4-1986",
+      "ISO_646.irv:1991",
+      "ISO646-US",
+      "us",
+      "IBM367",
+      "cp367",
+      "csASCII",
+      "ASCII",
+      "ISO_8859-1:1987",
+      "iso-ir-100",
+      "ISO_8859-1",
+      "ISO-8859-1",
+      "latin1",
+      "l1",
+      "IBM819",
+      "CP819",
+      "csISOLatin1",
+      "ISO_8859-2:1987",
+      "iso-ir-101",
+      "ISO_8859-2",
+      "ISO-8859-2",
+      "latin2",
+      "l2",
+      "csISOLatin2",
+      "ISO_8859-3:1988",
+      "iso-ir-109",
+      "ISO_8859-3",
+      "ISO-8859-3",
+      "latin3",
+      "l3",
+      "csISOLatin3",
+      "ISO_8859-4:1988",
+      "iso-ir-110",
+      "ISO_8859-4",
+      "ISO-8859-4",
+      "latin4",
+      "l4",
+      "csISOLatin4",
+      "ISO_8859-5:1988",
+      "iso-ir-144",
+      "ISO_8859-5",
+      "ISO-8859-5",
+      "cyrillic",
+      "csISOLatinCyrillic",
+      "ISO_8859-6:1987",
+      "iso-ir-127",
+      "ISO_8859-6",
+      "ISO-8859-6",
+      "ECMA-114",
+      "ASMO-708",
+      "arabic",
+      "csISOLatinArabic",
+      "ISO_8859-7:1987",
+      "iso-ir-126",
+      "ISO_8859-7",
+      "ISO-8859-7",
+      "ELOT_928",
+      "ECMA-118",
+      "greek",
+      "greek8",
+      "csISOLatinGreek",
+      "ISO_8859-8:1988",
+      "iso-ir-138",
+      "ISO_8859-8",
+      "ISO-8859-8",
+      "hebrew",
+      "csISOLatinHebrew",
+      "ISO_8859-9:1989",
+      "iso-ir-148",
+      "ISO_8859-9",
+      "ISO-8859-9",
+      "latin5",
+      "l5",
+      "csISOLatin5",
+      "ISO-8859-10",
+      "iso-ir-157",
+      "l6",
+      "ISO_8859-10:1992",
+      "csISOLatin6",
+      "latin6",
+      "ISO_6937-2-add",
+      "iso-ir-142",
+      "csISOTextComm",
+      "JIS_X0201",
+      "X0201",
+      "csHalfWidthKatakana",
+      "JIS_Encoding",
+      "csJISEncoding",
+      "Shift_JIS",
+      "MS_Kanji",
+      "csShiftJIS",
+      "Extended_UNIX_Code_Packed_Format_for_Japanese",
+      "csEUCPkdFmtJapanese",
+      "EUC-JP",
+      "Extended_UNIX_Code_Fixed_Width_for_Japanese",
+      "csEUCFixWidJapanese",
+      "BS_4730",
+      "iso-ir-4",
+      "ISO646-GB",
+      "gb",
+      "uk",
+      "csISO4UnitedKingdom",
+      "SEN_850200_C",
+      "iso-ir-11",
+      "ISO646-SE2",
+      "se2",
+      "csISO11SwedishForNames",
+      "IT",
+      "iso-ir-15",
+      "ISO646-IT",
+      "csISO15Italian",
+      "ES",
+      "iso-ir-17",
+      "ISO646-ES",
+      "csISO17Spanish",
+      "DIN_66003",
+      "iso-ir-21",
+      "de",
+      "ISO646-DE",
+      "csISO21German",
+      "NS_4551-1",
+      "iso-ir-60",
+      "ISO646-NO",
+      "no",
+      "csISO60DanishNorwegian",
+      "csISO60Norwegian1",
+      "NF_Z_62-010",
+      "iso-ir-69",
+      "ISO646-FR",
+      "fr",
+      "csISO69French",
+      "ISO-10646-UTF-1",
+      "csISO10646UTF1",
+      "ISO_646.basic:1983",
+      "ref",
+      "csISO646basic1983",
+      "INVARIANT",
+      "csINVARIANT",
+      "ISO_646.irv:1983",
+      "iso-ir-2",
+      "irv",
+      "csISO2IntlRefVersion",
+      "NATS-SEFI",
+      "iso-ir-8-1",
+      "csNATSSEFI",
+      "NATS-SEFI-ADD",
+      "iso-ir-8-2",
+      "csNATSSEFIADD",
+      "SEN_850200_B",
+      "iso-ir-10",
+      "FI",
+      "ISO646-FI",
+      "ISO646-SE",
+      "se",
+      "csISO10Swedish",
+      "KS_C_5601-1987",
+      "iso-ir-149",
+      "KS_C_5601-1989",
+      "KSC_5601",
+      "korean",
+      "csKSC56011987",
+      "ISO-2022-KR",
+      "csISO2022KR",
+      "EUC-KR",
+      "csEUCKR",
+      "ISO-2022-JP",
+      "csISO2022JP",
+      "ISO-2022-JP-2",
+      "csISO2022JP2",
+      "JIS_C6220-1969-jp",
+      "JIS_C6220-1969",
+      "iso-ir-13",
+      "katakana",
+      "x0201-7",
+      "csISO13JISC6220jp",
+      "JIS_C6220-1969-ro",
+      "iso-ir-14",
+      "jp",
+      "ISO646-JP",
+      "csISO14JISC6220ro",
+      "PT",
+      "iso-ir-16",
+      "ISO646-PT",
+      "csISO16Portuguese",
+      "greek7-old",
+      "iso-ir-18",
+      "csISO18Greek7Old",
+      "latin-greek",
+      "iso-ir-19",
+      "csISO19LatinGreek",
+      "NF_Z_62-010_(1973)",
+      "iso-ir-25",
+      "ISO646-FR1",
+      "csISO25French",
+      "Latin-greek-1",
+      "iso-ir-27",
+      "csISO27LatinGreek1",
+      "ISO_5427",
+      "iso-ir-37",
+      "csISO5427Cyrillic",
+      "JIS_C6226-1978",
+      "iso-ir-42",
+      "csISO42JISC62261978",
+      "BS_viewdata",
+      "iso-ir-47",
+      "csISO47BSViewdata",
+      "INIS",
+      "iso-ir-49",
+      "csISO49INIS",
+      "INIS-8",
+      "iso-ir-50",
+      "csISO50INIS8",
+      "INIS-cyrillic",
+      "iso-ir-51",
+      "csISO51INISCyrillic",
+      "ISO_5427:1981",
+      "iso-ir-54",
+      "ISO5427Cyrillic1981",
+      "csISO54271981",
+      "ISO_5428:1980",
+      "iso-ir-55",
+      "csISO5428Greek",
+      "GB_1988-80",
+      "iso-ir-57",
+      "cn",
+      "ISO646-CN",
+      "csISO57GB1988",
+      "GB_2312-80",
+      "iso-ir-58",
+      "chinese",
+      "csISO58GB231280",
+      "NS_4551-2",
+      "ISO646-NO2",
+      "iso-ir-61",
+      "no2",
+      "csISO61Norwegian2",
+      "videotex-suppl",
+      "iso-ir-70",
+      "csISO70VideotexSupp1",
+      "PT2",
+      "iso-ir-84",
+      "ISO646-PT2",
+      "csISO84Portuguese2",
+      "ES2",
+      "iso-ir-85",
+      "ISO646-ES2",
+      "csISO85Spanish2",
+      "MSZ_7795.3",
+      "iso-ir-86",
+      "ISO646-HU",
+      "hu",
+      "csISO86Hungarian",
+      "JIS_C6226-1983",
+      "iso-ir-87",
+      "x0208",
+      "JIS_X0208-1983",
+      "csISO87JISX0208",
+      "greek7",
+      "iso-ir-88",
+      "csISO88Greek7",
+      "ASMO_449",
+      "ISO_9036",
+      "arabic7",
+      "iso-ir-89",
+      "csISO89ASMO449",
+      "iso-ir-90",
+      "csISO90",
+      "JIS_C6229-1984-a",
+      "iso-ir-91",
+      "jp-ocr-a",
+      "csISO91JISC62291984a",
+      "JIS_C6229-1984-b",
+      "iso-ir-92",
+      "ISO646-JP-OCR-B",
+      "jp-ocr-b",
+      "csISO92JISC62991984b",
+      "JIS_C6229-1984-b-add",
+      "iso-ir-93",
+      "jp-ocr-b-add",
+      "csISO93JIS62291984badd",
+      "JIS_C6229-1984-hand",
+      "iso-ir-94",
+      "jp-ocr-hand",
+      "csISO94JIS62291984hand",
+      "JIS_C6229-1984-hand-add",
+      "iso-ir-95",
+      "jp-ocr-hand-add",
+      "csISO95JIS62291984handadd",
+      "JIS_C6229-1984-kana",
+      "iso-ir-96",
+      "csISO96JISC62291984kana",
+      "ISO_2033-1983",
+      "iso-ir-98",
+      "e13b",
+      "csISO2033",
+      "ANSI_X3.110-1983",
+      "iso-ir-99",
+      "CSA_T500-1983",
+      "NAPLPS",
+      "csISO99NAPLPS",
+      "T.61-7bit",
+      "iso-ir-102",
+      "csISO102T617bit",
+      "T.61-8bit",
+      "T.61",
+      "iso-ir-103",
+      "csISO103T618bit",
+      "ECMA-cyrillic",
+      "iso-ir-111",
+      "KOI8-E",
+      "csISO111ECMACyrillic",
+      "CSA_Z243.4-1985-1",
+      "iso-ir-121",
+      "ISO646-CA",
+      "csa7-1",
+      "csa71",
+      "ca",
+      "csISO121Canadian1",
+      "CSA_Z243.4-1985-2",
+      "iso-ir-122",
+      "ISO646-CA2",
+      "csa7-2",
+      "csa72",
+      "csISO122Canadian2",
+      "CSA_Z243.4-1985-gr",
+      "iso-ir-123",
+      "csISO123CSAZ24341985gr",
+      "ISO_8859-6-E",
+      "csISO88596E",
+      "ISO-8859-6-E",
+      "ISO_8859-6-I",
+      "csISO88596I",
+      "ISO-8859-6-I",
+      "T.101-G2",
+      "iso-ir-128",
+      "csISO128T101G2",
+      "ISO_8859-8-E",
+      "csISO88598E",
+      "ISO-8859-8-E",
+      "ISO_8859-8-I",
+      "csISO88598I",
+      "ISO-8859-8-I",
+      "CSN_369103",
+      "iso-ir-139",
+      "csISO139CSN369103",
+      "JUS_I.B1.002",
+      "iso-ir-141",
+      "ISO646-YU",
+      "js",
+      "yu",
+      "csISO141JUSIB1002",
+      "IEC_P27-1",
+      "iso-ir-143",
+      "csISO143IECP271",
+      "JUS_I.B1.003-serb",
+      "iso-ir-146",
+      "serbian",
+      "csISO146Serbian",
+      "JUS_I.B1.003-mac",
+      "macedonian",
+      "iso-ir-147",
+      "csISO147Macedonian",
+      "greek-ccitt",
+      "iso-ir-150",
+      "csISO150",
+      "csISO150GreekCCITT",
+      "NC_NC00-10:81",
+      "cuba",
+      "iso-ir-151",
+      "ISO646-CU",
+      "csISO151Cuba",
+      "ISO_6937-2-25",
+      "iso-ir-152",
+      "csISO6937Add",
+      "GOST_19768-74",
+      "ST_SEV_358-88",
+      "iso-ir-153",
+      "csISO153GOST1976874",
+      "ISO_8859-supp",
+      "iso-ir-154",
+      "latin1-2-5",
+      "csISO8859Supp",
+      "ISO_10367-box",
+      "iso-ir-155",
+      "csISO10367Box",
+      "latin-lap",
+      "lap",
+      "iso-ir-158",
+      "csISO158Lap",
+      "JIS_X0212-1990",
+      "x0212",
+      "iso-ir-159",
+      "csISO159JISX02121990",
+      "DS_2089",
+      "DS2089",
+      "ISO646-DK",
+      "dk",
+      "csISO646Danish",
+      "us-dk",
+      "csUSDK",
+      "dk-us",
+      "csDKUS",
+      "KSC5636",
+      "ISO646-KR",
+      "csKSC5636",
+      "UNICODE-1-1-UTF-7",
+      "csUnicode11UTF7",
+      "ISO-2022-CN",
+      "csISO2022CN",
+      "ISO-2022-CN-EXT",
+      "csISO2022CNEXT",
+      "UTF-8",
+      "csUTF8",
+      "ISO-8859-13",
+      "csISO885913",
+      "ISO-8859-14",
+      "iso-ir-199",
+      "ISO_8859-14:1998",
+      "ISO_8859-14",
+      "latin8",
+      "iso-celtic",
+      "l8",
+      "csISO885914",
+      "ISO-8859-15",
+      "ISO_8859-15",
+      "Latin-9",
+      "csISO885915",
+      "ISO-8859-16",
+      "iso-ir-226",
+      "ISO_8859-16:2001",
+      "ISO_8859-16",
+      "latin10",
+      "l10",
+      "csISO885916",
+      "GBK",
+      "CP936",
+      "MS936",
+      "windows-936",
+      "csGBK",
+      "GB18030",
+      "csGB18030",
+      "OSD_EBCDIC_DF04_15",
+      "csOSDEBCDICDF0415",
+      "OSD_EBCDIC_DF03_IRV",
+      "csOSDEBCDICDF03IRV",
+      "OSD_EBCDIC_DF04_1",
+      "csOSDEBCDICDF041",
+      "ISO-11548-1",
+      "ISO_11548-1",
+      "ISO_TR_11548-1",
+      "csISO115481",
+      "KZ-1048",
+      "STRK1048-2002",
+      "RK1048",
+      "csKZ1048",
+      "ISO-10646-UCS-2",
+      "csUnicode",
+      "ISO-10646-UCS-4",
+      "csUCS4",
+      "ISO-10646-UCS-Basic",
+      "csUnicodeASCII",
+      "ISO-10646-Unicode-Latin1",
+      "csUnicodeLatin1",
+      "ISO-10646",
+      "ISO-10646-J-1",
+      "csUnicodeJapanese",
+      "ISO-Unicode-IBM-1261",
+      "csUnicodeIBM1261",
+      "ISO-Unicode-IBM-1268",
+      "csUnicodeIBM1268",
+      "ISO-Unicode-IBM-1276",
+      "csUnicodeIBM1276",
+      "ISO-Unicode-IBM-1264",
+      "csUnicodeIBM1264",
+      "ISO-Unicode-IBM-1265",
+      "csUnicodeIBM1265",
+      "UNICODE-1-1",
+      "csUnicode11",
+      "SCSU",
+      "csSCSU",
+      "UTF-7",
+      "csUTF7",
+      "UTF-16BE",
+      "csUTF16BE",
+      "UTF-16LE",
+      "csUTF16LE",
+      "UTF-16",
+      "csUTF16",
+      "CESU-8",
+      "csCESU8",
+      "csCESU-8",
+      "UTF-32",
+      "csUTF32",
+      "UTF-32BE",
+      "csUTF32BE",
+      "UTF-32LE",
+      "csUTF32LE",
+      "BOCU-1",
+      "csBOCU1",
+      "csBOCU-1",
+      "UTF-7-IMAP",
+      "csUTF7IMAP",
+      "ISO-8859-1-Windows-3.0-Latin-1",
+      "csWindows30Latin1",
+      "ISO-8859-1-Windows-3.1-Latin-1",
+      "csWindows31Latin1",
+      "ISO-8859-2-Windows-Latin-2",
+      "csWindows31Latin2",
+      "ISO-8859-9-Windows-Latin-5",
+      "csWindows31Latin5",
+      "hp-roman8",
+      "roman8",
+      "r8",
+      "csHPRoman8",
+      "Adobe-Standard-Encoding",
+      "csAdobeStandardEncoding",
+      "Ventura-US",
+      "csVenturaUS",
+      "Ventura-International",
+      "csVenturaInternational",
+      "DEC-MCS",
+      "dec",
+      "csDECMCS",
+      "IBM850",
+      "cp850",
+      "850",
+      "csPC850Multilingual",
+      "IBM852",
+      "cp852",
+      "852",
+      "csPCp852",
+      "IBM437",
+      "cp437",
+      "437",
+      "csPC8CodePage437",
+      "PC8-Danish-Norwegian",
+      "csPC8DanishNorwegian",
+      "IBM862",
+      "cp862",
+      "862",
+      "csPC862LatinHebrew",
+      "PC8-Turkish",
+      "csPC8Turkish",
+      "IBM-Symbols",
+      "csIBMSymbols",
+      "IBM-Thai",
+      "csIBMThai",
+      "HP-Legal",
+      "csHPLegal",
+      "HP-Pi-font",
+      "csHPPiFont",
+      "HP-Math8",
+      "csHPMath8",
+      "Adobe-Symbol-Encoding",
+      "csHPPSMath",
+      "HP-DeskTop",
+      "csHPDesktop",
+      "Ventura-Math",
+      "csVenturaMath",
+      "Microsoft-Publishing",
+      "csMicrosoftPublishing",
+      "Windows-31J",
+      "csWindows31J",
+      "GB2312",
+      "csGB2312",
+      "Big5",
+      "csBig5",
+      "macintosh",
+      "mac",
+      "csMacintosh",
+      "IBM037",
+      "cp037",
+      "ebcdic-cp-us",
+      "ebcdic-cp-ca",
+      "ebcdic-cp-wt",
+      "ebcdic-cp-nl",
+      "csIBM037",
+      "IBM038",
+      "EBCDIC-INT",
+      "cp038",
+      "csIBM038",
+      "IBM273",
+      "CP273",
+      "csIBM273",
+      "IBM274",
+      "EBCDIC-BE",
+      "CP274",
+      "csIBM274",
+      "IBM275",
+      "EBCDIC-BR",
+      "cp275",
+      "csIBM275",
+      "IBM277",
+      "EBCDIC-CP-DK",
+      "EBCDIC-CP-NO",
+      "csIBM277",
+      "IBM278",
+      "CP278",
+      "ebcdic-cp-fi",
+      "ebcdic-cp-se",
+      "csIBM278",
+      "IBM280",
+      "CP280",
+      "ebcdic-cp-it",
+      "csIBM280",
+      "IBM281",
+      "EBCDIC-JP-E",
+      "cp281",
+      "csIBM281",
+      "IBM284",
+      "CP284",
+      "ebcdic-cp-es",
+      "csIBM284",
+      "IBM285",
+      "CP285",
+      "ebcdic-cp-gb",
+      "csIBM285",
+      "IBM290",
+      "cp290",
+      "EBCDIC-JP-kana",
+      "csIBM290",
+      "IBM297",
+      "cp297",
+      "ebcdic-cp-fr",
+      "csIBM297",
+      "IBM420",
+      "cp420",
+      "ebcdic-cp-ar1",
+      "csIBM420",
+      "IBM423",
+      "cp423",
+      "ebcdic-cp-gr",
+      "csIBM423",
+      "IBM424",
+      "cp424",
+      "ebcdic-cp-he",
+      "csIBM424",
+      "IBM500",
+      "CP500",
+      "ebcdic-cp-be",
+      "ebcdic-cp-ch",
+      "csIBM500",
+      "IBM851",
+      "cp851",
+      "851",
+      "csIBM851",
+      "IBM855",
+      "cp855",
+      "855",
+      "csIBM855",
+      "IBM857",
+      "cp857",
+      "857",
+      "csIBM857",
+      "IBM860",
+      "cp860",
+      "860",
+      "csIBM860",
+      "IBM861",
+      "cp861",
+      "861",
+      "cp-is",
+      "csIBM861",
+      "IBM863",
+      "cp863",
+      "863",
+      "csIBM863",
+      "IBM864",
+      "cp864",
+      "csIBM864",
+      "IBM865",
+      "cp865",
+      "865",
+      "csIBM865",
+      "IBM868",
+      "CP868",
+      "cp-ar",
+      "csIBM868",
+      "IBM869",
+      "cp869",
+      "869",
+      "cp-gr",
+      "csIBM869",
+      "IBM870",
+      "CP870",
+      "ebcdic-cp-roece",
+      "ebcdic-cp-yu",
+      "csIBM870",
+      "IBM871",
+      "CP871",
+      "ebcdic-cp-is",
+      "csIBM871",
+      "IBM880",
+      "cp880",
+      "EBCDIC-Cyrillic",
+      "csIBM880",
+      "IBM891",
+      "cp891",
+      "csIBM891",
+      "IBM903",
+      "cp903",
+      "csIBM903",
+      "IBM904",
+      "cp904",
+      "904",
+      "csIBBM904",
+      "IBM905",
+      "CP905",
+      "ebcdic-cp-tr",
+      "csIBM905",
+      "IBM918",
+      "CP918",
+      "ebcdic-cp-ar2",
+      "csIBM918",
+      "IBM1026",
+      "CP1026",
+      "csIBM1026",
+      "EBCDIC-AT-DE",
+      "csIBMEBCDICATDE",
+      "EBCDIC-AT-DE-A",
+      "csEBCDICATDEA",
+      "EBCDIC-CA-FR",
+      "csEBCDICCAFR",
+      "EBCDIC-DK-NO",
+      "csEBCDICDKNO",
+      "EBCDIC-DK-NO-A",
+      "csEBCDICDKNOA",
+      "EBCDIC-FI-SE",
+      "csEBCDICFISE",
+      "EBCDIC-FI-SE-A",
+      "csEBCDICFISEA",
+      "EBCDIC-FR",
+      "csEBCDICFR",
+      "EBCDIC-IT",
+      "csEBCDICIT",
+      "EBCDIC-PT",
+      "csEBCDICPT",
+      "EBCDIC-ES",
+      "csEBCDICES",
+      "EBCDIC-ES-A",
+      "csEBCDICESA",
+      "EBCDIC-ES-S",
+      "csEBCDICESS",
+      "EBCDIC-UK",
+      "csEBCDICUK",
+      "EBCDIC-US",
+      "csEBCDICUS",
+      "UNKNOWN-8BIT",
+      "csUnknown8BiT",
+      "MNEMONIC",
+      "csMnemonic",
+      "MNEM",
+      "csMnem",
+      "VISCII",
+      "csVISCII",
+      "VIQR",
+      "csVIQR",
+      "KOI8-R",
+      "csKOI8R",
+      "HZ-GB-2312",
+      "IBM866",
+      "cp866",
+      "866",
+      "csIBM866",
+      "IBM775",
+      "cp775",
+      "csPC775Baltic",
+      "KOI8-U",
+      "csKOI8U",
+      "IBM00858",
+      "CCSID00858",
+      "CP00858",
+      "PC-Multilingual-850+euro",
+      "csIBM00858",
+      "IBM00924",
+      "CCSID00924",
+      "CP00924",
+      "ebcdic-Latin9--euro",
+      "csIBM00924",
+      "IBM01140",
+      "CCSID01140",
+      "CP01140",
+      "ebcdic-us-37+euro",
+      "csIBM01140",
+      "IBM01141",
+      "CCSID01141",
+      "CP01141",
+      "ebcdic-de-273+euro",
+      "csIBM01141",
+      "IBM01142",
+      "CCSID01142",
+      "CP01142",
+      "ebcdic-dk-277+euro",
+      "ebcdic-no-277+euro",
+      "csIBM01142",
+      "IBM01143",
+      "CCSID01143",
+      "CP01143",
+      "ebcdic-fi-278+euro",
+      "ebcdic-se-278+euro",
+      "csIBM01143",
+      "IBM01144",
+      "CCSID01144",
+      "CP01144",
+      "ebcdic-it-280+euro",
+      "csIBM01144",
+      "IBM01145",
+      "CCSID01145",
+      "CP01145",
+      "ebcdic-es-284+euro",
+      "csIBM01145",
+      "IBM01146",
+      "CCSID01146",
+      "CP01146",
+      "ebcdic-gb-285+euro",
+      "csIBM01146",
+      "IBM01147",
+      "CCSID01147",
+      "CP01147",
+      "ebcdic-fr-297+euro",
+      "csIBM01147",
+      "IBM01148",
+      "CCSID01148",
+      "CP01148",
+      "ebcdic-international-500+euro",
+      "csIBM01148",
+      "IBM01149",
+      "CCSID01149",
+      "CP01149",
+      "ebcdic-is-871+euro",
+      "csIBM01149",
+      "Big5-HKSCS",
+      "csBig5HKSCS",
+      "IBM1047",
+      "IBM-1047",
+      "csIBM1047",
+      "PTCP154",
+      "csPTCP154",
+      "PT154",
+      "CP154",
+      "Cyrillic-Asian",
+      "Amiga-1251",
+      "Ami1251",
+      "Amiga1251",
+      "Ami-1251",
+      "csAmiga1251",
+      "KOI7-switched",
+      "csKOI7switched",
+      "BRF",
+      "csBRF",
+      "TSCII",
+      "csTSCII",
+      "CP51932",
+      "csCP51932",
+      "windows-874",
+      "cswindows874",
+      "windows-1250",
+      "cswindows1250",
+      "windows-1251",
+      "cswindows1251",
+      "windows-1252",
+      "cswindows1252",
+      "windows-1253",
+      "cswindows1253",
+      "windows-1254",
+      "cswindows1254",
+      "windows-1255",
+      "cswindows1255",
+      "windows-1256",
+      "cswindows1256",
+      "windows-1257",
+      "cswindows1257",
+      "windows-1258",
+      "cswindows1258",
+      "TIS-620",
+      "csTIS620",
+      "ISO-8859-11",
+      "CP50220",
+      "csCP50220",
+  };
 };
 
 _LIBCPP_END_NAMESPACE_STD

>From 676d27fe9149498ec6026597cc3b7524205b6f26 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 9 Feb 2026 23:29:03 -0500
Subject: [PATCH 06/58] Clean up ctor tests

---
 .../text_encoding/text_encoding.ctor/id.pass.cpp |  6 +++---
 .../text_encoding.ctor/string_view.pass.cpp      | 16 ++++++++--------
 2 files changed, 11 insertions(+), 11 deletions(-)

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 aadae652d5b91..f0c2c79045b62 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
@@ -22,17 +22,17 @@
 
 using id = std::text_encoding::id;
 
-constexpr void id_ctor(id i, id expect_id, std::string_view expect_name) {
+constexpr void id_ctor(id i, std::string_view expect_name) {
   std::text_encoding te = std::text_encoding(i);
 
-  assert(te.mib() == expect_id);
+  assert(te.mib() == i);
   assert(expect_name == te.name());
   assert(std::ranges::contains(te.aliases(), expect_name));
 }
 
 constexpr void id_ctors() {
   for (auto pair : unique_encoding_data) {
-    id_ctor(id(pair.mib), id(pair.mib), pair.name);
+    id_ctor(id(pair.mib), pair.name);
   }
 }
 
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
index 8b92d5fa7fba8..9557e8bb2d4bb 100644
--- 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
@@ -21,11 +21,11 @@
 
 #include "../test_text_encoding.h"
 
-constexpr void test_ctor(std::string_view str, std::string_view expect, std::text_encoding::id expect_id) {
+constexpr void test_ctor(std::string_view str, std::text_encoding::id expect_id) {
   std::text_encoding te = std::text_encoding(str);
 
   assert(te.mib() == expect_id);
-  assert(te.name() == expect);
+  assert(te.name() == str);
 }
 
 constexpr void test_primary_encoding_spellings() {
@@ -53,27 +53,27 @@ constexpr bool test() {
   }
 
   {
-    test_ctor("U_T_F-8", "U_T_F-8", std::text_encoding::UTF8);
+    test_ctor("U_T_F-8", std::text_encoding::UTF8);
   }
 
   {
-    test_ctor("utf8", "utf8", std::text_encoding::UTF8);
+    test_ctor("utf8", std::text_encoding::UTF8);
   }
 
   {
-    test_ctor("u.t.f-008", "u.t.f-008", std::text_encoding::UTF8);
+    test_ctor("u.t.f-008", std::text_encoding::UTF8);
   }
 
   {
-    test_ctor("utf-80", "utf-80", std::text_encoding::other);
+    test_ctor("utf-80", std::text_encoding::other);
   }
 
   {
-    test_ctor("iso885931988", "iso885931988", std::text_encoding::ISOLatin3);
+    test_ctor("iso885931988", std::text_encoding::ISOLatin3);
   }
 
   {
-    test_ctor("iso00885931988", "iso00885931988", std::text_encoding::ISOLatin3);
+    test_ctor("iso00885931988", std::text_encoding::ISOLatin3);
   }
 
   {

>From 770cea800a30868afbe68bedc21379e5b1d7bd86 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 10 Feb 2026 20:14:21 -0500
Subject: [PATCH 07/58] Remove wrap_iter change

---
 libcxx/include/__iterator/wrap_iter.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h
index a1c8235a46c29..128aeab3ac7cd 100644
--- a/libcxx/include/__iterator/wrap_iter.h
+++ b/libcxx/include/__iterator/wrap_iter.h
@@ -119,7 +119,6 @@ class __wrap_iter {
   friend struct array;
   template <class _Tp, class>
   friend struct __optional_iterator;
-  friend struct __te_impl;
 };
 
 template <class _Iter1>

>From 66274460ef757ff82aa3f7929fc2531f73245a8b Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 10 Feb 2026 20:19:04 -0500
Subject: [PATCH 08/58] Add more GCC steps

---
 .../text_encoding/text_encoding.ctor/string_view.pass.cpp       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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
index 9557e8bb2d4bb..c8d1ed298b421 100644
--- 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
@@ -8,7 +8,7 @@
 
 // REQUIRES: std-at-least-c++26
 // ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=30000000
-// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-ops-limit): -fconstexpr-ops-limit=99000000
+// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-ops-limit): -fconstexpr-ops-limit=1000000000
 
 // <text_encoding>
 

>From f5869798aac46e6b15a51bbd16feecbdc9900f46 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Feb 2026 19:33:34 -0500
Subject: [PATCH 09/58] Clean up header

---
 libcxx/include/__text_encoding/te_impl.h | 13 ++++++++-----
 libcxx/include/text_encoding             | 19 +++++++------------
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index 4c20847b6bc89..630cabf537eff 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -65,7 +65,7 @@ struct __te_impl {
     INVARIANT               = 29,
     ISO2IntlRefVersion      = 30,
     NATSSEFI                = 31,
-    NATSSEFIADD             = 32,
+    NATSSEFIADD             = 32, // NATS-DANO (33) and NATS-DANO-ADD (34) are omitted by the standard.
     ISO10Swedish            = 35,
     KSC56011987             = 36,
     ISO2022KR               = 37,
@@ -372,7 +372,7 @@ struct __te_impl {
 
     const __te_data* __found = std::find_if(__entries + 2, std::end(__entries), __pred);
     if (__found == std::end(__entries)) {
-      return 0u; // other
+      return __other_idx_; // other
     }
 
     return __found - __entries;
@@ -386,7 +386,7 @@ struct __te_impl {
     auto __found = std::lower_bound(std::begin(__entries), std::end(__entries), __i);
 
     if (__found == std::end(__entries)) {
-      return 1u; // unknown
+      return __unknown_idx_; // unknown
     }
 
     return __found - __entries;
@@ -595,9 +595,12 @@ struct __te_impl {
       {857, 2108, 2}, {859, 2109, 2}, {861, 2250, 2}, {863, 2251, 2}, {865, 2252, 2}, {867, 2253, 2}, {869, 2254, 2},
       {871, 2255, 2}, {873, 2256, 2}, {875, 2257, 2}, {877, 2258, 2}, {879, 2259, 3}, {882, 2260, 2}};
 
+  static constexpr auto __other_idx_   = 0u;
+  static constexpr auto __unknown_idx_ = 1u;
+
   static constexpr char const* __aliases_table[] = {
-      "",
-      "",
+      "", // other
+      "", // unknown
       "US-ASCII",
       "iso-ir-6",
       "ANSI_X3.4-1968",
diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 45962b3cc7438..4ae4a8cf6f284 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -57,23 +57,20 @@ struct text_encoding
 
 */
 
-#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
-#  include <__cxx03/__config>
-#else
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 26
 
-#  include <__config>
 #  include <__functional/hash.h>
 #  include <__ranges/enable_borrowed_range.h>
 #  include <__text_encoding/te_impl.h>
 #  include <string_view>
 #  include <version>
 
-#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#    pragma GCC system_header
-#  endif
-
-#  if _LIBCPP_STD_VER >= 26
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 struct text_encoding {
@@ -137,6 +134,4 @@ _LIBCPP_END_NAMESPACE_STD
 
 #  endif // _LIBCPP_STD_VER >= 26
 
-#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
-
 #endif // _LIBCPP_TEXT_ENCODING

>From f5cadc4c9082471ebbfda3574fa2c0f321463f8c Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Feb 2026 19:43:44 -0500
Subject: [PATCH 10/58] Add enumeration test

---
 .../text_encoding.members/id.compile.pass.cpp | 276 ++++++++++++++++++
 1 file changed, 276 insertions(+)
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/id.compile.pass.cpp

diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/id.compile.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/id.compile.pass.cpp
new file mode 100644
index 0000000000000..d35aabdd3c08b
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/id.compile.pass.cpp
@@ -0,0 +1,276 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// std::text_encoding::id;
+// Test that every member of the id enumeration has the correct value.
+
+#include <cstddef>
+#include <text_encoding>
+
+static_assert(int_least32_t(std::text_encoding::id::other) == 1);
+static_assert(int_least32_t(std::text_encoding::id::unknown) == 2);
+static_assert(int_least32_t(std::text_encoding::id::ASCII) == 3);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatin1) == 4);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatin2) == 5);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatin3) == 6);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatin4) == 7);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatinCyrillic) == 8);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatinArabic) == 9);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatinGreek) == 10);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatinHebrew) == 11);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatin5) == 12);
+static_assert(int_least32_t(std::text_encoding::id::ISOLatin6) == 13);
+static_assert(int_least32_t(std::text_encoding::id::ISOTextComm) == 14);
+static_assert(int_least32_t(std::text_encoding::id::HalfWidthKatakana) == 15);
+static_assert(int_least32_t(std::text_encoding::id::JISEncoding) == 16);
+static_assert(int_least32_t(std::text_encoding::id::ShiftJIS) == 17);
+static_assert(int_least32_t(std::text_encoding::id::EUCPkdFmtJapanese) == 18);
+static_assert(int_least32_t(std::text_encoding::id::EUCFixWidJapanese) == 19);
+static_assert(int_least32_t(std::text_encoding::id::ISO4UnitedKingdom) == 20);
+static_assert(int_least32_t(std::text_encoding::id::ISO11SwedishForNames) == 21);
+static_assert(int_least32_t(std::text_encoding::id::ISO15Italian) == 22);
+static_assert(int_least32_t(std::text_encoding::id::ISO17Spanish) == 23);
+static_assert(int_least32_t(std::text_encoding::id::ISO21German) == 24);
+static_assert(int_least32_t(std::text_encoding::id::ISO60DanishNorwegian) == 25);
+static_assert(int_least32_t(std::text_encoding::id::ISO69French) == 26);
+static_assert(int_least32_t(std::text_encoding::id::ISO10646UTF1) == 27);
+static_assert(int_least32_t(std::text_encoding::id::ISO646basic1983) == 28);
+static_assert(int_least32_t(std::text_encoding::id::INVARIANT) == 29);
+static_assert(int_least32_t(std::text_encoding::id::ISO2IntlRefVersion) == 30);
+static_assert(int_least32_t(std::text_encoding::id::NATSSEFI) == 31);
+static_assert(int_least32_t(std::text_encoding::id::NATSSEFIADD) == 32);
+static_assert(int_least32_t(std::text_encoding::id::ISO10Swedish) == 35);
+static_assert(int_least32_t(std::text_encoding::id::KSC56011987) == 36);
+static_assert(int_least32_t(std::text_encoding::id::ISO2022KR) == 37);
+static_assert(int_least32_t(std::text_encoding::id::EUCKR) == 38);
+static_assert(int_least32_t(std::text_encoding::id::ISO2022JP) == 39);
+static_assert(int_least32_t(std::text_encoding::id::ISO2022JP2) == 40);
+static_assert(int_least32_t(std::text_encoding::id::ISO13JISC6220jp) == 41);
+static_assert(int_least32_t(std::text_encoding::id::ISO14JISC6220ro) == 42);
+static_assert(int_least32_t(std::text_encoding::id::ISO16Portuguese) == 43);
+static_assert(int_least32_t(std::text_encoding::id::ISO18Greek7Old) == 44);
+static_assert(int_least32_t(std::text_encoding::id::ISO19LatinGreek) == 45);
+static_assert(int_least32_t(std::text_encoding::id::ISO25French) == 46);
+static_assert(int_least32_t(std::text_encoding::id::ISO27LatinGreek1) == 47);
+static_assert(int_least32_t(std::text_encoding::id::ISO5427Cyrillic) == 48);
+static_assert(int_least32_t(std::text_encoding::id::ISO42JISC62261978) == 49);
+static_assert(int_least32_t(std::text_encoding::id::ISO47BSViewdata) == 50);
+static_assert(int_least32_t(std::text_encoding::id::ISO49INIS) == 51);
+static_assert(int_least32_t(std::text_encoding::id::ISO50INIS8) == 52);
+static_assert(int_least32_t(std::text_encoding::id::ISO51INISCyrillic) == 53);
+static_assert(int_least32_t(std::text_encoding::id::ISO54271981) == 54);
+static_assert(int_least32_t(std::text_encoding::id::ISO5428Greek) == 55);
+static_assert(int_least32_t(std::text_encoding::id::ISO57GB1988) == 56);
+static_assert(int_least32_t(std::text_encoding::id::ISO58GB231280) == 57);
+static_assert(int_least32_t(std::text_encoding::id::ISO61Norwegian2) == 58);
+static_assert(int_least32_t(std::text_encoding::id::ISO70VideotexSupp1) == 59);
+static_assert(int_least32_t(std::text_encoding::id::ISO84Portuguese2) == 60);
+static_assert(int_least32_t(std::text_encoding::id::ISO85Spanish2) == 61);
+static_assert(int_least32_t(std::text_encoding::id::ISO86Hungarian) == 62);
+static_assert(int_least32_t(std::text_encoding::id::ISO87JISX0208) == 63);
+static_assert(int_least32_t(std::text_encoding::id::ISO88Greek7) == 64);
+static_assert(int_least32_t(std::text_encoding::id::ISO89ASMO449) == 65);
+static_assert(int_least32_t(std::text_encoding::id::ISO90) == 66);
+static_assert(int_least32_t(std::text_encoding::id::ISO91JISC62291984a) == 67);
+static_assert(int_least32_t(std::text_encoding::id::ISO92JISC62991984b) == 68);
+static_assert(int_least32_t(std::text_encoding::id::ISO93JIS62291984badd) == 69);
+static_assert(int_least32_t(std::text_encoding::id::ISO94JIS62291984hand) == 70);
+static_assert(int_least32_t(std::text_encoding::id::ISO95JIS62291984handadd) == 71);
+static_assert(int_least32_t(std::text_encoding::id::ISO96JISC62291984kana) == 72);
+static_assert(int_least32_t(std::text_encoding::id::ISO2033) == 73);
+static_assert(int_least32_t(std::text_encoding::id::ISO99NAPLPS) == 74);
+static_assert(int_least32_t(std::text_encoding::id::ISO102T617bit) == 75);
+static_assert(int_least32_t(std::text_encoding::id::ISO103T618bit) == 76);
+static_assert(int_least32_t(std::text_encoding::id::ISO111ECMACyrillic) == 77);
+static_assert(int_least32_t(std::text_encoding::id::ISO121Canadian1) == 78);
+static_assert(int_least32_t(std::text_encoding::id::ISO122Canadian2) == 79);
+static_assert(int_least32_t(std::text_encoding::id::ISO123CSAZ24341985gr) == 80);
+static_assert(int_least32_t(std::text_encoding::id::ISO88596E) == 81);
+static_assert(int_least32_t(std::text_encoding::id::ISO88596I) == 82);
+static_assert(int_least32_t(std::text_encoding::id::ISO128T101G2) == 83);
+static_assert(int_least32_t(std::text_encoding::id::ISO88598E) == 84);
+static_assert(int_least32_t(std::text_encoding::id::ISO88598I) == 85);
+static_assert(int_least32_t(std::text_encoding::id::ISO139CSN369103) == 86);
+static_assert(int_least32_t(std::text_encoding::id::ISO141JUSIB1002) == 87);
+static_assert(int_least32_t(std::text_encoding::id::ISO143IECP271) == 88);
+static_assert(int_least32_t(std::text_encoding::id::ISO146Serbian) == 89);
+static_assert(int_least32_t(std::text_encoding::id::ISO147Macedonian) == 90);
+static_assert(int_least32_t(std::text_encoding::id::ISO150) == 91);
+static_assert(int_least32_t(std::text_encoding::id::ISO151Cuba) == 92);
+static_assert(int_least32_t(std::text_encoding::id::ISO6937Add) == 93);
+static_assert(int_least32_t(std::text_encoding::id::ISO153GOST1976874) == 94);
+static_assert(int_least32_t(std::text_encoding::id::ISO8859Supp) == 95);
+static_assert(int_least32_t(std::text_encoding::id::ISO10367Box) == 96);
+static_assert(int_least32_t(std::text_encoding::id::ISO158Lap) == 97);
+static_assert(int_least32_t(std::text_encoding::id::ISO159JISX02121990) == 98);
+static_assert(int_least32_t(std::text_encoding::id::ISO646Danish) == 99);
+static_assert(int_least32_t(std::text_encoding::id::USDK) == 100);
+static_assert(int_least32_t(std::text_encoding::id::DKUS) == 101);
+static_assert(int_least32_t(std::text_encoding::id::KSC5636) == 102);
+static_assert(int_least32_t(std::text_encoding::id::Unicode11UTF7) == 103);
+static_assert(int_least32_t(std::text_encoding::id::ISO2022CN) == 104);
+static_assert(int_least32_t(std::text_encoding::id::ISO2022CNEXT) == 105);
+static_assert(int_least32_t(std::text_encoding::id::UTF8) == 106);
+static_assert(int_least32_t(std::text_encoding::id::ISO885913) == 109);
+static_assert(int_least32_t(std::text_encoding::id::ISO885914) == 110);
+static_assert(int_least32_t(std::text_encoding::id::ISO885915) == 111);
+static_assert(int_least32_t(std::text_encoding::id::ISO885916) == 112);
+static_assert(int_least32_t(std::text_encoding::id::GBK) == 113);
+static_assert(int_least32_t(std::text_encoding::id::GB18030) == 114);
+static_assert(int_least32_t(std::text_encoding::id::OSDEBCDICDF0415) == 115);
+static_assert(int_least32_t(std::text_encoding::id::OSDEBCDICDF03IRV) == 116);
+static_assert(int_least32_t(std::text_encoding::id::OSDEBCDICDF041) == 117);
+static_assert(int_least32_t(std::text_encoding::id::ISO115481) == 118);
+static_assert(int_least32_t(std::text_encoding::id::KZ1048) == 119);
+static_assert(int_least32_t(std::text_encoding::id::UCS2) == 1000);
+static_assert(int_least32_t(std::text_encoding::id::UCS4) == 1001);
+static_assert(int_least32_t(std::text_encoding::id::UnicodeASCII) == 1002);
+static_assert(int_least32_t(std::text_encoding::id::UnicodeLatin1) == 1003);
+static_assert(int_least32_t(std::text_encoding::id::UnicodeJapanese) == 1004);
+static_assert(int_least32_t(std::text_encoding::id::UnicodeIBM1261) == 1005);
+static_assert(int_least32_t(std::text_encoding::id::UnicodeIBM1268) == 1006);
+static_assert(int_least32_t(std::text_encoding::id::UnicodeIBM1276) == 1007);
+static_assert(int_least32_t(std::text_encoding::id::UnicodeIBM1264) == 1008);
+static_assert(int_least32_t(std::text_encoding::id::UnicodeIBM1265) == 1009);
+static_assert(int_least32_t(std::text_encoding::id::Unicode11) == 1010);
+static_assert(int_least32_t(std::text_encoding::id::SCSU) == 1011);
+static_assert(int_least32_t(std::text_encoding::id::UTF7) == 1012);
+static_assert(int_least32_t(std::text_encoding::id::UTF16BE) == 1013);
+static_assert(int_least32_t(std::text_encoding::id::UTF16LE) == 1014);
+static_assert(int_least32_t(std::text_encoding::id::UTF16) == 1015);
+static_assert(int_least32_t(std::text_encoding::id::CESU8) == 1016);
+static_assert(int_least32_t(std::text_encoding::id::UTF32) == 1017);
+static_assert(int_least32_t(std::text_encoding::id::UTF32BE) == 1018);
+static_assert(int_least32_t(std::text_encoding::id::UTF32LE) == 1019);
+static_assert(int_least32_t(std::text_encoding::id::BOCU1) == 1020);
+static_assert(int_least32_t(std::text_encoding::id::UTF7IMAP) == 1021);
+static_assert(int_least32_t(std::text_encoding::id::Windows30Latin1) == 2000);
+static_assert(int_least32_t(std::text_encoding::id::Windows31Latin1) == 2001);
+static_assert(int_least32_t(std::text_encoding::id::Windows31Latin2) == 2002);
+static_assert(int_least32_t(std::text_encoding::id::Windows31Latin5) == 2003);
+static_assert(int_least32_t(std::text_encoding::id::HPRoman8) == 2004);
+static_assert(int_least32_t(std::text_encoding::id::AdobeStandardEncoding) == 2005);
+static_assert(int_least32_t(std::text_encoding::id::VenturaUS) == 2006);
+static_assert(int_least32_t(std::text_encoding::id::VenturaInternational) == 2007);
+static_assert(int_least32_t(std::text_encoding::id::DECMCS) == 2008);
+static_assert(int_least32_t(std::text_encoding::id::PC850Multilingual) == 2009);
+static_assert(int_least32_t(std::text_encoding::id::PC8DanishNorwegian) == 2012);
+static_assert(int_least32_t(std::text_encoding::id::PC862LatinHebrew) == 2013);
+static_assert(int_least32_t(std::text_encoding::id::PC8Turkish) == 2014);
+static_assert(int_least32_t(std::text_encoding::id::IBMSymbols) == 2015);
+static_assert(int_least32_t(std::text_encoding::id::IBMThai) == 2016);
+static_assert(int_least32_t(std::text_encoding::id::HPLegal) == 2017);
+static_assert(int_least32_t(std::text_encoding::id::HPPiFont) == 2018);
+static_assert(int_least32_t(std::text_encoding::id::HPMath8) == 2019);
+static_assert(int_least32_t(std::text_encoding::id::HPPSMath) == 2020);
+static_assert(int_least32_t(std::text_encoding::id::HPDesktop) == 2021);
+static_assert(int_least32_t(std::text_encoding::id::VenturaMath) == 2022);
+static_assert(int_least32_t(std::text_encoding::id::MicrosoftPublishing) == 2023);
+static_assert(int_least32_t(std::text_encoding::id::Windows31J) == 2024);
+static_assert(int_least32_t(std::text_encoding::id::GB2312) == 2025);
+static_assert(int_least32_t(std::text_encoding::id::Big5) == 2026);
+static_assert(int_least32_t(std::text_encoding::id::Macintosh) == 2027);
+static_assert(int_least32_t(std::text_encoding::id::IBM037) == 2028);
+static_assert(int_least32_t(std::text_encoding::id::IBM038) == 2029);
+static_assert(int_least32_t(std::text_encoding::id::IBM273) == 2030);
+static_assert(int_least32_t(std::text_encoding::id::IBM274) == 2031);
+static_assert(int_least32_t(std::text_encoding::id::IBM275) == 2032);
+static_assert(int_least32_t(std::text_encoding::id::IBM277) == 2033);
+static_assert(int_least32_t(std::text_encoding::id::IBM278) == 2034);
+static_assert(int_least32_t(std::text_encoding::id::IBM280) == 2035);
+static_assert(int_least32_t(std::text_encoding::id::IBM281) == 2036);
+static_assert(int_least32_t(std::text_encoding::id::IBM284) == 2037);
+static_assert(int_least32_t(std::text_encoding::id::IBM285) == 2038);
+static_assert(int_least32_t(std::text_encoding::id::IBM290) == 2039);
+static_assert(int_least32_t(std::text_encoding::id::IBM297) == 2040);
+static_assert(int_least32_t(std::text_encoding::id::IBM420) == 2041);
+static_assert(int_least32_t(std::text_encoding::id::IBM423) == 2042);
+static_assert(int_least32_t(std::text_encoding::id::IBM424) == 2043);
+static_assert(int_least32_t(std::text_encoding::id::PC8CodePage437) == 2011);
+static_assert(int_least32_t(std::text_encoding::id::IBM500) == 2044);
+static_assert(int_least32_t(std::text_encoding::id::IBM851) == 2045);
+static_assert(int_least32_t(std::text_encoding::id::PCp852) == 2010);
+static_assert(int_least32_t(std::text_encoding::id::IBM855) == 2046);
+static_assert(int_least32_t(std::text_encoding::id::IBM857) == 2047);
+static_assert(int_least32_t(std::text_encoding::id::IBM860) == 2048);
+static_assert(int_least32_t(std::text_encoding::id::IBM861) == 2049);
+static_assert(int_least32_t(std::text_encoding::id::IBM863) == 2050);
+static_assert(int_least32_t(std::text_encoding::id::IBM864) == 2051);
+static_assert(int_least32_t(std::text_encoding::id::IBM865) == 2052);
+static_assert(int_least32_t(std::text_encoding::id::IBM868) == 2053);
+static_assert(int_least32_t(std::text_encoding::id::IBM869) == 2054);
+static_assert(int_least32_t(std::text_encoding::id::IBM870) == 2055);
+static_assert(int_least32_t(std::text_encoding::id::IBM871) == 2056);
+static_assert(int_least32_t(std::text_encoding::id::IBM880) == 2057);
+static_assert(int_least32_t(std::text_encoding::id::IBM891) == 2058);
+static_assert(int_least32_t(std::text_encoding::id::IBM903) == 2059);
+static_assert(int_least32_t(std::text_encoding::id::IBM904) == 2060);
+static_assert(int_least32_t(std::text_encoding::id::IBM905) == 2061);
+static_assert(int_least32_t(std::text_encoding::id::IBM918) == 2062);
+static_assert(int_least32_t(std::text_encoding::id::IBM1026) == 2063);
+static_assert(int_least32_t(std::text_encoding::id::IBMEBCDICATDE) == 2064);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICATDEA) == 2065);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICCAFR) == 2066);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICDKNO) == 2067);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICDKNOA) == 2068);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICFISE) == 2069);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICFISEA) == 2070);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICFR) == 2071);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICIT) == 2072);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICPT) == 2073);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICES) == 2074);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICESA) == 2075);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICESS) == 2076);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICUK) == 2077);
+static_assert(int_least32_t(std::text_encoding::id::EBCDICUS) == 2078);
+static_assert(int_least32_t(std::text_encoding::id::Unknown8BiT) == 2079);
+static_assert(int_least32_t(std::text_encoding::id::Mnemonic) == 2080);
+static_assert(int_least32_t(std::text_encoding::id::Mnem) == 2081);
+static_assert(int_least32_t(std::text_encoding::id::VISCII) == 2082);
+static_assert(int_least32_t(std::text_encoding::id::VIQR) == 2083);
+static_assert(int_least32_t(std::text_encoding::id::KOI8R) == 2084);
+static_assert(int_least32_t(std::text_encoding::id::HZGB2312) == 2085);
+static_assert(int_least32_t(std::text_encoding::id::IBM866) == 2086);
+static_assert(int_least32_t(std::text_encoding::id::PC775Baltic) == 2087);
+static_assert(int_least32_t(std::text_encoding::id::KOI8U) == 2088);
+static_assert(int_least32_t(std::text_encoding::id::IBM00858) == 2089);
+static_assert(int_least32_t(std::text_encoding::id::IBM00924) == 2090);
+static_assert(int_least32_t(std::text_encoding::id::IBM01140) == 2091);
+static_assert(int_least32_t(std::text_encoding::id::IBM01141) == 2092);
+static_assert(int_least32_t(std::text_encoding::id::IBM01142) == 2093);
+static_assert(int_least32_t(std::text_encoding::id::IBM01143) == 2094);
+static_assert(int_least32_t(std::text_encoding::id::IBM01144) == 2095);
+static_assert(int_least32_t(std::text_encoding::id::IBM01145) == 2096);
+static_assert(int_least32_t(std::text_encoding::id::IBM01146) == 2097);
+static_assert(int_least32_t(std::text_encoding::id::IBM01147) == 2098);
+static_assert(int_least32_t(std::text_encoding::id::IBM01148) == 2099);
+static_assert(int_least32_t(std::text_encoding::id::IBM01149) == 2100);
+static_assert(int_least32_t(std::text_encoding::id::Big5HKSCS) == 2101);
+static_assert(int_least32_t(std::text_encoding::id::IBM1047) == 2102);
+static_assert(int_least32_t(std::text_encoding::id::PTCP154) == 2103);
+static_assert(int_least32_t(std::text_encoding::id::Amiga1251) == 2104);
+static_assert(int_least32_t(std::text_encoding::id::KOI7switched) == 2105);
+static_assert(int_least32_t(std::text_encoding::id::BRF) == 2106);
+static_assert(int_least32_t(std::text_encoding::id::TSCII) == 2107);
+static_assert(int_least32_t(std::text_encoding::id::CP51932) == 2108);
+static_assert(int_least32_t(std::text_encoding::id::windows874) == 2109);
+static_assert(int_least32_t(std::text_encoding::id::windows1250) == 2250);
+static_assert(int_least32_t(std::text_encoding::id::windows1251) == 2251);
+static_assert(int_least32_t(std::text_encoding::id::windows1252) == 2252);
+static_assert(int_least32_t(std::text_encoding::id::windows1253) == 2253);
+static_assert(int_least32_t(std::text_encoding::id::windows1254) == 2254);
+static_assert(int_least32_t(std::text_encoding::id::windows1255) == 2255);
+static_assert(int_least32_t(std::text_encoding::id::windows1256) == 2256);
+static_assert(int_least32_t(std::text_encoding::id::windows1257) == 2257);
+static_assert(int_least32_t(std::text_encoding::id::windows1258) == 2258);
+static_assert(int_least32_t(std::text_encoding::id::TIS620) == 2259);
+static_assert(int_least32_t(std::text_encoding::id::CP50220) == 2260);

>From 2de0154428ab3683627e6e3c075053d4c3a1987a Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Feb 2026 20:27:16 -0500
Subject: [PATCH 11/58] Fix iterator

---
 libcxx/include/__text_encoding/te_impl.h | 57 ++++++++++++------------
 libcxx/include/text_encoding             |  2 +-
 2 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index 630cabf537eff..a66918385e730 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -308,16 +308,16 @@ struct __te_impl {
       return __enc.__mib_rep_ < static_cast<unsigned short>(__i);
     }
 
-    _LIBCPP_HIDE_FROM_ABI constexpr const char* const* __aliases_begin() const {
+    _LIBCPP_HIDE_FROM_ABI constexpr const char* const* __aliases_begin() const noexcept {
       return &__aliases_table[__first_alias_index_];
     }
 
-    _LIBCPP_HIDE_FROM_ABI constexpr const char* const* __aliases_end() const {
+    _LIBCPP_HIDE_FROM_ABI constexpr const char* const* __aliases_end() const noexcept {
       return &__aliases_table[__first_alias_index_ + __num_aliases_];
     }
   };
 
-  _LIBCPP_HIDE_FROM_ABI static constexpr bool __comp_name(string_view __a, string_view __b) {
+  _LIBCPP_HIDE_FROM_ABI static constexpr bool __comp_name(string_view __a, string_view __b) noexcept {
     if (__a.empty() || __b.empty()) {
       return false;
     }
@@ -359,7 +359,7 @@ struct __te_impl {
     return true;
   }
 
-  _LIBCPP_HIDE_FROM_ABI static constexpr unsigned short __find_data_idx(string_view __a) {
+  _LIBCPP_HIDE_FROM_ABI static constexpr unsigned short __find_data_idx(string_view __a) noexcept {
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__a.size() <= __max_name_length_, "input string_view must have size <= 63");
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__a.contains('\0'), "input string_view must not contain '\\0'");
 
@@ -378,7 +378,7 @@ struct __te_impl {
     return __found - __entries;
   }
 
-  _LIBCPP_HIDE_FROM_ABI static constexpr unsigned short __find_data_idx_by_id(__id __i) {
+  _LIBCPP_HIDE_FROM_ABI static constexpr unsigned short __find_data_idx_by_id(__id __i) noexcept {
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__i >= __id::other, "invalid text_encoding::id passed");
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__i <= __id::CP50220, "invalid text_encoding::id passed");
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(int_least32_t(__i) != __NATS_DANO_, "Mib for NATS-DANO used");
@@ -423,71 +423,65 @@ struct __te_impl {
 
       constexpr __iterator() noexcept = default;
 
-      _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const { return *__data_; }
+      _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const noexcept { return *__data_; }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const {
+      _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const noexcept {
         auto __it = *this;
         return *(__it + __n);
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator->() const { return __data_; }
+      _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator->() const noexcept { return __data_; }
 
-      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator __it, difference_type __n) {
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator __it, difference_type __n) noexcept {
         __it += __n;
         return __it;
       }
 
-      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, __iterator __it) {
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, __iterator __it) noexcept {
         __it += __n;
         return __it;
       }
 
-      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(__iterator __it, difference_type __n) {
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(__iterator __it, difference_type __n) noexcept {
         __it -= __n;
         return __it;
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __iterator& __other) const {
+      _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __iterator& __other) const noexcept {
         return __data_ - __other.__data_;
       }
 
-      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(difference_type __n, __iterator& __it) {
-        __it -= __n;
-        return __it;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() {
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() noexcept {
         __data_++;
         return *this;
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) {
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) noexcept {
         auto __old = *this;
         __data_++;
         return __old;
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() {
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() noexcept {
         __data_--;
         return *this;
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int) {
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int) noexcept {
         auto __old = *this;
         __data_--;
         return __old;
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) {
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) noexcept {
         __data_ += __n;
         return *this;
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) { return (*this += -__n); }
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) noexcept { return (*this += -__n); }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const __iterator& __it) const { return __data_ == __it.__data_; }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(__iterator __it) const { return __data_ <=> __it.__data_; }
+      _LIBCPP_HIDE_FROM_ABI friend constexpr auto
+      operator<=>(const __iterator& __it, const __iterator& __it2) noexcept = default;
 
     private:
       friend struct __aliases_view;
@@ -497,8 +491,13 @@ struct __te_impl {
       const char* const* __data_;
     }; // __iterator
 
-    _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const { return __iterator{__view_data_->__aliases_begin()}; }
-    _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const { return __iterator{__view_data_->__aliases_end()}; }
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const noexcept {
+      return __iterator{__view_data_->__aliases_begin()};
+    }
+
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const noexcept {
+      return __iterator{__view_data_->__aliases_end()};
+    }
 
   private:
     friend struct __te_impl;
@@ -507,7 +506,7 @@ struct __te_impl {
     const __te_data* __view_data_;
   }; // __aliases_view
 
-  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view __aliases() const {
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view __aliases() const noexcept {
     return __aliases_view(&__entries[__encoding_idx_]);
   }
 
diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 4ae4a8cf6f284..289b42333ae4b 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -90,7 +90,7 @@ public:
 
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr id mib() const noexcept { return __impl_.__mib(); }
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const char* name() const noexcept { return __impl_.__name(); }
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr aliases_view aliases() const { return __impl_.__aliases(); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr aliases_view aliases() const noexcept { return __impl_.__aliases(); }
 
   _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const text_encoding& __a, const text_encoding& __b) noexcept {
     return __a.__impl_ == __b.__impl_;

>From 675aaa14340923f8da54df23031ac4cc3d1880fc Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Feb 2026 20:32:02 -0500
Subject: [PATCH 12/58] Add noexcept tests

---
 .../text_encoding/text_encoding.ctor/default.pass.cpp      | 3 ++-
 .../utilities/text_encoding/text_encoding.ctor/id.pass.cpp | 3 ++-
 .../text_encoding/text_encoding.ctor/string_view.pass.cpp  | 7 ++++---
 .../text_encoding/text_encoding.eq/equal.id.pass.cpp       | 3 ++-
 .../text_encoding/text_encoding.eq/equal.pass.cpp          | 3 ++-
 .../text_encoding.members/aliases_view.compile.pass.cpp    | 1 +
 .../text_encoding.aliases_view/begin.pass.cpp              | 2 ++
 .../text_encoding.aliases_view/end.pass.cpp                | 3 +++
 8 files changed, 18 insertions(+), 7 deletions(-)

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
index d84b36d86d88f..61e9fe41bab2e 100644
--- 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
@@ -13,11 +13,12 @@
 // text_encoding::text_encoding() noexcept
 
 #include <cassert>
+#include <concepts>
 #include <text_encoding>
 #include <type_traits>
 
 constexpr bool test() {
-  std::text_encoding te = std::text_encoding();
+  std::same_as<std::text_encoding> decltype(auto) te = std::text_encoding();
   assert(te.mib() == std::text_encoding::unknown);
   assert(std::string_view("") == te.name());
 
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 f0c2c79045b62..c7b8a193df573 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
@@ -14,6 +14,7 @@
 
 #include <algorithm>
 #include <cassert>
+#include <concepts>
 #include <ranges>
 #include <text_encoding>
 #include <type_traits>
@@ -23,7 +24,7 @@
 using id = std::text_encoding::id;
 
 constexpr void id_ctor(id i, std::string_view expect_name) {
-  std::text_encoding te = std::text_encoding(i);
+  std::same_as<std::text_encoding> decltype(auto) te = std::text_encoding(i);
 
   assert(te.mib() == i);
   assert(expect_name == te.name());
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
index c8d1ed298b421..2b69b386cba7b 100644
--- 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
@@ -15,6 +15,7 @@
 // text_encoding::text_encoding(string_view) noexcept
 
 #include <cassert>
+#include <concepts>
 #include <string_view>
 #include <text_encoding>
 #include <type_traits>
@@ -22,7 +23,7 @@
 #include "../test_text_encoding.h"
 
 constexpr void test_ctor(std::string_view str, std::text_encoding::id expect_id) {
-  std::text_encoding te = std::text_encoding(str);
+  std::same_as<std::text_encoding> decltype(auto) te = std::text_encoding(str);
 
   assert(te.mib() == expect_id);
   assert(te.name() == str);
@@ -30,7 +31,7 @@ constexpr void test_ctor(std::string_view str, std::text_encoding::id expect_id)
 
 constexpr void test_primary_encoding_spellings() {
   for (auto& data : unique_encoding_data) {
-    std::text_encoding te = std::text_encoding(data.name);
+    std::same_as<std::text_encoding> decltype(auto) te = std::text_encoding(data.name);
 
     assert(te.mib() == std::text_encoding::id(data.mib));
     assert(te.name() == data.name);
@@ -39,7 +40,7 @@ constexpr void test_primary_encoding_spellings() {
 
 constexpr void test_others() {
   for (auto& name : other_names) {
-    std::text_encoding te = std::text_encoding(name);
+    std::same_as<std::text_encoding> decltype(auto) te = std::text_encoding(name);
 
     assert(te.mib() == std::text_encoding::other);
     assert(te.name() == name);
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 3dd8b4322e82e..385a3fb523f09 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
@@ -28,9 +28,10 @@ constexpr void test_primary_encodings() {
 }
 
 constexpr bool test() {
-  // 1. operator==(const text_encoding&, id) must be noexcept
+  // 1. operator==(const text_encoding&, id) must be noexcept and returns bool
   {
     std::text_encoding te = std::text_encoding();
+    ASSERT_SAME_TYPE(decltype(te == id::UTF8), bool);
     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 eefbf02bc5bcf..c3ba6a6a37490 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
@@ -20,9 +20,10 @@
 using id = std::text_encoding::id;
 
 constexpr bool test() {
-  // 1. operator==(const text_encoding&, const text_encoding&) must be noexcept
+  // 1. operator==(const text_encoding&, const text_encoding&) must be noexcept and returns bool
   {
     ASSERT_NOEXCEPT(std::text_encoding() == std::text_encoding());
+    ASSERT_SAME_TYPE(bool, decltype(std::text_encoding() == std::text_encoding()));
   }
 
   // 2. operator==(const text_encoding&, const text_encoding&) returns true if both text_encoding ids are equal
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases_view.compile.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases_view.compile.pass.cpp
index 711ad99476e77..d19bd04d9f077 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases_view.compile.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/aliases_view.compile.pass.cpp
@@ -21,3 +21,4 @@ static_assert(std::ranges::random_access_range<std::text_encoding::aliases_view>
 static_assert(std::ranges::borrowed_range<std::text_encoding::aliases_view>);
 static_assert(std::same_as<std::ranges::range_value_t<std::text_encoding::aliases_view>, const char*>);
 static_assert(std::same_as<std::ranges::range_reference_t<std::text_encoding::aliases_view>, const char*>);
+static_assert(noexcept(std::text_encoding().aliases()));
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 8664eeb6213ab..f07b1a0e754df 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
@@ -12,6 +12,7 @@
 
 // text_encoding::aliases_view::begin()
 
+#include "test_macros.h"
 #include <cassert>
 #include <ranges>
 #include <text_encoding>
@@ -23,6 +24,7 @@ constexpr bool test() {
 
     std::text_encoding::aliases_view view1 = te.aliases();
     std::text_encoding::aliases_view view2 = te.aliases();
+    ASSERT_NOEXCEPT(view1.begin());
 
     assert(std::ranges::begin(view1) == std::ranges::begin(view2));
     assert(view1.begin() == view2.begin());
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/end.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/end.pass.cpp
index b19069dd54b77..c1b0c5e9cf310 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/end.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/end.pass.cpp
@@ -15,12 +15,15 @@
 #include <cassert>
 #include <text_encoding>
 
+#include "test_macros.h"
+
 constexpr bool test() {
   std::text_encoding a_other = std::text_encoding("foobar");
 
   std::text_encoding::aliases_view other_aliases = a_other.aliases();
 
   // 1. begin() of an aliases_view of "other" is equal to end()
+  ASSERT_NOEXCEPT(other_aliases.end());
   assert(other_aliases.begin() == other_aliases.end());
 
   return true;

>From 392f584dc960273b2b09e94ebd00dc6654b8b36e Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Feb 2026 20:47:09 -0500
Subject: [PATCH 13/58] Strengthen iterator tests

---
 .../dereference.pass.cpp                      | 34 +++++++++++
 .../iterator.pass.cpp                         | 59 +++++++++++++++++--
 2 files changed, 89 insertions(+), 4 deletions(-)
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp

diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp
new file mode 100644
index 0000000000000..e16b2210ebaef
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=9000000
+
+// <text_encoding>
+
+// text_encoding::aliases_view::operator[]
+
+#include <cassert>
+#include <string_view>
+#include <text_encoding>
+
+#include "test_macros.h"
+
+constexpr bool test() {
+  std::text_encoding te(std::text_encoding::id::UTF8);
+  std::text_encoding::aliases_view aliases = te.aliases();
+  auto iter = aliases.begin();
+
+  ASSERT_SAME_TYPE(decltype(aliases[0]), const char*);
+  assert(std::string_view(aliases[0]) == "US-ASCII");
+  assert(std::string_view(aliases[1]) == std::string_view(*(iter + 1)));
+}
+
+int main(int, char**) {
+
+}
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
index 63e714c68abd3..fc5bbaa0c9605 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
@@ -16,7 +16,9 @@
 #include <compare>
 #include <string_view>
 #include <text_encoding>
-#include <utility>
+#include <type_traits>
+
+#include "test_macros.h"
 
 constexpr bool test() {
   // Test iterator operators.
@@ -26,12 +28,14 @@ constexpr bool test() {
   auto j = te.aliases().begin();
   auto k = te.aliases().end();
 
-  static_assert(std::three_way_comparable<decltype(i), std::strong_ordering>);
+  static_assert(std::three_way_comparable<decltype(i)>);
 
   {
     assert(i == j);
     assert(i != k);
-    assert((i <=> j) == std::strong_ordering::equal);
+    assert(i <= j);
+    assert(i >= j);
+    assert(i <=> j == std::strong_ordering::equal);
     assert(std::string_view(*i) == std::string_view(*j));
   }
   {
@@ -41,7 +45,10 @@ constexpr bool test() {
   {
     i++;
     assert(i > j);
-    assert((i <=> j) == std::strong_ordering::greater);
+    assert(i >= j);
+    assert(!(i <= j));
+    assert(i <=> j == std::strong_ordering::greater);
+    assert(i - j == 1);
     assert(std::string_view(*i) != std::string_view(*j));
   }
   {
@@ -92,6 +99,50 @@ constexpr bool test() {
     assert(j != tempj && (tempj - j) == 3);
   }
 
+  { // noexcept
+    ASSERT_NOEXCEPT(*i);
+    ASSERT_NOEXCEPT(i[0]);
+    ASSERT_NOEXCEPT(i.operator->());
+    ASSERT_NOEXCEPT(i + 1);
+    ASSERT_NOEXCEPT(1 + i);
+    ASSERT_NOEXCEPT(i - 1);
+    ASSERT_NOEXCEPT(i - j);
+    ASSERT_NOEXCEPT(i++);
+    ASSERT_NOEXCEPT(++i);
+    ASSERT_NOEXCEPT(i--);
+    ASSERT_NOEXCEPT(--i);
+    ASSERT_NOEXCEPT(i += 2);
+    ASSERT_NOEXCEPT(i -= 2);
+    ASSERT_NOEXCEPT(i == j);
+    ASSERT_NOEXCEPT(i != k);
+    ASSERT_NOEXCEPT(i <=> j);
+    ASSERT_NOEXCEPT(i > j);
+    ASSERT_NOEXCEPT(i < j);
+    ASSERT_NOEXCEPT(i >= j);
+    ASSERT_NOEXCEPT(i <= j);
+  }
+  { // iterator operator return types
+    ASSERT_SAME_TYPE(const char*, decltype(*i));
+    ASSERT_SAME_TYPE(const char*, decltype(i[0]));
+    ASSERT_SAME_TYPE(const char* const*, decltype(i.operator->()));
+    ASSERT_SAME_TYPE(decltype(i), decltype(i + 1));
+    ASSERT_SAME_TYPE(decltype(i), decltype(1 + i));
+    ASSERT_SAME_TYPE(decltype(i), decltype(i - 1));
+    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(++i));
+    ASSERT_SAME_TYPE(decltype(i), decltype(i++));
+    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(--i));
+    ASSERT_SAME_TYPE(decltype(i), decltype(i--));
+    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(i += 1));
+    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(i -= 1));
+    ASSERT_SAME_TYPE(bool, decltype(i == j));
+    ASSERT_SAME_TYPE(bool, decltype(i != j));
+    ASSERT_SAME_TYPE(bool, decltype(i > j));
+    ASSERT_SAME_TYPE(bool, decltype(i < j));
+    ASSERT_SAME_TYPE(bool, decltype(i >= j));
+    ASSERT_SAME_TYPE(bool, decltype(i <= j));
+    ASSERT_SAME_TYPE(std::strong_ordering, decltype(i <=> j));
+  }
+
   return true;
 }
 

>From b3886411779bf3e4584b4d7e0ef94d2349015593 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Feb 2026 20:50:16 -0500
Subject: [PATCH 14/58] Update transitive includes

---
 .../test/libcxx/transitive_includes/cxx03.csv | 33 ------------------
 .../test/libcxx/transitive_includes/cxx11.csv | 33 ------------------
 .../test/libcxx/transitive_includes/cxx14.csv | 34 -------------------
 .../test/libcxx/transitive_includes/cxx17.csv | 33 ------------------
 .../test/libcxx/transitive_includes/cxx20.csv | 33 ------------------
 .../test/libcxx/transitive_includes/cxx23.csv | 13 -------
 6 files changed, 179 deletions(-)

diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index 7d8aad95f3b8c..c0031543e47bc 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -2282,39 +2282,6 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
-text_encoding algorithm
-text_encoding atomic
-text_encoding bit
-text_encoding cctype
-text_encoding climits
-text_encoding cmath
-text_encoding compare
-text_encoding concepts
-text_encoding cstddef
-text_encoding cstdint
-text_encoding cstdio
-text_encoding cstdlib
-text_encoding cstring
-text_encoding ctime
-text_encoding cwchar
-text_encoding cwctype
-text_encoding exception
-text_encoding initializer_list
-text_encoding iosfwd
-text_encoding iterator
-text_encoding limits
-text_encoding memory
-text_encoding new
-text_encoding optional
-text_encoding ratio
-text_encoding stdexcept
-text_encoding string_view
-text_encoding tuple
-text_encoding type_traits
-text_encoding typeinfo
-text_encoding utility
-text_encoding variant
-text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv
index 7d8aad95f3b8c..c0031543e47bc 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -2282,39 +2282,6 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
-text_encoding algorithm
-text_encoding atomic
-text_encoding bit
-text_encoding cctype
-text_encoding climits
-text_encoding cmath
-text_encoding compare
-text_encoding concepts
-text_encoding cstddef
-text_encoding cstdint
-text_encoding cstdio
-text_encoding cstdlib
-text_encoding cstring
-text_encoding ctime
-text_encoding cwchar
-text_encoding cwctype
-text_encoding exception
-text_encoding initializer_list
-text_encoding iosfwd
-text_encoding iterator
-text_encoding limits
-text_encoding memory
-text_encoding new
-text_encoding optional
-text_encoding ratio
-text_encoding stdexcept
-text_encoding string_view
-text_encoding tuple
-text_encoding type_traits
-text_encoding typeinfo
-text_encoding utility
-text_encoding variant
-text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv
index bbdb10a75993d..c2eb5b44e8d7a 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -2328,40 +2328,6 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
-text_encoding algorithm
-text_encoding atomic
-text_encoding bit
-text_encoding cctype
-text_encoding climits
-text_encoding cmath
-text_encoding compare
-text_encoding concepts
-text_encoding cstddef
-text_encoding cstdint
-text_encoding cstdio
-text_encoding cstdlib
-text_encoding cstring
-text_encoding ctime
-text_encoding cwchar
-text_encoding cwctype
-text_encoding exception
-text_encoding execution
-text_encoding initializer_list
-text_encoding iosfwd
-text_encoding iterator
-text_encoding limits
-text_encoding memory
-text_encoding new
-text_encoding optional
-text_encoding ratio
-text_encoding stdexcept
-text_encoding string_view
-text_encoding tuple
-text_encoding type_traits
-text_encoding typeinfo
-text_encoding utility
-text_encoding variant
-text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv
index 53b8325423fa9..332cb62f35b5f 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx17.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv
@@ -2335,39 +2335,6 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
-text_encoding algorithm
-text_encoding atomic
-text_encoding bit
-text_encoding cctype
-text_encoding climits
-text_encoding cmath
-text_encoding compare
-text_encoding concepts
-text_encoding cstddef
-text_encoding cstdint
-text_encoding cstdio
-text_encoding cstdlib
-text_encoding cstring
-text_encoding ctime
-text_encoding cwchar
-text_encoding cwctype
-text_encoding exception
-text_encoding initializer_list
-text_encoding iosfwd
-text_encoding iterator
-text_encoding limits
-text_encoding memory
-text_encoding new
-text_encoding optional
-text_encoding ratio
-text_encoding stdexcept
-text_encoding string_view
-text_encoding tuple
-text_encoding type_traits
-text_encoding typeinfo
-text_encoding utility
-text_encoding variant
-text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv
index f15b13738dd8a..55c79acff5a8f 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx20.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv
@@ -2365,39 +2365,6 @@ system_error typeinfo
 system_error utility
 system_error variant
 system_error version
-text_encoding algorithm
-text_encoding atomic
-text_encoding bit
-text_encoding cctype
-text_encoding climits
-text_encoding cmath
-text_encoding compare
-text_encoding concepts
-text_encoding cstddef
-text_encoding cstdint
-text_encoding cstdio
-text_encoding cstdlib
-text_encoding cstring
-text_encoding ctime
-text_encoding cwchar
-text_encoding cwctype
-text_encoding exception
-text_encoding initializer_list
-text_encoding iosfwd
-text_encoding iterator
-text_encoding limits
-text_encoding memory
-text_encoding new
-text_encoding optional
-text_encoding ratio
-text_encoding stdexcept
-text_encoding string_view
-text_encoding tuple
-text_encoding type_traits
-text_encoding typeinfo
-text_encoding utility
-text_encoding variant
-text_encoding version
 thread algorithm
 thread array
 thread atomic
diff --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv
index 4714f5f9ca0ba..c5cc61f06678c 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx23.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv
@@ -1069,19 +1069,6 @@ system_error string
 system_error string_view
 system_error tuple
 system_error version
-text_encoding cctype
-text_encoding compare
-text_encoding cstdint
-text_encoding cstdio
-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

>From 4e0d87b0bd0a2698f4bfe5c6b12f1ae5ad328b7f Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Feb 2026 21:30:16 -0500
Subject: [PATCH 15/58] Formatting + missed test change

---
 libcxx/include/text_encoding                             | 8 ++++----
 .../text_encoding.aliases_view/dereference.pass.cpp      | 9 ++++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 289b42333ae4b..706b294130df4 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -103,7 +103,7 @@ public:
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval text_encoding literal() noexcept {
     return text_encoding(__te_impl::__literal());
   }
-#    if _LIBCPP_HAS_LOCALIZATION && !defined(__ANDROID__)
+#  if _LIBCPP_HAS_LOCALIZATION && !defined(__ANDROID__)
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static text_encoding environment() {
     return text_encoding(__te_impl::__environment());
   };
@@ -112,12 +112,12 @@ public:
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool environment_is() {
     return __te_impl::__environment_is<_Id>();
   }
-#    else
+#  else
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static text_encoding environment() = delete;
 
   template <id _Id>
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool environment_is() = delete;
-#    endif
+#  endif
 };
 
 template <>
@@ -132,6 +132,6 @@ inline constexpr bool ranges::enable_borrowed_range<text_encoding::aliases_view>
 
 _LIBCPP_END_NAMESPACE_STD
 
-#  endif // _LIBCPP_STD_VER >= 26
+#endif // _LIBCPP_STD_VER >= 26
 
 #endif // _LIBCPP_TEXT_ENCODING
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp
index e16b2210ebaef..3ea75aa4e2867 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp
@@ -22,13 +22,16 @@
 constexpr bool test() {
   std::text_encoding te(std::text_encoding::id::UTF8);
   std::text_encoding::aliases_view aliases = te.aliases();
-  auto iter = aliases.begin();
+  auto iter                                = aliases.begin();
 
   ASSERT_SAME_TYPE(decltype(aliases[0]), const char*);
-  assert(std::string_view(aliases[0]) == "US-ASCII");
+  assert(std::string_view(aliases[0]) == *iter);
   assert(std::string_view(aliases[1]) == std::string_view(*(iter + 1)));
+
+  return true;
 }
 
 int main(int, char**) {
-
+  test();
+  static_assert(test());
 }

>From 21162d02cae176ff8e04e937d85cc5297a32bd4b Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Feb 2026 22:00:50 -0500
Subject: [PATCH 16/58] Fix test failures

---
 libcxx/include/text_encoding                  | 35 +++++++++++--------
 .../text_encoding.members/id.compile.pass.cpp |  2 +-
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 706b294130df4..5d849fadaeba7 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -57,20 +57,25 @@ struct text_encoding
 
 */
 
-#include <__config>
+#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
+#  include <__cxx03/__config>
+#else
+#  include <__config>
 
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-#if _LIBCPP_STD_VER >= 26
+#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#    pragma GCC system_header
+#  endif
 
-#  include <__functional/hash.h>
-#  include <__ranges/enable_borrowed_range.h>
-#  include <__text_encoding/te_impl.h>
-#  include <string_view>
 #  include <version>
 
+#  if _LIBCPP_STD_VER >= 26
+
+#    include <__functional/hash.h>
+#    include <__ranges/enable_borrowed_range.h>
+#    include <__ranges/view_interface.h>
+#    include <__text_encoding/te_impl.h>
+#    include <string_view>
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 struct text_encoding {
@@ -103,7 +108,7 @@ public:
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval text_encoding literal() noexcept {
     return text_encoding(__te_impl::__literal());
   }
-#  if _LIBCPP_HAS_LOCALIZATION && !defined(__ANDROID__)
+#    if _LIBCPP_HAS_LOCALIZATION && !defined(__ANDROID__)
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static text_encoding environment() {
     return text_encoding(__te_impl::__environment());
   };
@@ -112,12 +117,12 @@ public:
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool environment_is() {
     return __te_impl::__environment_is<_Id>();
   }
-#  else
+#    else
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static text_encoding environment() = delete;
 
   template <id _Id>
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool environment_is() = delete;
-#  endif
+#    endif
 };
 
 template <>
@@ -132,6 +137,8 @@ inline constexpr bool ranges::enable_borrowed_range<text_encoding::aliases_view>
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // _LIBCPP_STD_VER >= 26
+#  endif // _LIBCPP_STD_VER >= 26
+
+#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
 
 #endif // _LIBCPP_TEXT_ENCODING
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/id.compile.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/id.compile.pass.cpp
index d35aabdd3c08b..f1a22845d37a1 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/id.compile.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/id.compile.pass.cpp
@@ -13,7 +13,7 @@
 // std::text_encoding::id;
 // Test that every member of the id enumeration has the correct value.
 
-#include <cstddef>
+#include <cstdint>
 #include <text_encoding>
 
 static_assert(int_least32_t(std::text_encoding::id::other) == 1);

>From 3ee8f25844f4841da5101e3bdb55f8a7685f2a84 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Feb 2026 22:48:55 -0500
Subject: [PATCH 17/58] Move version header

---
 libcxx/include/text_encoding | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 5d849fadaeba7..f3e6c63a15e3b 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -66,8 +66,6 @@ struct text_encoding
 #    pragma GCC system_header
 #  endif
 
-#  include <version>
-
 #  if _LIBCPP_STD_VER >= 26
 
 #    include <__functional/hash.h>
@@ -75,6 +73,7 @@ struct text_encoding
 #    include <__ranges/view_interface.h>
 #    include <__text_encoding/te_impl.h>
 #    include <string_view>
+#    include <version>
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 

>From 44d397aa40432c71c4b1b839842a09aba8e6a85e Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 10 Mar 2026 20:44:21 -0400
Subject: [PATCH 18/58] Make environment helpers friend functions

---
 libcxx/include/__text_encoding/te_impl.h | 11 ++++++----
 libcxx/src/text_encoding.cpp             | 26 +++++++++++-------------
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index a66918385e730..82fc63de25e28 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -532,10 +532,13 @@ struct __te_impl {
   }
 
 #  if _LIBCPP_HAS_LOCALIZATION
-  _LIBCPP_HIDDEN static __te_impl __get_locale_encoding(const char* __name);
-  _LIBCPP_HIDDEN static __te_impl __get_env_encoding();
-#    if defined(_LIBCPP_WIN32API)
-  _LIBCPP_HIDDEN static __id __get_win32_acp();
+
+  _LIBCPP_HIDDEN friend __te_impl __get_locale_encoding(const char* __name);
+  _LIBCPP_HIDDEN friend __te_impl __get_env_encoding();
+#    if defined(_LIBCPP_WIN32)
+  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp();
+#    else
+  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp() = delete;
 #    endif
 
   [[__nodiscard__]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment();
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 8c5a1889c4799..fe5ba9439ac33 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -18,7 +18,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if defined(_LIBCPP_WIN32API)
-_LIBCPP_HIDDEN __te_impl::__id __te_impl::__get_win32_acp() {
+_LIBCPP_HIDDEN __te_impl __get_win32_acp() {
   switch (GetACP()) {
   case 037:
     return __te_impl::__id::IBM037;
@@ -208,10 +208,14 @@ _LIBCPP_HIDDEN __te_impl::__id __te_impl::__get_win32_acp() {
     return __te_impl::__id::other;
   }
 }
-#endif // _LIBCPP_WIN32API
 
-#if !defined(__ANDROID__) && !defined(_LIBCPP_WIN32API)
-_LIBCPP_HIDDEN __te_impl __te_impl::__get_locale_encoding(const char* __name) {
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name [[maybe_unused]]) { return __te_impl(); }
+_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_win32_acp(); }
+
+#elif defined(__linux__) || defined(__APPLE__) || defined(__FREEBSD__) || defined(__NETBSD__) ||                       \
+    _LIBCPP_LIBC_NEWLIB || defined(_AIX) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
+// POSIX
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name) {
   __te_impl __e;
 
   __locale::__locale_t __l = __locale::__newlocale(_LIBCPP_CTYPE_MASK, __name, static_cast<__locale::__locale_t>(0));
@@ -237,20 +241,14 @@ _LIBCPP_HIDDEN __te_impl __te_impl::__get_locale_encoding(const char* __name) {
   return __e;
 }
 
+_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
 #else
-_LIBCPP_HIDDEN __te_impl __te_impl::__get_locale_encoding(const char* __name [[maybe_unused]]) { return __te_impl(); }
-#endif
-
-_LIBCPP_HIDDEN __te_impl __te_impl::__get_env_encoding() {
-#if defined(_LIBCPP_WIN32API)
-  return __te_impl(__get_win32_acp());
-#else
-  return __get_locale_encoding("");
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name [[maybe_unused]]) { return __te_impl(); }
+_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
 #endif // _LIBCPP_WIN32API
-}
 
 _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI __te_impl __te_impl::__environment() {
-  return __te_impl::__get_env_encoding();
+  return __get_env_encoding();
 }
 
 _LIBCPP_END_NAMESPACE_STD

>From 2e9125aad605ad3d74dfedc279595637cf398d14 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 10 Mar 2026 21:54:56 -0400
Subject: [PATCH 19/58] [AI-Assisted] Implement __get_locale_encoding on
 Windows

---
 libcxx/include/__text_encoding/te_impl.h |  6 +--
 libcxx/src/text_encoding.cpp             | 47 ++++++++++++++++++++----
 2 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index 82fc63de25e28..57b17db8b5173 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -533,12 +533,12 @@ struct __te_impl {
 
 #  if _LIBCPP_HAS_LOCALIZATION
 
-  _LIBCPP_HIDDEN friend __te_impl __get_locale_encoding(const char* __name);
+  _LIBCPP_HIDDEN friend __te_impl __get_locale_encoding(string_view __name);
   _LIBCPP_HIDDEN friend __te_impl __get_env_encoding();
 #    if defined(_LIBCPP_WIN32)
-  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp();
+  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int*);
 #    else
-  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp() = delete;
+  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int*) = delete;
 #    endif
 
   [[__nodiscard__]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment();
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index fe5ba9439ac33..17c86dc4f7dd0 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -10,6 +10,8 @@
 #include <__text_encoding/te_impl.h>
 
 #if defined(_LIBCPP_WIN32API)
+#  include <__algorithm/max.h>
+#  include <cwchar>
 #  include <windows.h>
 #else
 #  include <__locale_dir/locale_base_api.h>
@@ -18,8 +20,17 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if defined(_LIBCPP_WIN32API)
-_LIBCPP_HIDDEN __te_impl __get_win32_acp() {
-  switch (GetACP()) {
+_LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int* __codepage) {
+  unsigned int __acp = __codepage == nullptr ? GetACP() : *__codepage;
+
+  switch (__acp) {
+  case 0:
+    // If no ANSI code page is available, only Unicode can be used for the locale.
+    // In this case, the value is CP_ACP (0).
+    // Such a locale cannot be set as the system locale.
+    // Applications that do not support Unicode do not work correctly with locales
+    // marked as "Unicode only".
+    return __te_impl::id::unkown;
   case 037:
     return __te_impl::__id::IBM037;
   case 437:
@@ -209,16 +220,38 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp() {
   }
 }
 
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name [[maybe_unused]]) { return __te_impl(); }
-_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_win32_acp(); }
+[[maybe_unused]] _LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name) {
+  wchar_t __locale_wbuffer[LOCALE_NAME_MAX_LENGTH + 1]{};
+  wchar_t __number_buffer[11]{};
+
+  auto __codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
+  auto __lctype = ::AreFileApisANSI() ? LOCALE_IDEFAULTANSICODEPAGE : LOCALE_IDEFAULTCODEPAGE;
+
+  int __ret = ::MultiByteToWideChar(
+      __codepage, MB_ERR_INVALID_CHARS, __name.data(), __name.size(), __locale_wbuffer, LOCALE_MAX_NAME_LENGTH);
+
+  if (__ret <= 0)
+    return te_impl();
+
+  // The below function fills the string with the number in text.
+  int __result = ::GetLocaleInfoEx(__locale_wbuffer, __lctype, __number_buffer, 10);
+
+  unsigned int __acp = std::wcstoul(__number_buffer, nullptr, 10);
+
+  return __get_win32_acp(&__acp);
+}
+
+_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_win32_acp(nullptr); }
 
 #elif defined(__linux__) || defined(__APPLE__) || defined(__FREEBSD__) || defined(__NETBSD__) ||                       \
     _LIBCPP_LIBC_NEWLIB || defined(_AIX) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
 // POSIX
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name) {
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name) {
+  // TODO: An assert that checks if the string is null-terminated may be prudent.
   __te_impl __e;
 
-  __locale::__locale_t __l = __locale::__newlocale(_LIBCPP_CTYPE_MASK, __name, static_cast<__locale::__locale_t>(0));
+  __locale::__locale_t __l =
+      __locale::__newlocale(_LIBCPP_CTYPE_MASK, __name.data(), static_cast<__locale::__locale_t>(0));
 
   if (!__l) {
     return __e;
@@ -243,7 +276,7 @@ _LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name) {
 
 _LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
 #else
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name [[maybe_unused]]) { return __te_impl(); }
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name [[maybe_unused]]) { return __te_impl(); }
 _LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
 #endif // _LIBCPP_WIN32API
 

>From 9441c9fc5eb9c1718e63c1401ec2c8b3c29929e2 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 10 Mar 2026 22:00:31 -0400
Subject: [PATCH 20/58] Deuglify nodiscards, remove on deleted functions

---
 libcxx/include/__text_encoding/te_impl.h | 12 ++++++------
 libcxx/include/text_encoding             |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index 57b17db8b5173..2b12167a12256 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -406,11 +406,11 @@ struct __te_impl {
     }
   }
 
-  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __id __mib() const noexcept {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __id __mib() const noexcept {
     return __id(__entries[__encoding_idx_].__mib_rep_);
   }
 
-  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr const char* __name() const noexcept { return __name_; }
+  [[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> {
@@ -506,7 +506,7 @@ struct __te_impl {
     const __te_data* __view_data_;
   }; // __aliases_view
 
-  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view __aliases() const noexcept {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view __aliases() const noexcept {
     return __aliases_view(&__entries[__encoding_idx_]);
   }
 
@@ -520,7 +520,7 @@ struct __te_impl {
     return __encoding.__mib() == __i;
   }
 
-  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static consteval __te_impl __literal() noexcept {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval __te_impl __literal() noexcept {
     // TODO: Remove this branch once we have __GNUC_EXECUTION_CHARSET_NAME or __clang_literal_encoding__ unconditionally
 #  ifdef __GNUC_EXECUTION_CHARSET_NAME
     return __te_impl(__GNUC_EXECUTION_CHARSET_NAME);
@@ -541,10 +541,10 @@ struct __te_impl {
   _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int*) = delete;
 #    endif
 
-  [[__nodiscard__]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment();
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment();
 
   template <__id _Id>
-  [[__nodiscard__]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool __environment_is() {
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool __environment_is() {
     return __environment() == _Id;
   }
 
diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index f3e6c63a15e3b..457f6e9f4ffad 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -117,10 +117,10 @@ public:
     return __te_impl::__environment_is<_Id>();
   }
 #    else
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static text_encoding environment() = delete;
+  static text_encoding environment() = delete;
 
   template <id _Id>
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool environment_is() = delete;
+  static bool environment_is() = delete;
 #    endif
 };
 

>From 7a8979aa2357d337cd95a5497baaa2f31cbbb136 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 10 Mar 2026 22:00:36 -0400
Subject: [PATCH 21/58] Bump step count

---
 .../text_encoding/text_encoding.ctor/string_view.pass.cpp       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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
index 2b69b386cba7b..f16a05bb1a0ab 100644
--- 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
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // REQUIRES: std-at-least-c++26
-// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=30000000
+// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=40000000
 // ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-ops-limit): -fconstexpr-ops-limit=1000000000
 
 // <text_encoding>

>From 5075841567186c18481eff3feb18941041649aa6 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 10 Mar 2026 22:10:52 -0400
Subject: [PATCH 22/58] Update C locale API and documentation, enable for
 Android API >= 26

---
 libcxx/include/__locale_dir/locale_base_api.h |  3 ++
 libcxx/include/__locale_dir/support/linux.h   |  4 +--
 libcxx/include/__text_encoding/te_impl.h      |  1 -
 libcxx/src/text_encoding.cpp                  |  3 +-
 .../text_encoding/environment.pass.cpp        | 28 +++++++++++--------
 .../environment.pass.cpp                      | 16 ++++++++---
 6 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index 56826c8e636f1..b803e0a806d64 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -49,6 +49,7 @@
 // #define _LIBCPP_MESSAGES_MASK  /* implementation-defined */
 // #define _LIBCPP_ALL_MASK       /* implementation-defined */
 // #define _LIBCPP_LC_ALL         /* implementation-defined */
+// #define _LIBCPP_NL_CODESET     /* implementation-defined */
 //
 // Strtonum functions
 // ------------------
@@ -102,6 +103,8 @@
 //
 //  int     __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers
 //  int     __asprintf(char**, __locale_t, const char*, ...);        // required by the headers
+//
+// const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc);
 // }
 
 #if _LIBCPP_HAS_LOCALIZATION
diff --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index 96bda017cee43..64794b4d6f747 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -214,8 +214,8 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps,
 }
 #  endif // _LIBCPP_HAS_WIDE_CHARACTERS
 
-// TODO: Android has langinfo.h but not nl_langinfo_l
-#  ifndef __ANDROID__
+// Android pre-API 26 does not have nl_langinfo_l
+#  if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
 inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
   return ::nl_langinfo_l(__item, __loc);
 }
diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index 2b12167a12256..adae4681cdbed 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -532,7 +532,6 @@ struct __te_impl {
   }
 
 #  if _LIBCPP_HAS_LOCALIZATION
-
   _LIBCPP_HIDDEN friend __te_impl __get_locale_encoding(string_view __name);
   _LIBCPP_HIDDEN friend __te_impl __get_env_encoding();
 #    if defined(_LIBCPP_WIN32)
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 17c86dc4f7dd0..e7e97680984ac 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -243,8 +243,7 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int* __codepage) {
 
 _LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_win32_acp(nullptr); }
 
-#elif defined(__linux__) || defined(__APPLE__) || defined(__FREEBSD__) || defined(__NETBSD__) ||                       \
-    _LIBCPP_LIBC_NEWLIB || defined(_AIX) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
+#elif !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
 // POSIX
 _LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name) {
   // TODO: An assert that checks if the string is null-terminated may be prudent.
diff --git a/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp
index 03909f474a246..17c7e9202ebb2 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp
@@ -12,7 +12,6 @@
 // REQUIRES: locale.fr_CA.ISO8859-1
 
 // UNSUPPORTED: no-localization
-// UNSUPPORTED: android
 // UNSUPPORTED: windows
 // UNSUPPORTED: availability-te-environment-missing
 
@@ -24,15 +23,22 @@
 #include "platform_support.h" // locale name macros
 
 int main(int, char**) {
+#if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
   // text_encoding::environment() is (unfortunately) affected by changes to the "LANG" environment variable on POSIX systems.
-  {
-    setenv("LANG", LOCALE_fr_CA_ISO8859_1, 1);
-
-    auto te = std::text_encoding::environment();
-
-    assert(std::text_encoding::environment_is<std::text_encoding::id::ISOLatin1>());
-    assert(te == std::text_encoding::environment());
-    assert(te.mib() == std::text_encoding::id::ISOLatin1);
-    assert(std::ranges::contains(te.aliases(), std::string_view("ISO_8859-1")));
-  }
+  setenv("LANG", LOCALE_fr_CA_ISO8859_1, 1);
+
+  auto te = std::text_encoding::environment();
+
+  assert(std::text_encoding::environment_is<std::text_encoding::id::ISOLatin1>());
+  assert(te == std::text_encoding::environment());
+  assert(te.mib() == std::text_encoding::id::ISOLatin1);
+  assert(std::ranges::contains(te.aliases(), std::string_view("ISO_8859-1")));
+#else
+  // On implementations that do not have nl_langinfo_l, the unknown text encoding is returned.
+  auto te = std::text_encoding::environment();
+  assert(std::text_encoding::environment_is<std::text_encoding::id::unknown>());
+  assert(te.mib() == std::text_encoding::id::unknown);
+#endif
+
+  return 0;
 }
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 a527581ec1e34..6d4a8c420221a 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
@@ -10,7 +10,6 @@
 // REQUIRES: locale.en_US.UTF-8
 
 // UNSUPPORTED: no-localization
-// UNSUPPORTED: android
 // UNSUPPORTED: availability-te-environment-missing
 
 // <text_encoding>
@@ -25,16 +24,17 @@
 #include "platform_support.h"
 
 int main(int, char**) {
+#if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
   std::text_encoding te = std::text_encoding::environment();
   // 1. Depending on the platform's default, verify that environment() returns the corresponding text encoding.
   {
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
+#  if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
     assert(te.mib() == std::text_encoding::ASCII);
     assert(std::text_encoding::environment_is<std::text_encoding::ASCII>());
-#elif defined(_WIN32)
+#  elif defined(_WIN32)
     assert(te.mib() == std::text_encoding::windows1252);
     assert(std::text_encoding::environment_is<std::text_encoding::windows1252>());
-#endif
+#  endif
   }
 
   // 2. text_encoding::environment() still returns the default locale encoding when the locale is set to "en_US.UTF-8".
@@ -46,5 +46,13 @@ int main(int, char**) {
     assert(te == te2);
   }
 
+  {
+    std::setlocale(LC_CTYPE, LOCALE_en_US_UTF_8);
+
+    std::text_encoding te2 = std::text_encoding::environment();
+    assert(te2 != std::text_encoding::UTF8);
+    assert(te == te2);
+  }
+#endif
   return 0;
 }

>From e827c77d0c3b23da135dd42cdc1726eae22640fd Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 10 Mar 2026 22:42:09 -0400
Subject: [PATCH 23/58] Format

---
 libcxx/src/text_encoding.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index e7e97680984ac..26bda2baf8fad 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -225,7 +225,7 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int* __codepage) {
   wchar_t __number_buffer[11]{};
 
   auto __codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
-  auto __lctype = ::AreFileApisANSI() ? LOCALE_IDEFAULTANSICODEPAGE : LOCALE_IDEFAULTCODEPAGE;
+  auto __lctype   = ::AreFileApisANSI() ? LOCALE_IDEFAULTANSICODEPAGE : LOCALE_IDEFAULTCODEPAGE;
 
   int __ret = ::MultiByteToWideChar(
       __codepage, MB_ERR_INVALID_CHARS, __name.data(), __name.size(), __locale_wbuffer, LOCALE_MAX_NAME_LENGTH);

>From e3891da79270a18b865c823788c46571566d4fce Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 10 Mar 2026 23:12:51 -0400
Subject: [PATCH 24/58] Gate environment() on android

---
 libcxx/include/text_encoding | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 457f6e9f4ffad..dd2dcd998294b 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -107,7 +107,7 @@ public:
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval text_encoding literal() noexcept {
     return text_encoding(__te_impl::__literal());
   }
-#    if _LIBCPP_HAS_LOCALIZATION && !defined(__ANDROID__)
+#    if _LIBCPP_HAS_LOCALIZATION && (!defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26))
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static text_encoding environment() {
     return text_encoding(__te_impl::__environment());
   };

>From 20cf9437c8634769455450528d2d89915bc6908b Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 11 Mar 2026 00:31:55 -0400
Subject: [PATCH 25/58] Android default encoding is UTF-8

---
 .../text_encoding/text_encoding.members/environment.pass.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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 6d4a8c420221a..5127888072166 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
@@ -28,7 +28,10 @@ int main(int, char**) {
   std::text_encoding te = std::text_encoding::environment();
   // 1. Depending on the platform's default, verify that environment() returns the corresponding text encoding.
   {
-#  if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
+#  if defined(__ANDROID__)
+    assert(te.mib() == std::text_encoding::UTF8);
+    assert(std::text_encoding::environment_is<std::text_encoding::UTF8>());
+#  elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
     assert(te.mib() == std::text_encoding::ASCII);
     assert(std::text_encoding::environment_is<std::text_encoding::ASCII>());
 #  elif defined(_WIN32)

>From cedd1e00f2d9258d35c988f5727e20df421d0de1 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 11 Mar 2026 00:32:04 -0400
Subject: [PATCH 26/58] Fix Windows build

---
 libcxx/include/__text_encoding/te_impl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index adae4681cdbed..ee5d9dc3aaec6 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -534,7 +534,7 @@ struct __te_impl {
 #  if _LIBCPP_HAS_LOCALIZATION
   _LIBCPP_HIDDEN friend __te_impl __get_locale_encoding(string_view __name);
   _LIBCPP_HIDDEN friend __te_impl __get_env_encoding();
-#    if defined(_LIBCPP_WIN32)
+#    if defined(_LIBCPP_WIN32API)
   _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int*);
 #    else
   _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int*) = delete;

>From c2ff35a9efaf54124f29957f81553edbc5ccf49c Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 11 Mar 2026 00:33:02 -0400
Subject: [PATCH 27/58] ditto

---
 libcxx/src/text_encoding.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 26bda2baf8fad..1d30048c10e80 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -30,7 +30,7 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int* __codepage) {
     // Such a locale cannot be set as the system locale.
     // Applications that do not support Unicode do not work correctly with locales
     // marked as "Unicode only".
-    return __te_impl::id::unkown;
+    return __te_impl::__id::unkown;
   case 037:
     return __te_impl::__id::IBM037;
   case 437:

>From fabf913747b5bbd16de7b310be5ce967be9fe1b3 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 11 Mar 2026 00:33:36 -0400
Subject: [PATCH 28/58] ditto

---
 libcxx/src/text_encoding.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 1d30048c10e80..04d6fe3bb85f1 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -30,7 +30,7 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int* __codepage) {
     // Such a locale cannot be set as the system locale.
     // Applications that do not support Unicode do not work correctly with locales
     // marked as "Unicode only".
-    return __te_impl::__id::unkown;
+    return __te_impl::__id::unknown;
   case 037:
     return __te_impl::__id::IBM037;
   case 437:

>From e32a79d6996e969b7dd1fc7ea9ff88558cb35fcd Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 11 Mar 2026 00:35:07 -0400
Subject: [PATCH 29/58] ditto

---
 libcxx/src/text_encoding.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 04d6fe3bb85f1..9f575b3915ba3 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -231,7 +231,7 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int* __codepage) {
       __codepage, MB_ERR_INVALID_CHARS, __name.data(), __name.size(), __locale_wbuffer, LOCALE_MAX_NAME_LENGTH);
 
   if (__ret <= 0)
-    return te_impl();
+    return __te_impl();
 
   // The below function fills the string with the number in text.
   int __result = ::GetLocaleInfoEx(__locale_wbuffer, __lctype, __number_buffer, 10);

>From b67b575a4cfb00eb720b4ed4f1c2528211a78789 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 11 Mar 2026 20:52:48 -0400
Subject: [PATCH 30/58] Fix Windows implementation

---
 libcxx/include/__text_encoding/te_impl.h |  4 ++--
 libcxx/src/text_encoding.cpp             | 20 +++++++++++---------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index ee5d9dc3aaec6..d61affa9f203c 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -535,9 +535,9 @@ struct __te_impl {
   _LIBCPP_HIDDEN friend __te_impl __get_locale_encoding(string_view __name);
   _LIBCPP_HIDDEN friend __te_impl __get_env_encoding();
 #    if defined(_LIBCPP_WIN32API)
-  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int*);
+  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int);
 #    else
-  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int*) = delete;
+  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int) = delete;
 #    endif
 
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment();
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 9f575b3915ba3..4230f6008160b 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -20,10 +20,8 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if defined(_LIBCPP_WIN32API)
-_LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int* __codepage) {
-  unsigned int __acp = __codepage == nullptr ? GetACP() : *__codepage;
-
-  switch (__acp) {
+_LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int __codepage) {
+  switch (__codepage) {
   case 0:
     // If no ANSI code page is available, only Unicode can be used for the locale.
     // In this case, the value is CP_ACP (0).
@@ -224,24 +222,28 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int* __codepage) {
   wchar_t __locale_wbuffer[LOCALE_NAME_MAX_LENGTH + 1]{};
   wchar_t __number_buffer[11]{};
 
-  auto __codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
-  auto __lctype   = ::AreFileApisANSI() ? LOCALE_IDEFAULTANSICODEPAGE : LOCALE_IDEFAULTCODEPAGE;
+  bool __is_ansi  = ::AreFileApisANSI();
+  auto __codepage = __is_ansi ? CP_ACP : CP_OEMCP;
 
   int __ret = ::MultiByteToWideChar(
-      __codepage, MB_ERR_INVALID_CHARS, __name.data(), __name.size(), __locale_wbuffer, LOCALE_MAX_NAME_LENGTH);
+      __codepage, MB_ERR_INVALID_CHARS, __name.data(), __name.size(), __locale_wbuffer, LOCALE_NAME_MAX_LENGTH);
 
   if (__ret <= 0)
     return __te_impl();
 
   // The below function fills the string with the number in text.
+  auto __lctype = __is_ansi ? LOCALE_IDEFAULTANSICODEPAGE : LOCALE_IDEFAULTCODEPAGE;
   int __result = ::GetLocaleInfoEx(__locale_wbuffer, __lctype, __number_buffer, 10);
 
+  if (__result <= 0)
+    return __te_impl();
+
   unsigned int __acp = std::wcstoul(__number_buffer, nullptr, 10);
 
-  return __get_win32_acp(&__acp);
+  return __get_win32_acp(__acp);
 }
 
-_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_win32_acp(nullptr); }
+_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_win32_acp(::GetACP()); }
 
 #elif !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
 // POSIX

>From f69991322d5f264c8caffdda59a9d4ee33ef3179 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 11 Mar 2026 20:56:11 -0400
Subject: [PATCH 31/58] Don't rely on system-specific encodings in environment
 test

---
 .../text_encoding.members/environment.pass.cpp  | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

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 5127888072166..d1ace8a9f204b 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
@@ -20,27 +20,13 @@
 #include <clocale>
 #include <text_encoding>
 
-#include "../test_text_encoding.h"
 #include "platform_support.h"
 
 int main(int, char**) {
 #if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
   std::text_encoding te = std::text_encoding::environment();
-  // 1. Depending on the platform's default, verify that environment() returns the corresponding text encoding.
-  {
-#  if defined(__ANDROID__)
-    assert(te.mib() == std::text_encoding::UTF8);
-    assert(std::text_encoding::environment_is<std::text_encoding::UTF8>());
-#  elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
-    assert(te.mib() == std::text_encoding::ASCII);
-    assert(std::text_encoding::environment_is<std::text_encoding::ASCII>());
-#  elif defined(_WIN32)
-    assert(te.mib() == std::text_encoding::windows1252);
-    assert(std::text_encoding::environment_is<std::text_encoding::windows1252>());
-#  endif
-  }
 
-  // 2. text_encoding::environment() still returns the default locale encoding when the locale is set to "en_US.UTF-8".
+  // 1. text_encoding::environment() still returns the default system encoding when the "LC_ALL" locale is changed.
   {
     std::setlocale(LC_ALL, LOCALE_en_US_UTF_8);
 
@@ -49,6 +35,7 @@ int main(int, char**) {
     assert(te == te2);
   }
 
+  // 2. text_encoding::environment() still returns the default system encoding when the "LC_CTYPE" locale is changed.
   {
     std::setlocale(LC_CTYPE, LOCALE_en_US_UTF_8);
 

>From 0a1ed64053fec99ab753c6ca3725e359d7bba044 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 11 Mar 2026 23:24:26 -0400
Subject: [PATCH 32/58] Store aliases as one string and store a table of
 indexes into that string Reduces runtime size 18.4Ki -> 13.1Ki Reduces file
 size 41.4Ki -> 15.5Ki (mostly attributed to eliminated relocation data)

---
 libcxx/include/__text_encoding/te_impl.h      | 1962 +++++++++--------
 .../iterator.pass.cpp                         |    2 -
 2 files changed, 1042 insertions(+), 922 deletions(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index d61affa9f203c..c55d4749f84e8 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -299,6 +299,11 @@ struct __te_impl {
 
   using enum __id;
   static constexpr size_t __max_name_length_ = 63;
+
+  // A __te_data structure stores:
+  // Index into an table of indexes that is an offset in the giant aliases string
+  // The MIB of that text encoding
+  // Number of aliases
   struct __te_data {
     unsigned short __first_alias_index_;
     unsigned short __mib_rep_;
@@ -307,14 +312,6 @@ struct __te_impl {
     _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __te_data& __enc, __id __i) noexcept {
       return __enc.__mib_rep_ < static_cast<unsigned short>(__i);
     }
-
-    _LIBCPP_HIDE_FROM_ABI constexpr const char* const* __aliases_begin() const noexcept {
-      return &__aliases_table[__first_alias_index_];
-    }
-
-    _LIBCPP_HIDE_FROM_ABI constexpr const char* const* __aliases_end() const noexcept {
-      return &__aliases_table[__first_alias_index_ + __num_aliases_];
-    }
   };
 
   _LIBCPP_HIDE_FROM_ABI static constexpr bool __comp_name(string_view __a, string_view __b) noexcept {
@@ -364,10 +361,11 @@ struct __te_impl {
     _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__a.contains('\0'), "input string_view must not contain '\\0'");
 
     auto __pred = [&__a](const __te_data& __entry) -> bool {
-      // Search slice of alias table that corresponds to the current MIB
-      return std::find_if(__entry.__aliases_begin(), __entry.__aliases_end(), [&__a](const char* __alias) {
+      // Search aliases of text encoding for string
+      __aliases_view __aliases(__entry);
+      return std::find_if(__aliases.begin(), __aliases.end(), [&__a](auto __alias) {
                return __comp_name(__a, __alias);
-             }) != __entry.__aliases_end();
+             }) != __aliases.end();
     };
 
     const __te_data* __found = std::find_if(__entries + 2, std::end(__entries), __pred);
@@ -400,15 +398,13 @@ struct __te_impl {
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr __te_impl(__id __i) noexcept : __encoding_idx_(__find_data_idx_by_id(__i)) {
-    const char* __alias = __aliases_table[__entries[__encoding_idx_].__first_alias_index_];
+    const char* __alias = __get_alias_from_idx_table_idx(__get().__first_alias_index_);
     if (__alias[0] != '\0') {
       string_view(__alias).copy(__name_, __max_name_length_);
     }
   }
 
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __id __mib() const noexcept {
-    return __id(__entries[__encoding_idx_].__mib_rep_);
-  }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __id __mib() const noexcept { return __id(__get().__mib_rep_); }
 
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const char* __name() const noexcept { return __name_; }
 
@@ -419,18 +415,20 @@ struct __te_impl {
       using iterator_category = random_access_iterator_tag;
       using value_type        = const char*;
       using reference         = const char*;
-      using difference_type   = ptrdiff_t;
+      using difference_type   = decltype(static_cast<unsigned short>(1) - static_cast<unsigned short>(1));
 
       constexpr __iterator() noexcept = default;
 
-      _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const noexcept { return *__data_; }
+      _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const noexcept {
+        return __get_alias_from_idx_table_idx(__current_idx_);
+      }
 
       _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const noexcept {
         auto __it = *this;
         return *(__it + __n);
       }
 
-      _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator->() const noexcept { return __data_; }
+      _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator->() = delete;
 
       _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator __it, difference_type __n) noexcept {
         __it += __n;
@@ -448,33 +446,33 @@ struct __te_impl {
       }
 
       _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __iterator& __other) const noexcept {
-        return __data_ - __other.__data_;
+        return __current_idx_ - __other.__current_idx_;
       }
 
       _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() noexcept {
-        __data_++;
+        __current_idx_++;
         return *this;
       }
 
       _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) noexcept {
         auto __old = *this;
-        __data_++;
+        __current_idx_++;
         return __old;
       }
 
       _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() noexcept {
-        __data_--;
+        __current_idx_--;
         return *this;
       }
 
       _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int) noexcept {
         auto __old = *this;
-        __data_--;
+        __current_idx_--;
         return __old;
       }
 
       _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) noexcept {
-        __data_ += __n;
+        __current_idx_ += __n;
         return *this;
       }
 
@@ -486,28 +484,27 @@ struct __te_impl {
     private:
       friend struct __aliases_view;
 
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator(const char* const* __enc_d) noexcept : __data_(__enc_d) {}
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator(unsigned short __enc_d) noexcept : __current_idx_(__enc_d) {}
 
-      const char* const* __data_;
+      unsigned short __current_idx_;
     }; // __iterator
 
-    _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const noexcept {
-      return __iterator{__view_data_->__aliases_begin()};
-    }
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const noexcept { return __iterator(__first_idx_); }
 
-    _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const noexcept {
-      return __iterator{__view_data_->__aliases_end()};
-    }
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const noexcept { return __iterator(__last_idx_); }
 
   private:
     friend struct __te_impl;
 
-    _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view(const __te_data* __d) : __view_data_(__d) {}
-    const __te_data* __view_data_;
+    _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view(const __te_data& __d)
+        : __first_idx_(__d.__first_alias_index_), __last_idx_(__d.__first_alias_index_ + __d.__num_aliases_) {}
+
+    unsigned short __first_idx_;
+    unsigned short __last_idx_;
   }; // __aliases_view
 
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view __aliases() const noexcept {
-    return __aliases_view(&__entries[__encoding_idx_]);
+    return __aliases_view(__get());
   }
 
   _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_impl& __a, const __te_impl& __b) noexcept {
@@ -548,6 +545,8 @@ struct __te_impl {
   }
 
 #  endif
+  constexpr const __te_data& __get() const { return __entries[__encoding_idx_]; }
+
   unsigned short __encoding_idx_{1u};
   char __name_[__max_name_length_ + 1]{};
 
@@ -599,891 +598,1014 @@ struct __te_impl {
   static constexpr auto __other_idx_   = 0u;
   static constexpr auto __unknown_idx_ = 1u;
 
-  static constexpr char const* __aliases_table[] = {
-      "", // other
-      "", // unknown
-      "US-ASCII",
-      "iso-ir-6",
-      "ANSI_X3.4-1968",
-      "ANSI_X3.4-1986",
-      "ISO_646.irv:1991",
-      "ISO646-US",
-      "us",
-      "IBM367",
-      "cp367",
-      "csASCII",
-      "ASCII",
-      "ISO_8859-1:1987",
-      "iso-ir-100",
-      "ISO_8859-1",
-      "ISO-8859-1",
-      "latin1",
-      "l1",
-      "IBM819",
-      "CP819",
-      "csISOLatin1",
-      "ISO_8859-2:1987",
-      "iso-ir-101",
-      "ISO_8859-2",
-      "ISO-8859-2",
-      "latin2",
-      "l2",
-      "csISOLatin2",
-      "ISO_8859-3:1988",
-      "iso-ir-109",
-      "ISO_8859-3",
-      "ISO-8859-3",
-      "latin3",
-      "l3",
-      "csISOLatin3",
-      "ISO_8859-4:1988",
-      "iso-ir-110",
-      "ISO_8859-4",
-      "ISO-8859-4",
-      "latin4",
-      "l4",
-      "csISOLatin4",
-      "ISO_8859-5:1988",
-      "iso-ir-144",
-      "ISO_8859-5",
-      "ISO-8859-5",
-      "cyrillic",
-      "csISOLatinCyrillic",
-      "ISO_8859-6:1987",
-      "iso-ir-127",
-      "ISO_8859-6",
-      "ISO-8859-6",
-      "ECMA-114",
-      "ASMO-708",
-      "arabic",
-      "csISOLatinArabic",
-      "ISO_8859-7:1987",
-      "iso-ir-126",
-      "ISO_8859-7",
-      "ISO-8859-7",
-      "ELOT_928",
-      "ECMA-118",
-      "greek",
-      "greek8",
-      "csISOLatinGreek",
-      "ISO_8859-8:1988",
-      "iso-ir-138",
-      "ISO_8859-8",
-      "ISO-8859-8",
-      "hebrew",
-      "csISOLatinHebrew",
-      "ISO_8859-9:1989",
-      "iso-ir-148",
-      "ISO_8859-9",
-      "ISO-8859-9",
-      "latin5",
-      "l5",
-      "csISOLatin5",
-      "ISO-8859-10",
-      "iso-ir-157",
-      "l6",
-      "ISO_8859-10:1992",
-      "csISOLatin6",
-      "latin6",
-      "ISO_6937-2-add",
-      "iso-ir-142",
-      "csISOTextComm",
-      "JIS_X0201",
-      "X0201",
-      "csHalfWidthKatakana",
-      "JIS_Encoding",
-      "csJISEncoding",
-      "Shift_JIS",
-      "MS_Kanji",
-      "csShiftJIS",
-      "Extended_UNIX_Code_Packed_Format_for_Japanese",
-      "csEUCPkdFmtJapanese",
-      "EUC-JP",
-      "Extended_UNIX_Code_Fixed_Width_for_Japanese",
-      "csEUCFixWidJapanese",
-      "BS_4730",
-      "iso-ir-4",
-      "ISO646-GB",
-      "gb",
-      "uk",
-      "csISO4UnitedKingdom",
-      "SEN_850200_C",
-      "iso-ir-11",
-      "ISO646-SE2",
-      "se2",
-      "csISO11SwedishForNames",
-      "IT",
-      "iso-ir-15",
-      "ISO646-IT",
-      "csISO15Italian",
-      "ES",
-      "iso-ir-17",
-      "ISO646-ES",
-      "csISO17Spanish",
-      "DIN_66003",
-      "iso-ir-21",
-      "de",
-      "ISO646-DE",
-      "csISO21German",
-      "NS_4551-1",
-      "iso-ir-60",
-      "ISO646-NO",
-      "no",
-      "csISO60DanishNorwegian",
-      "csISO60Norwegian1",
-      "NF_Z_62-010",
-      "iso-ir-69",
-      "ISO646-FR",
-      "fr",
-      "csISO69French",
-      "ISO-10646-UTF-1",
-      "csISO10646UTF1",
-      "ISO_646.basic:1983",
-      "ref",
-      "csISO646basic1983",
-      "INVARIANT",
-      "csINVARIANT",
-      "ISO_646.irv:1983",
-      "iso-ir-2",
-      "irv",
-      "csISO2IntlRefVersion",
-      "NATS-SEFI",
-      "iso-ir-8-1",
-      "csNATSSEFI",
-      "NATS-SEFI-ADD",
-      "iso-ir-8-2",
-      "csNATSSEFIADD",
-      "SEN_850200_B",
-      "iso-ir-10",
-      "FI",
-      "ISO646-FI",
-      "ISO646-SE",
-      "se",
-      "csISO10Swedish",
-      "KS_C_5601-1987",
-      "iso-ir-149",
-      "KS_C_5601-1989",
-      "KSC_5601",
-      "korean",
-      "csKSC56011987",
-      "ISO-2022-KR",
-      "csISO2022KR",
-      "EUC-KR",
-      "csEUCKR",
-      "ISO-2022-JP",
-      "csISO2022JP",
-      "ISO-2022-JP-2",
-      "csISO2022JP2",
-      "JIS_C6220-1969-jp",
-      "JIS_C6220-1969",
-      "iso-ir-13",
-      "katakana",
-      "x0201-7",
-      "csISO13JISC6220jp",
-      "JIS_C6220-1969-ro",
-      "iso-ir-14",
-      "jp",
-      "ISO646-JP",
-      "csISO14JISC6220ro",
-      "PT",
-      "iso-ir-16",
-      "ISO646-PT",
-      "csISO16Portuguese",
-      "greek7-old",
-      "iso-ir-18",
-      "csISO18Greek7Old",
-      "latin-greek",
-      "iso-ir-19",
-      "csISO19LatinGreek",
-      "NF_Z_62-010_(1973)",
-      "iso-ir-25",
-      "ISO646-FR1",
-      "csISO25French",
-      "Latin-greek-1",
-      "iso-ir-27",
-      "csISO27LatinGreek1",
-      "ISO_5427",
-      "iso-ir-37",
-      "csISO5427Cyrillic",
-      "JIS_C6226-1978",
-      "iso-ir-42",
-      "csISO42JISC62261978",
-      "BS_viewdata",
-      "iso-ir-47",
-      "csISO47BSViewdata",
-      "INIS",
-      "iso-ir-49",
-      "csISO49INIS",
-      "INIS-8",
-      "iso-ir-50",
-      "csISO50INIS8",
-      "INIS-cyrillic",
-      "iso-ir-51",
-      "csISO51INISCyrillic",
-      "ISO_5427:1981",
-      "iso-ir-54",
-      "ISO5427Cyrillic1981",
-      "csISO54271981",
-      "ISO_5428:1980",
-      "iso-ir-55",
-      "csISO5428Greek",
-      "GB_1988-80",
-      "iso-ir-57",
-      "cn",
-      "ISO646-CN",
-      "csISO57GB1988",
-      "GB_2312-80",
-      "iso-ir-58",
-      "chinese",
-      "csISO58GB231280",
-      "NS_4551-2",
-      "ISO646-NO2",
-      "iso-ir-61",
-      "no2",
-      "csISO61Norwegian2",
-      "videotex-suppl",
-      "iso-ir-70",
-      "csISO70VideotexSupp1",
-      "PT2",
-      "iso-ir-84",
-      "ISO646-PT2",
-      "csISO84Portuguese2",
-      "ES2",
-      "iso-ir-85",
-      "ISO646-ES2",
-      "csISO85Spanish2",
-      "MSZ_7795.3",
-      "iso-ir-86",
-      "ISO646-HU",
-      "hu",
-      "csISO86Hungarian",
-      "JIS_C6226-1983",
-      "iso-ir-87",
-      "x0208",
-      "JIS_X0208-1983",
-      "csISO87JISX0208",
-      "greek7",
-      "iso-ir-88",
-      "csISO88Greek7",
-      "ASMO_449",
-      "ISO_9036",
-      "arabic7",
-      "iso-ir-89",
-      "csISO89ASMO449",
-      "iso-ir-90",
-      "csISO90",
-      "JIS_C6229-1984-a",
-      "iso-ir-91",
-      "jp-ocr-a",
-      "csISO91JISC62291984a",
-      "JIS_C6229-1984-b",
-      "iso-ir-92",
-      "ISO646-JP-OCR-B",
-      "jp-ocr-b",
-      "csISO92JISC62991984b",
-      "JIS_C6229-1984-b-add",
-      "iso-ir-93",
-      "jp-ocr-b-add",
-      "csISO93JIS62291984badd",
-      "JIS_C6229-1984-hand",
-      "iso-ir-94",
-      "jp-ocr-hand",
-      "csISO94JIS62291984hand",
-      "JIS_C6229-1984-hand-add",
-      "iso-ir-95",
-      "jp-ocr-hand-add",
-      "csISO95JIS62291984handadd",
-      "JIS_C6229-1984-kana",
-      "iso-ir-96",
-      "csISO96JISC62291984kana",
-      "ISO_2033-1983",
-      "iso-ir-98",
-      "e13b",
-      "csISO2033",
-      "ANSI_X3.110-1983",
-      "iso-ir-99",
-      "CSA_T500-1983",
-      "NAPLPS",
-      "csISO99NAPLPS",
-      "T.61-7bit",
-      "iso-ir-102",
-      "csISO102T617bit",
-      "T.61-8bit",
-      "T.61",
-      "iso-ir-103",
-      "csISO103T618bit",
-      "ECMA-cyrillic",
-      "iso-ir-111",
-      "KOI8-E",
-      "csISO111ECMACyrillic",
-      "CSA_Z243.4-1985-1",
-      "iso-ir-121",
-      "ISO646-CA",
-      "csa7-1",
-      "csa71",
-      "ca",
-      "csISO121Canadian1",
-      "CSA_Z243.4-1985-2",
-      "iso-ir-122",
-      "ISO646-CA2",
-      "csa7-2",
-      "csa72",
-      "csISO122Canadian2",
-      "CSA_Z243.4-1985-gr",
-      "iso-ir-123",
-      "csISO123CSAZ24341985gr",
-      "ISO_8859-6-E",
-      "csISO88596E",
-      "ISO-8859-6-E",
-      "ISO_8859-6-I",
-      "csISO88596I",
-      "ISO-8859-6-I",
-      "T.101-G2",
-      "iso-ir-128",
-      "csISO128T101G2",
-      "ISO_8859-8-E",
-      "csISO88598E",
-      "ISO-8859-8-E",
-      "ISO_8859-8-I",
-      "csISO88598I",
-      "ISO-8859-8-I",
-      "CSN_369103",
-      "iso-ir-139",
-      "csISO139CSN369103",
-      "JUS_I.B1.002",
-      "iso-ir-141",
-      "ISO646-YU",
-      "js",
-      "yu",
-      "csISO141JUSIB1002",
-      "IEC_P27-1",
-      "iso-ir-143",
-      "csISO143IECP271",
-      "JUS_I.B1.003-serb",
-      "iso-ir-146",
-      "serbian",
-      "csISO146Serbian",
-      "JUS_I.B1.003-mac",
-      "macedonian",
-      "iso-ir-147",
-      "csISO147Macedonian",
-      "greek-ccitt",
-      "iso-ir-150",
-      "csISO150",
-      "csISO150GreekCCITT",
-      "NC_NC00-10:81",
-      "cuba",
-      "iso-ir-151",
-      "ISO646-CU",
-      "csISO151Cuba",
-      "ISO_6937-2-25",
-      "iso-ir-152",
-      "csISO6937Add",
-      "GOST_19768-74",
-      "ST_SEV_358-88",
-      "iso-ir-153",
-      "csISO153GOST1976874",
-      "ISO_8859-supp",
-      "iso-ir-154",
-      "latin1-2-5",
-      "csISO8859Supp",
-      "ISO_10367-box",
-      "iso-ir-155",
-      "csISO10367Box",
-      "latin-lap",
-      "lap",
-      "iso-ir-158",
-      "csISO158Lap",
-      "JIS_X0212-1990",
-      "x0212",
-      "iso-ir-159",
-      "csISO159JISX02121990",
-      "DS_2089",
-      "DS2089",
-      "ISO646-DK",
-      "dk",
-      "csISO646Danish",
-      "us-dk",
-      "csUSDK",
-      "dk-us",
-      "csDKUS",
-      "KSC5636",
-      "ISO646-KR",
-      "csKSC5636",
-      "UNICODE-1-1-UTF-7",
-      "csUnicode11UTF7",
-      "ISO-2022-CN",
-      "csISO2022CN",
-      "ISO-2022-CN-EXT",
-      "csISO2022CNEXT",
-      "UTF-8",
-      "csUTF8",
-      "ISO-8859-13",
-      "csISO885913",
-      "ISO-8859-14",
-      "iso-ir-199",
-      "ISO_8859-14:1998",
-      "ISO_8859-14",
-      "latin8",
-      "iso-celtic",
-      "l8",
-      "csISO885914",
-      "ISO-8859-15",
-      "ISO_8859-15",
-      "Latin-9",
-      "csISO885915",
-      "ISO-8859-16",
-      "iso-ir-226",
-      "ISO_8859-16:2001",
-      "ISO_8859-16",
-      "latin10",
-      "l10",
-      "csISO885916",
-      "GBK",
-      "CP936",
-      "MS936",
-      "windows-936",
-      "csGBK",
-      "GB18030",
-      "csGB18030",
-      "OSD_EBCDIC_DF04_15",
-      "csOSDEBCDICDF0415",
-      "OSD_EBCDIC_DF03_IRV",
-      "csOSDEBCDICDF03IRV",
-      "OSD_EBCDIC_DF04_1",
-      "csOSDEBCDICDF041",
-      "ISO-11548-1",
-      "ISO_11548-1",
-      "ISO_TR_11548-1",
-      "csISO115481",
-      "KZ-1048",
-      "STRK1048-2002",
-      "RK1048",
-      "csKZ1048",
-      "ISO-10646-UCS-2",
-      "csUnicode",
-      "ISO-10646-UCS-4",
-      "csUCS4",
-      "ISO-10646-UCS-Basic",
-      "csUnicodeASCII",
-      "ISO-10646-Unicode-Latin1",
-      "csUnicodeLatin1",
-      "ISO-10646",
-      "ISO-10646-J-1",
-      "csUnicodeJapanese",
-      "ISO-Unicode-IBM-1261",
-      "csUnicodeIBM1261",
-      "ISO-Unicode-IBM-1268",
-      "csUnicodeIBM1268",
-      "ISO-Unicode-IBM-1276",
-      "csUnicodeIBM1276",
-      "ISO-Unicode-IBM-1264",
-      "csUnicodeIBM1264",
-      "ISO-Unicode-IBM-1265",
-      "csUnicodeIBM1265",
-      "UNICODE-1-1",
-      "csUnicode11",
-      "SCSU",
-      "csSCSU",
-      "UTF-7",
-      "csUTF7",
-      "UTF-16BE",
-      "csUTF16BE",
-      "UTF-16LE",
-      "csUTF16LE",
-      "UTF-16",
-      "csUTF16",
-      "CESU-8",
-      "csCESU8",
-      "csCESU-8",
-      "UTF-32",
-      "csUTF32",
-      "UTF-32BE",
-      "csUTF32BE",
-      "UTF-32LE",
-      "csUTF32LE",
-      "BOCU-1",
-      "csBOCU1",
-      "csBOCU-1",
-      "UTF-7-IMAP",
-      "csUTF7IMAP",
-      "ISO-8859-1-Windows-3.0-Latin-1",
-      "csWindows30Latin1",
-      "ISO-8859-1-Windows-3.1-Latin-1",
-      "csWindows31Latin1",
-      "ISO-8859-2-Windows-Latin-2",
-      "csWindows31Latin2",
-      "ISO-8859-9-Windows-Latin-5",
-      "csWindows31Latin5",
-      "hp-roman8",
-      "roman8",
-      "r8",
-      "csHPRoman8",
-      "Adobe-Standard-Encoding",
-      "csAdobeStandardEncoding",
-      "Ventura-US",
-      "csVenturaUS",
-      "Ventura-International",
-      "csVenturaInternational",
-      "DEC-MCS",
-      "dec",
-      "csDECMCS",
-      "IBM850",
-      "cp850",
-      "850",
-      "csPC850Multilingual",
-      "IBM852",
-      "cp852",
-      "852",
-      "csPCp852",
-      "IBM437",
-      "cp437",
-      "437",
-      "csPC8CodePage437",
-      "PC8-Danish-Norwegian",
-      "csPC8DanishNorwegian",
-      "IBM862",
-      "cp862",
-      "862",
-      "csPC862LatinHebrew",
-      "PC8-Turkish",
-      "csPC8Turkish",
-      "IBM-Symbols",
-      "csIBMSymbols",
-      "IBM-Thai",
-      "csIBMThai",
-      "HP-Legal",
-      "csHPLegal",
-      "HP-Pi-font",
-      "csHPPiFont",
-      "HP-Math8",
-      "csHPMath8",
-      "Adobe-Symbol-Encoding",
-      "csHPPSMath",
-      "HP-DeskTop",
-      "csHPDesktop",
-      "Ventura-Math",
-      "csVenturaMath",
-      "Microsoft-Publishing",
-      "csMicrosoftPublishing",
-      "Windows-31J",
-      "csWindows31J",
-      "GB2312",
-      "csGB2312",
-      "Big5",
-      "csBig5",
-      "macintosh",
-      "mac",
-      "csMacintosh",
-      "IBM037",
-      "cp037",
-      "ebcdic-cp-us",
-      "ebcdic-cp-ca",
-      "ebcdic-cp-wt",
-      "ebcdic-cp-nl",
-      "csIBM037",
-      "IBM038",
-      "EBCDIC-INT",
-      "cp038",
-      "csIBM038",
-      "IBM273",
-      "CP273",
-      "csIBM273",
-      "IBM274",
-      "EBCDIC-BE",
-      "CP274",
-      "csIBM274",
-      "IBM275",
-      "EBCDIC-BR",
-      "cp275",
-      "csIBM275",
-      "IBM277",
-      "EBCDIC-CP-DK",
-      "EBCDIC-CP-NO",
-      "csIBM277",
-      "IBM278",
-      "CP278",
-      "ebcdic-cp-fi",
-      "ebcdic-cp-se",
-      "csIBM278",
-      "IBM280",
-      "CP280",
-      "ebcdic-cp-it",
-      "csIBM280",
-      "IBM281",
-      "EBCDIC-JP-E",
-      "cp281",
-      "csIBM281",
-      "IBM284",
-      "CP284",
-      "ebcdic-cp-es",
-      "csIBM284",
-      "IBM285",
-      "CP285",
-      "ebcdic-cp-gb",
-      "csIBM285",
-      "IBM290",
-      "cp290",
-      "EBCDIC-JP-kana",
-      "csIBM290",
-      "IBM297",
-      "cp297",
-      "ebcdic-cp-fr",
-      "csIBM297",
-      "IBM420",
-      "cp420",
-      "ebcdic-cp-ar1",
-      "csIBM420",
-      "IBM423",
-      "cp423",
-      "ebcdic-cp-gr",
-      "csIBM423",
-      "IBM424",
-      "cp424",
-      "ebcdic-cp-he",
-      "csIBM424",
-      "IBM500",
-      "CP500",
-      "ebcdic-cp-be",
-      "ebcdic-cp-ch",
-      "csIBM500",
-      "IBM851",
-      "cp851",
-      "851",
-      "csIBM851",
-      "IBM855",
-      "cp855",
-      "855",
-      "csIBM855",
-      "IBM857",
-      "cp857",
-      "857",
-      "csIBM857",
-      "IBM860",
-      "cp860",
-      "860",
-      "csIBM860",
-      "IBM861",
-      "cp861",
-      "861",
-      "cp-is",
-      "csIBM861",
-      "IBM863",
-      "cp863",
-      "863",
-      "csIBM863",
-      "IBM864",
-      "cp864",
-      "csIBM864",
-      "IBM865",
-      "cp865",
-      "865",
-      "csIBM865",
-      "IBM868",
-      "CP868",
-      "cp-ar",
-      "csIBM868",
-      "IBM869",
-      "cp869",
-      "869",
-      "cp-gr",
-      "csIBM869",
-      "IBM870",
-      "CP870",
-      "ebcdic-cp-roece",
-      "ebcdic-cp-yu",
-      "csIBM870",
-      "IBM871",
-      "CP871",
-      "ebcdic-cp-is",
-      "csIBM871",
-      "IBM880",
-      "cp880",
-      "EBCDIC-Cyrillic",
-      "csIBM880",
-      "IBM891",
-      "cp891",
-      "csIBM891",
-      "IBM903",
-      "cp903",
-      "csIBM903",
-      "IBM904",
-      "cp904",
-      "904",
-      "csIBBM904",
-      "IBM905",
-      "CP905",
-      "ebcdic-cp-tr",
-      "csIBM905",
-      "IBM918",
-      "CP918",
-      "ebcdic-cp-ar2",
-      "csIBM918",
-      "IBM1026",
-      "CP1026",
-      "csIBM1026",
-      "EBCDIC-AT-DE",
-      "csIBMEBCDICATDE",
-      "EBCDIC-AT-DE-A",
-      "csEBCDICATDEA",
-      "EBCDIC-CA-FR",
-      "csEBCDICCAFR",
-      "EBCDIC-DK-NO",
-      "csEBCDICDKNO",
-      "EBCDIC-DK-NO-A",
-      "csEBCDICDKNOA",
-      "EBCDIC-FI-SE",
-      "csEBCDICFISE",
-      "EBCDIC-FI-SE-A",
-      "csEBCDICFISEA",
-      "EBCDIC-FR",
-      "csEBCDICFR",
-      "EBCDIC-IT",
-      "csEBCDICIT",
-      "EBCDIC-PT",
-      "csEBCDICPT",
-      "EBCDIC-ES",
-      "csEBCDICES",
-      "EBCDIC-ES-A",
-      "csEBCDICESA",
-      "EBCDIC-ES-S",
-      "csEBCDICESS",
-      "EBCDIC-UK",
-      "csEBCDICUK",
-      "EBCDIC-US",
-      "csEBCDICUS",
-      "UNKNOWN-8BIT",
-      "csUnknown8BiT",
-      "MNEMONIC",
-      "csMnemonic",
-      "MNEM",
-      "csMnem",
-      "VISCII",
-      "csVISCII",
-      "VIQR",
-      "csVIQR",
-      "KOI8-R",
-      "csKOI8R",
-      "HZ-GB-2312",
-      "IBM866",
-      "cp866",
-      "866",
-      "csIBM866",
-      "IBM775",
-      "cp775",
-      "csPC775Baltic",
-      "KOI8-U",
-      "csKOI8U",
-      "IBM00858",
-      "CCSID00858",
-      "CP00858",
-      "PC-Multilingual-850+euro",
-      "csIBM00858",
-      "IBM00924",
-      "CCSID00924",
-      "CP00924",
-      "ebcdic-Latin9--euro",
-      "csIBM00924",
-      "IBM01140",
-      "CCSID01140",
-      "CP01140",
-      "ebcdic-us-37+euro",
-      "csIBM01140",
-      "IBM01141",
-      "CCSID01141",
-      "CP01141",
-      "ebcdic-de-273+euro",
-      "csIBM01141",
-      "IBM01142",
-      "CCSID01142",
-      "CP01142",
-      "ebcdic-dk-277+euro",
-      "ebcdic-no-277+euro",
-      "csIBM01142",
-      "IBM01143",
-      "CCSID01143",
-      "CP01143",
-      "ebcdic-fi-278+euro",
-      "ebcdic-se-278+euro",
-      "csIBM01143",
-      "IBM01144",
-      "CCSID01144",
-      "CP01144",
-      "ebcdic-it-280+euro",
-      "csIBM01144",
-      "IBM01145",
-      "CCSID01145",
-      "CP01145",
-      "ebcdic-es-284+euro",
-      "csIBM01145",
-      "IBM01146",
-      "CCSID01146",
-      "CP01146",
-      "ebcdic-gb-285+euro",
-      "csIBM01146",
-      "IBM01147",
-      "CCSID01147",
-      "CP01147",
-      "ebcdic-fr-297+euro",
-      "csIBM01147",
-      "IBM01148",
-      "CCSID01148",
-      "CP01148",
-      "ebcdic-international-500+euro",
-      "csIBM01148",
-      "IBM01149",
-      "CCSID01149",
-      "CP01149",
-      "ebcdic-is-871+euro",
-      "csIBM01149",
-      "Big5-HKSCS",
-      "csBig5HKSCS",
-      "IBM1047",
-      "IBM-1047",
-      "csIBM1047",
-      "PTCP154",
-      "csPTCP154",
-      "PT154",
-      "CP154",
-      "Cyrillic-Asian",
-      "Amiga-1251",
-      "Ami1251",
-      "Amiga1251",
-      "Ami-1251",
-      "csAmiga1251",
-      "KOI7-switched",
-      "csKOI7switched",
-      "BRF",
-      "csBRF",
-      "TSCII",
-      "csTSCII",
-      "CP51932",
-      "csCP51932",
-      "windows-874",
-      "cswindows874",
-      "windows-1250",
-      "cswindows1250",
-      "windows-1251",
-      "cswindows1251",
-      "windows-1252",
-      "cswindows1252",
-      "windows-1253",
-      "cswindows1253",
-      "windows-1254",
-      "cswindows1254",
-      "windows-1255",
-      "cswindows1255",
-      "windows-1256",
-      "cswindows1256",
-      "windows-1257",
-      "cswindows1257",
-      "windows-1258",
-      "cswindows1258",
-      "TIS-620",
-      "csTIS620",
-      "ISO-8859-11",
-      "CP50220",
-      "csCP50220",
+  static constexpr char const* __get_alias_from_idx_table_idx(unsigned short __idx) {
+    return __aliases_string + __alias_index_table_[__idx];
+  }
+
+  // We're saving space by storing a giant string and a table of indexes vs storing an array of const char*
+  // because we know ahead of time the offset can fit into 2 bytes.
+
+  static constexpr char __aliases_string[] =
+      "US-ASCII\0iso-ir-6\0ANSI_X3.4-1968\0ANSI_X3.4-1986\0ISO_646.irv:1991\0ISO646-"
+      "US\0us\0IBM367\0cp367\0csASCII\0ASCII\0ISO_8859-1:1987\0iso-ir-100\0ISO_8859-1\0ISO-8859-"
+      "1\0latin1\0l1\0IBM819\0CP819\0csISOLatin1\0ISO_8859-2:1987\0iso-ir-101\0ISO_8859-2\0ISO-8859-"
+      "2\0latin2\0l2\0csISOLatin2\0ISO_8859-3:1988\0iso-ir-109\0ISO_8859-3\0ISO-8859-3\0latin3\0l3\0csISOLatin3\0ISO_"
+      "8859-4:1988\0iso-ir-110\0ISO_8859-4\0ISO-8859-4\0latin4\0l4\0csISOLatin4\0ISO_8859-5:1988\0iso-ir-144\0ISO_8859-"
+      "5\0ISO-8859-5\0cyrillic\0csISOLatinCyrillic\0ISO_8859-6:1987\0iso-ir-127\0ISO_8859-6\0ISO-8859-6\0ECMA-"
+      "114\0ASMO-708\0arabic\0csISOLatinArabic\0ISO_8859-7:1987\0iso-ir-126\0ISO_8859-7\0ISO-8859-7\0ELOT_928\0ECMA-"
+      "118\0greek\0greek8\0csISOLatinGreek\0ISO_8859-8:1988\0iso-ir-138\0ISO_8859-8\0ISO-8859-"
+      "8\0hebrew\0csISOLatinHebrew\0ISO_8859-9:1989\0iso-ir-148\0ISO_8859-9\0ISO-8859-9\0latin5\0l5\0csISOLatin5\0ISO-"
+      "8859-10\0iso-ir-157\0l6\0ISO_8859-10:1992\0csISOLatin6\0latin6\0ISO_6937-2-add\0iso-ir-142\0csISOTextComm\0JIS_"
+      "X0201\0X0201\0csHalfWidthKatakana\0JIS_Encoding\0csJISEncoding\0Shift_JIS\0MS_Kanji\0csShiftJIS\0Extended_UNIX_"
+      "Code_Packed_Format_for_Japanese\0csEUCPkdFmtJapanese\0EUC-JP\0Extended_UNIX_Code_Fixed_Width_for_"
+      "Japanese\0csEUCFixWidJapanese\0BS_4730\0iso-ir-4\0ISO646-GB\0gb\0uk\0csISO4UnitedKingdom\0SEN_850200_C\0iso-ir-"
+      "11\0ISO646-SE2\0se2\0csISO11SwedishForNames\0IT\0iso-ir-15\0ISO646-IT\0csISO15Italian\0ES\0iso-ir-17\0ISO646-"
+      "ES\0csISO17Spanish\0DIN_66003\0iso-ir-21\0de\0ISO646-DE\0csISO21German\0NS_4551-1\0iso-ir-60\0ISO646-"
+      "NO\0no\0csISO60DanishNorwegian\0csISO60Norwegian1\0NF_Z_62-010\0iso-ir-69\0ISO646-FR\0fr\0csISO69French\0ISO-"
+      "10646-UTF-1\0csISO10646UTF1\0ISO_646.basic:1983\0ref\0csISO646basic1983\0INVARIANT\0csINVARIANT\0ISO_646.irv:"
+      "1983\0iso-ir-2\0irv\0csISO2IntlRefVersion\0NATS-SEFI\0iso-ir-8-1\0csNATSSEFI\0NATS-SEFI-ADD\0iso-ir-8-"
+      "2\0csNATSSEFIADD\0SEN_850200_B\0iso-ir-10\0FI\0ISO646-FI\0ISO646-SE\0se\0csISO10Swedish\0KS_C_5601-1987\0iso-ir-"
+      "149\0KS_C_5601-1989\0KSC_5601\0korean\0csKSC56011987\0ISO-2022-KR\0csISO2022KR\0EUC-KR\0csEUCKR\0ISO-2022-"
+      "JP\0csISO2022JP\0ISO-2022-JP-2\0csISO2022JP2\0JIS_C6220-1969-jp\0JIS_C6220-1969\0iso-ir-13\0katakana\0x0201-"
+      "7\0csISO13JISC6220jp\0JIS_C6220-1969-ro\0iso-ir-14\0jp\0ISO646-JP\0csISO14JISC6220ro\0PT\0iso-ir-16\0ISO646-"
+      "PT\0csISO16Portuguese\0greek7-old\0iso-ir-18\0csISO18Greek7Old\0latin-greek\0iso-ir-19\0csISO19LatinGreek\0NF_Z_"
+      "62-010_(1973)\0iso-ir-25\0ISO646-FR1\0csISO25French\0Latin-greek-1\0iso-ir-27\0csISO27LatinGreek1\0ISO_"
+      "5427\0iso-ir-37\0csISO5427Cyrillic\0JIS_C6226-1978\0iso-ir-42\0csISO42JISC62261978\0BS_viewdata\0iso-ir-"
+      "47\0csISO47BSViewdata\0INIS\0iso-ir-49\0csISO49INIS\0INIS-8\0iso-ir-50\0csISO50INIS8\0INIS-cyrillic\0iso-ir-"
+      "51\0csISO51INISCyrillic\0ISO_5427:1981\0iso-ir-54\0ISO5427Cyrillic1981\0csISO54271981\0ISO_5428:1980\0iso-ir-"
+      "55\0csISO5428Greek\0GB_1988-80\0iso-ir-57\0cn\0ISO646-CN\0csISO57GB1988\0GB_2312-80\0iso-ir-"
+      "58\0chinese\0csISO58GB231280\0NS_4551-2\0ISO646-NO2\0iso-ir-61\0no2\0csISO61Norwegian2\0videotex-suppl\0iso-ir-"
+      "70\0csISO70VideotexSupp1\0PT2\0iso-ir-84\0ISO646-PT2\0csISO84Portuguese2\0ES2\0iso-ir-85\0ISO646-"
+      "ES2\0csISO85Spanish2\0MSZ_7795.3\0iso-ir-86\0ISO646-HU\0hu\0csISO86Hungarian\0JIS_C6226-1983\0iso-ir-"
+      "87\0x0208\0JIS_X0208-1983\0csISO87JISX0208\0greek7\0iso-ir-88\0csISO88Greek7\0ASMO_449\0ISO_9036\0arabic7\0iso-"
+      "ir-89\0csISO89ASMO449\0iso-ir-90\0csISO90\0JIS_C6229-1984-a\0iso-ir-91\0jp-ocr-a\0csISO91JISC62291984a\0JIS_"
+      "C6229-1984-b\0iso-ir-92\0ISO646-JP-OCR-B\0jp-ocr-b\0csISO92JISC62991984b\0JIS_C6229-1984-b-add\0iso-ir-93\0jp-"
+      "ocr-b-add\0csISO93JIS62291984badd\0JIS_C6229-1984-hand\0iso-ir-94\0jp-ocr-hand\0csISO94JIS62291984hand\0JIS_"
+      "C6229-1984-hand-add\0iso-ir-95\0jp-ocr-hand-add\0csISO95JIS62291984handadd\0JIS_C6229-1984-kana\0iso-ir-"
+      "96\0csISO96JISC62291984kana\0ISO_2033-1983\0iso-ir-98\0e13b\0csISO2033\0ANSI_X3.110-1983\0iso-ir-99\0CSA_T500-"
+      "1983\0NAPLPS\0csISO99NAPLPS\0T.61-7bit\0iso-ir-102\0csISO102T617bit\0T.61-8bit\0T.61\0iso-ir-"
+      "103\0csISO103T618bit\0ECMA-cyrillic\0iso-ir-111\0KOI8-E\0csISO111ECMACyrillic\0CSA_Z243.4-1985-1\0iso-ir-"
+      "121\0ISO646-CA\0csa7-1\0csa71\0ca\0csISO121Canadian1\0CSA_Z243.4-1985-2\0iso-ir-122\0ISO646-CA2\0csa7-"
+      "2\0csa72\0csISO122Canadian2\0CSA_Z243.4-1985-gr\0iso-ir-123\0csISO123CSAZ24341985gr\0ISO_8859-6-"
+      "E\0csISO88596E\0ISO-8859-6-E\0ISO_8859-6-I\0csISO88596I\0ISO-8859-6-I\0T.101-G2\0iso-ir-"
+      "128\0csISO128T101G2\0ISO_8859-8-E\0csISO88598E\0ISO-8859-8-E\0ISO_8859-8-I\0csISO88598I\0ISO-8859-8-I\0CSN_"
+      "369103\0iso-ir-139\0csISO139CSN369103\0JUS_I.B1.002\0iso-ir-141\0ISO646-YU\0js\0yu\0csISO141JUSIB1002\0IEC_P27-"
+      "1\0iso-ir-143\0csISO143IECP271\0JUS_I.B1.003-serb\0iso-ir-146\0serbian\0csISO146Serbian\0JUS_I.B1.003-"
+      "mac\0macedonian\0iso-ir-147\0csISO147Macedonian\0greek-ccitt\0iso-ir-150\0csISO150\0csISO150GreekCCITT\0NC_NC00-"
+      "10:81\0cuba\0iso-ir-151\0ISO646-CU\0csISO151Cuba\0ISO_6937-2-25\0iso-ir-152\0csISO6937Add\0GOST_19768-74\0ST_"
+      "SEV_358-88\0iso-ir-153\0csISO153GOST1976874\0ISO_8859-supp\0iso-ir-154\0latin1-2-5\0csISO8859Supp\0ISO_10367-"
+      "box\0iso-ir-155\0csISO10367Box\0latin-lap\0lap\0iso-ir-158\0csISO158Lap\0JIS_X0212-1990\0x0212\0iso-ir-"
+      "159\0csISO159JISX02121990\0DS_2089\0DS2089\0ISO646-DK\0dk\0csISO646Danish\0us-dk\0csUSDK\0dk-"
+      "us\0csDKUS\0KSC5636\0ISO646-KR\0csKSC5636\0UNICODE-1-1-UTF-7\0csUnicode11UTF7\0ISO-2022-CN\0csISO2022CN\0ISO-"
+      "2022-CN-EXT\0csISO2022CNEXT\0UTF-8\0csUTF8\0ISO-8859-13\0csISO885913\0ISO-8859-14\0iso-ir-199\0ISO_8859-14:"
+      "1998\0ISO_8859-14\0latin8\0iso-celtic\0l8\0csISO885914\0ISO-8859-15\0ISO_8859-15\0Latin-9\0csISO885915\0ISO-"
+      "8859-16\0iso-ir-226\0ISO_8859-16:2001\0ISO_8859-16\0latin10\0l10\0csISO885916\0GBK\0CP936\0MS936\0windows-"
+      "936\0csGBK\0GB18030\0csGB18030\0OSD_EBCDIC_DF04_15\0csOSDEBCDICDF0415\0OSD_EBCDIC_DF03_"
+      "IRV\0csOSDEBCDICDF03IRV\0OSD_EBCDIC_DF04_1\0csOSDEBCDICDF041\0ISO-11548-1\0ISO_11548-1\0ISO_TR_11548-"
+      "1\0csISO115481\0KZ-1048\0STRK1048-2002\0RK1048\0csKZ1048\0ISO-10646-UCS-2\0csUnicode\0ISO-10646-UCS-"
+      "4\0csUCS4\0ISO-10646-UCS-Basic\0csUnicodeASCII\0ISO-10646-Unicode-Latin1\0csUnicodeLatin1\0ISO-10646\0ISO-10646-"
+      "J-1\0csUnicodeJapanese\0ISO-Unicode-IBM-1261\0csUnicodeIBM1261\0ISO-Unicode-IBM-1268\0csUnicodeIBM1268\0ISO-"
+      "Unicode-IBM-1276\0csUnicodeIBM1276\0ISO-Unicode-IBM-1264\0csUnicodeIBM1264\0ISO-Unicode-IBM-"
+      "1265\0csUnicodeIBM1265\0UNICODE-1-1\0csUnicode11\0SCSU\0csSCSU\0UTF-7\0csUTF7\0UTF-16BE\0csUTF16BE\0UTF-"
+      "16LE\0csUTF16LE\0UTF-16\0csUTF16\0CESU-8\0csCESU8\0csCESU-8\0UTF-32\0csUTF32\0UTF-32BE\0csUTF32BE\0UTF-"
+      "32LE\0csUTF32LE\0BOCU-1\0csBOCU1\0csBOCU-1\0UTF-7-IMAP\0csUTF7IMAP\0ISO-8859-1-Windows-3.0-Latin-"
+      "1\0csWindows30Latin1\0ISO-8859-1-Windows-3.1-Latin-1\0csWindows31Latin1\0ISO-8859-2-Windows-Latin-"
+      "2\0csWindows31Latin2\0ISO-8859-9-Windows-Latin-5\0csWindows31Latin5\0hp-roman8\0roman8\0r8\0csHPRoman8\0Adobe-"
+      "Standard-Encoding\0csAdobeStandardEncoding\0Ventura-US\0csVenturaUS\0Ventura-"
+      "International\0csVenturaInternational\0DEC-"
+      "MCS\0dec\0csDECMCS\0IBM850\0cp850\0850\0csPC850Multilingual\0IBM852\0cp852\0852\0csPCp852\0IBM437\0cp437\0"
+      "437\0csPC8CodePage437\0PC8-Danish-Norwegian\0csPC8DanishNorwegian\0IBM862\0cp862\0862\0csPC862LatinHebrew\0PC8-"
+      "Turkish\0csPC8Turkish\0IBM-Symbols\0csIBMSymbols\0IBM-Thai\0csIBMThai\0HP-Legal\0csHPLegal\0HP-Pi-"
+      "font\0csHPPiFont\0HP-Math8\0csHPMath8\0Adobe-Symbol-Encoding\0csHPPSMath\0HP-DeskTop\0csHPDesktop\0Ventura-"
+      "Math\0csVenturaMath\0Microsoft-Publishing\0csMicrosoftPublishing\0Windows-"
+      "31J\0csWindows31J\0GB2312\0csGB2312\0Big5\0csBig5\0macintosh\0mac\0csMacintosh\0IBM037\0cp037\0ebcdic-cp-"
+      "us\0ebcdic-cp-ca\0ebcdic-cp-wt\0ebcdic-cp-nl\0csIBM037\0IBM038\0EBCDIC-"
+      "INT\0cp038\0csIBM038\0IBM273\0CP273\0csIBM273\0IBM274\0EBCDIC-BE\0CP274\0csIBM274\0IBM275\0EBCDIC-"
+      "BR\0cp275\0csIBM275\0IBM277\0EBCDIC-CP-DK\0EBCDIC-CP-NO\0csIBM277\0IBM278\0CP278\0ebcdic-cp-fi\0ebcdic-cp-"
+      "se\0csIBM278\0IBM280\0CP280\0ebcdic-cp-it\0csIBM280\0IBM281\0EBCDIC-JP-"
+      "E\0cp281\0csIBM281\0IBM284\0CP284\0ebcdic-cp-es\0csIBM284\0IBM285\0CP285\0ebcdic-cp-"
+      "gb\0csIBM285\0IBM290\0cp290\0EBCDIC-JP-kana\0csIBM290\0IBM297\0cp297\0ebcdic-cp-"
+      "fr\0csIBM297\0IBM420\0cp420\0ebcdic-cp-ar1\0csIBM420\0IBM423\0cp423\0ebcdic-cp-"
+      "gr\0csIBM423\0IBM424\0cp424\0ebcdic-cp-he\0csIBM424\0IBM500\0CP500\0ebcdic-cp-be\0ebcdic-cp-"
+      "ch\0csIBM500\0IBM851\0cp851\0851\0csIBM851\0IBM855\0cp855\0855\0csIBM855\0IBM857\0cp857\0857\0csIBM857\0IBM860\0"
+      "cp860\0860\0csIBM860\0IBM861\0cp861\0861\0cp-"
+      "is\0csIBM861\0IBM863\0cp863\0863\0csIBM863\0IBM864\0cp864\0csIBM864\0IBM865\0cp865\0865\0csIBM865\0IBM868\0CP868"
+      "\0cp-ar\0csIBM868\0IBM869\0cp869\0869\0cp-gr\0csIBM869\0IBM870\0CP870\0ebcdic-cp-roece\0ebcdic-cp-"
+      "yu\0csIBM870\0IBM871\0CP871\0ebcdic-cp-is\0csIBM871\0IBM880\0cp880\0EBCDIC-"
+      "Cyrillic\0csIBM880\0IBM891\0cp891\0csIBM891\0IBM903\0cp903\0csIBM903\0IBM904\0cp904\0904\0csIBBM904\0IBM905\0CP9"
+      "05\0ebcdic-cp-tr\0csIBM905\0IBM918\0CP918\0ebcdic-cp-ar2\0csIBM918\0IBM1026\0CP1026\0csIBM1026\0EBCDIC-AT-"
+      "DE\0csIBMEBCDICATDE\0EBCDIC-AT-DE-A\0csEBCDICATDEA\0EBCDIC-CA-FR\0csEBCDICCAFR\0EBCDIC-DK-"
+      "NO\0csEBCDICDKNO\0EBCDIC-DK-NO-A\0csEBCDICDKNOA\0EBCDIC-FI-SE\0csEBCDICFISE\0EBCDIC-FI-SE-"
+      "A\0csEBCDICFISEA\0EBCDIC-FR\0csEBCDICFR\0EBCDIC-IT\0csEBCDICIT\0EBCDIC-PT\0csEBCDICPT\0EBCDIC-"
+      "ES\0csEBCDICES\0EBCDIC-ES-A\0csEBCDICESA\0EBCDIC-ES-S\0csEBCDICESS\0EBCDIC-UK\0csEBCDICUK\0EBCDIC-"
+      "US\0csEBCDICUS\0UNKNOWN-"
+      "8BIT\0csUnknown8BiT\0MNEMONIC\0csMnemonic\0MNEM\0csMnem\0VISCII\0csVISCII\0VIQR\0csVIQR\0KOI8-R\0csKOI8R\0HZ-GB-"
+      "2312\0IBM866\0cp866\0866\0csIBM866\0IBM775\0cp775\0csPC775Baltic\0KOI8-"
+      "U\0csKOI8U\0IBM00858\0CCSID00858\0CP00858\0PC-Multilingual-850+"
+      "euro\0csIBM00858\0IBM00924\0CCSID00924\0CP00924\0ebcdic-Latin9--"
+      "euro\0csIBM00924\0IBM01140\0CCSID01140\0CP01140\0ebcdic-us-37+"
+      "euro\0csIBM01140\0IBM01141\0CCSID01141\0CP01141\0ebcdic-de-273+"
+      "euro\0csIBM01141\0IBM01142\0CCSID01142\0CP01142\0ebcdic-dk-277+euro\0ebcdic-no-277+"
+      "euro\0csIBM01142\0IBM01143\0CCSID01143\0CP01143\0ebcdic-fi-278+euro\0ebcdic-se-278+"
+      "euro\0csIBM01143\0IBM01144\0CCSID01144\0CP01144\0ebcdic-it-280+"
+      "euro\0csIBM01144\0IBM01145\0CCSID01145\0CP01145\0ebcdic-es-284+"
+      "euro\0csIBM01145\0IBM01146\0CCSID01146\0CP01146\0ebcdic-gb-285+"
+      "euro\0csIBM01146\0IBM01147\0CCSID01147\0CP01147\0ebcdic-fr-297+"
+      "euro\0csIBM01147\0IBM01148\0CCSID01148\0CP01148\0ebcdic-international-500+"
+      "euro\0csIBM01148\0IBM01149\0CCSID01149\0CP01149\0ebcdic-is-871+euro\0csIBM01149\0Big5-"
+      "HKSCS\0csBig5HKSCS\0IBM1047\0IBM-1047\0csIBM1047\0PTCP154\0csPTCP154\0PT154\0CP154\0Cyrillic-Asian\0Amiga-"
+      "1251\0Ami1251\0Amiga1251\0Ami-1251\0csAmiga1251\0KOI7-"
+      "switched\0csKOI7switched\0BRF\0csBRF\0TSCII\0csTSCII\0CP51932\0csCP51932\0windows-874\0cswindows874\0windows-"
+      "1250\0cswindows1250\0windows-1251\0cswindows1251\0windows-1252\0cswindows1252\0windows-"
+      "1253\0cswindows1253\0windows-1254\0cswindows1254\0windows-1255\0cswindows1255\0windows-"
+      "1256\0cswindows1256\0windows-1257\0cswindows1257\0windows-1258\0cswindows1258\0TIS-620\0csTIS620\0ISO-8859-"
+      "11\0CP50220\0csCP50220\0";
+
+  static constexpr unsigned short __alias_index_table_[] = {
+      sizeof(__aliases_string) - 1,
+      sizeof(__aliases_string) - 1,
+      0,
+      9,
+      18,
+      33,
+      48,
+      65,
+      75,
+      78,
+      85,
+      91,
+      99,
+      105,
+      121,
+      132,
+      143,
+      154,
+      161,
+      164,
+      171,
+      177,
+      189,
+      205,
+      216,
+      227,
+      238,
+      245,
+      248,
+      260,
+      276,
+      287,
+      298,
+      309,
+      316,
+      319,
+      331,
+      347,
+      358,
+      369,
+      380,
+      387,
+      390,
+      402,
+      418,
+      429,
+      440,
+      451,
+      460,
+      479,
+      495,
+      506,
+      517,
+      528,
+      537,
+      546,
+      553,
+      570,
+      586,
+      597,
+      608,
+      619,
+      628,
+      637,
+      643,
+      650,
+      666,
+      682,
+      693,
+      704,
+      715,
+      722,
+      739,
+      755,
+      766,
+      777,
+      788,
+      795,
+      798,
+      810,
+      822,
+      833,
+      836,
+      853,
+      865,
+      872,
+      887,
+      898,
+      912,
+      922,
+      928,
+      948,
+      961,
+      975,
+      985,
+      994,
+      1005,
+      1051,
+      1071,
+      1078,
+      1122,
+      1142,
+      1150,
+      1159,
+      1169,
+      1172,
+      1175,
+      1195,
+      1208,
+      1218,
+      1229,
+      1233,
+      1256,
+      1259,
+      1269,
+      1279,
+      1294,
+      1297,
+      1307,
+      1317,
+      1332,
+      1342,
+      1352,
+      1355,
+      1365,
+      1379,
+      1389,
+      1399,
+      1409,
+      1412,
+      1435,
+      1453,
+      1465,
+      1475,
+      1485,
+      1488,
+      1502,
+      1518,
+      1533,
+      1552,
+      1556,
+      1574,
+      1584,
+      1596,
+      1613,
+      1622,
+      1626,
+      1647,
+      1657,
+      1668,
+      1679,
+      1693,
+      1704,
+      1718,
+      1731,
+      1741,
+      1744,
+      1754,
+      1764,
+      1767,
+      1782,
+      1797,
+      1808,
+      1823,
+      1832,
+      1839,
+      1853,
+      1865,
+      1877,
+      1884,
+      1892,
+      1904,
+      1916,
+      1930,
+      1943,
+      1961,
+      1976,
+      1986,
+      1995,
+      2003,
+      2021,
+      2039,
+      2049,
+      2052,
+      2062,
+      2080,
+      2083,
+      2093,
+      2103,
+      2121,
+      2132,
+      2142,
+      2159,
+      2171,
+      2181,
+      2199,
+      2218,
+      2228,
+      2239,
+      2253,
+      2267,
+      2277,
+      2296,
+      2305,
+      2315,
+      2333,
+      2348,
+      2358,
+      2378,
+      2390,
+      2400,
+      2418,
+      2423,
+      2433,
+      2445,
+      2452,
+      2462,
+      2475,
+      2489,
+      2499,
+      2519,
+      2533,
+      2543,
+      2563,
+      2577,
+      2591,
+      2601,
+      2616,
+      2627,
+      2637,
+      2640,
+      2650,
+      2664,
+      2675,
+      2685,
+      2693,
+      2709,
+      2719,
+      2730,
+      2740,
+      2744,
+      2762,
+      2777,
+      2787,
+      2808,
+      2812,
+      2822,
+      2833,
+      2852,
+      2856,
+      2866,
+      2877,
+      2893,
+      2904,
+      2914,
+      2924,
+      2927,
+      2944,
+      2959,
+      2969,
+      2975,
+      2990,
+      3006,
+      3013,
+      3023,
+      3037,
+      3046,
+      3055,
+      3063,
+      3073,
+      3088,
+      3098,
+      3106,
+      3123,
+      3133,
+      3142,
+      3163,
+      3180,
+      3190,
+      3206,
+      3215,
+      3236,
+      3257,
+      3267,
+      3280,
+      3303,
+      3323,
+      3333,
+      3345,
+      3368,
+      3392,
+      3402,
+      3418,
+      3444,
+      3464,
+      3474,
+      3498,
+      3512,
+      3522,
+      3527,
+      3537,
+      3554,
+      3564,
+      3578,
+      3585,
+      3599,
+      3609,
+      3620,
+      3636,
+      3646,
+      3651,
+      3662,
+      3678,
+      3692,
+      3703,
+      3710,
+      3731,
+      3749,
+      3760,
+      3770,
+      3777,
+      3783,
+      3786,
+      3804,
+      3822,
+      3833,
+      3844,
+      3851,
+      3857,
+      3875,
+      3894,
+      3905,
+      3928,
+      3941,
+      3953,
+      3966,
+      3979,
+      3991,
+      4004,
+      4013,
+      4024,
+      4039,
+      4052,
+      4064,
+      4077,
+      4090,
+      4102,
+      4115,
+      4126,
+      4137,
+      4155,
+      4168,
+      4179,
+      4189,
+      4192,
+      4195,
+      4213,
+      4223,
+      4234,
+      4250,
+      4268,
+      4279,
+      4287,
+      4303,
+      4320,
+      4331,
+      4342,
+      4361,
+      4373,
+      4384,
+      4393,
+      4412,
+      4426,
+      4431,
+      4442,
+      4452,
+      4465,
+      4479,
+      4490,
+      4503,
+      4517,
+      4531,
+      4542,
+      4562,
+      4576,
+      4587,
+      4598,
+      4612,
+      4626,
+      4637,
+      4651,
+      4661,
+      4665,
+      4676,
+      4688,
+      4703,
+      4709,
+      4720,
+      4741,
+      4749,
+      4756,
+      4766,
+      4769,
+      4784,
+      4790,
+      4797,
+      4803,
+      4810,
+      4818,
+      4828,
+      4838,
+      4856,
+      4872,
+      4884,
+      4896,
+      4912,
+      4927,
+      4933,
+      4940,
+      4952,
+      4964,
+      4976,
+      4987,
+      5004,
+      5016,
+      5023,
+      5034,
+      5037,
+      5049,
+      5061,
+      5073,
+      5081,
+      5093,
+      5105,
+      5116,
+      5133,
+      5145,
+      5153,
+      5157,
+      5169,
+      5173,
+      5179,
+      5185,
+      5197,
+      5203,
+      5211,
+      5221,
+      5240,
+      5258,
+      5278,
+      5297,
+      5315,
+      5332,
+      5344,
+      5356,
+      5371,
+      5383,
+      5391,
+      5405,
+      5412,
+      5421,
+      5437,
+      5447,
+      5463,
+      5470,
+      5490,
+      5505,
+      5530,
+      5546,
+      5556,
+      5570,
+      5588,
+      5609,
+      5626,
+      5647,
+      5664,
+      5685,
+      5702,
+      5723,
+      5740,
+      5761,
+      5778,
+      5790,
+      5802,
+      5807,
+      5814,
+      5820,
+      5827,
+      5836,
+      5846,
+      5855,
+      5865,
+      5872,
+      5880,
+      5887,
+      5895,
+      5904,
+      5911,
+      5919,
+      5928,
+      5938,
+      5947,
+      5957,
+      5964,
+      5972,
+      5981,
+      5992,
+      6003,
+      6034,
+      6052,
+      6083,
+      6101,
+      6128,
+      6146,
+      6173,
+      6191,
+      6201,
+      6208,
+      6211,
+      6222,
+      6246,
+      6270,
+      6281,
+      6293,
+      6315,
+      6338,
+      6346,
+      6350,
+      6359,
+      6366,
+      6372,
+      6376,
+      6396,
+      6403,
+      6409,
+      6413,
+      6422,
+      6429,
+      6435,
+      6439,
+      6456,
+      6477,
+      6498,
+      6505,
+      6511,
+      6515,
+      6534,
+      6546,
+      6559,
+      6571,
+      6584,
+      6593,
+      6603,
+      6612,
+      6622,
+      6633,
+      6644,
+      6653,
+      6663,
+      6685,
+      6696,
+      6707,
+      6719,
+      6732,
+      6746,
+      6767,
+      6789,
+      6801,
+      6814,
+      6821,
+      6830,
+      6835,
+      6842,
+      6852,
+      6856,
+      6868,
+      6875,
+      6881,
+      6894,
+      6907,
+      6920,
+      6933,
+      6942,
+      6949,
+      6960,
+      6966,
+      6975,
+      6982,
+      6988,
+      6997,
+      7004,
+      7014,
+      7020,
+      7029,
+      7036,
+      7046,
+      7052,
+      7061,
+      7068,
+      7081,
+      7094,
+      7103,
+      7110,
+      7116,
+      7129,
+      7142,
+      7151,
+      7158,
+      7164,
+      7177,
+      7186,
+      7193,
+      7205,
+      7211,
+      7220,
+      7227,
+      7233,
+      7246,
+      7255,
+      7262,
+      7268,
+      7281,
+      7290,
+      7297,
+      7303,
+      7318,
+      7327,
+      7334,
+      7340,
+      7353,
+      7362,
+      7369,
+      7375,
+      7389,
+      7398,
+      7405,
+      7411,
+      7424,
+      7433,
+      7440,
+      7446,
+      7459,
+      7468,
+      7475,
+      7481,
+      7494,
+      7507,
+      7516,
+      7523,
+      7529,
+      7533,
+      7542,
+      7549,
+      7555,
+      7559,
+      7568,
+      7575,
+      7581,
+      7585,
+      7594,
+      7601,
+      7607,
+      7611,
+      7620,
+      7627,
+      7633,
+      7637,
+      7643,
+      7652,
+      7659,
+      7665,
+      7669,
+      7678,
+      7685,
+      7691,
+      7700,
+      7707,
+      7713,
+      7717,
+      7726,
+      7733,
+      7739,
+      7745,
+      7754,
+      7761,
+      7767,
+      7771,
+      7777,
+      7786,
+      7793,
+      7799,
+      7815,
+      7828,
+      7837,
+      7844,
+      7850,
+      7863,
+      7872,
+      7879,
+      7885,
+      7901,
+      7910,
+      7917,
+      7923,
+      7932,
+      7939,
+      7945,
+      7954,
+      7961,
+      7967,
+      7971,
+      7981,
+      7988,
+      7994,
+      8007,
+      8016,
+      8023,
+      8029,
+      8043,
+      8052,
+      8060,
+      8067,
+      8077,
+      8090,
+      8106,
+      8121,
+      8135,
+      8148,
+      8161,
+      8174,
+      8187,
+      8202,
+      8216,
+      8229,
+      8242,
+      8257,
+      8271,
+      8281,
+      8292,
+      8302,
+      8313,
+      8323,
+      8334,
+      8344,
+      8355,
+      8367,
+      8379,
+      8391,
+      8403,
+      8413,
+      8424,
+      8434,
+      8445,
+      8458,
+      8472,
+      8481,
+      8492,
+      8497,
+      8504,
+      8511,
+      8520,
+      8525,
+      8532,
+      8539,
+      8547,
+      8558,
+      8565,
+      8571,
+      8575,
+      8584,
+      8591,
+      8597,
+      8611,
+      8618,
+      8626,
+      8635,
+      8646,
+      8654,
+      8679,
+      8690,
+      8699,
+      8710,
+      8718,
+      8738,
+      8749,
+      8758,
+      8769,
+      8777,
+      8795,
+      8806,
+      8815,
+      8826,
+      8834,
+      8853,
+      8864,
+      8873,
+      8884,
+      8892,
+      8911,
+      8930,
+      8941,
+      8950,
+      8961,
+      8969,
+      8988,
+      9007,
+      9018,
+      9027,
+      9038,
+      9046,
+      9065,
+      9076,
+      9085,
+      9096,
+      9104,
+      9123,
+      9134,
+      9143,
+      9154,
+      9162,
+      9181,
+      9192,
+      9201,
+      9212,
+      9220,
+      9239,
+      9250,
+      9259,
+      9270,
+      9278,
+      9308,
+      9319,
+      9328,
+      9339,
+      9347,
+      9366,
+      9377,
+      9388,
+      9400,
+      9408,
+      9417,
+      9427,
+      9435,
+      9445,
+      9451,
+      9457,
+      9472,
+      9483,
+      9491,
+      9501,
+      9510,
+      9522,
+      9536,
+      9551,
+      9555,
+      9561,
+      9567,
+      9575,
+      9583,
+      9593,
+      9605,
+      9618,
+      9631,
+      9645,
+      9658,
+      9672,
+      9685,
+      9699,
+      9712,
+      9726,
+      9739,
+      9753,
+      9766,
+      9780,
+      9793,
+      9807,
+      9820,
+      9834,
+      9847,
+      9861,
+      9869,
+      9878,
+      9890,
+      9898,
   };
 };
 
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
index fc5bbaa0c9605..7da0f97143559 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
@@ -102,7 +102,6 @@ constexpr bool test() {
   { // noexcept
     ASSERT_NOEXCEPT(*i);
     ASSERT_NOEXCEPT(i[0]);
-    ASSERT_NOEXCEPT(i.operator->());
     ASSERT_NOEXCEPT(i + 1);
     ASSERT_NOEXCEPT(1 + i);
     ASSERT_NOEXCEPT(i - 1);
@@ -124,7 +123,6 @@ constexpr bool test() {
   { // iterator operator return types
     ASSERT_SAME_TYPE(const char*, decltype(*i));
     ASSERT_SAME_TYPE(const char*, decltype(i[0]));
-    ASSERT_SAME_TYPE(const char* const*, decltype(i.operator->()));
     ASSERT_SAME_TYPE(decltype(i), decltype(i + 1));
     ASSERT_SAME_TYPE(decltype(i), decltype(1 + i));
     ASSERT_SAME_TYPE(decltype(i), decltype(i - 1));

>From fd43337b66da1cf79238bae76d79c7484b5746cc Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 11 Mar 2026 23:31:38 -0400
Subject: [PATCH 33/58] Formatting

---
 libcxx/src/text_encoding.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 4230f6008160b..d23c740a068a1 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -233,7 +233,7 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int __codepage) {
 
   // The below function fills the string with the number in text.
   auto __lctype = __is_ansi ? LOCALE_IDEFAULTANSICODEPAGE : LOCALE_IDEFAULTCODEPAGE;
-  int __result = ::GetLocaleInfoEx(__locale_wbuffer, __lctype, __number_buffer, 10);
+  int __result  = ::GetLocaleInfoEx(__locale_wbuffer, __lctype, __number_buffer, 10);
 
   if (__result <= 0)
     return __te_impl();

>From 39c74a26de0b67cbcf53e3afde52adf3413b1953 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Thu, 12 Mar 2026 18:08:36 -0400
Subject: [PATCH 34/58] Revert "Don't rely on system-specific encodings in
 environment test"

This reverts commit f69991322d5f264c8caffdda59a9d4ee33ef3179.
---
 .../text_encoding.members/environment.pass.cpp  | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

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 d1ace8a9f204b..5127888072166 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
@@ -20,13 +20,27 @@
 #include <clocale>
 #include <text_encoding>
 
+#include "../test_text_encoding.h"
 #include "platform_support.h"
 
 int main(int, char**) {
 #if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
   std::text_encoding te = std::text_encoding::environment();
+  // 1. Depending on the platform's default, verify that environment() returns the corresponding text encoding.
+  {
+#  if defined(__ANDROID__)
+    assert(te.mib() == std::text_encoding::UTF8);
+    assert(std::text_encoding::environment_is<std::text_encoding::UTF8>());
+#  elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
+    assert(te.mib() == std::text_encoding::ASCII);
+    assert(std::text_encoding::environment_is<std::text_encoding::ASCII>());
+#  elif defined(_WIN32)
+    assert(te.mib() == std::text_encoding::windows1252);
+    assert(std::text_encoding::environment_is<std::text_encoding::windows1252>());
+#  endif
+  }
 
-  // 1. text_encoding::environment() still returns the default system encoding when the "LC_ALL" locale is changed.
+  // 2. text_encoding::environment() still returns the default locale encoding when the locale is set to "en_US.UTF-8".
   {
     std::setlocale(LC_ALL, LOCALE_en_US_UTF_8);
 
@@ -35,7 +49,6 @@ int main(int, char**) {
     assert(te == te2);
   }
 
-  // 2. text_encoding::environment() still returns the default system encoding when the "LC_CTYPE" locale is changed.
   {
     std::setlocale(LC_CTYPE, LOCALE_en_US_UTF_8);
 

>From e191979313f6f988642db1d3cefaf7874fb69c52 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Thu, 12 Mar 2026 18:19:02 -0400
Subject: [PATCH 35/58] Make environment failure message a little easier

---
 .../environment.pass.cpp                      | 38 ++++++++++++++-----
 1 file changed, 28 insertions(+), 10 deletions(-)

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 5127888072166..09a527c1349d0 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
@@ -18,28 +18,46 @@
 
 #include <cassert>
 #include <clocale>
+#include <format>
+#include <iostream>
 #include <text_encoding>
 
-#include "../test_text_encoding.h"
 #include "platform_support.h"
 
 int main(int, char**) {
 #if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
-  std::text_encoding te = std::text_encoding::environment();
-  // 1. Depending on the platform's default, verify that environment() returns the corresponding text encoding.
-  {
+  auto check_env = []() {
 #  if defined(__ANDROID__)
-    assert(te.mib() == std::text_encoding::UTF8);
-    assert(std::text_encoding::environment_is<std::text_encoding::UTF8>());
+    constexpr std::text_encoding::id expected_id = std::text_encoding::UTF8;
 #  elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
-    assert(te.mib() == std::text_encoding::ASCII);
-    assert(std::text_encoding::environment_is<std::text_encoding::ASCII>());
+    constexpr std::text_encoding::id expected_id = std::text_encoding::ASCII;
 #  elif defined(_WIN32)
-    assert(te.mib() == std::text_encoding::windows1252);
-    assert(std::text_encoding::environment_is<std::text_encoding::windows1252>());
+    constexpr std::text_encoding::id expected_id = std::text_encoding::windows1252;
+#  else
+    constexpr std::text_encoding::id expected_id = std::text_encoding::unknown;
 #  endif
+
+    std::text_encoding te = std::text_encoding::environment();
+    bool fail             = false;
+    if (te != expected_id) {
+      std::cerr << std::format(
+          "Environment mismatch: Expected ID {}, received: {{{},{}}}\n", int(expected_id), int(te.mib()), te.name());
+      fail = true;
+    }
+
+    if (!std::text_encoding::environment_is<expected_id>()) {
+      fail = true;
+    }
+
+    return !fail;
+  };
+
+  {
+    // 1. Depending on the platform's default, verify that environment() returns the corresponding text encoding.
+    assert(check_env());
   }
 
+  std::text_encoding te = std::text_encoding::environment();
   // 2. text_encoding::environment() still returns the default locale encoding when the locale is set to "en_US.UTF-8".
   {
     std::setlocale(LC_ALL, LOCALE_en_US_UTF_8);

>From 09291c443d3a4464e0bd079f37b7365b3db205a6 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Sun, 15 Mar 2026 00:01:23 -0400
Subject: [PATCH 36/58] Assume android to be UTF-8 always

---
 libcxx/src/text_encoding.cpp                  | 20 +++++++++++++++----
 .../environment.pass.cpp                      |  8 +++++---
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index d23c740a068a1..9304b8a312cf0 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -245,10 +245,8 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int __codepage) {
 
 _LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_win32_acp(::GetACP()); }
 
-#elif !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
-// POSIX
+#elif !defined(__ANDROID__) // POSIX
 _LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name) {
-  // TODO: An assert that checks if the string is null-terminated may be prudent.
   __te_impl __e;
 
   __locale::__locale_t __l =
@@ -261,6 +259,7 @@ _LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name) {
   const char* __codeset = __locale::__nl_langinfo_l(_LIBCPP_NL_CODESET, __l);
 
   if (!__codeset) {
+    __locale::__freelocale(__l);
     return __e;
   }
 
@@ -277,12 +276,25 @@ _LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name) {
 
 _LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
 #else
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name [[maybe_unused]]) { return __te_impl(); }
+#  if defined(__ANDROID__)
+// Android is pretty much assumed to always be UTF-8.
+// Problematic for locale::encoding because nl_langinfo_l on Android essentially returns "ASCII" or "UTF-8"
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding([[maybe_unused]] string_view) {
+  return __te_impl(__te_impl::__id::UTF8);
+}
+_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
+#  else
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding([[maybe_unused]] string_view) { return __te_impl(); }
 _LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
+#  endif
 #endif // _LIBCPP_WIN32API
 
 _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI __te_impl __te_impl::__environment() {
+#if defined(__ANDROID__)
+  return __te_impl(__te_impl::__id::UTF8);
+#else
   return __get_env_encoding();
+#endif
 }
 
 _LIBCPP_END_NAMESPACE_STD
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 09a527c1349d0..74c80181501d8 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
@@ -27,12 +27,14 @@
 int main(int, char**) {
 #if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
   auto check_env = []() {
-#  if defined(__ANDROID__)
-    constexpr std::text_encoding::id expected_id = std::text_encoding::UTF8;
-#  elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
+#  if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
     constexpr std::text_encoding::id expected_id = std::text_encoding::ASCII;
+#  elif defined(__ANDROID__)
+    constexpr std::text_encoding::id expected_id = std::text_encoding::UTF8;
 #  elif defined(_WIN32)
     constexpr std::text_encoding::id expected_id = std::text_encoding::windows1252;
+#  elif defined(_AIX)
+    constexpr std::text_encoding::id expected_id = std::text_encoding::ISOLatin1;
 #  else
     constexpr std::text_encoding::id expected_id = std::text_encoding::unknown;
 #  endif

>From b22976c174d8f1315decd1ad9e4beb816030e669 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 23 Mar 2026 23:27:36 -0400
Subject: [PATCH 37/58] Fix test

---
 .../text_encoding.members/environment.pass.cpp            | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

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 74c80181501d8..1d5e83ac32e9d 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
@@ -25,12 +25,11 @@
 #include "platform_support.h"
 
 int main(int, char**) {
-#if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
   auto check_env = []() {
-#  if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
-    constexpr std::text_encoding::id expected_id = std::text_encoding::ASCII;
-#  elif defined(__ANDROID__)
+#if defined(__ANDROID__)
     constexpr std::text_encoding::id expected_id = std::text_encoding::UTF8;
+#elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
+    constexpr std::text_encoding::id expected_id = std::text_encoding::ASCII;
 #  elif defined(_WIN32)
     constexpr std::text_encoding::id expected_id = std::text_encoding::windows1252;
 #  elif defined(_AIX)
@@ -76,6 +75,5 @@ int main(int, char**) {
     assert(te2 != std::text_encoding::UTF8);
     assert(te == te2);
   }
-#endif
   return 0;
 }

>From 76f0888d3827a0519eefc61033876688baaaa184 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 24 Mar 2026 20:57:47 -0400
Subject: [PATCH 38/58] Implement __get_locale_encoding(..) for Android

---
 libcxx/include/__text_encoding/te_impl.h      |  2 +-
 libcxx/src/text_encoding.cpp                  | 34 +++++++++++--------
 .../environment.pass.cpp                      | 12 +++----
 3 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
index c55d4749f84e8..61c16500b5f46 100644
--- a/libcxx/include/__text_encoding/te_impl.h
+++ b/libcxx/include/__text_encoding/te_impl.h
@@ -529,7 +529,7 @@ struct __te_impl {
   }
 
 #  if _LIBCPP_HAS_LOCALIZATION
-  _LIBCPP_HIDDEN friend __te_impl __get_locale_encoding(string_view __name);
+  _LIBCPP_HIDDEN friend __te_impl __get_locale_encoding(const char* __name);
   _LIBCPP_HIDDEN friend __te_impl __get_env_encoding();
 #    if defined(_LIBCPP_WIN32API)
   _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int);
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 9304b8a312cf0..26bc968b1794a 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -218,15 +218,16 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int __codepage) {
   }
 }
 
-[[maybe_unused]] _LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name) {
+[[maybe_unused]] _LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name) {
   wchar_t __locale_wbuffer[LOCALE_NAME_MAX_LENGTH + 1]{};
   wchar_t __number_buffer[11]{};
 
   bool __is_ansi  = ::AreFileApisANSI();
   auto __codepage = __is_ansi ? CP_ACP : CP_OEMCP;
 
+  string_view __sv(__name);
   int __ret = ::MultiByteToWideChar(
-      __codepage, MB_ERR_INVALID_CHARS, __name.data(), __name.size(), __locale_wbuffer, LOCALE_NAME_MAX_LENGTH);
+      __codepage, MB_ERR_INVALID_CHARS, __name, __sv.size(), __locale_wbuffer, LOCALE_NAME_MAX_LENGTH);
 
   if (__ret <= 0)
     return __te_impl();
@@ -246,11 +247,10 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int __codepage) {
 _LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_win32_acp(::GetACP()); }
 
 #elif !defined(__ANDROID__) // POSIX
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name) {
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name) {
   __te_impl __e;
 
-  __locale::__locale_t __l =
-      __locale::__newlocale(_LIBCPP_CTYPE_MASK, __name.data(), static_cast<__locale::__locale_t>(0));
+  __locale::__locale_t __l = __locale::__newlocale(_LIBCPP_CTYPE_MASK, __name, static_cast<__locale::__locale_t>(0));
 
   if (!__l) {
     return __e;
@@ -277,24 +277,28 @@ _LIBCPP_HIDDEN __te_impl __get_locale_encoding(string_view __name) {
 _LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
 #else
 #  if defined(__ANDROID__)
-// Android is pretty much assumed to always be UTF-8.
-// Problematic for locale::encoding because nl_langinfo_l on Android essentially returns "ASCII" or "UTF-8"
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding([[maybe_unused]] string_view) {
-  return __te_impl(__te_impl::__id::UTF8);
+// Android has minimal libc suppport for locale, and doesn't support any other locale
+// than the ones checked for below.
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name) {
+  string_view __sv(__name);
+  if (!__name[0] || __name[0] == '*' || (__name[0] == 'C' && __sv.size() == 1) || __sv == "POSIX" ||
+      __sv.contains("UTF-8")) {
+    return __te_impl(__te_impl::__id::UTF8);
+  }
+
+  return __te_impl();
 }
-_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
+
+// Android is pretty much assumed to always be UTF-8.
+_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __te_impl(__te_impl::__id::UTF8); }
 #  else
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding([[maybe_unused]] string_view) { return __te_impl(); }
+_LIBCPP_HIDDEN __te_impl __get_locale_encoding([[maybe_unused]] const char*) { return __te_impl(); }
 _LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
 #  endif
 #endif // _LIBCPP_WIN32API
 
 _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI __te_impl __te_impl::__environment() {
-#if defined(__ANDROID__)
-  return __te_impl(__te_impl::__id::UTF8);
-#else
   return __get_env_encoding();
-#endif
 }
 
 _LIBCPP_END_NAMESPACE_STD
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 1d5e83ac32e9d..6fc36ab02a5b7 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
@@ -30,13 +30,13 @@ int main(int, char**) {
     constexpr std::text_encoding::id expected_id = std::text_encoding::UTF8;
 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
     constexpr std::text_encoding::id expected_id = std::text_encoding::ASCII;
-#  elif defined(_WIN32)
+#elif defined(_WIN32)
     constexpr std::text_encoding::id expected_id = std::text_encoding::windows1252;
-#  elif defined(_AIX)
+#elif defined(_AIX)
     constexpr std::text_encoding::id expected_id = std::text_encoding::ISOLatin1;
-#  else
+#else
     constexpr std::text_encoding::id expected_id = std::text_encoding::unknown;
-#  endif
+#endif
 
     std::text_encoding te = std::text_encoding::environment();
     bool fail             = false;
@@ -59,12 +59,11 @@ int main(int, char**) {
   }
 
   std::text_encoding te = std::text_encoding::environment();
-  // 2. text_encoding::environment() still returns the default locale encoding when the locale is set to "en_US.UTF-8".
+  // 2. text_encoding::environment()'s return value isn't altered by changes to locale.
   {
     std::setlocale(LC_ALL, LOCALE_en_US_UTF_8);
 
     std::text_encoding te2 = std::text_encoding::environment();
-    assert(te2 != std::text_encoding::UTF8);
     assert(te == te2);
   }
 
@@ -72,7 +71,6 @@ int main(int, char**) {
     std::setlocale(LC_CTYPE, LOCALE_en_US_UTF_8);
 
     std::text_encoding te2 = std::text_encoding::environment();
-    assert(te2 != std::text_encoding::UTF8);
     assert(te == te2);
   }
   return 0;

>From cfd5fae6a47ce60ef54b9cb40d7a7998b0e46263 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 25 Mar 2026 21:23:38 -0400
Subject: [PATCH 39/58] Library now built with C++26

---
 libcxx/include/CMakeLists.txt                 |    1 -
 libcxx/include/__locale_dir/locale_base_api.h |    4 +-
 libcxx/include/__locale_dir/support/aix.h     |    2 +-
 .../include/__locale_dir/support/bsd_like.h   |    2 +-
 libcxx/include/__locale_dir/support/linux.h   |    2 +-
 libcxx/include/__locale_dir/support/newlib.h  |    2 +-
 libcxx/include/__text_encoding/te_impl.h      | 1618 -----------------
 libcxx/include/module.modulemap.in            |    4 +-
 libcxx/include/text_encoding                  | 1568 +++++++++++++++-
 libcxx/src/text_encoding.cpp                  |  263 +--
 10 files changed, 1688 insertions(+), 1778 deletions(-)
 delete mode 100644 libcxx/include/__text_encoding/te_impl.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 5d6c6a3875b38..8d194dc12639c 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -781,7 +781,6 @@ set(files
   __system_error/error_condition.h
   __system_error/system_error.h
   __system_error/throw_system_error.h
-  __text_encoding/te_impl.h
   __thread/formatter.h
   __thread/id.h
   __thread/jthread.h
diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index 4c075d64bc338..88831f92aab72 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -104,7 +104,7 @@
 //  int     __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers
 //  int     __asprintf(char**, __locale_t, const char*, ...);        // required by the headers
 //
-// const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc);
+// const char* __nl_langinfo(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc);
 // }
 
 #if _LIBCPP_HAS_LOCALIZATION
@@ -274,7 +274,7 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps,
 }
 #      endif // _LIBCPP_HAS_WIDE_CHARACTERS
 
-inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
   return ::nl_langinfo_l(__item, __loc);
 }
 
diff --git a/libcxx/include/__locale_dir/support/aix.h b/libcxx/include/__locale_dir/support/aix.h
index 499f6d8e076a3..57ef514b2f74e 100644
--- a/libcxx/include/__locale_dir/support/aix.h
+++ b/libcxx/include/__locale_dir/support/aix.h
@@ -82,7 +82,7 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
   return std::localeconv();
 }
 
-inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
   return ::nl_langinfo_l(__item, __loc);
 }
 #endif // _LIBCPP_BUILDING_LIBRARY
diff --git a/libcxx/include/__locale_dir/support/bsd_like.h b/libcxx/include/__locale_dir/support/bsd_like.h
index c157fdabb93aa..c992d9d6e9ddb 100644
--- a/libcxx/include/__locale_dir/support/bsd_like.h
+++ b/libcxx/include/__locale_dir/support/bsd_like.h
@@ -183,7 +183,7 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps,
 }
 #  endif // _LIBCPP_HAS_WIDE_CHARACTERS
 
-inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
   return ::nl_langinfo_l(__item, __loc);
 }
 #endif // _LIBCPP_BUILDING_LIBRARY
diff --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index 0f8a0db67a793..3772ad8b45cc2 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -216,7 +216,7 @@ __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps,
 
 // Android pre-API 26 does not have nl_langinfo_l
 #  if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
-inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
   return ::nl_langinfo_l(__item, __loc);
 }
 #  endif
diff --git a/libcxx/include/__locale_dir/support/newlib.h b/libcxx/include/__locale_dir/support/newlib.h
index 640ab571bcd0a..146f45d2851f4 100644
--- a/libcxx/include/__locale_dir/support/newlib.h
+++ b/libcxx/include/__locale_dir/support/newlib.h
@@ -79,7 +79,7 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
   return std::localeconv();
 }
 
-inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo_l(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
+inline _LIBCPP_HIDE_FROM_ABI const char* __nl_langinfo(decltype(_LIBCPP_NL_CODESET) __item, __locale_t __loc) {
   return ::nl_langinfo_l(__item, __loc);
 }
 #endif // _LIBCPP_BUILDING_LIBRARY
diff --git a/libcxx/include/__text_encoding/te_impl.h b/libcxx/include/__text_encoding/te_impl.h
deleted file mode 100644
index 61c16500b5f46..0000000000000
--- a/libcxx/include/__text_encoding/te_impl.h
+++ /dev/null
@@ -1,1618 +0,0 @@
-// -*- 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_TE_IMPL_H
-#define _LIBCPP__TEXT_ENCODING_TE_IMPL_H
-
-#include <__algorithm/find_if.h>
-#include <__algorithm/lower_bound.h>
-#include <__config>
-#include <__cstddef/ptrdiff_t.h>
-#include <__iterator/iterator_traits.h>
-#include <__ranges/view_interface.h>
-#include <cstdint>
-#include <string_view>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-#if _LIBCPP_STD_VER >= 23
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-struct __te_impl {
-private:
-  friend struct text_encoding;
-  enum class __id : int_least32_t {
-    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, // NATS-DANO (33) and NATS-DANO-ADD (34) are omitted by the standard.
-    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,
-    IBM904                  = 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
-  };
-
-  static constexpr int __NATS_DANO_     = 33;
-  static constexpr int __NATS_DANO_ADD_ = 34;
-
-  using enum __id;
-  static constexpr size_t __max_name_length_ = 63;
-
-  // A __te_data structure stores:
-  // Index into an table of indexes that is an offset in the giant aliases string
-  // The MIB of that text encoding
-  // Number of aliases
-  struct __te_data {
-    unsigned short __first_alias_index_;
-    unsigned short __mib_rep_;
-    unsigned char __num_aliases_;
-
-    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __te_data& __enc, __id __i) noexcept {
-      return __enc.__mib_rep_ < static_cast<unsigned short>(__i);
-    }
-  };
-
-  _LIBCPP_HIDE_FROM_ABI static constexpr bool __comp_name(string_view __a, string_view __b) noexcept {
-    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 {
-      if (__n == '0') {
-        return __in_number ? '0' : 255;
-      }
-      __in_number = __n >= '1' && __n <= '9';
-
-      if ((__n >= '1' && __n <= '9') || (__n >= 'a' && __n <= 'z')) {
-        return __n;
-      }
-      if (__n >= 'A' && __n <= 'Z') {
-        return __n + ('a' - 'A'); // tolower
-      }
-
-      return 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_ptr != __a.end() && (__a_val = __map_char(*__a_ptr, __a_in_number)) == 255)
-        __a_ptr++;
-      while (__b_ptr != __b.end() && (__b_val = __map_char(*__b_ptr, __b_in_number)) == 255)
-        __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 unsigned short __find_data_idx(string_view __a) noexcept {
-    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__a.size() <= __max_name_length_, "input string_view must have size <= 63");
-    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__a.contains('\0'), "input string_view must not contain '\\0'");
-
-    auto __pred = [&__a](const __te_data& __entry) -> bool {
-      // Search aliases of text encoding for string
-      __aliases_view __aliases(__entry);
-      return std::find_if(__aliases.begin(), __aliases.end(), [&__a](auto __alias) {
-               return __comp_name(__a, __alias);
-             }) != __aliases.end();
-    };
-
-    const __te_data* __found = std::find_if(__entries + 2, std::end(__entries), __pred);
-    if (__found == std::end(__entries)) {
-      return __other_idx_; // other
-    }
-
-    return __found - __entries;
-  }
-
-  _LIBCPP_HIDE_FROM_ABI static constexpr unsigned short __find_data_idx_by_id(__id __i) noexcept {
-    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__i >= __id::other, "invalid text_encoding::id passed");
-    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__i <= __id::CP50220, "invalid text_encoding::id passed");
-    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(int_least32_t(__i) != __NATS_DANO_, "Mib for NATS-DANO used");
-    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(int_least32_t(__i) != __NATS_DANO_ADD_, "Mib for NATS-DANO-ADD used");
-    auto __found = std::lower_bound(std::begin(__entries), std::end(__entries), __i);
-
-    if (__found == std::end(__entries)) {
-      return __unknown_idx_; // unknown
-    }
-
-    return __found - __entries;
-  }
-
-  _LIBCPP_HIDE_FROM_ABI constexpr __te_impl() = default;
-
-  _LIBCPP_HIDE_FROM_ABI constexpr explicit __te_impl(string_view __enc) noexcept
-      : __encoding_idx_(__find_data_idx(__enc)) {
-    __enc.copy(__name_, __max_name_length_, 0);
-  }
-
-  _LIBCPP_HIDE_FROM_ABI constexpr __te_impl(__id __i) noexcept : __encoding_idx_(__find_data_idx_by_id(__i)) {
-    const char* __alias = __get_alias_from_idx_table_idx(__get().__first_alias_index_);
-    if (__alias[0] != '\0') {
-      string_view(__alias).copy(__name_, __max_name_length_);
-    }
-  }
-
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __id __mib() const noexcept { return __id(__get().__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> {
-    struct __iterator {
-      using iterator_concept  = random_access_iterator_tag;
-      using iterator_category = random_access_iterator_tag;
-      using value_type        = const char*;
-      using reference         = const char*;
-      using difference_type   = decltype(static_cast<unsigned short>(1) - static_cast<unsigned short>(1));
-
-      constexpr __iterator() noexcept = default;
-
-      _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const noexcept {
-        return __get_alias_from_idx_table_idx(__current_idx_);
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const noexcept {
-        auto __it = *this;
-        return *(__it + __n);
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator->() = delete;
-
-      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator __it, difference_type __n) noexcept {
-        __it += __n;
-        return __it;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, __iterator __it) noexcept {
-        __it += __n;
-        return __it;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(__iterator __it, difference_type __n) noexcept {
-        __it -= __n;
-        return __it;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __iterator& __other) const noexcept {
-        return __current_idx_ - __other.__current_idx_;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() noexcept {
-        __current_idx_++;
-        return *this;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) noexcept {
-        auto __old = *this;
-        __current_idx_++;
-        return __old;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() noexcept {
-        __current_idx_--;
-        return *this;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int) noexcept {
-        auto __old = *this;
-        __current_idx_--;
-        return __old;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) noexcept {
-        __current_idx_ += __n;
-        return *this;
-      }
-
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) noexcept { return (*this += -__n); }
-
-      _LIBCPP_HIDE_FROM_ABI friend constexpr auto
-      operator<=>(const __iterator& __it, const __iterator& __it2) noexcept = default;
-
-    private:
-      friend struct __aliases_view;
-
-      _LIBCPP_HIDE_FROM_ABI constexpr __iterator(unsigned short __enc_d) noexcept : __current_idx_(__enc_d) {}
-
-      unsigned short __current_idx_;
-    }; // __iterator
-
-    _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const noexcept { return __iterator(__first_idx_); }
-
-    _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const noexcept { return __iterator(__last_idx_); }
-
-  private:
-    friend struct __te_impl;
-
-    _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view(const __te_data& __d)
-        : __first_idx_(__d.__first_alias_index_), __last_idx_(__d.__first_alias_index_ + __d.__num_aliases_) {}
-
-    unsigned short __first_idx_;
-    unsigned short __last_idx_;
-  }; // __aliases_view
-
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __aliases_view __aliases() const noexcept {
-    return __aliases_view(__get());
-  }
-
-  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_impl& __a, const __te_impl& __b) noexcept {
-    return __a.__mib() == __id::other && __b.__mib() == __id::other
-             ? __comp_name(__a.__name_, __b.__name_)
-             : __a.__mib() == __b.__mib();
-  }
-
-  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __te_impl& __encoding, __id __i) noexcept {
-    return __encoding.__mib() == __i;
-  }
-
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval __te_impl __literal() noexcept {
-    // TODO: Remove this branch once we have __GNUC_EXECUTION_CHARSET_NAME or __clang_literal_encoding__ unconditionally
-#  ifdef __GNUC_EXECUTION_CHARSET_NAME
-    return __te_impl(__GNUC_EXECUTION_CHARSET_NAME);
-#  elif defined(__clang_literal_encoding__)
-    return __te_impl(__clang_literal_encoding__);
-#  else
-    return __te_impl();
-#  endif
-  }
-
-#  if _LIBCPP_HAS_LOCALIZATION
-  _LIBCPP_HIDDEN friend __te_impl __get_locale_encoding(const char* __name);
-  _LIBCPP_HIDDEN friend __te_impl __get_env_encoding();
-#    if defined(_LIBCPP_WIN32API)
-  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int);
-#    else
-  _LIBCPP_HIDDEN friend __te_impl __get_win32_acp(unsigned int) = delete;
-#    endif
-
-  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment();
-
-  template <__id _Id>
-  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool __environment_is() {
-    return __environment() == _Id;
-  }
-
-#  endif
-  constexpr const __te_data& __get() const { return __entries[__encoding_idx_]; }
-
-  unsigned short __encoding_idx_{1u};
-  char __name_[__max_name_length_ + 1]{};
-
-  // Structuring the text encoding data and the table in this manner has a few benefits:
-  // Smaller footprint: We only need 6 bytes for the information we need.
-  // Smaller total table: We only need one entry per Mib.
-  // Easier aliases_view: We know the begin, and end of each range of aliases, which makes iterator
-  // implementation simple.
-
-  static constexpr __te_data __entries[] = {
-      {0, 1, 0},      {1, 2, 0},      {2, 3, 11},     {13, 4, 9},     {22, 5, 7},     {29, 6, 7},     {36, 7, 7},
-      {43, 8, 6},     {49, 9, 8},     {57, 10, 9},    {66, 11, 6},    {72, 12, 7},    {79, 13, 6},    {85, 14, 3},
-      {88, 15, 3},    {91, 16, 2},    {93, 17, 3},    {96, 18, 3},    {99, 19, 2},    {101, 20, 6},   {107, 21, 5},
-      {112, 22, 4},   {116, 23, 4},   {120, 24, 5},   {125, 25, 6},   {131, 26, 5},   {136, 27, 2},   {138, 28, 3},
-      {141, 29, 2},   {143, 30, 4},   {147, 31, 3},   {150, 32, 3},   {153, 35, 7},   {160, 36, 6},   {166, 37, 2},
-      {168, 38, 2},   {170, 39, 2},   {172, 40, 2},   {174, 41, 6},   {180, 42, 5},   {185, 43, 4},   {189, 44, 3},
-      {192, 45, 3},   {195, 46, 4},   {199, 47, 3},   {202, 48, 3},   {205, 49, 3},   {208, 50, 3},   {211, 51, 3},
-      {214, 52, 3},   {217, 53, 3},   {220, 54, 4},   {224, 55, 3},   {227, 56, 5},   {232, 57, 4},   {236, 58, 5},
-      {241, 59, 3},   {244, 60, 4},   {248, 61, 4},   {252, 62, 5},   {257, 63, 5},   {262, 64, 3},   {265, 65, 5},
-      {270, 66, 2},   {272, 67, 4},   {276, 68, 5},   {281, 69, 4},   {285, 70, 4},   {289, 71, 4},   {293, 72, 3},
-      {296, 73, 4},   {300, 74, 5},   {305, 75, 3},   {308, 76, 4},   {312, 77, 4},   {316, 78, 7},   {323, 79, 6},
-      {329, 80, 3},   {332, 81, 3},   {335, 82, 3},   {338, 83, 3},   {341, 84, 3},   {344, 85, 3},   {347, 86, 3},
-      {350, 87, 6},   {356, 88, 3},   {359, 89, 4},   {363, 90, 4},   {367, 91, 4},   {371, 92, 5},   {376, 93, 3},
-      {379, 94, 4},   {383, 95, 4},   {387, 96, 3},   {390, 97, 4},   {394, 98, 4},   {398, 99, 5},   {403, 100, 2},
-      {405, 101, 2},  {407, 102, 3},  {410, 103, 2},  {412, 104, 2},  {414, 105, 2},  {416, 106, 2},  {418, 109, 2},
-      {420, 110, 8},  {428, 111, 4},  {432, 112, 7},  {439, 113, 5},  {444, 114, 2},  {446, 115, 2},  {448, 116, 2},
-      {450, 117, 2},  {452, 118, 4},  {456, 119, 4},  {460, 1000, 2}, {462, 1001, 2}, {464, 1002, 2}, {466, 1003, 3},
-      {469, 1004, 2}, {471, 1005, 2}, {473, 1006, 2}, {475, 1007, 2}, {477, 1008, 2}, {479, 1009, 2}, {481, 1010, 2},
-      {483, 1011, 2}, {485, 1012, 2}, {487, 1013, 2}, {489, 1014, 2}, {491, 1015, 2}, {493, 1016, 3}, {496, 1017, 2},
-      {498, 1018, 2}, {500, 1019, 2}, {502, 1020, 3}, {505, 1021, 2}, {507, 2000, 2}, {509, 2001, 2}, {511, 2002, 2},
-      {513, 2003, 2}, {515, 2004, 4}, {519, 2005, 2}, {521, 2006, 2}, {523, 2007, 2}, {525, 2008, 3}, {528, 2009, 4},
-      {532, 2010, 4}, {536, 2011, 4}, {540, 2012, 2}, {542, 2013, 4}, {546, 2014, 2}, {548, 2015, 2}, {550, 2016, 2},
-      {552, 2017, 2}, {554, 2018, 2}, {556, 2019, 2}, {558, 2020, 2}, {560, 2021, 2}, {562, 2022, 2}, {564, 2023, 2},
-      {566, 2024, 2}, {568, 2025, 2}, {570, 2026, 2}, {572, 2027, 3}, {575, 2028, 7}, {582, 2029, 4}, {586, 2030, 3},
-      {589, 2031, 4}, {593, 2032, 4}, {597, 2033, 4}, {601, 2034, 5}, {606, 2035, 4}, {610, 2036, 4}, {614, 2037, 4},
-      {618, 2038, 4}, {622, 2039, 4}, {626, 2040, 4}, {630, 2041, 4}, {634, 2042, 4}, {638, 2043, 4}, {642, 2044, 5},
-      {647, 2045, 4}, {651, 2046, 4}, {655, 2047, 4}, {659, 2048, 4}, {663, 2049, 5}, {668, 2050, 4}, {672, 2051, 3},
-      {675, 2052, 4}, {679, 2053, 4}, {683, 2054, 5}, {688, 2055, 5}, {693, 2056, 4}, {697, 2057, 4}, {701, 2058, 3},
-      {704, 2059, 3}, {707, 2060, 4}, {711, 2061, 4}, {715, 2062, 4}, {719, 2063, 3}, {722, 2064, 2}, {724, 2065, 2},
-      {726, 2066, 2}, {728, 2067, 2}, {730, 2068, 2}, {732, 2069, 2}, {734, 2070, 2}, {736, 2071, 2}, {738, 2072, 2},
-      {740, 2073, 2}, {742, 2074, 2}, {744, 2075, 2}, {746, 2076, 2}, {748, 2077, 2}, {750, 2078, 2}, {752, 2079, 2},
-      {754, 2080, 2}, {756, 2081, 2}, {758, 2082, 2}, {760, 2083, 2}, {762, 2084, 2}, {764, 2085, 1}, {765, 2086, 4},
-      {769, 2087, 3}, {772, 2088, 2}, {774, 2089, 5}, {779, 2090, 5}, {784, 2091, 5}, {789, 2092, 5}, {794, 2093, 6},
-      {800, 2094, 6}, {806, 2095, 5}, {811, 2096, 5}, {816, 2097, 5}, {821, 2098, 5}, {826, 2099, 5}, {831, 2100, 5},
-      {836, 2101, 2}, {838, 2102, 3}, {841, 2103, 5}, {846, 2104, 5}, {851, 2105, 2}, {853, 2106, 2}, {855, 2107, 2},
-      {857, 2108, 2}, {859, 2109, 2}, {861, 2250, 2}, {863, 2251, 2}, {865, 2252, 2}, {867, 2253, 2}, {869, 2254, 2},
-      {871, 2255, 2}, {873, 2256, 2}, {875, 2257, 2}, {877, 2258, 2}, {879, 2259, 3}, {882, 2260, 2}};
-
-  static constexpr auto __other_idx_   = 0u;
-  static constexpr auto __unknown_idx_ = 1u;
-
-  static constexpr char const* __get_alias_from_idx_table_idx(unsigned short __idx) {
-    return __aliases_string + __alias_index_table_[__idx];
-  }
-
-  // We're saving space by storing a giant string and a table of indexes vs storing an array of const char*
-  // because we know ahead of time the offset can fit into 2 bytes.
-
-  static constexpr char __aliases_string[] =
-      "US-ASCII\0iso-ir-6\0ANSI_X3.4-1968\0ANSI_X3.4-1986\0ISO_646.irv:1991\0ISO646-"
-      "US\0us\0IBM367\0cp367\0csASCII\0ASCII\0ISO_8859-1:1987\0iso-ir-100\0ISO_8859-1\0ISO-8859-"
-      "1\0latin1\0l1\0IBM819\0CP819\0csISOLatin1\0ISO_8859-2:1987\0iso-ir-101\0ISO_8859-2\0ISO-8859-"
-      "2\0latin2\0l2\0csISOLatin2\0ISO_8859-3:1988\0iso-ir-109\0ISO_8859-3\0ISO-8859-3\0latin3\0l3\0csISOLatin3\0ISO_"
-      "8859-4:1988\0iso-ir-110\0ISO_8859-4\0ISO-8859-4\0latin4\0l4\0csISOLatin4\0ISO_8859-5:1988\0iso-ir-144\0ISO_8859-"
-      "5\0ISO-8859-5\0cyrillic\0csISOLatinCyrillic\0ISO_8859-6:1987\0iso-ir-127\0ISO_8859-6\0ISO-8859-6\0ECMA-"
-      "114\0ASMO-708\0arabic\0csISOLatinArabic\0ISO_8859-7:1987\0iso-ir-126\0ISO_8859-7\0ISO-8859-7\0ELOT_928\0ECMA-"
-      "118\0greek\0greek8\0csISOLatinGreek\0ISO_8859-8:1988\0iso-ir-138\0ISO_8859-8\0ISO-8859-"
-      "8\0hebrew\0csISOLatinHebrew\0ISO_8859-9:1989\0iso-ir-148\0ISO_8859-9\0ISO-8859-9\0latin5\0l5\0csISOLatin5\0ISO-"
-      "8859-10\0iso-ir-157\0l6\0ISO_8859-10:1992\0csISOLatin6\0latin6\0ISO_6937-2-add\0iso-ir-142\0csISOTextComm\0JIS_"
-      "X0201\0X0201\0csHalfWidthKatakana\0JIS_Encoding\0csJISEncoding\0Shift_JIS\0MS_Kanji\0csShiftJIS\0Extended_UNIX_"
-      "Code_Packed_Format_for_Japanese\0csEUCPkdFmtJapanese\0EUC-JP\0Extended_UNIX_Code_Fixed_Width_for_"
-      "Japanese\0csEUCFixWidJapanese\0BS_4730\0iso-ir-4\0ISO646-GB\0gb\0uk\0csISO4UnitedKingdom\0SEN_850200_C\0iso-ir-"
-      "11\0ISO646-SE2\0se2\0csISO11SwedishForNames\0IT\0iso-ir-15\0ISO646-IT\0csISO15Italian\0ES\0iso-ir-17\0ISO646-"
-      "ES\0csISO17Spanish\0DIN_66003\0iso-ir-21\0de\0ISO646-DE\0csISO21German\0NS_4551-1\0iso-ir-60\0ISO646-"
-      "NO\0no\0csISO60DanishNorwegian\0csISO60Norwegian1\0NF_Z_62-010\0iso-ir-69\0ISO646-FR\0fr\0csISO69French\0ISO-"
-      "10646-UTF-1\0csISO10646UTF1\0ISO_646.basic:1983\0ref\0csISO646basic1983\0INVARIANT\0csINVARIANT\0ISO_646.irv:"
-      "1983\0iso-ir-2\0irv\0csISO2IntlRefVersion\0NATS-SEFI\0iso-ir-8-1\0csNATSSEFI\0NATS-SEFI-ADD\0iso-ir-8-"
-      "2\0csNATSSEFIADD\0SEN_850200_B\0iso-ir-10\0FI\0ISO646-FI\0ISO646-SE\0se\0csISO10Swedish\0KS_C_5601-1987\0iso-ir-"
-      "149\0KS_C_5601-1989\0KSC_5601\0korean\0csKSC56011987\0ISO-2022-KR\0csISO2022KR\0EUC-KR\0csEUCKR\0ISO-2022-"
-      "JP\0csISO2022JP\0ISO-2022-JP-2\0csISO2022JP2\0JIS_C6220-1969-jp\0JIS_C6220-1969\0iso-ir-13\0katakana\0x0201-"
-      "7\0csISO13JISC6220jp\0JIS_C6220-1969-ro\0iso-ir-14\0jp\0ISO646-JP\0csISO14JISC6220ro\0PT\0iso-ir-16\0ISO646-"
-      "PT\0csISO16Portuguese\0greek7-old\0iso-ir-18\0csISO18Greek7Old\0latin-greek\0iso-ir-19\0csISO19LatinGreek\0NF_Z_"
-      "62-010_(1973)\0iso-ir-25\0ISO646-FR1\0csISO25French\0Latin-greek-1\0iso-ir-27\0csISO27LatinGreek1\0ISO_"
-      "5427\0iso-ir-37\0csISO5427Cyrillic\0JIS_C6226-1978\0iso-ir-42\0csISO42JISC62261978\0BS_viewdata\0iso-ir-"
-      "47\0csISO47BSViewdata\0INIS\0iso-ir-49\0csISO49INIS\0INIS-8\0iso-ir-50\0csISO50INIS8\0INIS-cyrillic\0iso-ir-"
-      "51\0csISO51INISCyrillic\0ISO_5427:1981\0iso-ir-54\0ISO5427Cyrillic1981\0csISO54271981\0ISO_5428:1980\0iso-ir-"
-      "55\0csISO5428Greek\0GB_1988-80\0iso-ir-57\0cn\0ISO646-CN\0csISO57GB1988\0GB_2312-80\0iso-ir-"
-      "58\0chinese\0csISO58GB231280\0NS_4551-2\0ISO646-NO2\0iso-ir-61\0no2\0csISO61Norwegian2\0videotex-suppl\0iso-ir-"
-      "70\0csISO70VideotexSupp1\0PT2\0iso-ir-84\0ISO646-PT2\0csISO84Portuguese2\0ES2\0iso-ir-85\0ISO646-"
-      "ES2\0csISO85Spanish2\0MSZ_7795.3\0iso-ir-86\0ISO646-HU\0hu\0csISO86Hungarian\0JIS_C6226-1983\0iso-ir-"
-      "87\0x0208\0JIS_X0208-1983\0csISO87JISX0208\0greek7\0iso-ir-88\0csISO88Greek7\0ASMO_449\0ISO_9036\0arabic7\0iso-"
-      "ir-89\0csISO89ASMO449\0iso-ir-90\0csISO90\0JIS_C6229-1984-a\0iso-ir-91\0jp-ocr-a\0csISO91JISC62291984a\0JIS_"
-      "C6229-1984-b\0iso-ir-92\0ISO646-JP-OCR-B\0jp-ocr-b\0csISO92JISC62991984b\0JIS_C6229-1984-b-add\0iso-ir-93\0jp-"
-      "ocr-b-add\0csISO93JIS62291984badd\0JIS_C6229-1984-hand\0iso-ir-94\0jp-ocr-hand\0csISO94JIS62291984hand\0JIS_"
-      "C6229-1984-hand-add\0iso-ir-95\0jp-ocr-hand-add\0csISO95JIS62291984handadd\0JIS_C6229-1984-kana\0iso-ir-"
-      "96\0csISO96JISC62291984kana\0ISO_2033-1983\0iso-ir-98\0e13b\0csISO2033\0ANSI_X3.110-1983\0iso-ir-99\0CSA_T500-"
-      "1983\0NAPLPS\0csISO99NAPLPS\0T.61-7bit\0iso-ir-102\0csISO102T617bit\0T.61-8bit\0T.61\0iso-ir-"
-      "103\0csISO103T618bit\0ECMA-cyrillic\0iso-ir-111\0KOI8-E\0csISO111ECMACyrillic\0CSA_Z243.4-1985-1\0iso-ir-"
-      "121\0ISO646-CA\0csa7-1\0csa71\0ca\0csISO121Canadian1\0CSA_Z243.4-1985-2\0iso-ir-122\0ISO646-CA2\0csa7-"
-      "2\0csa72\0csISO122Canadian2\0CSA_Z243.4-1985-gr\0iso-ir-123\0csISO123CSAZ24341985gr\0ISO_8859-6-"
-      "E\0csISO88596E\0ISO-8859-6-E\0ISO_8859-6-I\0csISO88596I\0ISO-8859-6-I\0T.101-G2\0iso-ir-"
-      "128\0csISO128T101G2\0ISO_8859-8-E\0csISO88598E\0ISO-8859-8-E\0ISO_8859-8-I\0csISO88598I\0ISO-8859-8-I\0CSN_"
-      "369103\0iso-ir-139\0csISO139CSN369103\0JUS_I.B1.002\0iso-ir-141\0ISO646-YU\0js\0yu\0csISO141JUSIB1002\0IEC_P27-"
-      "1\0iso-ir-143\0csISO143IECP271\0JUS_I.B1.003-serb\0iso-ir-146\0serbian\0csISO146Serbian\0JUS_I.B1.003-"
-      "mac\0macedonian\0iso-ir-147\0csISO147Macedonian\0greek-ccitt\0iso-ir-150\0csISO150\0csISO150GreekCCITT\0NC_NC00-"
-      "10:81\0cuba\0iso-ir-151\0ISO646-CU\0csISO151Cuba\0ISO_6937-2-25\0iso-ir-152\0csISO6937Add\0GOST_19768-74\0ST_"
-      "SEV_358-88\0iso-ir-153\0csISO153GOST1976874\0ISO_8859-supp\0iso-ir-154\0latin1-2-5\0csISO8859Supp\0ISO_10367-"
-      "box\0iso-ir-155\0csISO10367Box\0latin-lap\0lap\0iso-ir-158\0csISO158Lap\0JIS_X0212-1990\0x0212\0iso-ir-"
-      "159\0csISO159JISX02121990\0DS_2089\0DS2089\0ISO646-DK\0dk\0csISO646Danish\0us-dk\0csUSDK\0dk-"
-      "us\0csDKUS\0KSC5636\0ISO646-KR\0csKSC5636\0UNICODE-1-1-UTF-7\0csUnicode11UTF7\0ISO-2022-CN\0csISO2022CN\0ISO-"
-      "2022-CN-EXT\0csISO2022CNEXT\0UTF-8\0csUTF8\0ISO-8859-13\0csISO885913\0ISO-8859-14\0iso-ir-199\0ISO_8859-14:"
-      "1998\0ISO_8859-14\0latin8\0iso-celtic\0l8\0csISO885914\0ISO-8859-15\0ISO_8859-15\0Latin-9\0csISO885915\0ISO-"
-      "8859-16\0iso-ir-226\0ISO_8859-16:2001\0ISO_8859-16\0latin10\0l10\0csISO885916\0GBK\0CP936\0MS936\0windows-"
-      "936\0csGBK\0GB18030\0csGB18030\0OSD_EBCDIC_DF04_15\0csOSDEBCDICDF0415\0OSD_EBCDIC_DF03_"
-      "IRV\0csOSDEBCDICDF03IRV\0OSD_EBCDIC_DF04_1\0csOSDEBCDICDF041\0ISO-11548-1\0ISO_11548-1\0ISO_TR_11548-"
-      "1\0csISO115481\0KZ-1048\0STRK1048-2002\0RK1048\0csKZ1048\0ISO-10646-UCS-2\0csUnicode\0ISO-10646-UCS-"
-      "4\0csUCS4\0ISO-10646-UCS-Basic\0csUnicodeASCII\0ISO-10646-Unicode-Latin1\0csUnicodeLatin1\0ISO-10646\0ISO-10646-"
-      "J-1\0csUnicodeJapanese\0ISO-Unicode-IBM-1261\0csUnicodeIBM1261\0ISO-Unicode-IBM-1268\0csUnicodeIBM1268\0ISO-"
-      "Unicode-IBM-1276\0csUnicodeIBM1276\0ISO-Unicode-IBM-1264\0csUnicodeIBM1264\0ISO-Unicode-IBM-"
-      "1265\0csUnicodeIBM1265\0UNICODE-1-1\0csUnicode11\0SCSU\0csSCSU\0UTF-7\0csUTF7\0UTF-16BE\0csUTF16BE\0UTF-"
-      "16LE\0csUTF16LE\0UTF-16\0csUTF16\0CESU-8\0csCESU8\0csCESU-8\0UTF-32\0csUTF32\0UTF-32BE\0csUTF32BE\0UTF-"
-      "32LE\0csUTF32LE\0BOCU-1\0csBOCU1\0csBOCU-1\0UTF-7-IMAP\0csUTF7IMAP\0ISO-8859-1-Windows-3.0-Latin-"
-      "1\0csWindows30Latin1\0ISO-8859-1-Windows-3.1-Latin-1\0csWindows31Latin1\0ISO-8859-2-Windows-Latin-"
-      "2\0csWindows31Latin2\0ISO-8859-9-Windows-Latin-5\0csWindows31Latin5\0hp-roman8\0roman8\0r8\0csHPRoman8\0Adobe-"
-      "Standard-Encoding\0csAdobeStandardEncoding\0Ventura-US\0csVenturaUS\0Ventura-"
-      "International\0csVenturaInternational\0DEC-"
-      "MCS\0dec\0csDECMCS\0IBM850\0cp850\0850\0csPC850Multilingual\0IBM852\0cp852\0852\0csPCp852\0IBM437\0cp437\0"
-      "437\0csPC8CodePage437\0PC8-Danish-Norwegian\0csPC8DanishNorwegian\0IBM862\0cp862\0862\0csPC862LatinHebrew\0PC8-"
-      "Turkish\0csPC8Turkish\0IBM-Symbols\0csIBMSymbols\0IBM-Thai\0csIBMThai\0HP-Legal\0csHPLegal\0HP-Pi-"
-      "font\0csHPPiFont\0HP-Math8\0csHPMath8\0Adobe-Symbol-Encoding\0csHPPSMath\0HP-DeskTop\0csHPDesktop\0Ventura-"
-      "Math\0csVenturaMath\0Microsoft-Publishing\0csMicrosoftPublishing\0Windows-"
-      "31J\0csWindows31J\0GB2312\0csGB2312\0Big5\0csBig5\0macintosh\0mac\0csMacintosh\0IBM037\0cp037\0ebcdic-cp-"
-      "us\0ebcdic-cp-ca\0ebcdic-cp-wt\0ebcdic-cp-nl\0csIBM037\0IBM038\0EBCDIC-"
-      "INT\0cp038\0csIBM038\0IBM273\0CP273\0csIBM273\0IBM274\0EBCDIC-BE\0CP274\0csIBM274\0IBM275\0EBCDIC-"
-      "BR\0cp275\0csIBM275\0IBM277\0EBCDIC-CP-DK\0EBCDIC-CP-NO\0csIBM277\0IBM278\0CP278\0ebcdic-cp-fi\0ebcdic-cp-"
-      "se\0csIBM278\0IBM280\0CP280\0ebcdic-cp-it\0csIBM280\0IBM281\0EBCDIC-JP-"
-      "E\0cp281\0csIBM281\0IBM284\0CP284\0ebcdic-cp-es\0csIBM284\0IBM285\0CP285\0ebcdic-cp-"
-      "gb\0csIBM285\0IBM290\0cp290\0EBCDIC-JP-kana\0csIBM290\0IBM297\0cp297\0ebcdic-cp-"
-      "fr\0csIBM297\0IBM420\0cp420\0ebcdic-cp-ar1\0csIBM420\0IBM423\0cp423\0ebcdic-cp-"
-      "gr\0csIBM423\0IBM424\0cp424\0ebcdic-cp-he\0csIBM424\0IBM500\0CP500\0ebcdic-cp-be\0ebcdic-cp-"
-      "ch\0csIBM500\0IBM851\0cp851\0851\0csIBM851\0IBM855\0cp855\0855\0csIBM855\0IBM857\0cp857\0857\0csIBM857\0IBM860\0"
-      "cp860\0860\0csIBM860\0IBM861\0cp861\0861\0cp-"
-      "is\0csIBM861\0IBM863\0cp863\0863\0csIBM863\0IBM864\0cp864\0csIBM864\0IBM865\0cp865\0865\0csIBM865\0IBM868\0CP868"
-      "\0cp-ar\0csIBM868\0IBM869\0cp869\0869\0cp-gr\0csIBM869\0IBM870\0CP870\0ebcdic-cp-roece\0ebcdic-cp-"
-      "yu\0csIBM870\0IBM871\0CP871\0ebcdic-cp-is\0csIBM871\0IBM880\0cp880\0EBCDIC-"
-      "Cyrillic\0csIBM880\0IBM891\0cp891\0csIBM891\0IBM903\0cp903\0csIBM903\0IBM904\0cp904\0904\0csIBBM904\0IBM905\0CP9"
-      "05\0ebcdic-cp-tr\0csIBM905\0IBM918\0CP918\0ebcdic-cp-ar2\0csIBM918\0IBM1026\0CP1026\0csIBM1026\0EBCDIC-AT-"
-      "DE\0csIBMEBCDICATDE\0EBCDIC-AT-DE-A\0csEBCDICATDEA\0EBCDIC-CA-FR\0csEBCDICCAFR\0EBCDIC-DK-"
-      "NO\0csEBCDICDKNO\0EBCDIC-DK-NO-A\0csEBCDICDKNOA\0EBCDIC-FI-SE\0csEBCDICFISE\0EBCDIC-FI-SE-"
-      "A\0csEBCDICFISEA\0EBCDIC-FR\0csEBCDICFR\0EBCDIC-IT\0csEBCDICIT\0EBCDIC-PT\0csEBCDICPT\0EBCDIC-"
-      "ES\0csEBCDICES\0EBCDIC-ES-A\0csEBCDICESA\0EBCDIC-ES-S\0csEBCDICESS\0EBCDIC-UK\0csEBCDICUK\0EBCDIC-"
-      "US\0csEBCDICUS\0UNKNOWN-"
-      "8BIT\0csUnknown8BiT\0MNEMONIC\0csMnemonic\0MNEM\0csMnem\0VISCII\0csVISCII\0VIQR\0csVIQR\0KOI8-R\0csKOI8R\0HZ-GB-"
-      "2312\0IBM866\0cp866\0866\0csIBM866\0IBM775\0cp775\0csPC775Baltic\0KOI8-"
-      "U\0csKOI8U\0IBM00858\0CCSID00858\0CP00858\0PC-Multilingual-850+"
-      "euro\0csIBM00858\0IBM00924\0CCSID00924\0CP00924\0ebcdic-Latin9--"
-      "euro\0csIBM00924\0IBM01140\0CCSID01140\0CP01140\0ebcdic-us-37+"
-      "euro\0csIBM01140\0IBM01141\0CCSID01141\0CP01141\0ebcdic-de-273+"
-      "euro\0csIBM01141\0IBM01142\0CCSID01142\0CP01142\0ebcdic-dk-277+euro\0ebcdic-no-277+"
-      "euro\0csIBM01142\0IBM01143\0CCSID01143\0CP01143\0ebcdic-fi-278+euro\0ebcdic-se-278+"
-      "euro\0csIBM01143\0IBM01144\0CCSID01144\0CP01144\0ebcdic-it-280+"
-      "euro\0csIBM01144\0IBM01145\0CCSID01145\0CP01145\0ebcdic-es-284+"
-      "euro\0csIBM01145\0IBM01146\0CCSID01146\0CP01146\0ebcdic-gb-285+"
-      "euro\0csIBM01146\0IBM01147\0CCSID01147\0CP01147\0ebcdic-fr-297+"
-      "euro\0csIBM01147\0IBM01148\0CCSID01148\0CP01148\0ebcdic-international-500+"
-      "euro\0csIBM01148\0IBM01149\0CCSID01149\0CP01149\0ebcdic-is-871+euro\0csIBM01149\0Big5-"
-      "HKSCS\0csBig5HKSCS\0IBM1047\0IBM-1047\0csIBM1047\0PTCP154\0csPTCP154\0PT154\0CP154\0Cyrillic-Asian\0Amiga-"
-      "1251\0Ami1251\0Amiga1251\0Ami-1251\0csAmiga1251\0KOI7-"
-      "switched\0csKOI7switched\0BRF\0csBRF\0TSCII\0csTSCII\0CP51932\0csCP51932\0windows-874\0cswindows874\0windows-"
-      "1250\0cswindows1250\0windows-1251\0cswindows1251\0windows-1252\0cswindows1252\0windows-"
-      "1253\0cswindows1253\0windows-1254\0cswindows1254\0windows-1255\0cswindows1255\0windows-"
-      "1256\0cswindows1256\0windows-1257\0cswindows1257\0windows-1258\0cswindows1258\0TIS-620\0csTIS620\0ISO-8859-"
-      "11\0CP50220\0csCP50220\0";
-
-  static constexpr unsigned short __alias_index_table_[] = {
-      sizeof(__aliases_string) - 1,
-      sizeof(__aliases_string) - 1,
-      0,
-      9,
-      18,
-      33,
-      48,
-      65,
-      75,
-      78,
-      85,
-      91,
-      99,
-      105,
-      121,
-      132,
-      143,
-      154,
-      161,
-      164,
-      171,
-      177,
-      189,
-      205,
-      216,
-      227,
-      238,
-      245,
-      248,
-      260,
-      276,
-      287,
-      298,
-      309,
-      316,
-      319,
-      331,
-      347,
-      358,
-      369,
-      380,
-      387,
-      390,
-      402,
-      418,
-      429,
-      440,
-      451,
-      460,
-      479,
-      495,
-      506,
-      517,
-      528,
-      537,
-      546,
-      553,
-      570,
-      586,
-      597,
-      608,
-      619,
-      628,
-      637,
-      643,
-      650,
-      666,
-      682,
-      693,
-      704,
-      715,
-      722,
-      739,
-      755,
-      766,
-      777,
-      788,
-      795,
-      798,
-      810,
-      822,
-      833,
-      836,
-      853,
-      865,
-      872,
-      887,
-      898,
-      912,
-      922,
-      928,
-      948,
-      961,
-      975,
-      985,
-      994,
-      1005,
-      1051,
-      1071,
-      1078,
-      1122,
-      1142,
-      1150,
-      1159,
-      1169,
-      1172,
-      1175,
-      1195,
-      1208,
-      1218,
-      1229,
-      1233,
-      1256,
-      1259,
-      1269,
-      1279,
-      1294,
-      1297,
-      1307,
-      1317,
-      1332,
-      1342,
-      1352,
-      1355,
-      1365,
-      1379,
-      1389,
-      1399,
-      1409,
-      1412,
-      1435,
-      1453,
-      1465,
-      1475,
-      1485,
-      1488,
-      1502,
-      1518,
-      1533,
-      1552,
-      1556,
-      1574,
-      1584,
-      1596,
-      1613,
-      1622,
-      1626,
-      1647,
-      1657,
-      1668,
-      1679,
-      1693,
-      1704,
-      1718,
-      1731,
-      1741,
-      1744,
-      1754,
-      1764,
-      1767,
-      1782,
-      1797,
-      1808,
-      1823,
-      1832,
-      1839,
-      1853,
-      1865,
-      1877,
-      1884,
-      1892,
-      1904,
-      1916,
-      1930,
-      1943,
-      1961,
-      1976,
-      1986,
-      1995,
-      2003,
-      2021,
-      2039,
-      2049,
-      2052,
-      2062,
-      2080,
-      2083,
-      2093,
-      2103,
-      2121,
-      2132,
-      2142,
-      2159,
-      2171,
-      2181,
-      2199,
-      2218,
-      2228,
-      2239,
-      2253,
-      2267,
-      2277,
-      2296,
-      2305,
-      2315,
-      2333,
-      2348,
-      2358,
-      2378,
-      2390,
-      2400,
-      2418,
-      2423,
-      2433,
-      2445,
-      2452,
-      2462,
-      2475,
-      2489,
-      2499,
-      2519,
-      2533,
-      2543,
-      2563,
-      2577,
-      2591,
-      2601,
-      2616,
-      2627,
-      2637,
-      2640,
-      2650,
-      2664,
-      2675,
-      2685,
-      2693,
-      2709,
-      2719,
-      2730,
-      2740,
-      2744,
-      2762,
-      2777,
-      2787,
-      2808,
-      2812,
-      2822,
-      2833,
-      2852,
-      2856,
-      2866,
-      2877,
-      2893,
-      2904,
-      2914,
-      2924,
-      2927,
-      2944,
-      2959,
-      2969,
-      2975,
-      2990,
-      3006,
-      3013,
-      3023,
-      3037,
-      3046,
-      3055,
-      3063,
-      3073,
-      3088,
-      3098,
-      3106,
-      3123,
-      3133,
-      3142,
-      3163,
-      3180,
-      3190,
-      3206,
-      3215,
-      3236,
-      3257,
-      3267,
-      3280,
-      3303,
-      3323,
-      3333,
-      3345,
-      3368,
-      3392,
-      3402,
-      3418,
-      3444,
-      3464,
-      3474,
-      3498,
-      3512,
-      3522,
-      3527,
-      3537,
-      3554,
-      3564,
-      3578,
-      3585,
-      3599,
-      3609,
-      3620,
-      3636,
-      3646,
-      3651,
-      3662,
-      3678,
-      3692,
-      3703,
-      3710,
-      3731,
-      3749,
-      3760,
-      3770,
-      3777,
-      3783,
-      3786,
-      3804,
-      3822,
-      3833,
-      3844,
-      3851,
-      3857,
-      3875,
-      3894,
-      3905,
-      3928,
-      3941,
-      3953,
-      3966,
-      3979,
-      3991,
-      4004,
-      4013,
-      4024,
-      4039,
-      4052,
-      4064,
-      4077,
-      4090,
-      4102,
-      4115,
-      4126,
-      4137,
-      4155,
-      4168,
-      4179,
-      4189,
-      4192,
-      4195,
-      4213,
-      4223,
-      4234,
-      4250,
-      4268,
-      4279,
-      4287,
-      4303,
-      4320,
-      4331,
-      4342,
-      4361,
-      4373,
-      4384,
-      4393,
-      4412,
-      4426,
-      4431,
-      4442,
-      4452,
-      4465,
-      4479,
-      4490,
-      4503,
-      4517,
-      4531,
-      4542,
-      4562,
-      4576,
-      4587,
-      4598,
-      4612,
-      4626,
-      4637,
-      4651,
-      4661,
-      4665,
-      4676,
-      4688,
-      4703,
-      4709,
-      4720,
-      4741,
-      4749,
-      4756,
-      4766,
-      4769,
-      4784,
-      4790,
-      4797,
-      4803,
-      4810,
-      4818,
-      4828,
-      4838,
-      4856,
-      4872,
-      4884,
-      4896,
-      4912,
-      4927,
-      4933,
-      4940,
-      4952,
-      4964,
-      4976,
-      4987,
-      5004,
-      5016,
-      5023,
-      5034,
-      5037,
-      5049,
-      5061,
-      5073,
-      5081,
-      5093,
-      5105,
-      5116,
-      5133,
-      5145,
-      5153,
-      5157,
-      5169,
-      5173,
-      5179,
-      5185,
-      5197,
-      5203,
-      5211,
-      5221,
-      5240,
-      5258,
-      5278,
-      5297,
-      5315,
-      5332,
-      5344,
-      5356,
-      5371,
-      5383,
-      5391,
-      5405,
-      5412,
-      5421,
-      5437,
-      5447,
-      5463,
-      5470,
-      5490,
-      5505,
-      5530,
-      5546,
-      5556,
-      5570,
-      5588,
-      5609,
-      5626,
-      5647,
-      5664,
-      5685,
-      5702,
-      5723,
-      5740,
-      5761,
-      5778,
-      5790,
-      5802,
-      5807,
-      5814,
-      5820,
-      5827,
-      5836,
-      5846,
-      5855,
-      5865,
-      5872,
-      5880,
-      5887,
-      5895,
-      5904,
-      5911,
-      5919,
-      5928,
-      5938,
-      5947,
-      5957,
-      5964,
-      5972,
-      5981,
-      5992,
-      6003,
-      6034,
-      6052,
-      6083,
-      6101,
-      6128,
-      6146,
-      6173,
-      6191,
-      6201,
-      6208,
-      6211,
-      6222,
-      6246,
-      6270,
-      6281,
-      6293,
-      6315,
-      6338,
-      6346,
-      6350,
-      6359,
-      6366,
-      6372,
-      6376,
-      6396,
-      6403,
-      6409,
-      6413,
-      6422,
-      6429,
-      6435,
-      6439,
-      6456,
-      6477,
-      6498,
-      6505,
-      6511,
-      6515,
-      6534,
-      6546,
-      6559,
-      6571,
-      6584,
-      6593,
-      6603,
-      6612,
-      6622,
-      6633,
-      6644,
-      6653,
-      6663,
-      6685,
-      6696,
-      6707,
-      6719,
-      6732,
-      6746,
-      6767,
-      6789,
-      6801,
-      6814,
-      6821,
-      6830,
-      6835,
-      6842,
-      6852,
-      6856,
-      6868,
-      6875,
-      6881,
-      6894,
-      6907,
-      6920,
-      6933,
-      6942,
-      6949,
-      6960,
-      6966,
-      6975,
-      6982,
-      6988,
-      6997,
-      7004,
-      7014,
-      7020,
-      7029,
-      7036,
-      7046,
-      7052,
-      7061,
-      7068,
-      7081,
-      7094,
-      7103,
-      7110,
-      7116,
-      7129,
-      7142,
-      7151,
-      7158,
-      7164,
-      7177,
-      7186,
-      7193,
-      7205,
-      7211,
-      7220,
-      7227,
-      7233,
-      7246,
-      7255,
-      7262,
-      7268,
-      7281,
-      7290,
-      7297,
-      7303,
-      7318,
-      7327,
-      7334,
-      7340,
-      7353,
-      7362,
-      7369,
-      7375,
-      7389,
-      7398,
-      7405,
-      7411,
-      7424,
-      7433,
-      7440,
-      7446,
-      7459,
-      7468,
-      7475,
-      7481,
-      7494,
-      7507,
-      7516,
-      7523,
-      7529,
-      7533,
-      7542,
-      7549,
-      7555,
-      7559,
-      7568,
-      7575,
-      7581,
-      7585,
-      7594,
-      7601,
-      7607,
-      7611,
-      7620,
-      7627,
-      7633,
-      7637,
-      7643,
-      7652,
-      7659,
-      7665,
-      7669,
-      7678,
-      7685,
-      7691,
-      7700,
-      7707,
-      7713,
-      7717,
-      7726,
-      7733,
-      7739,
-      7745,
-      7754,
-      7761,
-      7767,
-      7771,
-      7777,
-      7786,
-      7793,
-      7799,
-      7815,
-      7828,
-      7837,
-      7844,
-      7850,
-      7863,
-      7872,
-      7879,
-      7885,
-      7901,
-      7910,
-      7917,
-      7923,
-      7932,
-      7939,
-      7945,
-      7954,
-      7961,
-      7967,
-      7971,
-      7981,
-      7988,
-      7994,
-      8007,
-      8016,
-      8023,
-      8029,
-      8043,
-      8052,
-      8060,
-      8067,
-      8077,
-      8090,
-      8106,
-      8121,
-      8135,
-      8148,
-      8161,
-      8174,
-      8187,
-      8202,
-      8216,
-      8229,
-      8242,
-      8257,
-      8271,
-      8281,
-      8292,
-      8302,
-      8313,
-      8323,
-      8334,
-      8344,
-      8355,
-      8367,
-      8379,
-      8391,
-      8403,
-      8413,
-      8424,
-      8434,
-      8445,
-      8458,
-      8472,
-      8481,
-      8492,
-      8497,
-      8504,
-      8511,
-      8520,
-      8525,
-      8532,
-      8539,
-      8547,
-      8558,
-      8565,
-      8571,
-      8575,
-      8584,
-      8591,
-      8597,
-      8611,
-      8618,
-      8626,
-      8635,
-      8646,
-      8654,
-      8679,
-      8690,
-      8699,
-      8710,
-      8718,
-      8738,
-      8749,
-      8758,
-      8769,
-      8777,
-      8795,
-      8806,
-      8815,
-      8826,
-      8834,
-      8853,
-      8864,
-      8873,
-      8884,
-      8892,
-      8911,
-      8930,
-      8941,
-      8950,
-      8961,
-      8969,
-      8988,
-      9007,
-      9018,
-      9027,
-      9038,
-      9046,
-      9065,
-      9076,
-      9085,
-      9096,
-      9104,
-      9123,
-      9134,
-      9143,
-      9154,
-      9162,
-      9181,
-      9192,
-      9201,
-      9212,
-      9220,
-      9239,
-      9250,
-      9259,
-      9270,
-      9278,
-      9308,
-      9319,
-      9328,
-      9339,
-      9347,
-      9366,
-      9377,
-      9388,
-      9400,
-      9408,
-      9417,
-      9427,
-      9435,
-      9445,
-      9451,
-      9457,
-      9472,
-      9483,
-      9491,
-      9501,
-      9510,
-      9522,
-      9536,
-      9551,
-      9555,
-      9561,
-      9567,
-      9575,
-      9583,
-      9593,
-      9605,
-      9618,
-      9631,
-      9645,
-      9658,
-      9672,
-      9685,
-      9699,
-      9712,
-      9726,
-      9739,
-      9753,
-      9766,
-      9780,
-      9793,
-      9807,
-      9820,
-      9834,
-      9847,
-      9861,
-      9869,
-      9878,
-      9890,
-      9898,
-  };
-};
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP_STD_VER >= 23
-
-_LIBCPP_POP_MACROS
-
-#endif // _LIBCPP__TEXT_ENCODING_TE_IMPL_H
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index e96779a983f60..f6dec2f84b6dc 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2112,12 +2112,10 @@ module std [system] {
   }
 
   module text_encoding {
-    module text_encoding { header "__text_encoding/te_impl.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
index dd2dcd998294b..e06ea4a0893d3 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -68,53 +68,517 @@ struct text_encoding
 
 #  if _LIBCPP_STD_VER >= 26
 
+#    include <__algorithm/lower_bound.h>
 #    include <__functional/hash.h>
 #    include <__ranges/enable_borrowed_range.h>
 #    include <__ranges/view_interface.h>
-#    include <__text_encoding/te_impl.h>
 #    include <string_view>
 #    include <version>
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 struct text_encoding {
+  enum class id : int_least32_t {
+    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, // NATS-DANO (33) and NATS-DANO-ADD (34) are omitted by the standard.
+    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,
+    IBM904                  = 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
+  };
+
 private:
-  __te_impl __impl_;
-  _LIBCPP_HIDE_FROM_ABI constexpr explicit text_encoding(__te_impl&& __imp) : __impl_(__imp) {}
+  static constexpr int __NATS_DANO_     = 33;
+  static constexpr int __NATS_DANO_ADD_ = 34;
+
+  // A __te_data structure stores:
+  // Index into an table of indexes that is an offset in the giant aliases string
+  // The MIB of that text encoding
+  // Number of aliases
+  struct __te_data {
+    unsigned short __first_alias_index_;
+    unsigned short __mib_rep_;
+    unsigned char __num_aliases_;
+
+    _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __te_data& __enc, id __i) noexcept {
+      return __enc.__mib_rep_ < static_cast<unsigned short>(__i);
+    }
+  };
+
+  _LIBCPP_HIDE_FROM_ABI static constexpr bool __comp_name(string_view __a, string_view __b) noexcept {
+    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 {
+      if (__n == '0') {
+        return __in_number ? '0' : 255;
+      }
+      __in_number = __n >= '1' && __n <= '9';
+
+      if ((__n >= '1' && __n <= '9') || (__n >= 'a' && __n <= 'z')) {
+        return __n;
+      }
+      if (__n >= 'A' && __n <= 'Z') {
+        return __n + ('a' - 'A'); // tolower
+      }
+
+      return 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_ptr != __a.end() && (__a_val = __map_char(*__a_ptr, __a_in_number)) == 255)
+        __a_ptr++;
+      while (__b_ptr != __b.end() && (__b_val = __map_char(*__b_ptr, __b_in_number)) == 255)
+        __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 unsigned short __find_data_idx(string_view __a) noexcept {
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__a.size() <= max_name_length, "input string_view must have size <= 63");
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__a.contains('\0'), "input string_view must not contain '\\0'");
+
+    auto __pred = [&__a](const __te_data& __entry) -> bool {
+      // Search aliases of text encoding for string
+      aliases_view __aliases(__entry);
+      return std::find_if(__aliases.begin(), __aliases.end(), [&__a](auto __alias) {
+               return __comp_name(__a, __alias);
+             }) != __aliases.end();
+    };
+
+    const __te_data* __found = std::find_if(__entries + 2, std::end(__entries), __pred);
+    if (__found == std::end(__entries)) {
+      return __other_idx_; // other
+    }
+
+    return __found - __entries;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI static constexpr unsigned short __find_data_idx_by_id(id __i) noexcept {
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__i >= id::other, "invalid text_encoding::id passed");
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__i <= id::CP50220, "invalid text_encoding::id passed");
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(int_least32_t(__i) != __NATS_DANO_, "Mib for NATS-DANO used");
+    _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(int_least32_t(__i) != __NATS_DANO_ADD_, "Mib for NATS-DANO-ADD used");
+    auto __found = std::lower_bound(std::begin(__entries), std::end(__entries), __i);
+
+    if (__found == std::end(__entries)) {
+      return __unknown_idx_; // unknown
+    }
+
+    return __found - __entries;
+  }
 
 public:
-  static constexpr auto max_name_length = __te_impl::__max_name_length_;
-  using id                              = __te_impl::__id;
-  using aliases_view                    = __te_impl::__aliases_view;
   using enum id;
+  static constexpr size_t max_name_length = 63;
+
+  // [text.encoding.aliases], class text_encoding::aliases_view
+  struct aliases_view : ranges::view_interface<aliases_view> {
+    struct __iterator {
+      using iterator_concept  = random_access_iterator_tag;
+      using iterator_category = random_access_iterator_tag;
+      using value_type        = const char*;
+      using reference         = const char*;
+      using difference_type   = decltype(static_cast<unsigned short>(1) - static_cast<unsigned short>(1));
+
+      constexpr __iterator() noexcept = default;
+
+      _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const noexcept {
+        return __get_alias_from_idx_table_idx(__current_idx_);
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const noexcept {
+        auto __it = *this;
+        return *(__it + __n);
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator->() = delete;
+
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(__iterator __it, difference_type __n) noexcept {
+        __it += __n;
+        return __it;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, __iterator __it) noexcept {
+        __it += __n;
+        return __it;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(__iterator __it, difference_type __n) noexcept {
+        __it -= __n;
+        return __it;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __iterator& __other) const noexcept {
+        return __current_idx_ - __other.__current_idx_;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() noexcept {
+        __current_idx_++;
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int) noexcept {
+        auto __old = *this;
+        __current_idx_++;
+        return __old;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() noexcept {
+        __current_idx_--;
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int) noexcept {
+        auto __old = *this;
+        __current_idx_--;
+        return __old;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n) noexcept {
+        __current_idx_ += __n;
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n) noexcept { return (*this += -__n); }
+
+      _LIBCPP_HIDE_FROM_ABI friend constexpr auto
+      operator<=>(const __iterator& __it, const __iterator& __it2) noexcept = default;
+
+    private:
+      friend struct aliases_view;
+
+      _LIBCPP_HIDE_FROM_ABI constexpr __iterator(unsigned short __enc_d) noexcept : __current_idx_(__enc_d) {}
+
+      unsigned short __current_idx_;
+    }; // __iterator
+
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const noexcept { return __iterator(__first_idx_); }
+
+    _LIBCPP_HIDE_FROM_ABI constexpr __iterator end() const noexcept { return __iterator(__last_idx_); }
+
+  private:
+    friend struct text_encoding;
+
+    _LIBCPP_HIDE_FROM_ABI constexpr aliases_view(const __te_data& __d)
+        : __first_idx_(__d.__first_alias_index_), __last_idx_(__d.__first_alias_index_ + __d.__num_aliases_) {}
+
+    unsigned short __first_idx_;
+    unsigned short __last_idx_;
+  }; // aliases_view
 
   _LIBCPP_HIDE_FROM_ABI constexpr text_encoding() = default;
-  _LIBCPP_HIDE_FROM_ABI constexpr explicit text_encoding(string_view __enc) noexcept : __impl_(__enc) {}
-  _LIBCPP_HIDE_FROM_ABI constexpr text_encoding(id __i) noexcept : __impl_(__i) {}
 
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr id mib() const noexcept { return __impl_.__mib(); }
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const char* name() const noexcept { return __impl_.__name(); }
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr aliases_view aliases() const noexcept { return __impl_.__aliases(); }
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit text_encoding(string_view __enc) noexcept
+      : __encoding_idx_(__find_data_idx(__enc)) {
+    __enc.copy(__name_, max_name_length, 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr text_encoding(id __i) noexcept : __encoding_idx_(__find_data_idx_by_id(__i)) {
+    const char* __alias = __get_alias_from_idx_table_idx(__get().__first_alias_index_);
+    if (__alias[0] != '\0') {
+      string_view(__alias).copy(__name_, max_name_length);
+    }
+  }
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr id mib() const noexcept { return id(__get().__mib_rep_); }
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const char* name() const noexcept { return __name_; }
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr aliases_view aliases() const noexcept { return aliases_view(__get()); }
 
   _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const text_encoding& __a, const text_encoding& __b) noexcept {
-    return __a.__impl_ == __b.__impl_;
+    return __a.mib() == id::other && __b.mib() == id::other
+             ? __comp_name(__a.__name_, __b.__name_)
+             : __a.mib() == __b.mib();
   }
 
-  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const text_encoding& __enc, const id __i) noexcept {
-    return __enc.__impl_ == __i;
+  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const text_encoding& __encoding, id __i) noexcept {
+    return __encoding.mib() == __i;
   }
 
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval text_encoding literal() noexcept {
-    return text_encoding(__te_impl::__literal());
+    // TODO: Remove this branch once we have __GNUC_EXECUTION_CHARSET_NAME or __clang_literal_encoding__ unconditionally
+#    ifdef __GNUC_EXECUTION_CHARSET_NAME
+    return __te_impl(__GNUC_EXECUTION_CHARSET_NAME);
+#    elif defined(__clang_literal_encoding__)
+    return text_encoding(__clang_literal_encoding__);
+#    else
+    return __te_impl();
+#    endif
   }
-#    if _LIBCPP_HAS_LOCALIZATION && (!defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26))
-  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static text_encoding environment() {
-    return text_encoding(__te_impl::__environment());
-  };
+
+#    if _LIBCPP_HAS_LOCALIZATION
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI static text_encoding environment();
 
   template <id _Id>
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool environment_is() {
-    return __te_impl::__environment_is<_Id>();
+    return environment() == _Id;
   }
 #    else
   static text_encoding environment() = delete;
@@ -122,6 +586,1070 @@ public:
   template <id _Id>
   static bool environment_is() = delete;
 #    endif
+
+private:
+  constexpr const __te_data& __get() const { return __entries[__encoding_idx_]; }
+
+  static constexpr char const* __get_alias_from_idx_table_idx(unsigned short __idx) {
+    return __aliases_string + __alias_index_table_[__idx];
+  }
+
+  static constexpr auto __other_idx_   = 0u;
+  static constexpr auto __unknown_idx_ = 1u;
+
+  unsigned short __encoding_idx_{1u};
+  char __name_[max_name_length + 1]{};
+
+  // Structuring the text encoding data and the table in this manner has a few benefits:
+  // Smaller footprint: We only need 6 bytes for the information we need.
+  // Smaller total table: We only need one entry per Mib.
+  // Easier aliases_view: We know the begin, and end of each range of aliases, which makes iterator
+  // implementation simple.
+
+  static constexpr __te_data __entries[] = {
+      {0, 1, 0},      {1, 2, 0},      {2, 3, 11},     {13, 4, 9},     {22, 5, 7},     {29, 6, 7},     {36, 7, 7},
+      {43, 8, 6},     {49, 9, 8},     {57, 10, 9},    {66, 11, 6},    {72, 12, 7},    {79, 13, 6},    {85, 14, 3},
+      {88, 15, 3},    {91, 16, 2},    {93, 17, 3},    {96, 18, 3},    {99, 19, 2},    {101, 20, 6},   {107, 21, 5},
+      {112, 22, 4},   {116, 23, 4},   {120, 24, 5},   {125, 25, 6},   {131, 26, 5},   {136, 27, 2},   {138, 28, 3},
+      {141, 29, 2},   {143, 30, 4},   {147, 31, 3},   {150, 32, 3},   {153, 35, 7},   {160, 36, 6},   {166, 37, 2},
+      {168, 38, 2},   {170, 39, 2},   {172, 40, 2},   {174, 41, 6},   {180, 42, 5},   {185, 43, 4},   {189, 44, 3},
+      {192, 45, 3},   {195, 46, 4},   {199, 47, 3},   {202, 48, 3},   {205, 49, 3},   {208, 50, 3},   {211, 51, 3},
+      {214, 52, 3},   {217, 53, 3},   {220, 54, 4},   {224, 55, 3},   {227, 56, 5},   {232, 57, 4},   {236, 58, 5},
+      {241, 59, 3},   {244, 60, 4},   {248, 61, 4},   {252, 62, 5},   {257, 63, 5},   {262, 64, 3},   {265, 65, 5},
+      {270, 66, 2},   {272, 67, 4},   {276, 68, 5},   {281, 69, 4},   {285, 70, 4},   {289, 71, 4},   {293, 72, 3},
+      {296, 73, 4},   {300, 74, 5},   {305, 75, 3},   {308, 76, 4},   {312, 77, 4},   {316, 78, 7},   {323, 79, 6},
+      {329, 80, 3},   {332, 81, 3},   {335, 82, 3},   {338, 83, 3},   {341, 84, 3},   {344, 85, 3},   {347, 86, 3},
+      {350, 87, 6},   {356, 88, 3},   {359, 89, 4},   {363, 90, 4},   {367, 91, 4},   {371, 92, 5},   {376, 93, 3},
+      {379, 94, 4},   {383, 95, 4},   {387, 96, 3},   {390, 97, 4},   {394, 98, 4},   {398, 99, 5},   {403, 100, 2},
+      {405, 101, 2},  {407, 102, 3},  {410, 103, 2},  {412, 104, 2},  {414, 105, 2},  {416, 106, 2},  {418, 109, 2},
+      {420, 110, 8},  {428, 111, 4},  {432, 112, 7},  {439, 113, 5},  {444, 114, 2},  {446, 115, 2},  {448, 116, 2},
+      {450, 117, 2},  {452, 118, 4},  {456, 119, 4},  {460, 1000, 2}, {462, 1001, 2}, {464, 1002, 2}, {466, 1003, 3},
+      {469, 1004, 2}, {471, 1005, 2}, {473, 1006, 2}, {475, 1007, 2}, {477, 1008, 2}, {479, 1009, 2}, {481, 1010, 2},
+      {483, 1011, 2}, {485, 1012, 2}, {487, 1013, 2}, {489, 1014, 2}, {491, 1015, 2}, {493, 1016, 3}, {496, 1017, 2},
+      {498, 1018, 2}, {500, 1019, 2}, {502, 1020, 3}, {505, 1021, 2}, {507, 2000, 2}, {509, 2001, 2}, {511, 2002, 2},
+      {513, 2003, 2}, {515, 2004, 4}, {519, 2005, 2}, {521, 2006, 2}, {523, 2007, 2}, {525, 2008, 3}, {528, 2009, 4},
+      {532, 2010, 4}, {536, 2011, 4}, {540, 2012, 2}, {542, 2013, 4}, {546, 2014, 2}, {548, 2015, 2}, {550, 2016, 2},
+      {552, 2017, 2}, {554, 2018, 2}, {556, 2019, 2}, {558, 2020, 2}, {560, 2021, 2}, {562, 2022, 2}, {564, 2023, 2},
+      {566, 2024, 2}, {568, 2025, 2}, {570, 2026, 2}, {572, 2027, 3}, {575, 2028, 7}, {582, 2029, 4}, {586, 2030, 3},
+      {589, 2031, 4}, {593, 2032, 4}, {597, 2033, 4}, {601, 2034, 5}, {606, 2035, 4}, {610, 2036, 4}, {614, 2037, 4},
+      {618, 2038, 4}, {622, 2039, 4}, {626, 2040, 4}, {630, 2041, 4}, {634, 2042, 4}, {638, 2043, 4}, {642, 2044, 5},
+      {647, 2045, 4}, {651, 2046, 4}, {655, 2047, 4}, {659, 2048, 4}, {663, 2049, 5}, {668, 2050, 4}, {672, 2051, 3},
+      {675, 2052, 4}, {679, 2053, 4}, {683, 2054, 5}, {688, 2055, 5}, {693, 2056, 4}, {697, 2057, 4}, {701, 2058, 3},
+      {704, 2059, 3}, {707, 2060, 4}, {711, 2061, 4}, {715, 2062, 4}, {719, 2063, 3}, {722, 2064, 2}, {724, 2065, 2},
+      {726, 2066, 2}, {728, 2067, 2}, {730, 2068, 2}, {732, 2069, 2}, {734, 2070, 2}, {736, 2071, 2}, {738, 2072, 2},
+      {740, 2073, 2}, {742, 2074, 2}, {744, 2075, 2}, {746, 2076, 2}, {748, 2077, 2}, {750, 2078, 2}, {752, 2079, 2},
+      {754, 2080, 2}, {756, 2081, 2}, {758, 2082, 2}, {760, 2083, 2}, {762, 2084, 2}, {764, 2085, 1}, {765, 2086, 4},
+      {769, 2087, 3}, {772, 2088, 2}, {774, 2089, 5}, {779, 2090, 5}, {784, 2091, 5}, {789, 2092, 5}, {794, 2093, 6},
+      {800, 2094, 6}, {806, 2095, 5}, {811, 2096, 5}, {816, 2097, 5}, {821, 2098, 5}, {826, 2099, 5}, {831, 2100, 5},
+      {836, 2101, 2}, {838, 2102, 3}, {841, 2103, 5}, {846, 2104, 5}, {851, 2105, 2}, {853, 2106, 2}, {855, 2107, 2},
+      {857, 2108, 2}, {859, 2109, 2}, {861, 2250, 2}, {863, 2251, 2}, {865, 2252, 2}, {867, 2253, 2}, {869, 2254, 2},
+      {871, 2255, 2}, {873, 2256, 2}, {875, 2257, 2}, {877, 2258, 2}, {879, 2259, 3}, {882, 2260, 2}};
+
+  // We're saving space by storing a giant string and a table of indexes vs storing an array of const char*
+  // because we know ahead of time the offset can fit into 2 bytes.
+
+  static constexpr char __aliases_string[] =
+      "US-ASCII\0iso-ir-6\0ANSI_X3.4-1968\0ANSI_X3.4-1986\0ISO_646.irv:1991\0ISO646-"
+      "US\0us\0IBM367\0cp367\0csASCII\0ASCII\0ISO_8859-1:1987\0iso-ir-100\0ISO_8859-1\0ISO-8859-"
+      "1\0latin1\0l1\0IBM819\0CP819\0csISOLatin1\0ISO_8859-2:1987\0iso-ir-101\0ISO_8859-2\0ISO-8859-"
+      "2\0latin2\0l2\0csISOLatin2\0ISO_8859-3:1988\0iso-ir-109\0ISO_8859-3\0ISO-8859-3\0latin3\0l3\0csISOLatin3\0ISO_"
+      "8859-4:1988\0iso-ir-110\0ISO_8859-4\0ISO-8859-4\0latin4\0l4\0csISOLatin4\0ISO_8859-5:1988\0iso-ir-144\0ISO_8859-"
+      "5\0ISO-8859-5\0cyrillic\0csISOLatinCyrillic\0ISO_8859-6:1987\0iso-ir-127\0ISO_8859-6\0ISO-8859-6\0ECMA-"
+      "114\0ASMO-708\0arabic\0csISOLatinArabic\0ISO_8859-7:1987\0iso-ir-126\0ISO_8859-7\0ISO-8859-7\0ELOT_928\0ECMA-"
+      "118\0greek\0greek8\0csISOLatinGreek\0ISO_8859-8:1988\0iso-ir-138\0ISO_8859-8\0ISO-8859-"
+      "8\0hebrew\0csISOLatinHebrew\0ISO_8859-9:1989\0iso-ir-148\0ISO_8859-9\0ISO-8859-9\0latin5\0l5\0csISOLatin5\0ISO-"
+      "8859-10\0iso-ir-157\0l6\0ISO_8859-10:1992\0csISOLatin6\0latin6\0ISO_6937-2-add\0iso-ir-142\0csISOTextComm\0JIS_"
+      "X0201\0X0201\0csHalfWidthKatakana\0JIS_Encoding\0csJISEncoding\0Shift_JIS\0MS_Kanji\0csShiftJIS\0Extended_UNIX_"
+      "Code_Packed_Format_for_Japanese\0csEUCPkdFmtJapanese\0EUC-JP\0Extended_UNIX_Code_Fixed_Width_for_"
+      "Japanese\0csEUCFixWidJapanese\0BS_4730\0iso-ir-4\0ISO646-GB\0gb\0uk\0csISO4UnitedKingdom\0SEN_850200_C\0iso-ir-"
+      "11\0ISO646-SE2\0se2\0csISO11SwedishForNames\0IT\0iso-ir-15\0ISO646-IT\0csISO15Italian\0ES\0iso-ir-17\0ISO646-"
+      "ES\0csISO17Spanish\0DIN_66003\0iso-ir-21\0de\0ISO646-DE\0csISO21German\0NS_4551-1\0iso-ir-60\0ISO646-"
+      "NO\0no\0csISO60DanishNorwegian\0csISO60Norwegian1\0NF_Z_62-010\0iso-ir-69\0ISO646-FR\0fr\0csISO69French\0ISO-"
+      "10646-UTF-1\0csISO10646UTF1\0ISO_646.basic:1983\0ref\0csISO646basic1983\0INVARIANT\0csINVARIANT\0ISO_646.irv:"
+      "1983\0iso-ir-2\0irv\0csISO2IntlRefVersion\0NATS-SEFI\0iso-ir-8-1\0csNATSSEFI\0NATS-SEFI-ADD\0iso-ir-8-"
+      "2\0csNATSSEFIADD\0SEN_850200_B\0iso-ir-10\0FI\0ISO646-FI\0ISO646-SE\0se\0csISO10Swedish\0KS_C_5601-1987\0iso-ir-"
+      "149\0KS_C_5601-1989\0KSC_5601\0korean\0csKSC56011987\0ISO-2022-KR\0csISO2022KR\0EUC-KR\0csEUCKR\0ISO-2022-"
+      "JP\0csISO2022JP\0ISO-2022-JP-2\0csISO2022JP2\0JIS_C6220-1969-jp\0JIS_C6220-1969\0iso-ir-13\0katakana\0x0201-"
+      "7\0csISO13JISC6220jp\0JIS_C6220-1969-ro\0iso-ir-14\0jp\0ISO646-JP\0csISO14JISC6220ro\0PT\0iso-ir-16\0ISO646-"
+      "PT\0csISO16Portuguese\0greek7-old\0iso-ir-18\0csISO18Greek7Old\0latin-greek\0iso-ir-19\0csISO19LatinGreek\0NF_Z_"
+      "62-010_(1973)\0iso-ir-25\0ISO646-FR1\0csISO25French\0Latin-greek-1\0iso-ir-27\0csISO27LatinGreek1\0ISO_"
+      "5427\0iso-ir-37\0csISO5427Cyrillic\0JIS_C6226-1978\0iso-ir-42\0csISO42JISC62261978\0BS_viewdata\0iso-ir-"
+      "47\0csISO47BSViewdata\0INIS\0iso-ir-49\0csISO49INIS\0INIS-8\0iso-ir-50\0csISO50INIS8\0INIS-cyrillic\0iso-ir-"
+      "51\0csISO51INISCyrillic\0ISO_5427:1981\0iso-ir-54\0ISO5427Cyrillic1981\0csISO54271981\0ISO_5428:1980\0iso-ir-"
+      "55\0csISO5428Greek\0GB_1988-80\0iso-ir-57\0cn\0ISO646-CN\0csISO57GB1988\0GB_2312-80\0iso-ir-"
+      "58\0chinese\0csISO58GB231280\0NS_4551-2\0ISO646-NO2\0iso-ir-61\0no2\0csISO61Norwegian2\0videotex-suppl\0iso-ir-"
+      "70\0csISO70VideotexSupp1\0PT2\0iso-ir-84\0ISO646-PT2\0csISO84Portuguese2\0ES2\0iso-ir-85\0ISO646-"
+      "ES2\0csISO85Spanish2\0MSZ_7795.3\0iso-ir-86\0ISO646-HU\0hu\0csISO86Hungarian\0JIS_C6226-1983\0iso-ir-"
+      "87\0x0208\0JIS_X0208-1983\0csISO87JISX0208\0greek7\0iso-ir-88\0csISO88Greek7\0ASMO_449\0ISO_9036\0arabic7\0iso-"
+      "ir-89\0csISO89ASMO449\0iso-ir-90\0csISO90\0JIS_C6229-1984-a\0iso-ir-91\0jp-ocr-a\0csISO91JISC62291984a\0JIS_"
+      "C6229-1984-b\0iso-ir-92\0ISO646-JP-OCR-B\0jp-ocr-b\0csISO92JISC62991984b\0JIS_C6229-1984-b-add\0iso-ir-93\0jp-"
+      "ocr-b-add\0csISO93JIS62291984badd\0JIS_C6229-1984-hand\0iso-ir-94\0jp-ocr-hand\0csISO94JIS62291984hand\0JIS_"
+      "C6229-1984-hand-add\0iso-ir-95\0jp-ocr-hand-add\0csISO95JIS62291984handadd\0JIS_C6229-1984-kana\0iso-ir-"
+      "96\0csISO96JISC62291984kana\0ISO_2033-1983\0iso-ir-98\0e13b\0csISO2033\0ANSI_X3.110-1983\0iso-ir-99\0CSA_T500-"
+      "1983\0NAPLPS\0csISO99NAPLPS\0T.61-7bit\0iso-ir-102\0csISO102T617bit\0T.61-8bit\0T.61\0iso-ir-"
+      "103\0csISO103T618bit\0ECMA-cyrillic\0iso-ir-111\0KOI8-E\0csISO111ECMACyrillic\0CSA_Z243.4-1985-1\0iso-ir-"
+      "121\0ISO646-CA\0csa7-1\0csa71\0ca\0csISO121Canadian1\0CSA_Z243.4-1985-2\0iso-ir-122\0ISO646-CA2\0csa7-"
+      "2\0csa72\0csISO122Canadian2\0CSA_Z243.4-1985-gr\0iso-ir-123\0csISO123CSAZ24341985gr\0ISO_8859-6-"
+      "E\0csISO88596E\0ISO-8859-6-E\0ISO_8859-6-I\0csISO88596I\0ISO-8859-6-I\0T.101-G2\0iso-ir-"
+      "128\0csISO128T101G2\0ISO_8859-8-E\0csISO88598E\0ISO-8859-8-E\0ISO_8859-8-I\0csISO88598I\0ISO-8859-8-I\0CSN_"
+      "369103\0iso-ir-139\0csISO139CSN369103\0JUS_I.B1.002\0iso-ir-141\0ISO646-YU\0js\0yu\0csISO141JUSIB1002\0IEC_P27-"
+      "1\0iso-ir-143\0csISO143IECP271\0JUS_I.B1.003-serb\0iso-ir-146\0serbian\0csISO146Serbian\0JUS_I.B1.003-"
+      "mac\0macedonian\0iso-ir-147\0csISO147Macedonian\0greek-ccitt\0iso-ir-150\0csISO150\0csISO150GreekCCITT\0NC_NC00-"
+      "10:81\0cuba\0iso-ir-151\0ISO646-CU\0csISO151Cuba\0ISO_6937-2-25\0iso-ir-152\0csISO6937Add\0GOST_19768-74\0ST_"
+      "SEV_358-88\0iso-ir-153\0csISO153GOST1976874\0ISO_8859-supp\0iso-ir-154\0latin1-2-5\0csISO8859Supp\0ISO_10367-"
+      "box\0iso-ir-155\0csISO10367Box\0latin-lap\0lap\0iso-ir-158\0csISO158Lap\0JIS_X0212-1990\0x0212\0iso-ir-"
+      "159\0csISO159JISX02121990\0DS_2089\0DS2089\0ISO646-DK\0dk\0csISO646Danish\0us-dk\0csUSDK\0dk-"
+      "us\0csDKUS\0KSC5636\0ISO646-KR\0csKSC5636\0UNICODE-1-1-UTF-7\0csUnicode11UTF7\0ISO-2022-CN\0csISO2022CN\0ISO-"
+      "2022-CN-EXT\0csISO2022CNEXT\0UTF-8\0csUTF8\0ISO-8859-13\0csISO885913\0ISO-8859-14\0iso-ir-199\0ISO_8859-14:"
+      "1998\0ISO_8859-14\0latin8\0iso-celtic\0l8\0csISO885914\0ISO-8859-15\0ISO_8859-15\0Latin-9\0csISO885915\0ISO-"
+      "8859-16\0iso-ir-226\0ISO_8859-16:2001\0ISO_8859-16\0latin10\0l10\0csISO885916\0GBK\0CP936\0MS936\0windows-"
+      "936\0csGBK\0GB18030\0csGB18030\0OSD_EBCDIC_DF04_15\0csOSDEBCDICDF0415\0OSD_EBCDIC_DF03_"
+      "IRV\0csOSDEBCDICDF03IRV\0OSD_EBCDIC_DF04_1\0csOSDEBCDICDF041\0ISO-11548-1\0ISO_11548-1\0ISO_TR_11548-"
+      "1\0csISO115481\0KZ-1048\0STRK1048-2002\0RK1048\0csKZ1048\0ISO-10646-UCS-2\0csUnicode\0ISO-10646-UCS-"
+      "4\0csUCS4\0ISO-10646-UCS-Basic\0csUnicodeASCII\0ISO-10646-Unicode-Latin1\0csUnicodeLatin1\0ISO-10646\0ISO-10646-"
+      "J-1\0csUnicodeJapanese\0ISO-Unicode-IBM-1261\0csUnicodeIBM1261\0ISO-Unicode-IBM-1268\0csUnicodeIBM1268\0ISO-"
+      "Unicode-IBM-1276\0csUnicodeIBM1276\0ISO-Unicode-IBM-1264\0csUnicodeIBM1264\0ISO-Unicode-IBM-"
+      "1265\0csUnicodeIBM1265\0UNICODE-1-1\0csUnicode11\0SCSU\0csSCSU\0UTF-7\0csUTF7\0UTF-16BE\0csUTF16BE\0UTF-"
+      "16LE\0csUTF16LE\0UTF-16\0csUTF16\0CESU-8\0csCESU8\0csCESU-8\0UTF-32\0csUTF32\0UTF-32BE\0csUTF32BE\0UTF-"
+      "32LE\0csUTF32LE\0BOCU-1\0csBOCU1\0csBOCU-1\0UTF-7-IMAP\0csUTF7IMAP\0ISO-8859-1-Windows-3.0-Latin-"
+      "1\0csWindows30Latin1\0ISO-8859-1-Windows-3.1-Latin-1\0csWindows31Latin1\0ISO-8859-2-Windows-Latin-"
+      "2\0csWindows31Latin2\0ISO-8859-9-Windows-Latin-5\0csWindows31Latin5\0hp-roman8\0roman8\0r8\0csHPRoman8\0Adobe-"
+      "Standard-Encoding\0csAdobeStandardEncoding\0Ventura-US\0csVenturaUS\0Ventura-"
+      "International\0csVenturaInternational\0DEC-"
+      "MCS\0dec\0csDECMCS\0IBM850\0cp850\0850\0csPC850Multilingual\0IBM852\0cp852\0852\0csPCp852\0IBM437\0cp437\0"
+      "437\0csPC8CodePage437\0PC8-Danish-Norwegian\0csPC8DanishNorwegian\0IBM862\0cp862\0862\0csPC862LatinHebrew\0PC8-"
+      "Turkish\0csPC8Turkish\0IBM-Symbols\0csIBMSymbols\0IBM-Thai\0csIBMThai\0HP-Legal\0csHPLegal\0HP-Pi-"
+      "font\0csHPPiFont\0HP-Math8\0csHPMath8\0Adobe-Symbol-Encoding\0csHPPSMath\0HP-DeskTop\0csHPDesktop\0Ventura-"
+      "Math\0csVenturaMath\0Microsoft-Publishing\0csMicrosoftPublishing\0Windows-"
+      "31J\0csWindows31J\0GB2312\0csGB2312\0Big5\0csBig5\0macintosh\0mac\0csMacintosh\0IBM037\0cp037\0ebcdic-cp-"
+      "us\0ebcdic-cp-ca\0ebcdic-cp-wt\0ebcdic-cp-nl\0csIBM037\0IBM038\0EBCDIC-"
+      "INT\0cp038\0csIBM038\0IBM273\0CP273\0csIBM273\0IBM274\0EBCDIC-BE\0CP274\0csIBM274\0IBM275\0EBCDIC-"
+      "BR\0cp275\0csIBM275\0IBM277\0EBCDIC-CP-DK\0EBCDIC-CP-NO\0csIBM277\0IBM278\0CP278\0ebcdic-cp-fi\0ebcdic-cp-"
+      "se\0csIBM278\0IBM280\0CP280\0ebcdic-cp-it\0csIBM280\0IBM281\0EBCDIC-JP-"
+      "E\0cp281\0csIBM281\0IBM284\0CP284\0ebcdic-cp-es\0csIBM284\0IBM285\0CP285\0ebcdic-cp-"
+      "gb\0csIBM285\0IBM290\0cp290\0EBCDIC-JP-kana\0csIBM290\0IBM297\0cp297\0ebcdic-cp-"
+      "fr\0csIBM297\0IBM420\0cp420\0ebcdic-cp-ar1\0csIBM420\0IBM423\0cp423\0ebcdic-cp-"
+      "gr\0csIBM423\0IBM424\0cp424\0ebcdic-cp-he\0csIBM424\0IBM500\0CP500\0ebcdic-cp-be\0ebcdic-cp-"
+      "ch\0csIBM500\0IBM851\0cp851\0851\0csIBM851\0IBM855\0cp855\0855\0csIBM855\0IBM857\0cp857\0857\0csIBM857\0IBM860\0"
+      "cp860\0860\0csIBM860\0IBM861\0cp861\0861\0cp-"
+      "is\0csIBM861\0IBM863\0cp863\0863\0csIBM863\0IBM864\0cp864\0csIBM864\0IBM865\0cp865\0865\0csIBM865\0IBM868\0CP868"
+      "\0cp-ar\0csIBM868\0IBM869\0cp869\0869\0cp-gr\0csIBM869\0IBM870\0CP870\0ebcdic-cp-roece\0ebcdic-cp-"
+      "yu\0csIBM870\0IBM871\0CP871\0ebcdic-cp-is\0csIBM871\0IBM880\0cp880\0EBCDIC-"
+      "Cyrillic\0csIBM880\0IBM891\0cp891\0csIBM891\0IBM903\0cp903\0csIBM903\0IBM904\0cp904\0904\0csIBBM904\0IBM905\0CP9"
+      "05\0ebcdic-cp-tr\0csIBM905\0IBM918\0CP918\0ebcdic-cp-ar2\0csIBM918\0IBM1026\0CP1026\0csIBM1026\0EBCDIC-AT-"
+      "DE\0csIBMEBCDICATDE\0EBCDIC-AT-DE-A\0csEBCDICATDEA\0EBCDIC-CA-FR\0csEBCDICCAFR\0EBCDIC-DK-"
+      "NO\0csEBCDICDKNO\0EBCDIC-DK-NO-A\0csEBCDICDKNOA\0EBCDIC-FI-SE\0csEBCDICFISE\0EBCDIC-FI-SE-"
+      "A\0csEBCDICFISEA\0EBCDIC-FR\0csEBCDICFR\0EBCDIC-IT\0csEBCDICIT\0EBCDIC-PT\0csEBCDICPT\0EBCDIC-"
+      "ES\0csEBCDICES\0EBCDIC-ES-A\0csEBCDICESA\0EBCDIC-ES-S\0csEBCDICESS\0EBCDIC-UK\0csEBCDICUK\0EBCDIC-"
+      "US\0csEBCDICUS\0UNKNOWN-"
+      "8BIT\0csUnknown8BiT\0MNEMONIC\0csMnemonic\0MNEM\0csMnem\0VISCII\0csVISCII\0VIQR\0csVIQR\0KOI8-R\0csKOI8R\0HZ-GB-"
+      "2312\0IBM866\0cp866\0866\0csIBM866\0IBM775\0cp775\0csPC775Baltic\0KOI8-"
+      "U\0csKOI8U\0IBM00858\0CCSID00858\0CP00858\0PC-Multilingual-850+"
+      "euro\0csIBM00858\0IBM00924\0CCSID00924\0CP00924\0ebcdic-Latin9--"
+      "euro\0csIBM00924\0IBM01140\0CCSID01140\0CP01140\0ebcdic-us-37+"
+      "euro\0csIBM01140\0IBM01141\0CCSID01141\0CP01141\0ebcdic-de-273+"
+      "euro\0csIBM01141\0IBM01142\0CCSID01142\0CP01142\0ebcdic-dk-277+euro\0ebcdic-no-277+"
+      "euro\0csIBM01142\0IBM01143\0CCSID01143\0CP01143\0ebcdic-fi-278+euro\0ebcdic-se-278+"
+      "euro\0csIBM01143\0IBM01144\0CCSID01144\0CP01144\0ebcdic-it-280+"
+      "euro\0csIBM01144\0IBM01145\0CCSID01145\0CP01145\0ebcdic-es-284+"
+      "euro\0csIBM01145\0IBM01146\0CCSID01146\0CP01146\0ebcdic-gb-285+"
+      "euro\0csIBM01146\0IBM01147\0CCSID01147\0CP01147\0ebcdic-fr-297+"
+      "euro\0csIBM01147\0IBM01148\0CCSID01148\0CP01148\0ebcdic-international-500+"
+      "euro\0csIBM01148\0IBM01149\0CCSID01149\0CP01149\0ebcdic-is-871+euro\0csIBM01149\0Big5-"
+      "HKSCS\0csBig5HKSCS\0IBM1047\0IBM-1047\0csIBM1047\0PTCP154\0csPTCP154\0PT154\0CP154\0Cyrillic-Asian\0Amiga-"
+      "1251\0Ami1251\0Amiga1251\0Ami-1251\0csAmiga1251\0KOI7-"
+      "switched\0csKOI7switched\0BRF\0csBRF\0TSCII\0csTSCII\0CP51932\0csCP51932\0windows-874\0cswindows874\0windows-"
+      "1250\0cswindows1250\0windows-1251\0cswindows1251\0windows-1252\0cswindows1252\0windows-"
+      "1253\0cswindows1253\0windows-1254\0cswindows1254\0windows-1255\0cswindows1255\0windows-"
+      "1256\0cswindows1256\0windows-1257\0cswindows1257\0windows-1258\0cswindows1258\0TIS-620\0csTIS620\0ISO-8859-"
+      "11\0CP50220\0csCP50220\0";
+
+  static constexpr unsigned short __alias_index_table_[] = {
+      sizeof(__aliases_string) - 1,
+      sizeof(__aliases_string) - 1,
+      0,
+      9,
+      18,
+      33,
+      48,
+      65,
+      75,
+      78,
+      85,
+      91,
+      99,
+      105,
+      121,
+      132,
+      143,
+      154,
+      161,
+      164,
+      171,
+      177,
+      189,
+      205,
+      216,
+      227,
+      238,
+      245,
+      248,
+      260,
+      276,
+      287,
+      298,
+      309,
+      316,
+      319,
+      331,
+      347,
+      358,
+      369,
+      380,
+      387,
+      390,
+      402,
+      418,
+      429,
+      440,
+      451,
+      460,
+      479,
+      495,
+      506,
+      517,
+      528,
+      537,
+      546,
+      553,
+      570,
+      586,
+      597,
+      608,
+      619,
+      628,
+      637,
+      643,
+      650,
+      666,
+      682,
+      693,
+      704,
+      715,
+      722,
+      739,
+      755,
+      766,
+      777,
+      788,
+      795,
+      798,
+      810,
+      822,
+      833,
+      836,
+      853,
+      865,
+      872,
+      887,
+      898,
+      912,
+      922,
+      928,
+      948,
+      961,
+      975,
+      985,
+      994,
+      1005,
+      1051,
+      1071,
+      1078,
+      1122,
+      1142,
+      1150,
+      1159,
+      1169,
+      1172,
+      1175,
+      1195,
+      1208,
+      1218,
+      1229,
+      1233,
+      1256,
+      1259,
+      1269,
+      1279,
+      1294,
+      1297,
+      1307,
+      1317,
+      1332,
+      1342,
+      1352,
+      1355,
+      1365,
+      1379,
+      1389,
+      1399,
+      1409,
+      1412,
+      1435,
+      1453,
+      1465,
+      1475,
+      1485,
+      1488,
+      1502,
+      1518,
+      1533,
+      1552,
+      1556,
+      1574,
+      1584,
+      1596,
+      1613,
+      1622,
+      1626,
+      1647,
+      1657,
+      1668,
+      1679,
+      1693,
+      1704,
+      1718,
+      1731,
+      1741,
+      1744,
+      1754,
+      1764,
+      1767,
+      1782,
+      1797,
+      1808,
+      1823,
+      1832,
+      1839,
+      1853,
+      1865,
+      1877,
+      1884,
+      1892,
+      1904,
+      1916,
+      1930,
+      1943,
+      1961,
+      1976,
+      1986,
+      1995,
+      2003,
+      2021,
+      2039,
+      2049,
+      2052,
+      2062,
+      2080,
+      2083,
+      2093,
+      2103,
+      2121,
+      2132,
+      2142,
+      2159,
+      2171,
+      2181,
+      2199,
+      2218,
+      2228,
+      2239,
+      2253,
+      2267,
+      2277,
+      2296,
+      2305,
+      2315,
+      2333,
+      2348,
+      2358,
+      2378,
+      2390,
+      2400,
+      2418,
+      2423,
+      2433,
+      2445,
+      2452,
+      2462,
+      2475,
+      2489,
+      2499,
+      2519,
+      2533,
+      2543,
+      2563,
+      2577,
+      2591,
+      2601,
+      2616,
+      2627,
+      2637,
+      2640,
+      2650,
+      2664,
+      2675,
+      2685,
+      2693,
+      2709,
+      2719,
+      2730,
+      2740,
+      2744,
+      2762,
+      2777,
+      2787,
+      2808,
+      2812,
+      2822,
+      2833,
+      2852,
+      2856,
+      2866,
+      2877,
+      2893,
+      2904,
+      2914,
+      2924,
+      2927,
+      2944,
+      2959,
+      2969,
+      2975,
+      2990,
+      3006,
+      3013,
+      3023,
+      3037,
+      3046,
+      3055,
+      3063,
+      3073,
+      3088,
+      3098,
+      3106,
+      3123,
+      3133,
+      3142,
+      3163,
+      3180,
+      3190,
+      3206,
+      3215,
+      3236,
+      3257,
+      3267,
+      3280,
+      3303,
+      3323,
+      3333,
+      3345,
+      3368,
+      3392,
+      3402,
+      3418,
+      3444,
+      3464,
+      3474,
+      3498,
+      3512,
+      3522,
+      3527,
+      3537,
+      3554,
+      3564,
+      3578,
+      3585,
+      3599,
+      3609,
+      3620,
+      3636,
+      3646,
+      3651,
+      3662,
+      3678,
+      3692,
+      3703,
+      3710,
+      3731,
+      3749,
+      3760,
+      3770,
+      3777,
+      3783,
+      3786,
+      3804,
+      3822,
+      3833,
+      3844,
+      3851,
+      3857,
+      3875,
+      3894,
+      3905,
+      3928,
+      3941,
+      3953,
+      3966,
+      3979,
+      3991,
+      4004,
+      4013,
+      4024,
+      4039,
+      4052,
+      4064,
+      4077,
+      4090,
+      4102,
+      4115,
+      4126,
+      4137,
+      4155,
+      4168,
+      4179,
+      4189,
+      4192,
+      4195,
+      4213,
+      4223,
+      4234,
+      4250,
+      4268,
+      4279,
+      4287,
+      4303,
+      4320,
+      4331,
+      4342,
+      4361,
+      4373,
+      4384,
+      4393,
+      4412,
+      4426,
+      4431,
+      4442,
+      4452,
+      4465,
+      4479,
+      4490,
+      4503,
+      4517,
+      4531,
+      4542,
+      4562,
+      4576,
+      4587,
+      4598,
+      4612,
+      4626,
+      4637,
+      4651,
+      4661,
+      4665,
+      4676,
+      4688,
+      4703,
+      4709,
+      4720,
+      4741,
+      4749,
+      4756,
+      4766,
+      4769,
+      4784,
+      4790,
+      4797,
+      4803,
+      4810,
+      4818,
+      4828,
+      4838,
+      4856,
+      4872,
+      4884,
+      4896,
+      4912,
+      4927,
+      4933,
+      4940,
+      4952,
+      4964,
+      4976,
+      4987,
+      5004,
+      5016,
+      5023,
+      5034,
+      5037,
+      5049,
+      5061,
+      5073,
+      5081,
+      5093,
+      5105,
+      5116,
+      5133,
+      5145,
+      5153,
+      5157,
+      5169,
+      5173,
+      5179,
+      5185,
+      5197,
+      5203,
+      5211,
+      5221,
+      5240,
+      5258,
+      5278,
+      5297,
+      5315,
+      5332,
+      5344,
+      5356,
+      5371,
+      5383,
+      5391,
+      5405,
+      5412,
+      5421,
+      5437,
+      5447,
+      5463,
+      5470,
+      5490,
+      5505,
+      5530,
+      5546,
+      5556,
+      5570,
+      5588,
+      5609,
+      5626,
+      5647,
+      5664,
+      5685,
+      5702,
+      5723,
+      5740,
+      5761,
+      5778,
+      5790,
+      5802,
+      5807,
+      5814,
+      5820,
+      5827,
+      5836,
+      5846,
+      5855,
+      5865,
+      5872,
+      5880,
+      5887,
+      5895,
+      5904,
+      5911,
+      5919,
+      5928,
+      5938,
+      5947,
+      5957,
+      5964,
+      5972,
+      5981,
+      5992,
+      6003,
+      6034,
+      6052,
+      6083,
+      6101,
+      6128,
+      6146,
+      6173,
+      6191,
+      6201,
+      6208,
+      6211,
+      6222,
+      6246,
+      6270,
+      6281,
+      6293,
+      6315,
+      6338,
+      6346,
+      6350,
+      6359,
+      6366,
+      6372,
+      6376,
+      6396,
+      6403,
+      6409,
+      6413,
+      6422,
+      6429,
+      6435,
+      6439,
+      6456,
+      6477,
+      6498,
+      6505,
+      6511,
+      6515,
+      6534,
+      6546,
+      6559,
+      6571,
+      6584,
+      6593,
+      6603,
+      6612,
+      6622,
+      6633,
+      6644,
+      6653,
+      6663,
+      6685,
+      6696,
+      6707,
+      6719,
+      6732,
+      6746,
+      6767,
+      6789,
+      6801,
+      6814,
+      6821,
+      6830,
+      6835,
+      6842,
+      6852,
+      6856,
+      6868,
+      6875,
+      6881,
+      6894,
+      6907,
+      6920,
+      6933,
+      6942,
+      6949,
+      6960,
+      6966,
+      6975,
+      6982,
+      6988,
+      6997,
+      7004,
+      7014,
+      7020,
+      7029,
+      7036,
+      7046,
+      7052,
+      7061,
+      7068,
+      7081,
+      7094,
+      7103,
+      7110,
+      7116,
+      7129,
+      7142,
+      7151,
+      7158,
+      7164,
+      7177,
+      7186,
+      7193,
+      7205,
+      7211,
+      7220,
+      7227,
+      7233,
+      7246,
+      7255,
+      7262,
+      7268,
+      7281,
+      7290,
+      7297,
+      7303,
+      7318,
+      7327,
+      7334,
+      7340,
+      7353,
+      7362,
+      7369,
+      7375,
+      7389,
+      7398,
+      7405,
+      7411,
+      7424,
+      7433,
+      7440,
+      7446,
+      7459,
+      7468,
+      7475,
+      7481,
+      7494,
+      7507,
+      7516,
+      7523,
+      7529,
+      7533,
+      7542,
+      7549,
+      7555,
+      7559,
+      7568,
+      7575,
+      7581,
+      7585,
+      7594,
+      7601,
+      7607,
+      7611,
+      7620,
+      7627,
+      7633,
+      7637,
+      7643,
+      7652,
+      7659,
+      7665,
+      7669,
+      7678,
+      7685,
+      7691,
+      7700,
+      7707,
+      7713,
+      7717,
+      7726,
+      7733,
+      7739,
+      7745,
+      7754,
+      7761,
+      7767,
+      7771,
+      7777,
+      7786,
+      7793,
+      7799,
+      7815,
+      7828,
+      7837,
+      7844,
+      7850,
+      7863,
+      7872,
+      7879,
+      7885,
+      7901,
+      7910,
+      7917,
+      7923,
+      7932,
+      7939,
+      7945,
+      7954,
+      7961,
+      7967,
+      7971,
+      7981,
+      7988,
+      7994,
+      8007,
+      8016,
+      8023,
+      8029,
+      8043,
+      8052,
+      8060,
+      8067,
+      8077,
+      8090,
+      8106,
+      8121,
+      8135,
+      8148,
+      8161,
+      8174,
+      8187,
+      8202,
+      8216,
+      8229,
+      8242,
+      8257,
+      8271,
+      8281,
+      8292,
+      8302,
+      8313,
+      8323,
+      8334,
+      8344,
+      8355,
+      8367,
+      8379,
+      8391,
+      8403,
+      8413,
+      8424,
+      8434,
+      8445,
+      8458,
+      8472,
+      8481,
+      8492,
+      8497,
+      8504,
+      8511,
+      8520,
+      8525,
+      8532,
+      8539,
+      8547,
+      8558,
+      8565,
+      8571,
+      8575,
+      8584,
+      8591,
+      8597,
+      8611,
+      8618,
+      8626,
+      8635,
+      8646,
+      8654,
+      8679,
+      8690,
+      8699,
+      8710,
+      8718,
+      8738,
+      8749,
+      8758,
+      8769,
+      8777,
+      8795,
+      8806,
+      8815,
+      8826,
+      8834,
+      8853,
+      8864,
+      8873,
+      8884,
+      8892,
+      8911,
+      8930,
+      8941,
+      8950,
+      8961,
+      8969,
+      8988,
+      9007,
+      9018,
+      9027,
+      9038,
+      9046,
+      9065,
+      9076,
+      9085,
+      9096,
+      9104,
+      9123,
+      9134,
+      9143,
+      9154,
+      9162,
+      9181,
+      9192,
+      9201,
+      9212,
+      9220,
+      9239,
+      9250,
+      9259,
+      9270,
+      9278,
+      9308,
+      9319,
+      9328,
+      9339,
+      9347,
+      9366,
+      9377,
+      9388,
+      9400,
+      9408,
+      9417,
+      9427,
+      9435,
+      9445,
+      9451,
+      9457,
+      9472,
+      9483,
+      9491,
+      9501,
+      9510,
+      9522,
+      9536,
+      9551,
+      9555,
+      9561,
+      9567,
+      9575,
+      9583,
+      9593,
+      9605,
+      9618,
+      9631,
+      9645,
+      9658,
+      9672,
+      9685,
+      9699,
+      9712,
+      9726,
+      9739,
+      9753,
+      9766,
+      9780,
+      9793,
+      9807,
+      9820,
+      9834,
+      9847,
+      9861,
+      9869,
+      9878,
+      9890,
+      9898,
+  };
 };
 
 template <>
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 26bc968b1794a..1236201b71da4 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include <__config>
-#include <__text_encoding/te_impl.h>
+#include <text_encoding>
 
 #if defined(_LIBCPP_WIN32API)
 #  include <__algorithm/max.h>
@@ -15,12 +15,15 @@
 #  include <windows.h>
 #else
 #  include <__locale_dir/locale_base_api.h>
+#  include <__utility/scope_guard.h>
 #endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if defined(_LIBCPP_WIN32API)
-_LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int __codepage) {
+_LIBCPP_HIDDEN text_encoding __get_win32_acp(unsigned int __codepage);
+
+_LIBCPP_HIDDEN text_encoding static __get_win32_acp(unsigned int __codepage) {
   switch (__codepage) {
   case 0:
     // If no ANSI code page is available, only Unicode can be used for the locale.
@@ -28,197 +31,197 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int __codepage) {
     // Such a locale cannot be set as the system locale.
     // Applications that do not support Unicode do not work correctly with locales
     // marked as "Unicode only".
-    return __te_impl::__id::unknown;
+    return std::text_encoding::id::unknown;
   case 037:
-    return __te_impl::__id::IBM037;
+    return std::text_encoding::id::IBM037;
   case 437:
-    return __te_impl::__id::PC8CodePage437;
+    return std::text_encoding::id::PC8CodePage437;
   case 500:
-    return __te_impl::__id::IBM500;
+    return std::text_encoding::id::IBM500;
   case 708:
-    return __te_impl::__id::ISOLatinArabic;
+    return std::text_encoding::id::ISOLatinArabic;
   case 709:
-    return __te_impl::__id::ISO89ASMO449;
+    return std::text_encoding::id::ISO89ASMO449;
   case 775:
-    return __te_impl::__id::PC775Baltic;
+    return std::text_encoding::id::PC775Baltic;
   case 850:
-    return __te_impl::__id::PC850Multilingual;
+    return std::text_encoding::id::PC850Multilingual;
   case 852:
-    return __te_impl::__id::PCp852;
+    return std::text_encoding::id::PCp852;
   case 855:
-    return __te_impl::__id::IBM855;
+    return std::text_encoding::id::IBM855;
   case 857:
-    return __te_impl::__id::IBM857;
+    return std::text_encoding::id::IBM857;
   case 858:
-    return __te_impl::__id::IBM00858;
+    return std::text_encoding::id::IBM00858;
   case 860:
-    return __te_impl::__id::IBM860;
+    return std::text_encoding::id::IBM860;
   case 861:
-    return __te_impl::__id::IBM861;
+    return std::text_encoding::id::IBM861;
   case 862:
-    return __te_impl::__id::PC862LatinHebrew;
+    return std::text_encoding::id::PC862LatinHebrew;
   case 863:
-    return __te_impl::__id::IBM863;
+    return std::text_encoding::id::IBM863;
   case 864:
-    return __te_impl::__id::IBM864;
+    return std::text_encoding::id::IBM864;
   case 865:
-    return __te_impl::__id::IBM865;
+    return std::text_encoding::id::IBM865;
   case 866:
-    return __te_impl::__id::IBM866;
+    return std::text_encoding::id::IBM866;
   case 869:
-    return __te_impl::__id::IBM869;
+    return std::text_encoding::id::IBM869;
   case 870:
-    return __te_impl::__id::IBM870;
+    return std::text_encoding::id::IBM870;
   case 874:
-    return __te_impl::__id::windows874;
+    return std::text_encoding::id::windows874;
   case 932:
-    return __te_impl::__id::ShiftJIS;
+    return std::text_encoding::id::ShiftJIS;
   case 936:
-    return __te_impl::__id::GB2312;
+    return std::text_encoding::id::GB2312;
   case 949:
-    return __te_impl::__id::KSC56011987;
+    return std::text_encoding::id::KSC56011987;
   case 950:
-    return __te_impl::__id::Big5;
+    return std::text_encoding::id::Big5;
   case 1026:
-    return __te_impl::__id::IBM1026;
+    return std::text_encoding::id::IBM1026;
   case 1047:
-    return __te_impl::__id::IBM1047;
+    return std::text_encoding::id::IBM1047;
   case 1140:
-    return __te_impl::__id::IBM01140;
+    return std::text_encoding::id::IBM01140;
   case 1141:
-    return __te_impl::__id::IBM01141;
+    return std::text_encoding::id::IBM01141;
   case 1142:
-    return __te_impl::__id::IBM01142;
+    return std::text_encoding::id::IBM01142;
   case 1143:
-    return __te_impl::__id::IBM01143;
+    return std::text_encoding::id::IBM01143;
   case 1144:
-    return __te_impl::__id::IBM01144;
+    return std::text_encoding::id::IBM01144;
   case 1145:
-    return __te_impl::__id::IBM01145;
+    return std::text_encoding::id::IBM01145;
   case 1146:
-    return __te_impl::__id::IBM01146;
+    return std::text_encoding::id::IBM01146;
   case 1147:
-    return __te_impl::__id::IBM01147;
+    return std::text_encoding::id::IBM01147;
   case 1148:
-    return __te_impl::__id::IBM01148;
+    return std::text_encoding::id::IBM01148;
   case 1149:
-    return __te_impl::__id::IBM01149;
+    return std::text_encoding::id::IBM01149;
   case 1200:
-    return __te_impl::__id::UTF16LE;
+    return std::text_encoding::id::UTF16LE;
   case 1201:
-    return __te_impl::__id::UTF16BE;
+    return std::text_encoding::id::UTF16BE;
   case 1250:
-    return __te_impl::__id::windows1250;
+    return std::text_encoding::id::windows1250;
   case 1251:
-    return __te_impl::__id::windows1251;
+    return std::text_encoding::id::windows1251;
   case 1252:
-    return __te_impl::__id::windows1252;
+    return std::text_encoding::id::windows1252;
   case 1253:
-    return __te_impl::__id::windows1253;
+    return std::text_encoding::id::windows1253;
   case 1254:
-    return __te_impl::__id::windows1254;
+    return std::text_encoding::id::windows1254;
   case 1255:
-    return __te_impl::__id::windows1255;
+    return std::text_encoding::id::windows1255;
   case 1256:
-    return __te_impl::__id::windows1256;
+    return std::text_encoding::id::windows1256;
   case 1257:
-    return __te_impl::__id::windows1257;
+    return std::text_encoding::id::windows1257;
   case 1258:
-    return __te_impl::__id::windows1258;
+    return std::text_encoding::id::windows1258;
   case 10000:
-    return __te_impl::__id::Macintosh;
+    return std::text_encoding::id::Macintosh;
   case 12000:
-    return __te_impl::__id::UTF32LE;
+    return std::text_encoding::id::UTF32LE;
   case 12001:
-    return __te_impl::__id::UTF32BE;
+    return std::text_encoding::id::UTF32BE;
   case 20127:
-    return __te_impl::__id::ASCII;
+    return std::text_encoding::id::ASCII;
   case 20273:
-    return __te_impl::__id::IBM273;
+    return std::text_encoding::id::IBM273;
   case 20277:
-    return __te_impl::__id::IBM277;
+    return std::text_encoding::id::IBM277;
   case 20278:
-    return __te_impl::__id::IBM278;
+    return std::text_encoding::id::IBM278;
   case 20280:
-    return __te_impl::__id::IBM280;
+    return std::text_encoding::id::IBM280;
   case 20284:
-    return __te_impl::__id::IBM284;
+    return std::text_encoding::id::IBM284;
   case 20285:
-    return __te_impl::__id::IBM285;
+    return std::text_encoding::id::IBM285;
   case 20290:
-    return __te_impl::__id::IBM290;
+    return std::text_encoding::id::IBM290;
   case 20297:
-    return __te_impl::__id::IBM297;
+    return std::text_encoding::id::IBM297;
   case 20420:
-    return __te_impl::__id::IBM420;
+    return std::text_encoding::id::IBM420;
   case 20423:
-    return __te_impl::__id::IBM423;
+    return std::text_encoding::id::IBM423;
   case 20424:
-    return __te_impl::__id::IBM424;
+    return std::text_encoding::id::IBM424;
   case 20838:
-    return __te_impl::__id::IBMThai;
+    return std::text_encoding::id::IBMThai;
   case 20866:
-    return __te_impl::__id::KOI8R;
+    return std::text_encoding::id::KOI8R;
   case 20871:
-    return __te_impl::__id::IBM871;
+    return std::text_encoding::id::IBM871;
   case 20880:
-    return __te_impl::__id::IBM880;
+    return std::text_encoding::id::IBM880;
   case 20905:
-    return __te_impl::__id::IBM905;
+    return std::text_encoding::id::IBM905;
   case 20924:
-    return __te_impl::__id::IBM00924;
+    return std::text_encoding::id::IBM00924;
   case 20932:
-    return __te_impl::__id::EUCPkdFmtJapanese;
+    return std::text_encoding::id::EUCPkdFmtJapanese;
   case 21866:
-    return __te_impl::__id::KOI8U;
+    return std::text_encoding::id::KOI8U;
   case 28591:
-    return __te_impl::__id::ISOLatin1;
+    return std::text_encoding::id::ISOLatin1;
   case 28592:
-    return __te_impl::__id::ISOLatin2;
+    return std::text_encoding::id::ISOLatin2;
   case 28593:
-    return __te_impl::__id::ISOLatin3;
+    return std::text_encoding::id::ISOLatin3;
   case 28594:
-    return __te_impl::__id::ISOLatin4;
+    return std::text_encoding::id::ISOLatin4;
   case 28595:
-    return __te_impl::__id::ISOLatin5;
+    return std::text_encoding::id::ISOLatin5;
   case 28596:
-    return __te_impl::__id::ISOLatin6;
+    return std::text_encoding::id::ISOLatin6;
   case 28597:
-    return __te_impl::__id::ISOLatinGreek;
+    return std::text_encoding::id::ISOLatinGreek;
   case 28598:
-    return __te_impl::__id::ISOLatinHebrew;
+    return std::text_encoding::id::ISOLatinHebrew;
   case 28599:
-    return __te_impl::__id::Windows31Latin5;
+    return std::text_encoding::id::Windows31Latin5;
   case 28603:
-    return __te_impl::__id::ISO885913;
+    return std::text_encoding::id::ISO885913;
   case 28605:
-    return __te_impl::__id::ISO885915;
+    return std::text_encoding::id::ISO885915;
   case 38598:
-    return __te_impl::__id::ISO88598I;
+    return std::text_encoding::id::ISO88598I;
   case 50220:
   case 50221:
   case 50222:
-    return __te_impl::__id::ISO2022JP;
+    return std::text_encoding::id::ISO2022JP;
   case 51932:
-    return __te_impl::__id::EUCPkdFmtJapanese;
+    return std::text_encoding::id::EUCPkdFmtJapanese;
   case 51936:
-    return __te_impl::__id::GB2312;
+    return std::text_encoding::id::GB2312;
   case 51949:
-    return __te_impl::__id::EUCKR;
+    return std::text_encoding::id::EUCKR;
   case 52936:
-    return __te_impl::__id::HZGB2312;
+    return std::text_encoding::id::HZGB2312;
   case 54936:
-    return __te_impl::__id::GB18030;
+    return std::text_encoding::id::GB18030;
   case 65000:
-    return __te_impl::__id::UTF7;
+    return std::text_encoding::id::UTF7;
   case 65001:
-    return __te_impl::__id::UTF8;
+    return std::text_encoding::id::UTF8;
   default:
-    return __te_impl::__id::other;
+    return std::text_encoding::id::other;
   }
 }
 
-[[maybe_unused]] _LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name) {
+_LIBCPP_HIDDEN static std::text_encoding __get_locale_encoding(const char* __name) {
   wchar_t __locale_wbuffer[LOCALE_NAME_MAX_LENGTH + 1]{};
   wchar_t __number_buffer[11]{};
 
@@ -230,74 +233,74 @@ _LIBCPP_HIDDEN __te_impl __get_win32_acp(unsigned int __codepage) {
       __codepage, MB_ERR_INVALID_CHARS, __name, __sv.size(), __locale_wbuffer, LOCALE_NAME_MAX_LENGTH);
 
   if (__ret <= 0)
-    return __te_impl();
+    return std::text_encoding();
 
   // The below function fills the string with the number in text.
   auto __lctype = __is_ansi ? LOCALE_IDEFAULTANSICODEPAGE : LOCALE_IDEFAULTCODEPAGE;
   int __result  = ::GetLocaleInfoEx(__locale_wbuffer, __lctype, __number_buffer, 10);
 
   if (__result <= 0)
-    return __te_impl();
+    return std::text_encoding();
 
   unsigned int __acp = std::wcstoul(__number_buffer, nullptr, 10);
 
   return __get_win32_acp(__acp);
 }
 
-_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_win32_acp(::GetACP()); }
+_LIBCPP_HIDDEN static std::text_encoding __get_env_encoding() { return __get_win32_acp(::GetACP()); }
+
+#elif defined(__ANDROID__)
+// Android has minimal libc suppport for locale, and doesn't support any other locale
+// than the ones checked for below.
+_LIBCPP_HIDDEN static std::text_encoding __get_locale_encoding(const char* __name) {
+  string_view __sv(__name);
+  if (__sv == "" || __sv == '*' || __sv == "C" || __sv == "POSIX" || __sv.contains("UTF-8")) {
+    return std::text_encoding(std::text_encoding::id::UTF8);
+  }
+
+  return std::text_encoding();
+}
+
+// Android is pretty much assumed to always be UTF-8.
+_LIBCPP_HIDDEN static std::text_encoding __get_env_encoding() {
+  return std::text_encoding(std::text_encoding::id::UTF8);
+}
 
-#elif !defined(__ANDROID__) // POSIX
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name) {
-  __te_impl __e;
+#else  // POSIX
+_LIBCPP_HIDDEN static std::text_encoding __get_locale_encoding(const char* __name) {
+  std::text_encoding __e;
 
   __locale::__locale_t __l = __locale::__newlocale(_LIBCPP_CTYPE_MASK, __name, static_cast<__locale::__locale_t>(0));
 
+  __scope_guard __locale_guard([&__l] {
+    if (__l) {
+      __locale::__freelocale(__l);
+    }
+  });
+
   if (!__l) {
     return __e;
   }
 
-  const char* __codeset = __locale::__nl_langinfo_l(_LIBCPP_NL_CODESET, __l);
+  const char* __codeset = __locale::__nl_langinfo(_LIBCPP_NL_CODESET, __l);
 
   if (!__codeset) {
-    __locale::__freelocale(__l);
     return __e;
   }
 
   string_view __codeset_sv(__codeset);
 
-  if (__codeset_sv.size() <= __te_impl::__max_name_length_) {
-    __e = __te_impl(__codeset_sv);
+  if (__codeset_sv.size() <= std::text_encoding::max_name_length) {
+    __e = std::text_encoding(__codeset_sv);
   }
 
-  __locale::__freelocale(__l);
-
   return __e;
 }
 
-_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
-#else
-#  if defined(__ANDROID__)
-// Android has minimal libc suppport for locale, and doesn't support any other locale
-// than the ones checked for below.
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding(const char* __name) {
-  string_view __sv(__name);
-  if (!__name[0] || __name[0] == '*' || (__name[0] == 'C' && __sv.size() == 1) || __sv == "POSIX" ||
-      __sv.contains("UTF-8")) {
-    return __te_impl(__te_impl::__id::UTF8);
-  }
-
-  return __te_impl();
-}
-
-// Android is pretty much assumed to always be UTF-8.
-_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __te_impl(__te_impl::__id::UTF8); }
-#  else
-_LIBCPP_HIDDEN __te_impl __get_locale_encoding([[maybe_unused]] const char*) { return __te_impl(); }
-_LIBCPP_HIDDEN __te_impl __get_env_encoding() { return __get_locale_encoding(""); }
-#  endif
+_LIBCPP_HIDDEN static std::text_encoding __get_env_encoding() { return __get_locale_encoding(""); }
 #endif // _LIBCPP_WIN32API
 
-_LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI __te_impl __te_impl::__environment() {
+_LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI std::text_encoding std::text_encoding::environment() {
   return __get_env_encoding();
 }
 

>From 8438803ef282cd3d454fe2c365cd9ff66ae2bb3a Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 25 Mar 2026 22:54:24 -0400
Subject: [PATCH 40/58] Address test comments

---
 .../environment.android.pass.cpp              | 36 +++++++++++
 .../text_encoding/environment.pass.cpp        | 14 ++---
 .../environment.windows.pass.cpp              | 38 ++++++++++++
 .../text_encoding.ctor/assert.id.pass.cpp     |  4 +-
 .../assert.string_view.pass.cpp               | 12 ++--
 .../environment.delete.verify.cpp             | 30 ++++++++++
 .../environment.nodiscard.verify.cpp          |  1 -
 .../text_encoding.ctor/id.pass.cpp            |  2 +-
 .../text_encoding.eq/equal.pass.cpp           |  4 ++
 .../text_encoding.hash/enabled_hash.pass.cpp  |  1 -
 .../text_encoding.hash/hash.pass.cpp          |  2 +
 .../text_encoding.aliases_view/begin.pass.cpp |  2 +-
 .../dereference.pass.cpp                      |  2 +-
 .../text_encoding.aliases_view/empty.pass.cpp | 52 +++++-----------
 .../iterator.pass.cpp                         | 47 ++++++++-------
 .../operator-bool.pass.cpp                    | 60 +++++++++++++++++++
 16 files changed, 225 insertions(+), 82 deletions(-)
 create mode 100644 libcxx/test/libcxx/utilities/text_encoding/environment.android.pass.cpp
 create mode 100644 libcxx/test/libcxx/utilities/text_encoding/environment.windows.pass.cpp
 create mode 100644 libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp
 create mode 100644 libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/operator-bool.pass.cpp

diff --git a/libcxx/test/libcxx/utilities/text_encoding/environment.android.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/environment.android.pass.cpp
new file mode 100644
index 0000000000000..6a80e8224d528
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/text_encoding/environment.android.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.fr_CA.ISO8859-1
+
+// UNSUPPORTED: no-localization
+// UNSUPPORTED: availability-te-environment-missing
+// REQUIRES: android
+
+// std::text_encoding::environment()
+
+#include <cassert>
+#include <cstdlib>
+#include <text_encoding>
+
+#include "platform_support.h" // locale name macros
+
+int main(int, char**) {
+  // On Android, UTF-8 is unconditionally returned.
+  ::setenv("LANG", LOCALE_fr_CA_ISO8859_1, 1);
+
+  auto te = std::text_encoding::environment();
+  assert(std::text_encoding::environment_is<std::text_encoding::id::UTF8>());
+  assert(te == std::text_encoding::environment());
+  assert(te.mib() == std::text_encoding::id::UTF8);
+
+  return 0;
+}
diff --git a/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp
index 17c7e9202ebb2..b5c88c6e6d568 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/environment.pass.cpp
@@ -12,9 +12,11 @@
 // REQUIRES: locale.fr_CA.ISO8859-1
 
 // UNSUPPORTED: no-localization
-// UNSUPPORTED: windows
+// UNSUPPORTED: windows, android
 // UNSUPPORTED: availability-te-environment-missing
 
+// std::text_encoding::environment()
+
 #include <algorithm>
 #include <cassert>
 #include <cstdlib>
@@ -23,8 +25,8 @@
 #include "platform_support.h" // locale name macros
 
 int main(int, char**) {
-#if !defined(__ANDROID__) || (defined(__ANDROID__) && __ANDROID_API__ >= 26)
-  // text_encoding::environment() is (unfortunately) affected by changes to the "LANG" environment variable on POSIX systems.
+  // The default text_encoding::environment() which relies on nl_langinfo is
+  // affected by changes to the "LANG" environment variable on POSIX systems.
   setenv("LANG", LOCALE_fr_CA_ISO8859_1, 1);
 
   auto te = std::text_encoding::environment();
@@ -33,12 +35,6 @@ int main(int, char**) {
   assert(te == std::text_encoding::environment());
   assert(te.mib() == std::text_encoding::id::ISOLatin1);
   assert(std::ranges::contains(te.aliases(), std::string_view("ISO_8859-1")));
-#else
-  // On implementations that do not have nl_langinfo_l, the unknown text encoding is returned.
-  auto te = std::text_encoding::environment();
-  assert(std::text_encoding::environment_is<std::text_encoding::id::unknown>());
-  assert(te.mib() == std::text_encoding::id::unknown);
-#endif
 
   return 0;
 }
diff --git a/libcxx/test/libcxx/utilities/text_encoding/environment.windows.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/environment.windows.pass.cpp
new file mode 100644
index 0000000000000..b7f9f5c8084bd
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/text_encoding/environment.windows.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.fr_CA.ISO8859-1
+
+// UNSUPPORTED: no-localization
+// UNSUPPORTED: availability-te-environment-missing
+// REQUIRES: windows
+
+// std::text_encoding::environment()
+
+#include <cassert>
+#include <cstdlib>
+#include <text_encoding>
+
+#include "platform_support.h" // locale name macros
+
+int main(int, char**) {
+  // On Windows, changes to the "LANG" environment variable don't affect the result
+  // of std::text_encoding::environment() and environment_is()
+
+  ::setenv("LANG", LOCALE_fr_CA_ISO8859_1, 1);
+
+  auto te = std::text_encoding::environment();
+  assert(std::text_encoding::environment_is<std::text_encoding::id::windows1252>());
+  assert(te == std::text_encoding::environment());
+  assert(te.mib() == std::text_encoding::id::windows1252);
+
+  return 0;
+}
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp
index a2884b941dcf2..8aff3576dafc4 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.id.pass.cpp
@@ -11,7 +11,7 @@
 
 // <text_encoding>
 
-// text_encoding text_encoding(id)
+// text_encoding text_encoding(std::text_encoding::id) noexcept
 
 #include <climits>
 #include <text_encoding>
@@ -19,7 +19,7 @@
 #include "check_assertion.h"
 
 int main(int, char**) {
-  // Make sure that text_encoding(id) asserts when the input id not in the range of allowed values
+  // Make sure that text_encoding(id) asserts when the input id is not in the range of allowed values
 
   TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::text_encoding::id(33)), "Mib for NATS-DANO used");
   TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::text_encoding::id(34)), "Mib for NATS-DANO-ADD used");
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
index 3d50bdd4832f3..886249a50098e 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
@@ -13,25 +13,23 @@
 
 // text_encoding text_encoding(string_view)
 
+#include <string>
 #include <string_view>
 #include <text_encoding>
 
 #include "check_assertion.h"
 
 int main(int, char**) {
-  char str[std::text_encoding::max_name_length + 2] =
-      "HELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELL";
-  std::string_view view(str);
+  std::string str('X', std::text_encoding::max_name_length + 1);
 
   // text_encoding(string_view) asserts if its input size() > max_name_length
-  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(view), "input string_view must have size <= 63");
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::string_view(str)), "input string_view must have size <= 63");
 
   // text_encoding(string_view) asserts if its input contains a null terminator
-  char str2[std::text_encoding::max_name_length] = "HELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELL";
-  std::string_view view2(str2);
+  std::string str2('X', std::text_encoding::max_name_length);
   str2[3] = '\0';
 
-  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(view2), "input string_view must not contain '\\0'");
+  TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::string_view(str2)), "input string_view must not contain '\\0'");
 
   return 0;
 }
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp
new file mode 100644
index 0000000000000..5f0f222fb0ac2
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// REQUIRES: no-localization
+
+// <text_encoding>
+
+// text_encoding text_encoding::environment()
+// template<std::text_encoding::id> text_encoding text_encoding::environment_is()
+
+// environment() and environment_is() are deleted if there is libc++ is built
+// without localization.
+
+#include <text_encoding>
+
+int main(int, char**) {
+  // expected-warning at +1 {{attempt to use a deleted function}}
+  std::text_encoding::environment();
+  // expected-warning at +1 {{attempt to use a deleted function}}
+  std::text_encoding::environment_is<std::text_encoding::UTF8>();
+
+  return 0;
+}
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.nodiscard.verify.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.nodiscard.verify.cpp
index 97dc5c713f7a4..cc7f294e3d0f2 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.nodiscard.verify.cpp
@@ -9,7 +9,6 @@
 // REQUIRES: std-at-least-c++26
 
 // UNSUPPORTED: no-localization
-// UNSUPPORTED: android
 // UNSUPPORTED: availability-te-environment-missing
 
 // <text_encoding>
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 c7b8a193df573..f0353525bca23 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
@@ -10,7 +10,7 @@
 
 // <text_encoding>
 
-// text_encoding::text_encoding(id) noexcept
+// text_encoding::text_encoding(std::text_encoding::id) noexcept
 
 #include <algorithm>
 #include <cassert>
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 c3ba6a6a37490..6764937c432e3 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
@@ -31,6 +31,10 @@ constexpr bool test() {
     std::text_encoding te1 = std::text_encoding(id::UTF8);
     std::text_encoding te2 = std::text_encoding(id::UTF8);
     assert(te1 == te2);
+
+    const std::text_encoding& te11 = te1;
+    const std::text_encoding& te22 = te2;
+    assert(te11 == te22);
   }
 
   // 3. operator==(const text_encoding&, const text_encoding&) for text_encodings with ids of "other" return true if the names are equal
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.hash/enabled_hash.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.hash/enabled_hash.pass.cpp
index 981cb4f061268..642b67fa3c08c 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.hash/enabled_hash.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.hash/enabled_hash.pass.cpp
@@ -15,7 +15,6 @@
 #include <text_encoding>
 
 #include "poisoned_hash_helper.h"
-#include "test_macros.h"
 
 int main(int, char**) {
   test_library_hash_specializations_available();
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.hash/hash.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.hash/hash.pass.cpp
index 1171e2dab882b..82ca786174ad7 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.hash/hash.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.hash/hash.pass.cpp
@@ -12,6 +12,7 @@
 
 // template <> struct hash<text_encoding>
 
+#include "poisoned_hash_helper.h"
 #include <cassert>
 #include <cstdint>
 #include <text_encoding>
@@ -53,6 +54,7 @@ void test_te_hash() {
 
 int main(int, char**) {
   test_te_hash();
+  test_hash_enabled<std::text_encoding>();
 
   return 0;
 }
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 f07b1a0e754df..2e727928881d4 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
@@ -10,7 +10,7 @@
 
 // <text_encoding>
 
-// text_encoding::aliases_view::begin()
+// constexpr implementation-defined text_encoding::aliases_view::begin() const;
 
 #include "test_macros.h"
 #include <cassert>
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp
index 3ea75aa4e2867..d6376dbfa958f 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/dereference.pass.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 // REQUIRES: std-at-least-c++26
-// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=9000000
 
 // <text_encoding>
 
@@ -25,6 +24,7 @@ constexpr bool test() {
   auto iter                                = aliases.begin();
 
   ASSERT_SAME_TYPE(decltype(aliases[0]), const char*);
+  assert(aliases.size() >= 2 && "assumed below");
   assert(std::string_view(aliases[0]) == *iter);
   assert(std::string_view(aliases[1]) == std::string_view(*(iter + 1)));
 
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 525d448054436..667ea26779782 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
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 // REQUIRES: std-at-least-c++26
-// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=9000000
 
 // <text_encoding>
 
@@ -21,48 +20,29 @@
 
 using id = std::text_encoding::id;
 
-constexpr void test_other_unknown() {
-  {
-    std::text_encoding te_other = std::text_encoding(id::other);
-
-    std::text_encoding::aliases_view other_range = te_other.aliases();
-
-    assert(std::ranges::empty(other_range));
-    assert(other_range.empty());
-    assert(!bool(other_range));
-  }
-
-  {
-    std::text_encoding te_unknown = std::text_encoding(id::unknown);
-
-    std::text_encoding::aliases_view unknown_range = te_unknown.aliases();
-    assert(std::ranges::empty(unknown_range));
-    assert(unknown_range.empty());
-    assert(!bool(unknown_range));
-  }
-}
-
-constexpr void test_primary_encodings() {
-  for (auto& data : unique_encoding_data) {
-    std::text_encoding te = std::text_encoding(id(data.mib));
-
-    std::text_encoding::aliases_view range = te.aliases();
-
-    assert(!std::ranges::empty(range));
-    assert(!range.empty());
-    assert(bool(range));
-  }
-}
-
 constexpr bool test() {
   // 1. An alias_view of a text_encoding object for "other" and "unknown" are empty
   {
-    test_other_unknown();
+    {
+      std::text_encoding te_other                  = std::text_encoding(id::other);
+      std::text_encoding::aliases_view other_range = te_other.aliases();
+      assert(other_range.empty());
+    }
+
+    {
+      std::text_encoding te_unknown                  = std::text_encoding(id::unknown);
+      std::text_encoding::aliases_view unknown_range = te_unknown.aliases();
+      assert(unknown_range.empty());
+    }
   }
 
   // 2. An alias_view of a text_encoding object for a known encoding e.g. "UTF-8" is not empty
   {
-    test_primary_encodings();
+    for (auto& data : unique_encoding_data) {
+      std::text_encoding te                  = std::text_encoding(id(data.mib));
+      std::text_encoding::aliases_view range = te.aliases();
+      assert(!range.empty());
+    }
   }
 
   return true;
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
index 7da0f97143559..99416aab6a212 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
@@ -11,6 +11,8 @@
 // <text_encoding>
 
 // text_encoding::aliases_view::iterator (implementation-defined)
+//
+// Implementation is almost trivial, so everything is tested here.
 
 #include <cassert>
 #include <compare>
@@ -31,6 +33,13 @@ constexpr bool test() {
   static_assert(std::three_way_comparable<decltype(i)>);
 
   {
+    ASSERT_NOEXCEPT(i == j);
+    ASSERT_NOEXCEPT(i != k);
+    ASSERT_NOEXCEPT(i <=> j);
+    ASSERT_NOEXCEPT(i > j);
+    ASSERT_NOEXCEPT(i < j);
+    ASSERT_NOEXCEPT(i >= j);
+    ASSERT_NOEXCEPT(i <= j);
     assert(i == j);
     assert(i != k);
     assert(i <= j);
@@ -39,6 +48,8 @@ constexpr bool test() {
     assert(std::string_view(*i) == std::string_view(*j));
   }
   {
+    ASSERT_NOEXCEPT(*i);
+    ASSERT_NOEXCEPT(i[0]);
     assert(std::string_view(i[0]) == std::string_view(j[0]));
     assert(std::string_view(i[1]) != std::string_view(j[3]));
   }
@@ -67,6 +78,9 @@ constexpr bool test() {
     assert(std::string_view(*i) == std::string_view(*j));
   }
   {
+    ASSERT_NOEXCEPT(i + 1);
+    ASSERT_NOEXCEPT(1 + i);
+    ASSERT_NOEXCEPT(i - 1);
     auto temp = i + 2;
     assert(i != temp);
     assert(std::string_view(*temp) != std::string_view(*j));
@@ -74,17 +88,26 @@ constexpr bool test() {
     assert(std::string_view(*temp2) == std::string_view(*j));
   }
   {
+    ASSERT_NOEXCEPT(i - j);
     assert(i - j == 0);
     assert(k - i > 0);
   }
   {
-    auto temp = ++i;
+    ASSERT_NOEXCEPT(i++);
+    ASSERT_NOEXCEPT(++i);
+    ASSERT_NOEXCEPT(i--);
+    ASSERT_NOEXCEPT(--i);
+    auto& temp = ++i;
     assert(temp == i);
+    assert(&temp == &i);
+
     auto temp2 = j++;
     assert(temp2 == j - 1);
     assert(i == j);
   }
   {
+    ASSERT_NOEXCEPT(i += 2);
+    ASSERT_NOEXCEPT(i -= 2);
     i += 2;
     j += 3;
 
@@ -98,28 +121,6 @@ constexpr bool test() {
     assert(i != tempi && (tempi - i) == 2);
     assert(j != tempj && (tempj - j) == 3);
   }
-
-  { // noexcept
-    ASSERT_NOEXCEPT(*i);
-    ASSERT_NOEXCEPT(i[0]);
-    ASSERT_NOEXCEPT(i + 1);
-    ASSERT_NOEXCEPT(1 + i);
-    ASSERT_NOEXCEPT(i - 1);
-    ASSERT_NOEXCEPT(i - j);
-    ASSERT_NOEXCEPT(i++);
-    ASSERT_NOEXCEPT(++i);
-    ASSERT_NOEXCEPT(i--);
-    ASSERT_NOEXCEPT(--i);
-    ASSERT_NOEXCEPT(i += 2);
-    ASSERT_NOEXCEPT(i -= 2);
-    ASSERT_NOEXCEPT(i == j);
-    ASSERT_NOEXCEPT(i != k);
-    ASSERT_NOEXCEPT(i <=> j);
-    ASSERT_NOEXCEPT(i > j);
-    ASSERT_NOEXCEPT(i < j);
-    ASSERT_NOEXCEPT(i >= j);
-    ASSERT_NOEXCEPT(i <= j);
-  }
   { // iterator operator return types
     ASSERT_SAME_TYPE(const char*, decltype(*i));
     ASSERT_SAME_TYPE(const char*, decltype(i[0]));
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/operator-bool.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/operator-bool.pass.cpp
new file mode 100644
index 0000000000000..a05bcf15945c4
--- /dev/null
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/operator-bool.pass.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::aliases_view
+
+#include <cassert>
+#include <ranges>
+#include <text_encoding>
+
+#include "../../test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+constexpr void test_other_unknown() {}
+
+constexpr void test_primary_encodings() {}
+
+constexpr bool test() {
+  // 1. An alias_view of a text_encoding object for "other" and "unknown" are empty
+  {
+    {
+      std::text_encoding te_other                  = std::text_encoding(id::other);
+      std::text_encoding::aliases_view other_range = te_other.aliases();
+      assert(!bool(other_range));
+    }
+
+    {
+      std::text_encoding te_unknown                  = std::text_encoding(id::unknown);
+      std::text_encoding::aliases_view unknown_range = te_unknown.aliases();
+      assert(!bool(unknown_range));
+    }
+  }
+
+  // 2. An alias_view of a text_encoding object for a known encoding e.g. "UTF-8" is not empty
+  {
+    for (auto& data : unique_encoding_data) {
+      std::text_encoding te                  = std::text_encoding(id(data.mib));
+      std::text_encoding::aliases_view range = te.aliases();
+      assert(bool(range));
+    }
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}

>From bd318475fb241d77e5d3f06f49f957c0ef794386 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 25 Mar 2026 23:14:43 -0400
Subject: [PATCH 41/58] Implement locale::encoding()

---
 libcxx/include/__locale                       |  7 ++++
 libcxx/src/text_encoding.cpp                  |  8 ++++-
 .../locale/locale.members/encoding.pass.cpp   | 32 ++++++++++---------
 3 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index 5b1787451fb25..20caefa4512d7 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -54,6 +54,10 @@ _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale&) _NOEXCEPT;
 template <class _Facet>
 _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&);
 
+#  if _LIBCPP_STD_VER >= 26
+struct text_encoding;
+#  endif
+
 class _LIBCPP_EXPORTED_FROM_ABI locale {
 public:
   // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor,
@@ -107,6 +111,9 @@ public:
     return std::use_facet<std::collate<_CharT> >(*this).compare(
                __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0;
   }
+#  if _LIBCPP_STD_VER >= 26
+  _LIBCPP_EXPORTED_FROM_ABI std::text_encoding encoding() const;
+#  endif
 
   // global locale objects:
   static locale global(const locale&);
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 1236201b71da4..31a062f5d78a2 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include <__config>
+#include <locale>
 #include <text_encoding>
 
 #if defined(_LIBCPP_WIN32API)
@@ -217,7 +218,7 @@ _LIBCPP_HIDDEN text_encoding static __get_win32_acp(unsigned int __codepage) {
   case 65001:
     return std::text_encoding::id::UTF8;
   default:
-    return std::text_encoding::id::other;
+    return std::text_encoding::id::unknown;
   }
 }
 
@@ -304,4 +305,9 @@ _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI std::text_encoding
   return __get_env_encoding();
 }
 
+std::text_encoding locale::encoding() const {
+  std::string __name = name();
+
+  return __get_locale_encoding(__name.c_str());
+}
 _LIBCPP_END_NAMESPACE_STD
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
index e77ad12eb2267..5bbe0fba37800 100644
--- a/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
@@ -11,43 +11,45 @@
 // REQUIRES: std-at-least-c++26
 // REQUIRES: locale.en_US.UTF-8
 // UNSUPPORTED: no-localization
-// UNSUPPORTED: android
 
 // class locale
 
-// text_encoding encoding() const
+// text_encoding locale::encoding() const
 
 #include <cassert>
 #include <locale>
 #include <text_encoding>
 
-#include "test_macros.h"
 #include "platform_support.h"
 
 using id = std::text_encoding::id;
 
 int main(int, char**) {
-// FIXME: enable once locale::encoding() is implemented
-#if false
   {
-    // 1. Default locale returns a text_encoding representing "ASCII"
-    std::locale loc;
+    // 1. Default locale returns a text_encoding representing "ASCII", or "UTF-8 on Android.
+    const std::locale loc{};
 
-    auto te        = loc.encoding();
-    auto classicTE = std::text_encoding(id::ASCII);
+    std::text_encoding te = loc.encoding();
+
+#if !defined(__ANDROID__)
+    std::text_encoding classic_te = std::text_encoding(id::ASCII);
     assert(te == id::ASCII);
-    assert(te == classicTE);
+    assert(te == classic_te);
+#else
+    auto utf8_te = std::text_encoding(id::UTF8);
+    assert(te == id::UTF8);
+    assert(te == utf8_te);
+#endif
   }
 
   {
     // 2. Locale built with en_US.UTF-8 returns text_encoding representing "UTF-8"
-    std::locale utf8Locale(LOCALE_en_US_UTF_8);
+    const std::locale utf8_locale(LOCALE_en_US_UTF_8);
 
-    auto te     = utf8Locale.encoding();
-    auto utf8TE = std::text_encoding(id::UTF8);
+    std::text_encoding te      = utf8_locale.encoding();
+    std::text_encoding utf8_te = std::text_encoding(id::UTF8);
     assert(te == id::UTF8);
-    assert(te == utf8TE);
+    assert(te == utf8_te);
   }
-#endif
   return 0;
 }

>From 8235bdc29d7542a1ee0be1b7c30e1b614aa0b510 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 25 Mar 2026 23:20:25 -0400
Subject: [PATCH 42/58] Typo

---
 libcxx/src/text_encoding.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 31a062f5d78a2..6e367c09d6f9e 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -255,7 +255,7 @@ _LIBCPP_HIDDEN static std::text_encoding __get_env_encoding() { return __get_win
 // than the ones checked for below.
 _LIBCPP_HIDDEN static std::text_encoding __get_locale_encoding(const char* __name) {
   string_view __sv(__name);
-  if (__sv == "" || __sv == '*' || __sv == "C" || __sv == "POSIX" || __sv.contains("UTF-8")) {
+  if (__sv == "" || __sv == "*" || __sv == "C" || __sv == "POSIX" || __sv.contains("UTF-8")) {
     return std::text_encoding(std::text_encoding::id::UTF8);
   }
 

>From ab2e4ef35bfe9e9757a9be3e08b62b2e828a8db1 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 25 Mar 2026 23:34:39 -0400
Subject: [PATCH 43/58] Expose only internal __get_locale_encoding(...)

---
 libcxx/include/__locale      |  6 +++++-
 libcxx/include/text_encoding |  1 +
 libcxx/src/text_encoding.cpp | 12 +++---------
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index 20caefa4512d7..43a35b2b75a93 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -26,6 +26,7 @@
 #  include <cstdint>
 #  include <cstdlib>
 #  include <string>
+#  include <text_encoding>
 
 // Some platforms require more includes than others. Keep the includes on all plaforms for now.
 #  include <cstddef>
@@ -112,7 +113,10 @@ public:
                __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0;
   }
 #  if _LIBCPP_STD_VER >= 26
-  _LIBCPP_EXPORTED_FROM_ABI std::text_encoding encoding() const;
+  _LIBCPP_HIDE_FROM_ABI std::text_encoding encoding() const {
+    std::string __name = name();
+    return __get_locale_encoding(__name.c_str());
+  }
 #  endif
 
   // global locale objects:
diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index e06ea4a0893d3..ab4f7a0579d23 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -1662,6 +1662,7 @@ struct hash<text_encoding> {
 template <>
 inline constexpr bool ranges::enable_borrowed_range<text_encoding::aliases_view> = true;
 
+_LIBCPP_EXPORTED_FROM_ABI text_encoding __get_locale_encoding(const char* __name);
 _LIBCPP_END_NAMESPACE_STD
 
 #  endif // _LIBCPP_STD_VER >= 26
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 6e367c09d6f9e..4426d32a9915b 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include <__config>
-#include <locale>
 #include <text_encoding>
 
 #if defined(_LIBCPP_WIN32API)
@@ -222,7 +221,7 @@ _LIBCPP_HIDDEN text_encoding static __get_win32_acp(unsigned int __codepage) {
   }
 }
 
-_LIBCPP_HIDDEN static std::text_encoding __get_locale_encoding(const char* __name) {
+_LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* __name) {
   wchar_t __locale_wbuffer[LOCALE_NAME_MAX_LENGTH + 1]{};
   wchar_t __number_buffer[11]{};
 
@@ -253,7 +252,7 @@ _LIBCPP_HIDDEN static std::text_encoding __get_env_encoding() { return __get_win
 #elif defined(__ANDROID__)
 // Android has minimal libc suppport for locale, and doesn't support any other locale
 // than the ones checked for below.
-_LIBCPP_HIDDEN static std::text_encoding __get_locale_encoding(const char* __name) {
+_LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* __name) {
   string_view __sv(__name);
   if (__sv == "" || __sv == "*" || __sv == "C" || __sv == "POSIX" || __sv.contains("UTF-8")) {
     return std::text_encoding(std::text_encoding::id::UTF8);
@@ -268,7 +267,7 @@ _LIBCPP_HIDDEN static std::text_encoding __get_env_encoding() {
 }
 
 #else  // POSIX
-_LIBCPP_HIDDEN static std::text_encoding __get_locale_encoding(const char* __name) {
+_LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* __name) {
   std::text_encoding __e;
 
   __locale::__locale_t __l = __locale::__newlocale(_LIBCPP_CTYPE_MASK, __name, static_cast<__locale::__locale_t>(0));
@@ -305,9 +304,4 @@ _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI std::text_encoding
   return __get_env_encoding();
 }
 
-std::text_encoding locale::encoding() const {
-  std::string __name = name();
-
-  return __get_locale_encoding(__name.c_str());
-}
 _LIBCPP_END_NAMESPACE_STD

>From a9321648fe73fd67329f07207960c9aebea33795 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Thu, 26 Mar 2026 00:04:40 -0400
Subject: [PATCH 44/58] ABI list, transitive includes,

---
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |  3 +-
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |  3 +-
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |  3 +-
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |  3 +-
 .../test/libcxx/transitive_includes/cxx03.csv | 42 ++++++++++++++++++
 .../test/libcxx/transitive_includes/cxx11.csv | 42 ++++++++++++++++++
 .../test/libcxx/transitive_includes/cxx14.csv | 42 ++++++++++++++++++
 .../test/libcxx/transitive_includes/cxx17.csv | 43 +++++++++++++++++++
 .../test/libcxx/transitive_includes/cxx20.csv | 38 ++++++++++++++++
 .../test/libcxx/transitive_includes/cxx23.csv | 23 ++++++++++
 .../test/libcxx/transitive_includes/cxx26.csv | 23 ++++++++++
 11 files changed, 261 insertions(+), 4 deletions(-)

diff --git a/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
index 6a8e6cd8b66ba..36ec5612272f3 100644
--- a/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -943,6 +943,7 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvED1Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvED2Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvEaSERKS1_', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt6__ndk113text_encoding11environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_get_base10__get_baseERNS_8ios_baseE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_get_base5__srcE', 'size': 33, 'type': 'OBJECT'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_put_base12__format_intEPcPKcbj', 'type': 'FUNC'}
@@ -1197,6 +1198,7 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk120__libcpp_atomic_waitEPVKNS_17__cxx_atomic_implIiNS_22__cxx_atomic_base_implIiEEEEi', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk120__libcpp_atomic_waitEPVKvi', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk120__throw_system_errorEiPKc', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt6__ndk121__get_locale_encodingEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk121__throw_runtime_errorEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk121recursive_timed_mutex4lockEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk121recursive_timed_mutex6unlockEv', 'type': 'FUNC'}
@@ -1558,7 +1560,6 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZNSt6__ndk19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
index 104b108dcaa84..207d846b618bf 100644
--- a/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -420,6 +420,7 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED1Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED2Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvEaSERKS1_', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
+{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113text_encoding11environmentEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_get_base10__get_baseERNS_8ios_baseE', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_get_base5__srcE', 'storage_mapping_class': 'RO', 'type': 'OBJECT'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_put_base12__format_intEPcPKcbj', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
@@ -554,6 +555,7 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKNS_17__cxx_atomic_implIiNS_22__cxx_atomic_base_implIiEEEEi', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKvi', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__120__throw_system_errorEiPKc', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
+{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__121__get_locale_encodingEPKc', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__121__throw_runtime_errorEPKc', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex4lockEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex6unlockEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
@@ -855,7 +857,6 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_f', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_fNS_12chars_formatE', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_fNS_12chars_formatEi', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
-{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD0Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD1Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD2Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
index d22dc464d0506..c0fd1664ce6f7 100644
--- a/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -420,6 +420,7 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED1Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED2Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvEaSERKS1_', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
+{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113text_encoding11environmentEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_get_base10__get_baseERNS_8ios_baseE', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_get_base5__srcE', 'storage_mapping_class': 'RO', 'type': 'OBJECT'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_put_base12__format_intEPcPKcbj', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
@@ -554,6 +555,7 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKNS_17__cxx_atomic_implIlNS_22__cxx_atomic_base_implIlEEEEl', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKvl', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__120__throw_system_errorEiPKc', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
+{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__121__get_locale_encodingEPKc', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__121__throw_runtime_errorEPKc', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex4lockEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex6unlockEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
@@ -855,7 +857,6 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_f', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_fNS_12chars_formatE', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__18to_charsEPcS0_fNS_12chars_formatEi', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
-{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD0Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD1Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__19strstreamD2Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
index 7ced475882f9b..0b0c0846f0249 100644
--- a/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -943,6 +943,7 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvED1Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvED2Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvEaSERKS1_', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt6__ndk113text_encoding11environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_get_base10__get_baseERNS_8ios_baseE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_get_base5__srcE', 'size': 33, 'type': 'OBJECT'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_put_base12__format_intEPcPKcbj', 'type': 'FUNC'}
@@ -1197,6 +1198,7 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk120__libcpp_atomic_waitEPVKNS_17__cxx_atomic_implIiNS_22__cxx_atomic_base_implIiEEEEi', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk120__libcpp_atomic_waitEPVKvi', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk120__throw_system_errorEiPKc', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt6__ndk121__get_locale_encodingEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk121__throw_runtime_errorEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk121recursive_timed_mutex4lockEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk121recursive_timed_mutex6unlockEv', 'type': 'FUNC'}
@@ -1558,7 +1560,6 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZNSt6__ndk19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index c0031543e47bc..b0b58724e64ab 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -69,6 +69,7 @@ any streambuf
 any string
 any string_view
 any system_error
+any text_encoding
 any tuple
 any type_traits
 any typeinfo
@@ -122,15 +123,19 @@ atomic ratio
 atomic type_traits
 atomic version
 barrier atomic
+barrier cctype
 barrier climits
 barrier cmath
 barrier compare
 barrier concepts
 barrier cstddef
 barrier cstdint
+barrier cstdio
 barrier cstdlib
 barrier cstring
 barrier ctime
+barrier cwchar
+barrier cwctype
 barrier exception
 barrier initializer_list
 barrier iosfwd
@@ -234,6 +239,7 @@ ccomplex streambuf
 ccomplex string
 ccomplex string_view
 ccomplex system_error
+ccomplex text_encoding
 ccomplex tuple
 ccomplex type_traits
 ccomplex typeinfo
@@ -292,6 +298,7 @@ chrono streambuf
 chrono string
 chrono string_view
 chrono system_error
+chrono text_encoding
 chrono tuple
 chrono type_traits
 chrono typeinfo
@@ -337,6 +344,7 @@ codecvt stdexcept
 codecvt string
 codecvt string_view
 codecvt system_error
+codecvt text_encoding
 codecvt tuple
 codecvt type_traits
 codecvt typeinfo
@@ -396,6 +404,7 @@ complex streambuf
 complex string
 complex string_view
 complex system_error
+complex text_encoding
 complex tuple
 complex type_traits
 complex typeinfo
@@ -501,6 +510,7 @@ ctgmath streambuf
 ctgmath string
 ctgmath string_view
 ctgmath system_error
+ctgmath text_encoding
 ctgmath tuple
 ctgmath type_traits
 ctgmath typeinfo
@@ -552,6 +562,7 @@ deque streambuf
 deque string
 deque string_view
 deque system_error
+deque text_encoding
 deque tuple
 deque type_traits
 deque typeinfo
@@ -607,6 +618,7 @@ experimental/iterator streambuf
 experimental/iterator string
 experimental/iterator string_view
 experimental/iterator system_error
+experimental/iterator text_encoding
 experimental/iterator tuple
 experimental/iterator type_traits
 experimental/iterator typeinfo
@@ -732,6 +744,7 @@ format streambuf
 format string
 format string_view
 format system_error
+format text_encoding
 format tuple
 format type_traits
 format typeinfo
@@ -778,6 +791,7 @@ forward_list streambuf
 forward_list string
 forward_list string_view
 forward_list system_error
+forward_list text_encoding
 forward_list tuple
 forward_list type_traits
 forward_list typeinfo
@@ -834,6 +848,7 @@ fstream streambuf
 fstream string
 fstream string_view
 fstream system_error
+fstream text_encoding
 fstream tuple
 fstream type_traits
 fstream typeinfo
@@ -879,6 +894,7 @@ functional streambuf
 functional string
 functional string_view
 functional system_error
+functional text_encoding
 functional tuple
 functional type_traits
 functional typeinfo
@@ -936,6 +952,7 @@ future streambuf
 future string
 future string_view
 future system_error
+future text_encoding
 future thread
 future tuple
 future type_traits
@@ -993,6 +1010,7 @@ iomanip streambuf
 iomanip string
 iomanip string_view
 iomanip system_error
+iomanip text_encoding
 iomanip tuple
 iomanip type_traits
 iomanip typeinfo
@@ -1033,6 +1051,7 @@ ios stdexcept
 ios string
 ios string_view
 ios system_error
+ios text_encoding
 ios tuple
 ios type_traits
 ios typeinfo
@@ -1086,6 +1105,7 @@ iostream streambuf
 iostream string
 iostream string_view
 iostream system_error
+iostream text_encoding
 iostream tuple
 iostream type_traits
 iostream typeinfo
@@ -1139,6 +1159,7 @@ istream streambuf
 istream string
 istream string_view
 istream system_error
+istream text_encoding
 istream tuple
 istream type_traits
 istream typeinfo
@@ -1223,6 +1244,7 @@ list streambuf
 list string
 list string_view
 list system_error
+list text_encoding
 list tuple
 list type_traits
 list typeinfo
@@ -1266,6 +1288,7 @@ locale streambuf
 locale string
 locale string_view
 locale system_error
+locale text_encoding
 locale tuple
 locale type_traits
 locale typeinfo
@@ -1310,6 +1333,7 @@ map streambuf
 map string
 map string_view
 map system_error
+map text_encoding
 map tuple
 map type_traits
 map typeinfo
@@ -1442,6 +1466,7 @@ numeric streambuf
 numeric string
 numeric string_view
 numeric system_error
+numeric text_encoding
 numeric tuple
 numeric type_traits
 numeric typeinfo
@@ -1523,6 +1548,7 @@ ostream streambuf
 ostream string
 ostream string_view
 ostream system_error
+ostream text_encoding
 ostream tuple
 ostream type_traits
 ostream typeinfo
@@ -1573,6 +1599,7 @@ print streambuf
 print string
 print string_view
 print system_error
+print text_encoding
 print tuple
 print type_traits
 print typeinfo
@@ -1620,6 +1647,7 @@ queue streambuf
 queue string
 queue string_view
 queue system_error
+queue text_encoding
 queue tuple
 queue type_traits
 queue typeinfo
@@ -1668,6 +1696,7 @@ random streambuf
 random string
 random string_view
 random system_error
+random text_encoding
 random tuple
 random type_traits
 random typeinfo
@@ -1742,6 +1771,7 @@ regex streambuf
 regex string
 regex string_view
 regex system_error
+regex text_encoding
 regex tuple
 regex type_traits
 regex typeinfo
@@ -1830,6 +1860,7 @@ set streambuf
 set string
 set string_view
 set system_error
+set text_encoding
 set tuple
 set type_traits
 set typeinfo
@@ -1914,6 +1945,7 @@ span streambuf
 span string
 span string_view
 span system_error
+span text_encoding
 span tuple
 span type_traits
 span typeinfo
@@ -1968,6 +2000,7 @@ sstream streambuf
 sstream string
 sstream string_view
 sstream system_error
+sstream text_encoding
 sstream tuple
 sstream type_traits
 sstream typeinfo
@@ -2015,6 +2048,7 @@ stack streambuf
 stack string
 stack string_view
 stack system_error
+stack text_encoding
 stack tuple
 stack type_traits
 stack typeinfo
@@ -2032,6 +2066,7 @@ stdexcept new
 stdexcept type_traits
 stdexcept typeinfo
 stdexcept version
+stop_token cstddef
 stop_token iosfwd
 stop_token version
 streambuf algorithm
@@ -2067,6 +2102,7 @@ streambuf stdexcept
 streambuf string
 streambuf string_view
 streambuf system_error
+streambuf text_encoding
 streambuf tuple
 streambuf type_traits
 streambuf typeinfo
@@ -2184,6 +2220,7 @@ strstream streambuf
 strstream string
 strstream string_view
 strstream system_error
+strstream text_encoding
 strstream tuple
 strstream type_traits
 strstream typeinfo
@@ -2239,6 +2276,7 @@ syncstream streambuf
 syncstream string
 syncstream string_view
 syncstream system_error
+syncstream text_encoding
 syncstream tuple
 syncstream type_traits
 syncstream typeinfo
@@ -2331,6 +2369,7 @@ thread streambuf
 thread string
 thread string_view
 thread system_error
+thread text_encoding
 thread tuple
 thread type_traits
 thread typeinfo
@@ -2443,6 +2482,7 @@ unordered_set streambuf
 unordered_set string
 unordered_set string_view
 unordered_set system_error
+unordered_set text_encoding
 unordered_set tuple
 unordered_set type_traits
 unordered_set typeinfo
@@ -2499,6 +2539,7 @@ valarray streambuf
 valarray string
 valarray string_view
 valarray system_error
+valarray text_encoding
 valarray tuple
 valarray type_traits
 valarray typeinfo
@@ -2560,6 +2601,7 @@ vector streambuf
 vector string
 vector string_view
 vector system_error
+vector text_encoding
 vector tuple
 vector type_traits
 vector typeinfo
diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv
index c0031543e47bc..b0b58724e64ab 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -69,6 +69,7 @@ any streambuf
 any string
 any string_view
 any system_error
+any text_encoding
 any tuple
 any type_traits
 any typeinfo
@@ -122,15 +123,19 @@ atomic ratio
 atomic type_traits
 atomic version
 barrier atomic
+barrier cctype
 barrier climits
 barrier cmath
 barrier compare
 barrier concepts
 barrier cstddef
 barrier cstdint
+barrier cstdio
 barrier cstdlib
 barrier cstring
 barrier ctime
+barrier cwchar
+barrier cwctype
 barrier exception
 barrier initializer_list
 barrier iosfwd
@@ -234,6 +239,7 @@ ccomplex streambuf
 ccomplex string
 ccomplex string_view
 ccomplex system_error
+ccomplex text_encoding
 ccomplex tuple
 ccomplex type_traits
 ccomplex typeinfo
@@ -292,6 +298,7 @@ chrono streambuf
 chrono string
 chrono string_view
 chrono system_error
+chrono text_encoding
 chrono tuple
 chrono type_traits
 chrono typeinfo
@@ -337,6 +344,7 @@ codecvt stdexcept
 codecvt string
 codecvt string_view
 codecvt system_error
+codecvt text_encoding
 codecvt tuple
 codecvt type_traits
 codecvt typeinfo
@@ -396,6 +404,7 @@ complex streambuf
 complex string
 complex string_view
 complex system_error
+complex text_encoding
 complex tuple
 complex type_traits
 complex typeinfo
@@ -501,6 +510,7 @@ ctgmath streambuf
 ctgmath string
 ctgmath string_view
 ctgmath system_error
+ctgmath text_encoding
 ctgmath tuple
 ctgmath type_traits
 ctgmath typeinfo
@@ -552,6 +562,7 @@ deque streambuf
 deque string
 deque string_view
 deque system_error
+deque text_encoding
 deque tuple
 deque type_traits
 deque typeinfo
@@ -607,6 +618,7 @@ experimental/iterator streambuf
 experimental/iterator string
 experimental/iterator string_view
 experimental/iterator system_error
+experimental/iterator text_encoding
 experimental/iterator tuple
 experimental/iterator type_traits
 experimental/iterator typeinfo
@@ -732,6 +744,7 @@ format streambuf
 format string
 format string_view
 format system_error
+format text_encoding
 format tuple
 format type_traits
 format typeinfo
@@ -778,6 +791,7 @@ forward_list streambuf
 forward_list string
 forward_list string_view
 forward_list system_error
+forward_list text_encoding
 forward_list tuple
 forward_list type_traits
 forward_list typeinfo
@@ -834,6 +848,7 @@ fstream streambuf
 fstream string
 fstream string_view
 fstream system_error
+fstream text_encoding
 fstream tuple
 fstream type_traits
 fstream typeinfo
@@ -879,6 +894,7 @@ functional streambuf
 functional string
 functional string_view
 functional system_error
+functional text_encoding
 functional tuple
 functional type_traits
 functional typeinfo
@@ -936,6 +952,7 @@ future streambuf
 future string
 future string_view
 future system_error
+future text_encoding
 future thread
 future tuple
 future type_traits
@@ -993,6 +1010,7 @@ iomanip streambuf
 iomanip string
 iomanip string_view
 iomanip system_error
+iomanip text_encoding
 iomanip tuple
 iomanip type_traits
 iomanip typeinfo
@@ -1033,6 +1051,7 @@ ios stdexcept
 ios string
 ios string_view
 ios system_error
+ios text_encoding
 ios tuple
 ios type_traits
 ios typeinfo
@@ -1086,6 +1105,7 @@ iostream streambuf
 iostream string
 iostream string_view
 iostream system_error
+iostream text_encoding
 iostream tuple
 iostream type_traits
 iostream typeinfo
@@ -1139,6 +1159,7 @@ istream streambuf
 istream string
 istream string_view
 istream system_error
+istream text_encoding
 istream tuple
 istream type_traits
 istream typeinfo
@@ -1223,6 +1244,7 @@ list streambuf
 list string
 list string_view
 list system_error
+list text_encoding
 list tuple
 list type_traits
 list typeinfo
@@ -1266,6 +1288,7 @@ locale streambuf
 locale string
 locale string_view
 locale system_error
+locale text_encoding
 locale tuple
 locale type_traits
 locale typeinfo
@@ -1310,6 +1333,7 @@ map streambuf
 map string
 map string_view
 map system_error
+map text_encoding
 map tuple
 map type_traits
 map typeinfo
@@ -1442,6 +1466,7 @@ numeric streambuf
 numeric string
 numeric string_view
 numeric system_error
+numeric text_encoding
 numeric tuple
 numeric type_traits
 numeric typeinfo
@@ -1523,6 +1548,7 @@ ostream streambuf
 ostream string
 ostream string_view
 ostream system_error
+ostream text_encoding
 ostream tuple
 ostream type_traits
 ostream typeinfo
@@ -1573,6 +1599,7 @@ print streambuf
 print string
 print string_view
 print system_error
+print text_encoding
 print tuple
 print type_traits
 print typeinfo
@@ -1620,6 +1647,7 @@ queue streambuf
 queue string
 queue string_view
 queue system_error
+queue text_encoding
 queue tuple
 queue type_traits
 queue typeinfo
@@ -1668,6 +1696,7 @@ random streambuf
 random string
 random string_view
 random system_error
+random text_encoding
 random tuple
 random type_traits
 random typeinfo
@@ -1742,6 +1771,7 @@ regex streambuf
 regex string
 regex string_view
 regex system_error
+regex text_encoding
 regex tuple
 regex type_traits
 regex typeinfo
@@ -1830,6 +1860,7 @@ set streambuf
 set string
 set string_view
 set system_error
+set text_encoding
 set tuple
 set type_traits
 set typeinfo
@@ -1914,6 +1945,7 @@ span streambuf
 span string
 span string_view
 span system_error
+span text_encoding
 span tuple
 span type_traits
 span typeinfo
@@ -1968,6 +2000,7 @@ sstream streambuf
 sstream string
 sstream string_view
 sstream system_error
+sstream text_encoding
 sstream tuple
 sstream type_traits
 sstream typeinfo
@@ -2015,6 +2048,7 @@ stack streambuf
 stack string
 stack string_view
 stack system_error
+stack text_encoding
 stack tuple
 stack type_traits
 stack typeinfo
@@ -2032,6 +2066,7 @@ stdexcept new
 stdexcept type_traits
 stdexcept typeinfo
 stdexcept version
+stop_token cstddef
 stop_token iosfwd
 stop_token version
 streambuf algorithm
@@ -2067,6 +2102,7 @@ streambuf stdexcept
 streambuf string
 streambuf string_view
 streambuf system_error
+streambuf text_encoding
 streambuf tuple
 streambuf type_traits
 streambuf typeinfo
@@ -2184,6 +2220,7 @@ strstream streambuf
 strstream string
 strstream string_view
 strstream system_error
+strstream text_encoding
 strstream tuple
 strstream type_traits
 strstream typeinfo
@@ -2239,6 +2276,7 @@ syncstream streambuf
 syncstream string
 syncstream string_view
 syncstream system_error
+syncstream text_encoding
 syncstream tuple
 syncstream type_traits
 syncstream typeinfo
@@ -2331,6 +2369,7 @@ thread streambuf
 thread string
 thread string_view
 thread system_error
+thread text_encoding
 thread tuple
 thread type_traits
 thread typeinfo
@@ -2443,6 +2482,7 @@ unordered_set streambuf
 unordered_set string
 unordered_set string_view
 unordered_set system_error
+unordered_set text_encoding
 unordered_set tuple
 unordered_set type_traits
 unordered_set typeinfo
@@ -2499,6 +2539,7 @@ valarray streambuf
 valarray string
 valarray string_view
 valarray system_error
+valarray text_encoding
 valarray tuple
 valarray type_traits
 valarray typeinfo
@@ -2560,6 +2601,7 @@ vector streambuf
 vector string
 vector string_view
 vector system_error
+vector text_encoding
 vector tuple
 vector type_traits
 vector typeinfo
diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv
index c2eb5b44e8d7a..b438907b35195 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -71,6 +71,7 @@ any streambuf
 any string
 any string_view
 any system_error
+any text_encoding
 any tuple
 any type_traits
 any typeinfo
@@ -125,15 +126,19 @@ atomic ratio
 atomic type_traits
 atomic version
 barrier atomic
+barrier cctype
 barrier climits
 barrier cmath
 barrier compare
 barrier concepts
 barrier cstddef
 barrier cstdint
+barrier cstdio
 barrier cstdlib
 barrier cstring
 barrier ctime
+barrier cwchar
+barrier cwctype
 barrier exception
 barrier initializer_list
 barrier iosfwd
@@ -239,6 +244,7 @@ ccomplex streambuf
 ccomplex string
 ccomplex string_view
 ccomplex system_error
+ccomplex text_encoding
 ccomplex tuple
 ccomplex type_traits
 ccomplex typeinfo
@@ -298,6 +304,7 @@ chrono streambuf
 chrono string
 chrono string_view
 chrono system_error
+chrono text_encoding
 chrono tuple
 chrono type_traits
 chrono typeinfo
@@ -344,6 +351,7 @@ codecvt stdexcept
 codecvt string
 codecvt string_view
 codecvt system_error
+codecvt text_encoding
 codecvt tuple
 codecvt type_traits
 codecvt typeinfo
@@ -404,6 +412,7 @@ complex streambuf
 complex string
 complex string_view
 complex system_error
+complex text_encoding
 complex tuple
 complex type_traits
 complex typeinfo
@@ -511,6 +520,7 @@ ctgmath streambuf
 ctgmath string
 ctgmath string_view
 ctgmath system_error
+ctgmath text_encoding
 ctgmath tuple
 ctgmath type_traits
 ctgmath typeinfo
@@ -563,6 +573,7 @@ deque streambuf
 deque string
 deque string_view
 deque system_error
+deque text_encoding
 deque tuple
 deque type_traits
 deque typeinfo
@@ -619,6 +630,7 @@ experimental/iterator streambuf
 experimental/iterator string
 experimental/iterator string_view
 experimental/iterator system_error
+experimental/iterator text_encoding
 experimental/iterator tuple
 experimental/iterator type_traits
 experimental/iterator typeinfo
@@ -751,6 +763,7 @@ format streambuf
 format string
 format string_view
 format system_error
+format text_encoding
 format tuple
 format type_traits
 format typeinfo
@@ -798,6 +811,7 @@ forward_list streambuf
 forward_list string
 forward_list string_view
 forward_list system_error
+forward_list text_encoding
 forward_list tuple
 forward_list type_traits
 forward_list typeinfo
@@ -855,6 +869,7 @@ fstream streambuf
 fstream string
 fstream string_view
 fstream system_error
+fstream text_encoding
 fstream tuple
 fstream type_traits
 fstream typeinfo
@@ -901,6 +916,7 @@ functional streambuf
 functional string
 functional string_view
 functional system_error
+functional text_encoding
 functional tuple
 functional type_traits
 functional typeinfo
@@ -959,6 +975,7 @@ future streambuf
 future string
 future string_view
 future system_error
+future text_encoding
 future thread
 future tuple
 future type_traits
@@ -1017,6 +1034,7 @@ iomanip streambuf
 iomanip string
 iomanip string_view
 iomanip system_error
+iomanip text_encoding
 iomanip tuple
 iomanip type_traits
 iomanip typeinfo
@@ -1058,6 +1076,7 @@ ios stdexcept
 ios string
 ios string_view
 ios system_error
+ios text_encoding
 ios tuple
 ios type_traits
 ios typeinfo
@@ -1112,6 +1131,7 @@ iostream streambuf
 iostream string
 iostream string_view
 iostream system_error
+iostream text_encoding
 iostream tuple
 iostream type_traits
 iostream typeinfo
@@ -1166,6 +1186,7 @@ istream streambuf
 istream string
 istream string_view
 istream system_error
+istream text_encoding
 istream tuple
 istream type_traits
 istream typeinfo
@@ -1251,6 +1272,7 @@ list streambuf
 list string
 list string_view
 list system_error
+list text_encoding
 list tuple
 list type_traits
 list typeinfo
@@ -1295,6 +1317,7 @@ locale streambuf
 locale string
 locale string_view
 locale system_error
+locale text_encoding
 locale tuple
 locale type_traits
 locale typeinfo
@@ -1340,6 +1363,7 @@ map streambuf
 map string
 map string_view
 map system_error
+map text_encoding
 map tuple
 map type_traits
 map typeinfo
@@ -1473,6 +1497,7 @@ numeric streambuf
 numeric string
 numeric string_view
 numeric system_error
+numeric text_encoding
 numeric tuple
 numeric type_traits
 numeric typeinfo
@@ -1555,6 +1580,7 @@ ostream streambuf
 ostream string
 ostream string_view
 ostream system_error
+ostream text_encoding
 ostream tuple
 ostream type_traits
 ostream typeinfo
@@ -1606,6 +1632,7 @@ print streambuf
 print string
 print string_view
 print system_error
+print text_encoding
 print tuple
 print type_traits
 print typeinfo
@@ -1654,6 +1681,7 @@ queue streambuf
 queue string
 queue string_view
 queue system_error
+queue text_encoding
 queue tuple
 queue type_traits
 queue typeinfo
@@ -1702,6 +1730,7 @@ random streambuf
 random string
 random string_view
 random system_error
+random text_encoding
 random tuple
 random type_traits
 random typeinfo
@@ -1777,6 +1806,7 @@ regex streambuf
 regex string
 regex string_view
 regex system_error
+regex text_encoding
 regex tuple
 regex type_traits
 regex typeinfo
@@ -1866,6 +1896,7 @@ set streambuf
 set string
 set string_view
 set system_error
+set text_encoding
 set tuple
 set type_traits
 set typeinfo
@@ -1952,6 +1983,7 @@ span streambuf
 span string
 span string_view
 span system_error
+span text_encoding
 span tuple
 span type_traits
 span typeinfo
@@ -2007,6 +2039,7 @@ sstream streambuf
 sstream string
 sstream string_view
 sstream system_error
+sstream text_encoding
 sstream tuple
 sstream type_traits
 sstream typeinfo
@@ -2055,6 +2088,7 @@ stack streambuf
 stack string
 stack string_view
 stack system_error
+stack text_encoding
 stack tuple
 stack type_traits
 stack typeinfo
@@ -2072,6 +2106,7 @@ stdexcept new
 stdexcept type_traits
 stdexcept typeinfo
 stdexcept version
+stop_token cstddef
 stop_token iosfwd
 stop_token version
 streambuf algorithm
@@ -2108,6 +2143,7 @@ streambuf stdexcept
 streambuf string
 streambuf string_view
 streambuf system_error
+streambuf text_encoding
 streambuf tuple
 streambuf type_traits
 streambuf typeinfo
@@ -2228,6 +2264,7 @@ strstream streambuf
 strstream string
 strstream string_view
 strstream system_error
+strstream text_encoding
 strstream tuple
 strstream type_traits
 strstream typeinfo
@@ -2284,6 +2321,7 @@ syncstream streambuf
 syncstream string
 syncstream string_view
 syncstream system_error
+syncstream text_encoding
 syncstream tuple
 syncstream type_traits
 syncstream typeinfo
@@ -2378,6 +2416,7 @@ thread streambuf
 thread string
 thread string_view
 thread system_error
+thread text_encoding
 thread tuple
 thread type_traits
 thread typeinfo
@@ -2492,6 +2531,7 @@ unordered_set streambuf
 unordered_set string
 unordered_set string_view
 unordered_set system_error
+unordered_set text_encoding
 unordered_set tuple
 unordered_set type_traits
 unordered_set typeinfo
@@ -2549,6 +2589,7 @@ valarray streambuf
 valarray string
 valarray string_view
 valarray system_error
+valarray text_encoding
 valarray tuple
 valarray type_traits
 valarray typeinfo
@@ -2611,6 +2652,7 @@ vector streambuf
 vector string
 vector string_view
 vector system_error
+vector text_encoding
 vector tuple
 vector type_traits
 vector typeinfo
diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv
index 332cb62f35b5f..a93fb1e26196b 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx17.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv
@@ -69,6 +69,7 @@ any streambuf
 any string
 any string_view
 any system_error
+any text_encoding
 any tuple
 any type_traits
 any typeinfo
@@ -122,15 +123,19 @@ atomic ratio
 atomic type_traits
 atomic version
 barrier atomic
+barrier cctype
 barrier climits
 barrier cmath
 barrier compare
 barrier concepts
 barrier cstddef
 barrier cstdint
+barrier cstdio
 barrier cstdlib
 barrier cstring
 barrier ctime
+barrier cwchar
+barrier cwctype
 barrier exception
 barrier initializer_list
 barrier iosfwd
@@ -234,6 +239,7 @@ ccomplex streambuf
 ccomplex string
 ccomplex string_view
 ccomplex system_error
+ccomplex text_encoding
 ccomplex tuple
 ccomplex type_traits
 ccomplex typeinfo
@@ -294,6 +300,7 @@ chrono streambuf
 chrono string
 chrono string_view
 chrono system_error
+chrono text_encoding
 chrono tuple
 chrono type_traits
 chrono typeinfo
@@ -339,6 +346,7 @@ codecvt stdexcept
 codecvt string
 codecvt string_view
 codecvt system_error
+codecvt text_encoding
 codecvt tuple
 codecvt type_traits
 codecvt typeinfo
@@ -398,6 +406,7 @@ complex streambuf
 complex string
 complex string_view
 complex system_error
+complex text_encoding
 complex tuple
 complex type_traits
 complex typeinfo
@@ -503,6 +512,7 @@ ctgmath streambuf
 ctgmath string
 ctgmath string_view
 ctgmath system_error
+ctgmath text_encoding
 ctgmath tuple
 ctgmath type_traits
 ctgmath typeinfo
@@ -554,6 +564,7 @@ deque streambuf
 deque string
 deque string_view
 deque system_error
+deque text_encoding
 deque tuple
 deque type_traits
 deque typeinfo
@@ -609,6 +620,7 @@ experimental/iterator streambuf
 experimental/iterator string
 experimental/iterator string_view
 experimental/iterator system_error
+experimental/iterator text_encoding
 experimental/iterator tuple
 experimental/iterator type_traits
 experimental/iterator typeinfo
@@ -693,6 +705,7 @@ filesystem streambuf
 filesystem string
 filesystem string_view
 filesystem system_error
+filesystem text_encoding
 filesystem tuple
 filesystem type_traits
 filesystem typeinfo
@@ -758,6 +771,7 @@ format streambuf
 format string
 format string_view
 format system_error
+format text_encoding
 format tuple
 format type_traits
 format typeinfo
@@ -804,6 +818,7 @@ forward_list streambuf
 forward_list string
 forward_list string_view
 forward_list system_error
+forward_list text_encoding
 forward_list tuple
 forward_list type_traits
 forward_list typeinfo
@@ -860,6 +875,7 @@ fstream streambuf
 fstream string
 fstream string_view
 fstream system_error
+fstream text_encoding
 fstream tuple
 fstream type_traits
 fstream typeinfo
@@ -905,6 +921,7 @@ functional streambuf
 functional string
 functional string_view
 functional system_error
+functional text_encoding
 functional tuple
 functional type_traits
 functional typeinfo
@@ -962,6 +979,7 @@ future streambuf
 future string
 future string_view
 future system_error
+future text_encoding
 future thread
 future tuple
 future type_traits
@@ -1019,6 +1037,7 @@ iomanip streambuf
 iomanip string
 iomanip string_view
 iomanip system_error
+iomanip text_encoding
 iomanip tuple
 iomanip type_traits
 iomanip typeinfo
@@ -1059,6 +1078,7 @@ ios stdexcept
 ios string
 ios string_view
 ios system_error
+ios text_encoding
 ios tuple
 ios type_traits
 ios typeinfo
@@ -1112,6 +1132,7 @@ iostream streambuf
 iostream string
 iostream string_view
 iostream system_error
+iostream text_encoding
 iostream tuple
 iostream type_traits
 iostream typeinfo
@@ -1165,6 +1186,7 @@ istream streambuf
 istream string
 istream string_view
 istream system_error
+istream text_encoding
 istream tuple
 istream type_traits
 istream typeinfo
@@ -1249,6 +1271,7 @@ list streambuf
 list string
 list string_view
 list system_error
+list text_encoding
 list tuple
 list type_traits
 list typeinfo
@@ -1292,6 +1315,7 @@ locale streambuf
 locale string
 locale string_view
 locale system_error
+locale text_encoding
 locale tuple
 locale type_traits
 locale typeinfo
@@ -1336,6 +1360,7 @@ map streambuf
 map string
 map string_view
 map system_error
+map text_encoding
 map tuple
 map type_traits
 map typeinfo
@@ -1495,6 +1520,7 @@ numeric streambuf
 numeric string
 numeric string_view
 numeric system_error
+numeric text_encoding
 numeric tuple
 numeric type_traits
 numeric typeinfo
@@ -1576,6 +1602,7 @@ ostream streambuf
 ostream string
 ostream string_view
 ostream system_error
+ostream text_encoding
 ostream tuple
 ostream type_traits
 ostream typeinfo
@@ -1626,6 +1653,7 @@ print streambuf
 print string
 print string_view
 print system_error
+print text_encoding
 print tuple
 print type_traits
 print typeinfo
@@ -1673,6 +1701,7 @@ queue streambuf
 queue string
 queue string_view
 queue system_error
+queue text_encoding
 queue tuple
 queue type_traits
 queue typeinfo
@@ -1721,6 +1750,7 @@ random streambuf
 random string
 random string_view
 random system_error
+random text_encoding
 random tuple
 random type_traits
 random typeinfo
@@ -1795,6 +1825,7 @@ regex streambuf
 regex string
 regex string_view
 regex system_error
+regex text_encoding
 regex tuple
 regex type_traits
 regex typeinfo
@@ -1883,6 +1914,7 @@ set streambuf
 set string
 set string_view
 set system_error
+set text_encoding
 set tuple
 set type_traits
 set typeinfo
@@ -1967,6 +1999,7 @@ span streambuf
 span string
 span string_view
 span system_error
+span text_encoding
 span tuple
 span type_traits
 span typeinfo
@@ -2021,6 +2054,7 @@ sstream streambuf
 sstream string
 sstream string_view
 sstream system_error
+sstream text_encoding
 sstream tuple
 sstream type_traits
 sstream typeinfo
@@ -2068,6 +2102,7 @@ stack streambuf
 stack string
 stack string_view
 stack system_error
+stack text_encoding
 stack tuple
 stack type_traits
 stack typeinfo
@@ -2085,6 +2120,7 @@ stdexcept new
 stdexcept type_traits
 stdexcept typeinfo
 stdexcept version
+stop_token cstddef
 stop_token iosfwd
 stop_token version
 streambuf algorithm
@@ -2120,6 +2156,7 @@ streambuf stdexcept
 streambuf string
 streambuf string_view
 streambuf system_error
+streambuf text_encoding
 streambuf tuple
 streambuf type_traits
 streambuf typeinfo
@@ -2237,6 +2274,7 @@ strstream streambuf
 strstream string
 strstream string_view
 strstream system_error
+strstream text_encoding
 strstream tuple
 strstream type_traits
 strstream typeinfo
@@ -2292,6 +2330,7 @@ syncstream streambuf
 syncstream string
 syncstream string_view
 syncstream system_error
+syncstream text_encoding
 syncstream tuple
 syncstream type_traits
 syncstream typeinfo
@@ -2384,6 +2423,7 @@ thread streambuf
 thread string
 thread string_view
 thread system_error
+thread text_encoding
 thread tuple
 thread type_traits
 thread typeinfo
@@ -2496,6 +2536,7 @@ unordered_set streambuf
 unordered_set string
 unordered_set string_view
 unordered_set system_error
+unordered_set text_encoding
 unordered_set tuple
 unordered_set type_traits
 unordered_set typeinfo
@@ -2552,6 +2593,7 @@ valarray streambuf
 valarray string
 valarray string_view
 valarray system_error
+valarray text_encoding
 valarray tuple
 valarray type_traits
 valarray typeinfo
@@ -2613,6 +2655,7 @@ vector streambuf
 vector string
 vector string_view
 vector system_error
+vector text_encoding
 vector tuple
 vector type_traits
 vector typeinfo
diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv
index 55c79acff5a8f..ded0dd1a51c16 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx20.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv
@@ -219,6 +219,7 @@ ccomplex streambuf
 ccomplex string
 ccomplex string_view
 ccomplex system_error
+ccomplex text_encoding
 ccomplex tuple
 ccomplex type_traits
 ccomplex typeinfo
@@ -289,6 +290,7 @@ chrono streambuf
 chrono string
 chrono string_view
 chrono system_error
+chrono text_encoding
 chrono tuple
 chrono type_traits
 chrono typeinfo
@@ -334,6 +336,7 @@ codecvt stdexcept
 codecvt string
 codecvt string_view
 codecvt system_error
+codecvt text_encoding
 codecvt tuple
 codecvt type_traits
 codecvt typeinfo
@@ -393,6 +396,7 @@ complex streambuf
 complex string
 complex string_view
 complex system_error
+complex text_encoding
 complex tuple
 complex type_traits
 complex typeinfo
@@ -499,6 +503,7 @@ ctgmath streambuf
 ctgmath string
 ctgmath string_view
 ctgmath system_error
+ctgmath text_encoding
 ctgmath tuple
 ctgmath type_traits
 ctgmath typeinfo
@@ -550,6 +555,7 @@ deque streambuf
 deque string
 deque string_view
 deque system_error
+deque text_encoding
 deque tuple
 deque type_traits
 deque typeinfo
@@ -605,6 +611,7 @@ experimental/iterator streambuf
 experimental/iterator string
 experimental/iterator string_view
 experimental/iterator system_error
+experimental/iterator text_encoding
 experimental/iterator tuple
 experimental/iterator type_traits
 experimental/iterator typeinfo
@@ -689,6 +696,7 @@ filesystem streambuf
 filesystem string
 filesystem string_view
 filesystem system_error
+filesystem text_encoding
 filesystem tuple
 filesystem type_traits
 filesystem typeinfo
@@ -754,6 +762,7 @@ format streambuf
 format string
 format string_view
 format system_error
+format text_encoding
 format tuple
 format type_traits
 format typeinfo
@@ -800,6 +809,7 @@ forward_list streambuf
 forward_list string
 forward_list string_view
 forward_list system_error
+forward_list text_encoding
 forward_list tuple
 forward_list type_traits
 forward_list typeinfo
@@ -856,6 +866,7 @@ fstream streambuf
 fstream string
 fstream string_view
 fstream system_error
+fstream text_encoding
 fstream tuple
 fstream type_traits
 fstream typeinfo
@@ -901,6 +912,7 @@ functional streambuf
 functional string
 functional string_view
 functional system_error
+functional text_encoding
 functional tuple
 functional type_traits
 functional typeinfo
@@ -956,6 +968,7 @@ future streambuf
 future string
 future string_view
 future system_error
+future text_encoding
 future thread
 future tuple
 future type_traits
@@ -1013,6 +1026,7 @@ iomanip streambuf
 iomanip string
 iomanip string_view
 iomanip system_error
+iomanip text_encoding
 iomanip tuple
 iomanip type_traits
 iomanip typeinfo
@@ -1053,6 +1067,7 @@ ios stdexcept
 ios string
 ios string_view
 ios system_error
+ios text_encoding
 ios tuple
 ios type_traits
 ios typeinfo
@@ -1106,6 +1121,7 @@ iostream streambuf
 iostream string
 iostream string_view
 iostream system_error
+iostream text_encoding
 iostream tuple
 iostream type_traits
 iostream typeinfo
@@ -1159,6 +1175,7 @@ istream streambuf
 istream string
 istream string_view
 istream system_error
+istream text_encoding
 istream tuple
 istream type_traits
 istream typeinfo
@@ -1243,6 +1260,7 @@ list streambuf
 list string
 list string_view
 list system_error
+list text_encoding
 list tuple
 list type_traits
 list typeinfo
@@ -1286,6 +1304,7 @@ locale streambuf
 locale string
 locale string_view
 locale system_error
+locale text_encoding
 locale tuple
 locale type_traits
 locale typeinfo
@@ -1330,6 +1349,7 @@ map streambuf
 map string
 map string_view
 map system_error
+map text_encoding
 map tuple
 map type_traits
 map typeinfo
@@ -1489,6 +1509,7 @@ numeric streambuf
 numeric string
 numeric string_view
 numeric system_error
+numeric text_encoding
 numeric tuple
 numeric type_traits
 numeric typeinfo
@@ -1570,6 +1591,7 @@ ostream streambuf
 ostream string
 ostream string_view
 ostream system_error
+ostream text_encoding
 ostream tuple
 ostream type_traits
 ostream typeinfo
@@ -1620,6 +1642,7 @@ print streambuf
 print string
 print string_view
 print system_error
+print text_encoding
 print tuple
 print type_traits
 print typeinfo
@@ -1667,6 +1690,7 @@ queue streambuf
 queue string
 queue string_view
 queue system_error
+queue text_encoding
 queue tuple
 queue type_traits
 queue typeinfo
@@ -1715,6 +1739,7 @@ random streambuf
 random string
 random string_view
 random system_error
+random text_encoding
 random tuple
 random type_traits
 random typeinfo
@@ -1762,6 +1787,7 @@ ranges streambuf
 ranges string
 ranges string_view
 ranges system_error
+ranges text_encoding
 ranges tuple
 ranges type_traits
 ranges typeinfo
@@ -1813,6 +1839,7 @@ regex streambuf
 regex string
 regex string_view
 regex system_error
+regex text_encoding
 regex tuple
 regex type_traits
 regex typeinfo
@@ -1901,6 +1928,7 @@ set streambuf
 set string
 set string_view
 set system_error
+set text_encoding
 set tuple
 set type_traits
 set typeinfo
@@ -1985,6 +2013,7 @@ span streambuf
 span string
 span string_view
 span system_error
+span text_encoding
 span tuple
 span type_traits
 span typeinfo
@@ -2039,6 +2068,7 @@ sstream streambuf
 sstream string
 sstream string_view
 sstream system_error
+sstream text_encoding
 sstream tuple
 sstream type_traits
 sstream typeinfo
@@ -2086,6 +2116,7 @@ stack streambuf
 stack string
 stack string_view
 stack system_error
+stack text_encoding
 stack tuple
 stack type_traits
 stack typeinfo
@@ -2150,6 +2181,7 @@ streambuf stdexcept
 streambuf string
 streambuf string_view
 streambuf system_error
+streambuf text_encoding
 streambuf tuple
 streambuf type_traits
 streambuf typeinfo
@@ -2267,6 +2299,7 @@ strstream streambuf
 strstream string
 strstream string_view
 strstream system_error
+strstream text_encoding
 strstream tuple
 strstream type_traits
 strstream typeinfo
@@ -2322,6 +2355,7 @@ syncstream streambuf
 syncstream string
 syncstream string_view
 syncstream system_error
+syncstream text_encoding
 syncstream tuple
 syncstream type_traits
 syncstream typeinfo
@@ -2412,6 +2446,7 @@ thread streambuf
 thread string
 thread string_view
 thread system_error
+thread text_encoding
 thread tuple
 thread type_traits
 thread typeinfo
@@ -2524,6 +2559,7 @@ unordered_set streambuf
 unordered_set string
 unordered_set string_view
 unordered_set system_error
+unordered_set text_encoding
 unordered_set tuple
 unordered_set type_traits
 unordered_set typeinfo
@@ -2580,6 +2616,7 @@ valarray streambuf
 valarray string
 valarray string_view
 valarray system_error
+valarray text_encoding
 valarray tuple
 valarray type_traits
 valarray typeinfo
@@ -2641,6 +2678,7 @@ vector streambuf
 vector string
 vector string_view
 vector system_error
+vector text_encoding
 vector tuple
 vector type_traits
 vector typeinfo
diff --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv
index c5cc61f06678c..fb6fac5c15596 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx23.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv
@@ -89,6 +89,7 @@ ccomplex stdexcept
 ccomplex streambuf
 ccomplex string
 ccomplex string_view
+ccomplex text_encoding
 ccomplex tuple
 ccomplex typeinfo
 ccomplex version
@@ -128,6 +129,7 @@ chrono stdexcept
 chrono streambuf
 chrono string
 chrono string_view
+chrono text_encoding
 chrono tuple
 chrono typeinfo
 chrono version
@@ -151,6 +153,7 @@ codecvt limits
 codecvt stdexcept
 codecvt string
 codecvt string_view
+codecvt text_encoding
 codecvt tuple
 codecvt typeinfo
 codecvt version
@@ -184,6 +187,7 @@ complex stdexcept
 complex streambuf
 complex string
 complex string_view
+complex text_encoding
 complex tuple
 complex typeinfo
 complex version
@@ -233,6 +237,7 @@ ctgmath stdexcept
 ctgmath streambuf
 ctgmath string
 ctgmath string_view
+ctgmath text_encoding
 ctgmath tuple
 ctgmath typeinfo
 ctgmath version
@@ -284,6 +289,7 @@ experimental/iterator stdexcept
 experimental/iterator streambuf
 experimental/iterator string
 experimental/iterator string_view
+experimental/iterator text_encoding
 experimental/iterator tuple
 experimental/iterator typeinfo
 experimental/iterator variant
@@ -329,6 +335,7 @@ filesystem stdexcept
 filesystem streambuf
 filesystem string
 filesystem string_view
+filesystem text_encoding
 filesystem tuple
 filesystem typeinfo
 filesystem version
@@ -379,6 +386,7 @@ format optional
 format stdexcept
 format string
 format string_view
+format text_encoding
 format tuple
 format typeinfo
 format version
@@ -418,6 +426,7 @@ fstream stdexcept
 fstream streambuf
 fstream string
 fstream string_view
+fstream text_encoding
 fstream tuple
 fstream typeinfo
 fstream version
@@ -462,6 +471,7 @@ future stdexcept
 future streambuf
 future string
 future string_view
+future text_encoding
 future tuple
 future typeinfo
 future version
@@ -489,6 +499,7 @@ iomanip stdexcept
 iomanip streambuf
 iomanip string
 iomanip string_view
+iomanip text_encoding
 iomanip tuple
 iomanip typeinfo
 iomanip version
@@ -512,6 +523,7 @@ ios ratio
 ios stdexcept
 ios string
 ios string_view
+ios text_encoding
 ios tuple
 ios typeinfo
 ios version
@@ -547,6 +559,7 @@ iostream stdexcept
 iostream streambuf
 iostream string
 iostream string_view
+iostream text_encoding
 iostream tuple
 iostream typeinfo
 iostream version
@@ -574,6 +587,7 @@ istream stdexcept
 istream streambuf
 istream string
 istream string_view
+istream text_encoding
 istream tuple
 istream typeinfo
 istream version
@@ -630,6 +644,7 @@ locale stdexcept
 locale streambuf
 locale string
 locale string_view
+locale text_encoding
 locale tuple
 locale typeinfo
 locale version
@@ -734,6 +749,7 @@ ostream stdexcept
 ostream streambuf
 ostream string
 ostream string_view
+ostream text_encoding
 ostream tuple
 ostream typeinfo
 ostream version
@@ -759,6 +775,7 @@ print optional
 print stdexcept
 print string
 print string_view
+print text_encoding
 print tuple
 print typeinfo
 print version
@@ -849,6 +866,7 @@ regex limits
 regex stdexcept
 regex string
 regex string_view
+regex text_encoding
 regex tuple
 regex typeinfo
 regex vector
@@ -915,6 +933,7 @@ sstream stdexcept
 sstream streambuf
 sstream string
 sstream string_view
+sstream text_encoding
 sstream tuple
 sstream typeinfo
 sstream version
@@ -959,6 +978,7 @@ streambuf ratio
 streambuf stdexcept
 streambuf string
 streambuf string_view
+streambuf text_encoding
 streambuf tuple
 streambuf typeinfo
 streambuf version
@@ -1014,6 +1034,7 @@ strstream stdexcept
 strstream streambuf
 strstream string
 strstream string_view
+strstream text_encoding
 strstream tuple
 strstream typeinfo
 strstream version
@@ -1049,6 +1070,7 @@ syncstream stdexcept
 syncstream streambuf
 syncstream string
 syncstream string_view
+syncstream text_encoding
 syncstream tuple
 syncstream typeinfo
 syncstream version
@@ -1097,6 +1119,7 @@ thread stdexcept
 thread streambuf
 thread string
 thread string_view
+thread text_encoding
 thread tuple
 thread typeinfo
 thread version
diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index 97fcb58969a25..86a204090cb19 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -86,6 +86,7 @@ ccomplex stdexcept
 ccomplex streambuf
 ccomplex string
 ccomplex string_view
+ccomplex text_encoding
 ccomplex tuple
 ccomplex typeinfo
 ccomplex version
@@ -124,6 +125,7 @@ chrono stdexcept
 chrono streambuf
 chrono string
 chrono string_view
+chrono text_encoding
 chrono tuple
 chrono typeinfo
 chrono version
@@ -147,6 +149,7 @@ codecvt limits
 codecvt stdexcept
 codecvt string
 codecvt string_view
+codecvt text_encoding
 codecvt tuple
 codecvt typeinfo
 codecvt version
@@ -179,6 +182,7 @@ complex stdexcept
 complex streambuf
 complex string
 complex string_view
+complex text_encoding
 complex tuple
 complex typeinfo
 complex version
@@ -227,6 +231,7 @@ ctgmath stdexcept
 ctgmath streambuf
 ctgmath string
 ctgmath string_view
+ctgmath text_encoding
 ctgmath tuple
 ctgmath typeinfo
 ctgmath version
@@ -276,6 +281,7 @@ experimental/iterator stdexcept
 experimental/iterator streambuf
 experimental/iterator string
 experimental/iterator string_view
+experimental/iterator text_encoding
 experimental/iterator tuple
 experimental/iterator typeinfo
 experimental/iterator variant
@@ -320,6 +326,7 @@ filesystem ratio
 filesystem stdexcept
 filesystem string
 filesystem string_view
+filesystem text_encoding
 filesystem tuple
 filesystem typeinfo
 filesystem version
@@ -369,6 +376,7 @@ format optional
 format stdexcept
 format string
 format string_view
+format text_encoding
 format tuple
 format typeinfo
 format version
@@ -406,6 +414,7 @@ fstream stdexcept
 fstream streambuf
 fstream string
 fstream string_view
+fstream text_encoding
 fstream tuple
 fstream typeinfo
 fstream version
@@ -449,6 +458,7 @@ future stdexcept
 future streambuf
 future string
 future string_view
+future text_encoding
 future tuple
 future typeinfo
 future version
@@ -474,6 +484,7 @@ iomanip ratio
 iomanip stdexcept
 iomanip string
 iomanip string_view
+iomanip text_encoding
 iomanip tuple
 iomanip typeinfo
 iomanip version
@@ -497,6 +508,7 @@ ios ratio
 ios stdexcept
 ios string
 ios string_view
+ios text_encoding
 ios tuple
 ios typeinfo
 ios version
@@ -530,6 +542,7 @@ iostream stdexcept
 iostream streambuf
 iostream string
 iostream string_view
+iostream text_encoding
 iostream tuple
 iostream typeinfo
 iostream version
@@ -556,6 +569,7 @@ istream stdexcept
 istream streambuf
 istream string
 istream string_view
+istream text_encoding
 istream tuple
 istream typeinfo
 istream version
@@ -612,6 +626,7 @@ locale stdexcept
 locale streambuf
 locale string
 locale string_view
+locale text_encoding
 locale tuple
 locale typeinfo
 locale version
@@ -713,6 +728,7 @@ ostream stdexcept
 ostream streambuf
 ostream string
 ostream string_view
+ostream text_encoding
 ostream tuple
 ostream typeinfo
 ostream version
@@ -737,6 +753,7 @@ print optional
 print stdexcept
 print string
 print string_view
+print text_encoding
 print tuple
 print typeinfo
 print version
@@ -819,6 +836,7 @@ regex limits
 regex stdexcept
 regex string
 regex string_view
+regex text_encoding
 regex tuple
 regex typeinfo
 regex vector
@@ -884,6 +902,7 @@ sstream stdexcept
 sstream streambuf
 sstream string
 sstream string_view
+sstream text_encoding
 sstream tuple
 sstream typeinfo
 sstream version
@@ -928,6 +947,7 @@ streambuf ratio
 streambuf stdexcept
 streambuf string
 streambuf string_view
+streambuf text_encoding
 streambuf tuple
 streambuf typeinfo
 streambuf version
@@ -982,6 +1002,7 @@ strstream stdexcept
 strstream streambuf
 strstream string
 strstream string_view
+strstream text_encoding
 strstream tuple
 strstream typeinfo
 strstream version
@@ -1015,6 +1036,7 @@ syncstream stdexcept
 syncstream streambuf
 syncstream string
 syncstream string_view
+syncstream text_encoding
 syncstream tuple
 syncstream typeinfo
 syncstream version
@@ -1075,6 +1097,7 @@ thread stdexcept
 thread streambuf
 thread string
 thread string_view
+thread text_encoding
 thread tuple
 thread typeinfo
 thread version

>From cb0b52853973a2a8dd3121072d889c49acc431dd Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Thu, 26 Mar 2026 00:05:06 -0400
Subject: [PATCH 45/58] More test adjustments

---
 .../text_encoding.ctor/id.pass.cpp            | 54 ++++++++-----------
 .../text_encoding.eq/equal.pass.cpp           |  2 +-
 2 files changed, 22 insertions(+), 34 deletions(-)

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 f0353525bca23..d42b7225c0620 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
@@ -23,47 +23,35 @@
 
 using id = std::text_encoding::id;
 
-constexpr void id_ctor(id i, std::string_view expect_name) {
-  std::same_as<std::text_encoding> decltype(auto) te = std::text_encoding(i);
-
-  assert(te.mib() == i);
-  assert(expect_name == te.name());
-  assert(std::ranges::contains(te.aliases(), expect_name));
-}
-
-constexpr void id_ctors() {
-  for (auto pair : unique_encoding_data) {
-    id_ctor(id(pair.mib), pair.name);
-  }
-}
-
-constexpr void test_unknown_other() {
+constexpr bool test() {
   {
-    std::text_encoding te = std::text_encoding(id::other);
+    // 2. Constructing an object with a valid id must set mib() and the name to the corresponding value.
+    for (auto pair : unique_encoding_data) {
+      std::same_as<std::text_encoding> decltype(auto) te = std::text_encoding(id(pair.mib));
 
-    assert(te.mib() == id::other);
-    assert(std::string_view("") == te.name());
-    assert(std::ranges::empty(te.aliases()));
+      assert(te.mib() == id(pair.mib));
+      assert(pair.name == te.name());
+      assert(std::ranges::contains(te.aliases(), pair.name));
+    }
   }
 
   {
-    std::text_encoding te = std::text_encoding(id::unknown);
+    // 3. Constructing an object using id::unknown or id::other must set mib() to id::unknown or id::other, respectively, and the name to an empty string.
+    {
+      std::text_encoding te = std::text_encoding(id::other);
 
-    assert(te.mib() == id::unknown);
-    assert(std::string_view("") == te.name());
-    assert(std::ranges::empty(te.aliases()));
-  }
-}
+      assert(te.mib() == id::other);
+      assert(std::string_view("") == te.name());
+      assert(std::ranges::empty(te.aliases()));
+    }
 
-constexpr bool test() {
-  {
-    // 2. Constructing an object with a valid id must set mib() and the name to the corresponding value.
-    id_ctors();
-  }
+    {
+      std::text_encoding te = std::text_encoding(id::unknown);
 
-  {
-    // 3. Constructing an object using id::unknown or id::other must set mib() to id::unknown or id::other, respectively, and the name to an empty string.
-    test_unknown_other();
+      assert(te.mib() == id::unknown);
+      assert(std::string_view("") == te.name());
+      assert(std::ranges::empty(te.aliases()));
+    }
   }
 
   return true;
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 6764937c432e3..f96feda73ed61 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
@@ -44,7 +44,7 @@ constexpr bool test() {
     assert(other_te1 == other_te2);
   }
 
-  // 4. operator==(const text_encoding&, const text_encoding&) returns false when comparingtext_encodings with different ids
+  // 4. operator==(const text_encoding&, const text_encoding&) returns false when comparing text_encodings with different ids
   {
     std::text_encoding te1 = std::text_encoding(id::UTF8);
     std::text_encoding te2 = std::text_encoding(id::UTF16);

>From a3caebda162dbc96214f430eaca3cca6517b0e4e Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Thu, 26 Mar 2026 00:51:33 -0400
Subject: [PATCH 46/58] abi-list, fix includes, add debug print for
 encoding.pass.cpp

---
 libcxx/include/text_encoding                  |  4 ++++
 ...bcxxabi.v1.stable.exceptions.nonew.abilist |  5 +++--
 .../locale/locale.members/encoding.pass.cpp   | 19 ++++++++++++-------
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index ab4f7a0579d23..d32786fe73e0c 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -68,10 +68,14 @@ struct text_encoding
 
 #  if _LIBCPP_STD_VER >= 26
 
+#    include <__algorithm/find_if.h>
 #    include <__algorithm/lower_bound.h>
+#    include <__cstddef/ptrdiff_t.h>
 #    include <__functional/hash.h>
+#    include <__iterator/iterator_traits.h>
 #    include <__ranges/enable_borrowed_range.h>
 #    include <__ranges/view_interface.h>
+#    include <cstdint>
 #    include <string_view>
 #    include <version>
 
diff --git a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
index 27147840df0da..477c3a2ac91b2 100644
--- a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -955,6 +955,7 @@
 {'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED1Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED2Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__113shared_futureIvEaSERKS1_', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt3__113text_encoding11environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__114__num_get_base10__get_baseERNS_8ios_baseE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__114__num_get_base5__srcE', 'size': 33, 'type': 'OBJECT'}
 {'is_defined': True, 'name': '_ZNSt3__114__num_put_base12__format_intEPcPKcbj', 'type': 'FUNC'}
@@ -1209,6 +1210,7 @@
 {'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKNS_17__cxx_atomic_implIiNS_22__cxx_atomic_base_implIiEEEEi', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKvi', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__120__throw_system_errorEiPKc', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt3__121__get_locale_encodingEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__121__throw_runtime_errorEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex4lockEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex6unlockEv', 'type': 'FUNC'}
@@ -1570,7 +1572,6 @@
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
@@ -2028,4 +2029,4 @@
 {'is_defined': True, 'name': '_ZTv0_n24_NSt3__114basic_iostreamIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZTv0_n24_NSt3__114basic_iostreamIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZTv0_n24_NSt3__19strstreamD0Ev', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZTv0_n24_NSt3__19strstreamD1Ev', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZTv0_n24_NSt3__19strstreamD1Ev', 'type': 'FUNC'}
\ No newline at end of file
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
index 5bbe0fba37800..edfed0822dd62 100644
--- a/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
@@ -17,6 +17,8 @@
 // text_encoding locale::encoding() const
 
 #include <cassert>
+#include <format>
+#include <iostream>
 #include <locale>
 #include <text_encoding>
 
@@ -30,15 +32,18 @@ int main(int, char**) {
     const std::locale loc{};
 
     std::text_encoding te = loc.encoding();
-
 #if !defined(__ANDROID__)
-    std::text_encoding classic_te = std::text_encoding(id::ASCII);
-    assert(te == id::ASCII);
-    assert(te == classic_te);
+      std::text_encoding classic_te = std::text_encoding(id::ASCII);
+      if(te != id::ASCII) {
+        std::cerr << std::format(
+            "Expected ASCII, received: {{{}, \"{}\"}}, locale: \"{}\"", int(te.mib()), te.name(), loc.name());
+        assert(false);
+      }
+      assert(te == classic_te);
 #else
-    auto utf8_te = std::text_encoding(id::UTF8);
-    assert(te == id::UTF8);
-    assert(te == utf8_te);
+      auto utf8_te = std::text_encoding(id::UTF8);
+      assert(te == id::UTF8);
+      assert(te == utf8_te);
 #endif
   }
 

>From 4423fa35d2044a58795c65c06b5612da1120063f Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Thu, 26 Mar 2026 00:55:32 -0400
Subject: [PATCH 47/58] Formatting, papers

---
 libcxx/docs/Status/Cxx2cPapers.csv            |  2 +-
 .../locale/locale.members/encoding.pass.cpp   | 20 +++++++++----------
 script.sh                                     |  2 ++
 3 files changed, 13 insertions(+), 11 deletions(-)
 create mode 100644 script.sh

diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index 5cccf8c6d6163..ff65ea8e6b62a 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)","","","`#105370 <https://github.com/llvm/llvm-project/issues/105370>`__",""
 "`P2363R5 <https://wg21.link/P2363R5>`__","Extending associative containers with the remaining heterogeneous overloads","2023-06 (Varna)","","","`#105371 <https://github.com/llvm/llvm-project/issues/105371>`__",""
 "`P1901R2 <https://wg21.link/P1901R2>`__","Enabling the Use of ``weak_ptr`` as Keys in Unordered Associative Containers","2023-06 (Varna)","","","`#105372 <https://github.com/llvm/llvm-project/issues/105372>`__",""
-"`P1885R12 <https://wg21.link/P1885R12>`__","Naming Text Encodings to Demystify Them","2023-06 (Varna)","|Partial|","23","`#105373 <https://github.com/llvm/llvm-project/issues/105373>`__","locale::encoding() is not yet implemented."
+"`P1885R12 <https://wg21.link/P1885R12>`__","Naming Text Encodings to Demystify Them","2023-06 (Varna)","|Complete|","23","`#105373 <https://github.com/llvm/llvm-project/issues/105373>`__",""
 "`P0792R14 <https://wg21.link/P0792R14>`__","``function_ref``: a type-erased callable reference","2023-06 (Varna)","","","`#105376 <https://github.com/llvm/llvm-project/issues/105376>`__",""
 "`P2874R2 <https://wg21.link/P2874R2>`__","P2874R2: Mandating Annex D Require No More","2023-06 (Varna)","|Complete|","12","`#105377 <https://github.com/llvm/llvm-project/issues/105377>`__",""
 "`P2757R3 <https://wg21.link/P2757R3>`__","Type-checking format args","2023-06 (Varna)","","","`#105378 <https://github.com/llvm/llvm-project/issues/105378>`__",""
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
index edfed0822dd62..c744e795b3d8f 100644
--- a/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
@@ -33,17 +33,17 @@ int main(int, char**) {
 
     std::text_encoding te = loc.encoding();
 #if !defined(__ANDROID__)
-      std::text_encoding classic_te = std::text_encoding(id::ASCII);
-      if(te != id::ASCII) {
-        std::cerr << std::format(
-            "Expected ASCII, received: {{{}, \"{}\"}}, locale: \"{}\"", int(te.mib()), te.name(), loc.name());
-        assert(false);
-      }
-      assert(te == classic_te);
+    std::text_encoding classic_te = std::text_encoding(id::ASCII);
+    if (te != id::ASCII) {
+      std::cerr << std::format(
+          "Expected ASCII, received: {{{}, \"{}\"}}, locale: \"{}\"", int(te.mib()), te.name(), loc.name());
+      assert(false);
+    }
+    assert(te == classic_te);
 #else
-      auto utf8_te = std::text_encoding(id::UTF8);
-      assert(te == id::UTF8);
-      assert(te == utf8_te);
+    auto utf8_te = std::text_encoding(id::UTF8);
+    assert(te == id::UTF8);
+    assert(te == utf8_te);
 #endif
   }
 
diff --git a/script.sh b/script.sh
new file mode 100644
index 0000000000000..1706c5d52c997
--- /dev/null
+++ b/script.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+for std in c++03 c++11 c++14 c++17 c++20 c++23 c++26; do python3 ./build/generic-cxx26/bin/llvm-lit --param std=$std libcxx/test/libcxx/transitive_includes.gen.py; done

>From 86d6a886949ded3e4e68b0a4a74cb01fafd84d63 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Thu, 26 Mar 2026 01:07:19 -0400
Subject: [PATCH 48/58] Expose only __get_locale_encoding

---
 libcxx/include/__configuration/availability.h    |  2 +-
 libcxx/include/text_encoding                     | 12 ++++++++++--
 ....libcxxabi.v1.stable.exceptions.nonew.abilist |  1 -
 libcxx/src/text_encoding.cpp                     | 16 ++++------------
 4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/libcxx/include/__configuration/availability.h b/libcxx/include/__configuration/availability.h
index 8ccde06a221fe..103293530499f 100644
--- a/libcxx/include/__configuration/availability.h
+++ b/libcxx/include/__configuration/availability.h
@@ -293,7 +293,7 @@
 #  define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0
 #endif
 
-// Controls whether the internal implementation for text_encoding::environment() -> te_impl::__environment() is available
+// Controls whether the implementation for text_encoding::environment() is available
 #define _LIBCPP_AVAILABILITY_HAS_TE_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_23
 #define _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_INTRODUCED_IN_LLVM_23_ATTRIBUTE
 
diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index d32786fe73e0c..e90f5fc93c438 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -80,6 +80,9 @@ struct text_encoding
 #    include <version>
 
 _LIBCPP_BEGIN_NAMESPACE_STD
+struct text_encoding;
+
+_LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI text_encoding __get_locale_encoding(const char* __name);
 
 struct text_encoding {
   enum class id : int_least32_t {
@@ -578,7 +581,13 @@ public:
   }
 
 #    if _LIBCPP_HAS_LOCALIZATION
-  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI static text_encoding environment();
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static text_encoding environment() {
+#      if defined(_LIBCPP_WIN32API)
+    return __get_locale_encoding(nullptr);
+#      else
+    return __get_locale_encoding("");
+#      endif
+  }
 
   template <id _Id>
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool environment_is() {
@@ -1666,7 +1675,6 @@ struct hash<text_encoding> {
 template <>
 inline constexpr bool ranges::enable_borrowed_range<text_encoding::aliases_view> = true;
 
-_LIBCPP_EXPORTED_FROM_ABI text_encoding __get_locale_encoding(const char* __name);
 _LIBCPP_END_NAMESPACE_STD
 
 #  endif // _LIBCPP_STD_VER >= 26
diff --git a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
index 477c3a2ac91b2..174069ef12fbc 100644
--- a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -955,7 +955,6 @@
 {'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED1Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED2Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__113shared_futureIvEaSERKS1_', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZNSt3__113text_encoding11environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__114__num_get_base10__get_baseERNS_8ios_baseE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__114__num_get_base5__srcE', 'size': 33, 'type': 'OBJECT'}
 {'is_defined': True, 'name': '_ZNSt3__114__num_put_base12__format_intEPcPKcbj', 'type': 'FUNC'}
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 4426d32a9915b..f10dcd712f73a 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -222,6 +222,10 @@ _LIBCPP_HIDDEN text_encoding static __get_win32_acp(unsigned int __codepage) {
 }
 
 _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* __name) {
+  if (__name == nullptr) {
+    return __get_win32_acp(::GetACP());
+  }
+
   wchar_t __locale_wbuffer[LOCALE_NAME_MAX_LENGTH + 1]{};
   wchar_t __number_buffer[11]{};
 
@@ -247,8 +251,6 @@ _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* _
   return __get_win32_acp(__acp);
 }
 
-_LIBCPP_HIDDEN static std::text_encoding __get_env_encoding() { return __get_win32_acp(::GetACP()); }
-
 #elif defined(__ANDROID__)
 // Android has minimal libc suppport for locale, and doesn't support any other locale
 // than the ones checked for below.
@@ -261,11 +263,6 @@ _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* _
   return std::text_encoding();
 }
 
-// Android is pretty much assumed to always be UTF-8.
-_LIBCPP_HIDDEN static std::text_encoding __get_env_encoding() {
-  return std::text_encoding(std::text_encoding::id::UTF8);
-}
-
 #else  // POSIX
 _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* __name) {
   std::text_encoding __e;
@@ -297,11 +294,6 @@ _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* _
   return __e;
 }
 
-_LIBCPP_HIDDEN static std::text_encoding __get_env_encoding() { return __get_locale_encoding(""); }
 #endif // _LIBCPP_WIN32API
 
-_LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_EXPORTED_FROM_ABI std::text_encoding std::text_encoding::environment() {
-  return __get_env_encoding();
-}
-
 _LIBCPP_END_NAMESPACE_STD

>From 5c9d37a263fe22358ba74d3141c7f4cc9c9bfe50 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Thu, 26 Mar 2026 21:11:53 -0400
Subject: [PATCH 49/58] Remove default locale encoding test

---
 .../locale/locale.members/encoding.pass.cpp   | 31 ++-----------------
 1 file changed, 3 insertions(+), 28 deletions(-)

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
index c744e795b3d8f..664f50e52db16 100644
--- a/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
@@ -17,43 +17,18 @@
 // text_encoding locale::encoding() const
 
 #include <cassert>
-#include <format>
-#include <iostream>
 #include <locale>
 #include <text_encoding>
 
 #include "platform_support.h"
 
-using id = std::text_encoding::id;
-
 int main(int, char**) {
   {
-    // 1. Default locale returns a text_encoding representing "ASCII", or "UTF-8 on Android.
-    const std::locale loc{};
-
-    std::text_encoding te = loc.encoding();
-#if !defined(__ANDROID__)
-    std::text_encoding classic_te = std::text_encoding(id::ASCII);
-    if (te != id::ASCII) {
-      std::cerr << std::format(
-          "Expected ASCII, received: {{{}, \"{}\"}}, locale: \"{}\"", int(te.mib()), te.name(), loc.name());
-      assert(false);
-    }
-    assert(te == classic_te);
-#else
-    auto utf8_te = std::text_encoding(id::UTF8);
-    assert(te == id::UTF8);
-    assert(te == utf8_te);
-#endif
-  }
-
-  {
-    // 2. Locale built with en_US.UTF-8 returns text_encoding representing "UTF-8"
+    // 1. Locale built with en_US.UTF-8 returns text_encoding representing "UTF-8"
     const std::locale utf8_locale(LOCALE_en_US_UTF_8);
-
     std::text_encoding te      = utf8_locale.encoding();
-    std::text_encoding utf8_te = std::text_encoding(id::UTF8);
-    assert(te == id::UTF8);
+    std::text_encoding utf8_te = std::text_encoding(std::text_encoding::id::UTF8);
+    assert(te == std::text_encoding::id::UTF8);
     assert(te == utf8_te);
   }
   return 0;

>From 92bf58a0dfd637c32c0635cdd8360c792dbf249d Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Fri, 27 Mar 2026 18:49:06 -0400
Subject: [PATCH 50/58] Fix GCC, update ABI list

---
 libcxx/include/text_encoding                                  | 4 ++--
 ...nux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist | 1 -
 ...werpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist | 1 -
 ...rpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist | 1 -
 ...nux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist | 1 -
 ...known-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist | 4 ++--
 libcxx/src/text_encoding.cpp                                  | 2 +-
 7 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index e90f5fc93c438..7d06092fc1992 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -572,11 +572,11 @@ public:
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static consteval text_encoding literal() noexcept {
     // TODO: Remove this branch once we have __GNUC_EXECUTION_CHARSET_NAME or __clang_literal_encoding__ unconditionally
 #    ifdef __GNUC_EXECUTION_CHARSET_NAME
-    return __te_impl(__GNUC_EXECUTION_CHARSET_NAME);
+    return text_encoding(__GNUC_EXECUTION_CHARSET_NAME);
 #    elif defined(__clang_literal_encoding__)
     return text_encoding(__clang_literal_encoding__);
 #    else
-    return __te_impl();
+    return text_encoding();
 #    endif
   }
 
diff --git a/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
index 36ec5612272f3..34f8359c94317 100644
--- a/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -943,7 +943,6 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvED1Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvED2Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvEaSERKS1_', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZNSt6__ndk113text_encoding11environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_get_base10__get_baseERNS_8ios_baseE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_get_base5__srcE', 'size': 33, 'type': 'OBJECT'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_put_base12__format_intEPcPKcbj', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
index 207d846b618bf..f5dcf255d80f1 100644
--- a/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -420,7 +420,6 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED1Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED2Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvEaSERKS1_', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
-{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113text_encoding11environmentEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_get_base10__get_baseERNS_8ios_baseE', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_get_base5__srcE', 'storage_mapping_class': 'RO', 'type': 'OBJECT'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_put_base12__format_intEPcPKcbj', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
index c0fd1664ce6f7..d24652316ac34 100644
--- a/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -420,7 +420,6 @@
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED1Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvED2Ev', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113shared_futureIvEaSERKS1_', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
-{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__113text_encoding11environmentEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_get_base10__get_baseERNS_8ios_baseE', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_get_base5__srcE', 'storage_mapping_class': 'RO', 'type': 'OBJECT'}
 {'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__114__num_put_base12__format_intEPcPKcbj', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
index 0b0c0846f0249..43793f27e5389 100644
--- a/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -943,7 +943,6 @@
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvED1Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvED2Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk113shared_futureIvEaSERKS1_', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZNSt6__ndk113text_encoding11environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_get_base10__get_baseERNS_8ios_baseE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_get_base5__srcE', 'size': 33, 'type': 'OBJECT'}
 {'is_defined': True, 'name': '_ZNSt6__ndk114__num_put_base12__format_intEPcPKcbj', 'type': 'FUNC'}
diff --git a/libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist
index 09b2524bfa1a9..52dce4afd97e3 100644
--- a/libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -1211,6 +1211,7 @@
 {'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKNS_17__cxx_atomic_implIlNS_22__cxx_atomic_base_implIlEEEEl', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKvl', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__120__throw_system_errorEiPKc', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt3__121__get_locale_encodingEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__121__throw_runtime_errorEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex4lockEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex6unlockEv', 'type': 'FUNC'}
@@ -1571,7 +1572,6 @@
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
@@ -2029,4 +2029,4 @@
 {'is_defined': True, 'name': '_ZTv0_n24_NSt3__114basic_iostreamIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZTv0_n24_NSt3__114basic_iostreamIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZTv0_n24_NSt3__19strstreamD0Ev', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZTv0_n24_NSt3__19strstreamD1Ev', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZTv0_n24_NSt3__19strstreamD1Ev', 'type': 'FUNC'}
\ No newline at end of file
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index f10dcd712f73a..c3ba1dff54c2a 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -263,7 +263,7 @@ _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* _
   return std::text_encoding();
 }
 
-#else  // POSIX
+#else // POSIX
 _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* __name) {
   std::text_encoding __e;
 

>From 4177fce658f8463a9916aefacb15d5014583e4fb Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Fri, 27 Mar 2026 23:42:31 -0400
Subject: [PATCH 51/58] Fix tests

---
 ...inux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist | 2 +-
 libcxx/src/text_encoding.cpp                               | 2 --
 .../utilities/text_encoding/environment.windows.pass.cpp   | 5 +++--
 .../text_encoding.ctor/assert.string_view.pass.cpp         | 4 ++--
 .../text_encoding.members/environment.delete.verify.cpp    | 7 +++----
 5 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist
index 3bfe255563a56..d1b7a878b2812 100644
--- a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist
+++ b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist
@@ -1180,6 +1180,7 @@
 {'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKNS_17__cxx_atomic_implIiNS_22__cxx_atomic_base_implIiEEEEi', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__120__libcpp_atomic_waitEPVKvi', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__120__throw_system_errorEiPKc', 'type': 'FUNC'}
+{'is_defined': True, 'name': '_ZNSt3__121__get_locale_encodingEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__121__throw_runtime_errorEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex4lockEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__121recursive_timed_mutex6unlockEv', 'type': 'FUNC'}
@@ -1541,7 +1542,6 @@
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
-{'is_defined': True, 'name': '_ZNSt3__19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '_ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index c3ba1dff54c2a..26928a34e34ca 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -21,8 +21,6 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if defined(_LIBCPP_WIN32API)
-_LIBCPP_HIDDEN text_encoding __get_win32_acp(unsigned int __codepage);
-
 _LIBCPP_HIDDEN text_encoding static __get_win32_acp(unsigned int __codepage) {
   switch (__codepage) {
   case 0:
diff --git a/libcxx/test/libcxx/utilities/text_encoding/environment.windows.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/environment.windows.pass.cpp
index b7f9f5c8084bd..465a62078adc1 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/environment.windows.pass.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/environment.windows.pass.cpp
@@ -20,16 +20,17 @@
 #include <cassert>
 #include <cstdlib>
 #include <text_encoding>
+#include <windows.h>
 
 #include "platform_support.h" // locale name macros
 
 int main(int, char**) {
   // On Windows, changes to the "LANG" environment variable don't affect the result
   // of std::text_encoding::environment() and environment_is()
+  auto te = std::text_encoding::environment();
 
-  ::setenv("LANG", LOCALE_fr_CA_ISO8859_1, 1);
+  ::SetEnvironmentVariableA("LANG", LOCALE_fr_CA_ISO8859_1);
 
-  auto te = std::text_encoding::environment();
   assert(std::text_encoding::environment_is<std::text_encoding::id::windows1252>());
   assert(te == std::text_encoding::environment());
   assert(te.mib() == std::text_encoding::id::windows1252);
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
index 886249a50098e..82b6a009c7d49 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.ctor/assert.string_view.pass.cpp
@@ -20,13 +20,13 @@
 #include "check_assertion.h"
 
 int main(int, char**) {
-  std::string str('X', std::text_encoding::max_name_length + 1);
+  std::string str(std::text_encoding::max_name_length + 1, 'X');
 
   // text_encoding(string_view) asserts if its input size() > max_name_length
   TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::string_view(str)), "input string_view must have size <= 63");
 
   // text_encoding(string_view) asserts if its input contains a null terminator
-  std::string str2('X', std::text_encoding::max_name_length);
+  std::string str2(std::text_encoding::max_name_length, 'X');
   str2[3] = '\0';
 
   TEST_LIBCPP_ASSERT_FAILURE(std::text_encoding(std::string_view(str2)), "input string_view must not contain '\\0'");
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp
index 5f0f222fb0ac2..cfbe874a74c98 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp
@@ -15,15 +15,14 @@
 // text_encoding text_encoding::environment()
 // template<std::text_encoding::id> text_encoding text_encoding::environment_is()
 
-// environment() and environment_is() are deleted if there is libc++ is built
-// without localization.
+// environment() and environment_is() are deleted if libc++ is built without localization.
 
 #include <text_encoding>
 
 int main(int, char**) {
-  // expected-warning at +1 {{attempt to use a deleted function}}
+  // expected-error at +1 {{attempt to use a deleted function}}
   std::text_encoding::environment();
-  // expected-warning at +1 {{attempt to use a deleted function}}
+  // expected-error at +1 {{attempt to use a deleted function}}
   std::text_encoding::environment_is<std::text_encoding::UTF8>();
 
   return 0;

>From e552f99085ddfbe7bc4c9ef09f4a64e5b882dba6 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Sun, 29 Mar 2026 17:48:20 -0400
Subject: [PATCH 52/58] Cleanup

---
 libcxx/include/text_encoding                  | 10 ++--
 .../locale/locale.members/encoding.pass.cpp   |  8 ++-
 .../iterator.pass.cpp                         | 52 ++++++++++---------
 3 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 7d06092fc1992..852ea6b0d457e 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -351,9 +351,9 @@ private:
   static constexpr int __NATS_DANO_ADD_ = 34;
 
   // A __te_data structure stores:
-  // Index into an table of indexes that is an offset in the giant aliases string
+  // Index into a table of offsets in the giant aliases string
   // The MIB of that text encoding
-  // Number of aliases
+  // Number of aliases the current MIB holds
   struct __te_data {
     unsigned short __first_alias_index_;
     unsigned short __mib_rep_;
@@ -591,6 +591,8 @@ public:
 
   template <id _Id>
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool environment_is() {
+    // TODO: It may be worthwhile to implement an optimization for popular encodings, e.g. UTF-8,
+    // to allow checking the environment text encoding without needing to use the data tables.
     return environment() == _Id;
   }
 #    else
@@ -601,9 +603,9 @@ public:
 #    endif
 
 private:
-  constexpr const __te_data& __get() const { return __entries[__encoding_idx_]; }
+  _LIBCPP_HIDE_FROM_ABI constexpr const __te_data& __get() const { return __entries[__encoding_idx_]; }
 
-  static constexpr char const* __get_alias_from_idx_table_idx(unsigned short __idx) {
+  _LIBCPP_HIDE_FROM_ABI static constexpr char const* __get_alias_from_idx_table_idx(unsigned short __idx) {
     return __aliases_string + __alias_index_table_[__idx];
   }
 
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
index 664f50e52db16..f21325b08c593 100644
--- a/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
@@ -17,6 +17,8 @@
 // text_encoding locale::encoding() const
 
 #include <cassert>
+#include <format>
+#include <iostream>
 #include <locale>
 #include <text_encoding>
 
@@ -28,7 +30,11 @@ int main(int, char**) {
     const std::locale utf8_locale(LOCALE_en_US_UTF_8);
     std::text_encoding te      = utf8_locale.encoding();
     std::text_encoding utf8_te = std::text_encoding(std::text_encoding::id::UTF8);
-    assert(te == std::text_encoding::id::UTF8);
+
+    if (te != std::text_encoding::id::UTF8) {
+      std::cerr << std::format("Expected UTF-8, received {{ {}, \"{}\" }}", int(te.mib()), te.name());
+      assert(false);
+    }
     assert(te == utf8_te);
   }
   return 0;
diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
index 99416aab6a212..fcd159663256d 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
@@ -32,6 +32,26 @@ constexpr bool test() {
 
   static_assert(std::three_way_comparable<decltype(i)>);
 
+  { // iterator operator return types
+    ASSERT_SAME_TYPE(const char*, decltype(*i));
+    ASSERT_SAME_TYPE(const char*, decltype(i[0]));
+    ASSERT_SAME_TYPE(decltype(i), decltype(i + 1));
+    ASSERT_SAME_TYPE(decltype(i), decltype(1 + i));
+    ASSERT_SAME_TYPE(decltype(i), decltype(i - 1));
+    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(++i));
+    ASSERT_SAME_TYPE(decltype(i), decltype(i++));
+    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(--i));
+    ASSERT_SAME_TYPE(decltype(i), decltype(i--));
+    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(i += 1));
+    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(i -= 1));
+    ASSERT_SAME_TYPE(bool, decltype(i == j));
+    ASSERT_SAME_TYPE(bool, decltype(i != j));
+    ASSERT_SAME_TYPE(bool, decltype(i > j));
+    ASSERT_SAME_TYPE(bool, decltype(i < j));
+    ASSERT_SAME_TYPE(bool, decltype(i >= j));
+    ASSERT_SAME_TYPE(bool, decltype(i <= j));
+    ASSERT_SAME_TYPE(std::strong_ordering, decltype(i <=> j));
+  }
   {
     ASSERT_NOEXCEPT(i == j);
     ASSERT_NOEXCEPT(i != k);
@@ -67,7 +87,9 @@ constexpr bool test() {
     assert(i == te.aliases().begin());
     assert(i == j);
     assert(i != k);
-    assert(std::string_view(*i) == std::string_view(*j));
+    std::same_as<const char*> decltype(auto) str1 = *i;
+    std::same_as<const char*> decltype(auto) str2 = *j;
+    assert(std::string_view(str1) == std::string_view(str2));
   }
   {
     i++;
@@ -81,10 +103,10 @@ constexpr bool test() {
     ASSERT_NOEXCEPT(i + 1);
     ASSERT_NOEXCEPT(1 + i);
     ASSERT_NOEXCEPT(i - 1);
-    auto temp = i + 2;
+    std::same_as<decltype(j)> decltype(auto) temp = i + 2;
     assert(i != temp);
     assert(std::string_view(*temp) != std::string_view(*j));
-    auto temp2 = temp - 2;
+    std::same_as<decltype(j)> decltype(auto) temp2 = temp - 2;
     assert(std::string_view(*temp2) == std::string_view(*j));
   }
   {
@@ -97,11 +119,11 @@ constexpr bool test() {
     ASSERT_NOEXCEPT(++i);
     ASSERT_NOEXCEPT(i--);
     ASSERT_NOEXCEPT(--i);
-    auto& temp = ++i;
+    std::same_as<std::add_lvalue_reference_t<decltype(i)>> decltype(auto) temp = ++i;
     assert(temp == i);
     assert(&temp == &i);
 
-    auto temp2 = j++;
+    std::same_as<decltype(j)> decltype(auto) temp2 = j++;
     assert(temp2 == j - 1);
     assert(i == j);
   }
@@ -121,26 +143,6 @@ constexpr bool test() {
     assert(i != tempi && (tempi - i) == 2);
     assert(j != tempj && (tempj - j) == 3);
   }
-  { // iterator operator return types
-    ASSERT_SAME_TYPE(const char*, decltype(*i));
-    ASSERT_SAME_TYPE(const char*, decltype(i[0]));
-    ASSERT_SAME_TYPE(decltype(i), decltype(i + 1));
-    ASSERT_SAME_TYPE(decltype(i), decltype(1 + i));
-    ASSERT_SAME_TYPE(decltype(i), decltype(i - 1));
-    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(++i));
-    ASSERT_SAME_TYPE(decltype(i), decltype(i++));
-    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(--i));
-    ASSERT_SAME_TYPE(decltype(i), decltype(i--));
-    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(i += 1));
-    ASSERT_SAME_TYPE(std::add_lvalue_reference_t<decltype(i)>, decltype(i -= 1));
-    ASSERT_SAME_TYPE(bool, decltype(i == j));
-    ASSERT_SAME_TYPE(bool, decltype(i != j));
-    ASSERT_SAME_TYPE(bool, decltype(i > j));
-    ASSERT_SAME_TYPE(bool, decltype(i < j));
-    ASSERT_SAME_TYPE(bool, decltype(i >= j));
-    ASSERT_SAME_TYPE(bool, decltype(i <= j));
-    ASSERT_SAME_TYPE(std::strong_ordering, decltype(i <=> j));
-  }
 
   return true;
 }

>From 17dc4b13e084ee8a9993775540a881fd2f6e9ada Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Sun, 29 Mar 2026 18:19:05 -0400
Subject: [PATCH 53/58] ci

---
 .../text_encoding.aliases_view/iterator.pass.cpp                 | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
index fcd159663256d..34b10da1b07ff 100644
--- a/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
+++ b/libcxx/test/std/utilities/text_encoding/text_encoding.members/text_encoding.aliases_view/iterator.pass.cpp
@@ -16,6 +16,7 @@
 
 #include <cassert>
 #include <compare>
+#include <concepts>
 #include <string_view>
 #include <text_encoding>
 #include <type_traits>

>From 0a9b0fb5f01931dcecc86aa5cf4f4a5f5ad2aad2 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Sun, 29 Mar 2026 19:47:28 -0400
Subject: [PATCH 54/58] apple abi

---
 ...-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist b/libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist
index 4180bc584a3f3..5612bec47c267 100644
--- a/libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist
+++ b/libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist
@@ -1561,6 +1561,7 @@
 {'is_defined': True, 'name': '__ZNSt3__120__libcpp_atomic_waitEPVKNS_17__cxx_atomic_implIxNS_22__cxx_atomic_base_implIxEEEEx', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__120__libcpp_atomic_waitEPVKvx', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__120__throw_system_errorEiPKc', 'type': 'FUNC'}
+{'is_defined': True, 'name': '__ZNSt3__121__get_locale_encodingEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__121__throw_runtime_errorEPKc', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__121recursive_timed_mutex4lockEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__121recursive_timed_mutex6unlockEv', 'type': 'FUNC'}
@@ -1921,7 +1922,6 @@
 {'is_defined': True, 'name': '__ZNSt3__19__num_putIcE23__widen_and_group_floatEPcS2_S2_S2_RS2_S3_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19__num_putIwE21__widen_and_group_intEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19__num_putIwE23__widen_and_group_floatEPcS2_S2_PwRS3_S4_RKNS_6localeE', 'type': 'FUNC'}
-{'is_defined': True, 'name': '__ZNSt3__19__te_impl13__environmentEv', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19basic_iosIcNS_11char_traitsIcEEE7copyfmtERKS3_', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev', 'type': 'FUNC'}
 {'is_defined': True, 'name': '__ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev', 'type': 'FUNC'}
@@ -2653,4 +2653,4 @@
 {'is_defined': True, 'name': '___cxa_vec_new2', 'type': 'I'}
 {'is_defined': True, 'name': '___cxa_vec_new3', 'type': 'I'}
 {'is_defined': True, 'name': '___dynamic_cast', 'type': 'I'}
-{'is_defined': True, 'name': '___gxx_personality_v0', 'type': 'I'}
+{'is_defined': True, 'name': '___gxx_personality_v0', 'type': 'I'}
\ No newline at end of file

>From 1e96e02c53df9412fec3b0ce1bcdb0b926430322 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 30 Mar 2026 18:58:15 -0400
Subject: [PATCH 55/58] Return UTF-8 always on Android, try parse the locale
 name on Windows

---
 libcxx/include/text_encoding                  |  5 ++
 libcxx/src/text_encoding.cpp                  | 46 ++++++++++++++-----
 .../locale/locale.members/encoding.pass.cpp   | 16 +++++++
 3 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 852ea6b0d457e..0b289968d857b 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -593,7 +593,12 @@ public:
   [[nodiscard]] _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI static bool environment_is() {
     // TODO: It may be worthwhile to implement an optimization for popular encodings, e.g. UTF-8,
     // to allow checking the environment text encoding without needing to use the data tables.
+
+#      if defined(__ANDROID__)
+    return __Id == std::text_encoding::id::UTF8;
+#      else
     return environment() == _Id;
+#      endif
   }
 #    else
   static text_encoding environment() = delete;
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index 26928a34e34ca..adec469e4fb8a 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -11,6 +11,8 @@
 
 #if defined(_LIBCPP_WIN32API)
 #  include <__algorithm/max.h>
+#  include <cctype>
+#  include <charconv>
 #  include <cwchar>
 #  include <windows.h>
 #else
@@ -227,12 +229,37 @@ _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* _
   wchar_t __locale_wbuffer[LOCALE_NAME_MAX_LENGTH + 1]{};
   wchar_t __number_buffer[11]{};
 
-  bool __is_ansi  = ::AreFileApisANSI();
-  auto __codepage = __is_ansi ? CP_ACP : CP_OEMCP;
-
   string_view __sv(__name);
-  int __ret = ::MultiByteToWideChar(
-      __codepage, MB_ERR_INVALID_CHARS, __name, __sv.size(), __locale_wbuffer, LOCALE_NAME_MAX_LENGTH);
+  unsigned long long __name_size = __sv.size();
+  bool __is_ansi                 = ::AreFileApisANSI();
+
+  // locale :: "locale-name"
+  // | "language"[_country-region[.code-page]]
+  // | ".code-page"
+  // GetLocaleInfoEx doesn't accept anything other than BCP-47 locale names, e.g. "en_US",
+  // so we'll try to do a best-attempt to derive the text encoding from the name.
+  if (auto __dot = __sv.find('.'); __dot != std::string_view::npos) {
+    string_view __code_page(__name + __dot + 1);
+
+    // Windows allows the codepage number as part of the name,
+    // e.g. "en_US.1252" for English US, Windows-1252.
+    if (std::isdigit(__code_page[0])) {
+      unsigned int __cpage{};
+      auto res = std::from_chars(__code_page.data(), __code_page.data() + __code_page.size(), res);
+      if (res) {
+        return __get_win32_acp(__cpage)
+      }
+    } else { // POSIX-style name
+      std::text_encoding __te = std::text_encoding(__code_page);
+      if (__te != std::text_encoding::id::unknown) {
+        return __te;
+      }
+    }
+  }
+
+  auto __codepage = __is_ansi ? CP_ACP : CP_OEMCP;
+  int __ret       = ::MultiByteToWideChar(
+      __codepage, MB_ERR_INVALID_CHARS, __name, __name_size, __locale_wbuffer, LOCALE_NAME_MAX_LENGTH);
 
   if (__ret <= 0)
     return std::text_encoding();
@@ -252,13 +279,8 @@ _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* _
 #elif defined(__ANDROID__)
 // Android has minimal libc suppport for locale, and doesn't support any other locale
 // than the ones checked for below.
-_LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* __name) {
-  string_view __sv(__name);
-  if (__sv == "" || __sv == "*" || __sv == "C" || __sv == "POSIX" || __sv.contains("UTF-8")) {
-    return std::text_encoding(std::text_encoding::id::UTF8);
-  }
-
-  return std::text_encoding();
+_LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding([[maybe_unused]] const char* __name) {
+  return std::text_encoding(std::text_encoding::id::UTF8);
 }
 
 #else // POSIX
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
index f21325b08c593..9305b00d184c4 100644
--- a/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
@@ -37,5 +37,21 @@ int main(int, char**) {
     }
     assert(te == utf8_te);
   }
+#if defined(_WIN32)
+  {
+    const std::locale loc("en-US");
+    std::text_encoding te    = loc.encoding();
+    std::text_encoding w1252 = std::text_encoding(std::text_encoding::id::windows1252);
+    assert(te == std::text_encoding::id::windows1252);
+    assert(te == w1252);
+  }
+  {
+    const std::locale loc("en-US.1252");
+    std::text_encoding te    = loc.encoding();
+    std::text_encoding w1252 = std::text_encoding(std::text_encoding::id::windows1252);
+    assert(te == std::text_encoding::id::windows1252);
+    assert(te == w1252);
+  }
+#endif
   return 0;
 }

>From 35e496b9c5fd25ccdcd056d5faa02135fc47c20f Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Mon, 30 Mar 2026 20:27:16 -0400
Subject: [PATCH 56/58] Fix Windows, locale::encoding() availability

---
 libcxx/include/__locale      |  3 ++-
 libcxx/include/text_encoding |  2 +-
 libcxx/src/text_encoding.cpp | 18 +++++++++++-------
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index 43a35b2b75a93..052a0f60275f9 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -10,6 +10,7 @@
 #ifndef _LIBCPP___LOCALE
 #define _LIBCPP___LOCALE
 
+#include "__configuration/availability.h"
 #include <__config>
 
 #if _LIBCPP_HAS_LOCALIZATION
@@ -113,7 +114,7 @@ public:
                __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0;
   }
 #  if _LIBCPP_STD_VER >= 26
-  _LIBCPP_HIDE_FROM_ABI std::text_encoding encoding() const {
+  _LIBCPP_AVAILABILITY_TE_ENVIRONMENT _LIBCPP_HIDE_FROM_ABI std::text_encoding encoding() const {
     std::string __name = name();
     return __get_locale_encoding(__name.c_str());
   }
diff --git a/libcxx/include/text_encoding b/libcxx/include/text_encoding
index 0b289968d857b..03be408a8b017 100644
--- a/libcxx/include/text_encoding
+++ b/libcxx/include/text_encoding
@@ -595,7 +595,7 @@ public:
     // to allow checking the environment text encoding without needing to use the data tables.
 
 #      if defined(__ANDROID__)
-    return __Id == std::text_encoding::id::UTF8;
+    return _Id == std::text_encoding::id::UTF8;
 #      else
     return environment() == _Id;
 #      endif
diff --git a/libcxx/src/text_encoding.cpp b/libcxx/src/text_encoding.cpp
index adec469e4fb8a..6ccf5d433c7d7 100644
--- a/libcxx/src/text_encoding.cpp
+++ b/libcxx/src/text_encoding.cpp
@@ -230,24 +230,27 @@ _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* _
   wchar_t __number_buffer[11]{};
 
   string_view __sv(__name);
-  unsigned long long __name_size = __sv.size();
-  bool __is_ansi                 = ::AreFileApisANSI();
 
   // locale :: "locale-name"
   // | "language"[_country-region[.code-page]]
   // | ".code-page"
   // GetLocaleInfoEx doesn't accept anything other than BCP-47 locale names, e.g. "en_US",
   // so we'll try to do a best-attempt to derive the text encoding from the name.
-  if (auto __dot = __sv.find('.'); __dot != std::string_view::npos) {
+  if (__sv == "C" || __sv == "") {
+    // "A locale argument value of C specifies the minimal ANSI conforming environment for C translation.""
+    // TODO: Figure out what to do for an empty string:
+    // "If locale points to an empty string, the locale is the implementation-defined native environment."
+    return __get_win32_acp(::GetACP());
+  } else if (auto __dot = __sv.find('.'); __dot != std::string_view::npos) {
     string_view __code_page(__name + __dot + 1);
 
     // Windows allows the codepage number as part of the name,
     // e.g. "en_US.1252" for English US, Windows-1252.
     if (std::isdigit(__code_page[0])) {
       unsigned int __cpage{};
-      auto res = std::from_chars(__code_page.data(), __code_page.data() + __code_page.size(), res);
-      if (res) {
-        return __get_win32_acp(__cpage)
+      auto __res = std::from_chars(__code_page.data(), __code_page.data() + __code_page.size(), __cpage);
+      if (__res) {
+        return __get_win32_acp(__cpage);
       }
     } else { // POSIX-style name
       std::text_encoding __te = std::text_encoding(__code_page);
@@ -257,9 +260,10 @@ _LIBCPP_EXPORTED_FROM_ABI std::text_encoding __get_locale_encoding(const char* _
     }
   }
 
+  bool __is_ansi  = ::AreFileApisANSI();
   auto __codepage = __is_ansi ? CP_ACP : CP_OEMCP;
   int __ret       = ::MultiByteToWideChar(
-      __codepage, MB_ERR_INVALID_CHARS, __name, __name_size, __locale_wbuffer, LOCALE_NAME_MAX_LENGTH);
+      __codepage, MB_ERR_INVALID_CHARS, __name, __sv.size(), __locale_wbuffer, LOCALE_NAME_MAX_LENGTH);
 
   if (__ret <= 0)
     return std::text_encoding();

>From e1edb5389bb9ea048acf9d0062f72aa6f21fa999 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 31 Mar 2026 21:45:02 -0400
Subject: [PATCH 57/58] fix test failures

---
 libcxx/include/__locale                                  | 6 +-----
 .../text_encoding.members/environment.delete.verify.cpp  | 2 +-
 .../locales/locale/locale.members/encoding.pass.cpp      | 9 ++-------
 3 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index 052a0f60275f9..c08906e0717c1 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -10,8 +10,8 @@
 #ifndef _LIBCPP___LOCALE
 #define _LIBCPP___LOCALE
 
-#include "__configuration/availability.h"
 #include <__config>
+#include <__configuration/availability.h>
 
 #if _LIBCPP_HAS_LOCALIZATION
 
@@ -56,10 +56,6 @@ _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale&) _NOEXCEPT;
 template <class _Facet>
 _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&);
 
-#  if _LIBCPP_STD_VER >= 26
-struct text_encoding;
-#  endif
-
 class _LIBCPP_EXPORTED_FROM_ABI locale {
 public:
   // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor,
diff --git a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp
index cfbe874a74c98..23a3310948355 100644
--- a/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp
+++ b/libcxx/test/libcxx/utilities/text_encoding/text_encoding.members/environment.delete.verify.cpp
@@ -22,7 +22,7 @@
 int main(int, char**) {
   // expected-error at +1 {{attempt to use a deleted function}}
   std::text_encoding::environment();
-  // expected-error at +1 {{attempt to use a deleted function}}
+  // expected-error at +1 {{call to deleted function 'environment_is'}}
   std::text_encoding::environment_is<std::text_encoding::UTF8>();
 
   return 0;
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
index 9305b00d184c4..618a104fe4654 100644
--- a/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale/locale.members/encoding.pass.cpp
@@ -11,6 +11,7 @@
 // REQUIRES: std-at-least-c++26
 // REQUIRES: locale.en_US.UTF-8
 // UNSUPPORTED: no-localization
+// UNSUPPORTED: availability-te-environment-missing
 
 // class locale
 
@@ -39,19 +40,13 @@ int main(int, char**) {
   }
 #if defined(_WIN32)
   {
+    // BCP-47 locale name
     const std::locale loc("en-US");
     std::text_encoding te    = loc.encoding();
     std::text_encoding w1252 = std::text_encoding(std::text_encoding::id::windows1252);
     assert(te == std::text_encoding::id::windows1252);
     assert(te == w1252);
   }
-  {
-    const std::locale loc("en-US.1252");
-    std::text_encoding te    = loc.encoding();
-    std::text_encoding w1252 = std::text_encoding(std::text_encoding::id::windows1252);
-    assert(te == std::text_encoding::id::windows1252);
-    assert(te == w1252);
-  }
 #endif
   return 0;
 }

>From 1873197a0439d6b850b78e4275d268bdb2c413b5 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Tue, 31 Mar 2026 22:31:42 -0400
Subject: [PATCH 58/58] accidentally committed changes

---
 libcxx/test/support/platform_support.h | 1 -
 script.sh                              | 2 --
 2 files changed, 3 deletions(-)
 delete mode 100644 script.sh

diff --git a/libcxx/test/support/platform_support.h b/libcxx/test/support/platform_support.h
index 7ed4323c5ce8d..ff44096bf7171 100644
--- a/libcxx/test/support/platform_support.h
+++ b/libcxx/test/support/platform_support.h
@@ -33,7 +33,6 @@
 #define LOCALE_ru_RU_UTF_8     "ru_RU.UTF-8"
 #define LOCALE_zh_CN_UTF_8     "zh_CN.UTF-8"
 
-#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string>
diff --git a/script.sh b/script.sh
deleted file mode 100644
index 1706c5d52c997..0000000000000
--- a/script.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-for std in c++03 c++11 c++14 c++17 c++20 c++23 c++26; do python3 ./build/generic-cxx26/bin/llvm-lit --param std=$std libcxx/test/libcxx/transitive_includes.gen.py; done



More information about the libcxx-commits mailing list