1053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
2053d81ceSMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6053d81ceSMarshall Clow //
7053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
8053d81ceSMarshall Clow
9*4fc50236SJoe Loser // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10*4fc50236SJoe Loser
11053d81ceSMarshall Clow // <string_view>
12053d81ceSMarshall Clow
13053d81ceSMarshall Clow // void remove_prefix(size_type _n)
14053d81ceSMarshall Clow
15053d81ceSMarshall Clow #include <string_view>
16053d81ceSMarshall Clow #include <cassert>
17053d81ceSMarshall Clow
18053d81ceSMarshall Clow #include "test_macros.h"
19053d81ceSMarshall Clow
20053d81ceSMarshall Clow template<typename CharT>
test(const CharT * s,size_t len)21053d81ceSMarshall Clow void test ( const CharT *s, size_t len ) {
22053d81ceSMarshall Clow typedef std::basic_string_view<CharT> SV;
23053d81ceSMarshall Clow {
24053d81ceSMarshall Clow SV sv1 ( s );
25053d81ceSMarshall Clow assert ( sv1.size() == len );
26053d81ceSMarshall Clow assert ( sv1.data() == s );
27053d81ceSMarshall Clow
28053d81ceSMarshall Clow if ( len > 0 ) {
29053d81ceSMarshall Clow sv1.remove_prefix ( 1 );
30053d81ceSMarshall Clow assert ( sv1.size() == (len - 1));
31053d81ceSMarshall Clow assert ( sv1.data() == (s + 1));
32053d81ceSMarshall Clow sv1.remove_prefix ( len - 1 );
33053d81ceSMarshall Clow }
34053d81ceSMarshall Clow
35053d81ceSMarshall Clow assert ( sv1.size() == 0 );
36053d81ceSMarshall Clow sv1.remove_prefix ( 0 );
37053d81ceSMarshall Clow assert ( sv1.size() == 0 );
38053d81ceSMarshall Clow }
39053d81ceSMarshall Clow }
40053d81ceSMarshall Clow
410f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
test_ce(size_t n,size_t k)42053d81ceSMarshall Clow constexpr size_t test_ce ( size_t n, size_t k ) {
43053d81ceSMarshall Clow typedef std::basic_string_view<char> SV;
44053d81ceSMarshall Clow SV sv1{ "ABCDEFGHIJKL", n };
45053d81ceSMarshall Clow sv1.remove_prefix ( k );
46053d81ceSMarshall Clow return sv1.size();
47053d81ceSMarshall Clow }
48053d81ceSMarshall Clow #endif
49053d81ceSMarshall Clow
main(int,char **)502df59c50SJF Bastien int main(int, char**) {
51053d81ceSMarshall Clow test ( "ABCDE", 5 );
52053d81ceSMarshall Clow test ( "a", 1 );
53053d81ceSMarshall Clow test ( "", 0 );
54053d81ceSMarshall Clow
55f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
56053d81ceSMarshall Clow test ( L"ABCDE", 5 );
57053d81ceSMarshall Clow test ( L"a", 1 );
58053d81ceSMarshall Clow test ( L"", 0 );
59f4c1258dSLouis Dionne #endif
60053d81ceSMarshall Clow
61053d81ceSMarshall Clow #if TEST_STD_VER >= 11
62053d81ceSMarshall Clow test ( u"ABCDE", 5 );
63053d81ceSMarshall Clow test ( u"a", 1 );
64053d81ceSMarshall Clow test ( u"", 0 );
65053d81ceSMarshall Clow
66053d81ceSMarshall Clow test ( U"ABCDE", 5 );
67053d81ceSMarshall Clow test ( U"a", 1 );
68053d81ceSMarshall Clow test ( U"", 0 );
69053d81ceSMarshall Clow #endif
70053d81ceSMarshall Clow
710f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
72053d81ceSMarshall Clow {
73053d81ceSMarshall Clow static_assert ( test_ce ( 5, 0 ) == 5, "" );
74053d81ceSMarshall Clow static_assert ( test_ce ( 5, 1 ) == 4, "" );
75053d81ceSMarshall Clow static_assert ( test_ce ( 5, 5 ) == 0, "" );
76053d81ceSMarshall Clow static_assert ( test_ce ( 9, 3 ) == 6, "" );
77053d81ceSMarshall Clow }
78053d81ceSMarshall Clow #endif
792df59c50SJF Bastien
802df59c50SJF Bastien return 0;
81053d81ceSMarshall Clow }
82