1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT
13 // template <class Elem, unsigned long Maxcode = 0x10ffff,
14 // codecvt_mode Mode = (codecvt_mode)0>
16 // : public codecvt<Elem, char, mbstate_t>
21 // int length(stateT& state, const externT* from, const externT* from_end,
27 #include "test_macros.h"
29 template <class CharT
, std::size_t = sizeof(CharT
)>
32 template <class CharT
>
33 struct TestHelper
<CharT
, 2> {
37 template <class CharT
>
38 struct TestHelper
<CharT
, 4> {
42 template <class CharT
>
43 void TestHelper
<CharT
, 2>::test() {
45 typedef std::codecvt_utf8
<CharT
> C
;
47 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
49 int r
= c
.length(m
, n
, n
+ 4, 1);
55 r
= c
.length(m
, n
, n
+ 3, 2);
60 r
= c
.length(m
, n
, n
+ 2, 3);
64 r
= c
.length(m
, n
, n
+ 1, 3);
68 typedef std::codecvt_utf8
<CharT
, 0x1000> C
;
70 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
72 int r
= c
.length(m
, n
, n
+ 4, 1);
78 r
= c
.length(m
, n
, n
+ 3, 2);
83 r
= c
.length(m
, n
, n
+ 2, 3);
87 r
= c
.length(m
, n
, n
+ 1, 3);
91 typedef std::codecvt_utf8
<CharT
, 0xFFFFFFFF, std::consume_header
> C
;
93 char n
[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
95 int r
= c
.length(m
, n
, n
+ 7, 1);
101 r
= c
.length(m
, n
, n
+ 3, 2);
109 r
= c
.length(m
, n
, n
+ 5, 3);
113 r
= c
.length(m
, n
, n
+ 1, 3);
118 template <class CharT
>
119 void TestHelper
<CharT
, 4>::test() {
121 typedef std::codecvt_utf8
<CharT
> C
;
123 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
125 int r
= c
.length(m
, n
, n
+ 4, 1);
131 r
= c
.length(m
, n
, n
+ 3, 2);
136 r
= c
.length(m
, n
, n
+ 2, 3);
140 r
= c
.length(m
, n
, n
+ 1, 3);
144 typedef std::codecvt_utf8
<CharT
, 0x1000> C
;
146 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
148 int r
= c
.length(m
, n
, n
+ 4, 1);
154 r
= c
.length(m
, n
, n
+ 3, 2);
159 r
= c
.length(m
, n
, n
+ 2, 3);
163 r
= c
.length(m
, n
, n
+ 1, 3);
167 typedef std::codecvt_utf8
<CharT
, 0xFFFFFFFF, std::consume_header
> C
;
169 char n
[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
171 int r
= c
.length(m
, n
, n
+ 7, 1);
177 r
= c
.length(m
, n
, n
+ 3, 2);
185 r
= c
.length(m
, n
, n
+ 5, 3);
189 r
= c
.length(m
, n
, n
+ 1, 3);
194 int main(int, char**) {
195 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
196 TestHelper
<wchar_t>::test();
198 TestHelper
<char32_t
>::test();
199 TestHelper
<char16_t
>::test();