Message ID | f2279c73-ea70-25a6-dcd9-ee390fb32db7@verizon.net |
---|---|
State | New |
Headers | show |
Series | [libstdc++,C++20] Implement P0457R2 String Prefix and Suffix Checking. | expand |
On 29/11/18 21:35 -0500, Ed Smith-Rowland wrote: >Greetings, > >This patch implements starts_with and ends_with for basic_string and >basic_string_view for C++20. This was on my TODO list, thanks for taking care of it. >+#if __cplusplus > 201703L >+ bool >+ starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept >+ { return __sv_type(this->data(), this->size()).starts_with(__x); } >+ >+ bool >+ starts_with(_CharT __x) const noexcept >+ { return __sv_type(this->data(), this->size()).starts_with(__x); } >+ >+ bool >+ starts_with(const _CharT* __x) const This can be noexcept. It isn't in the standard, because it has a narrow contract (there's a precondition that __x is null-terminated). But since we can't reliably detect whether __x is null-terminated, and even if we could we wouldn't want to throw an exception, we can just make it noexcept. Same for the ends_with(const _CharT*) one, and the equivalent members in the COW basic_string and basic_string_view. >Index: include/std/string_view >=================================================================== >--- include/std/string_view (revision 266645) >+++ include/std/string_view (working copy) >@@ -227,7 +227,6 @@ > __sv = __tmp; > } > >- > // [string.view.ops], string operations: > > size_type >@@ -387,6 +386,36 @@ > traits_type::length(__str)); > } > >+#if __cplusplus > 201703L >+ constexpr bool >+ starts_with(basic_string_view __x) const noexcept >+ { return this->size() >= __x.size() >+ && this->compare(0, __x.size(), __x) == 0; } Please put the opening and closing braces on their own lines, as for ends_with below: >+ constexpr bool >+ ends_with(basic_string_view __x) const noexcept >+ { >+ return this->size() >= __x.size() >+ && this->compare(this->size() - __x.size(), npos, __x) == 0; >+ } OK with those changes, thanks.
On 11/30/18 5:33 AM, Jonathan Wakely wrote: > On 29/11/18 21:35 -0500, Ed Smith-Rowland wrote: >> Greetings, >> >> This patch implements starts_with and ends_with for basic_string and >> basic_string_view for C++20. > > This was on my TODO list, thanks for taking care of it. > >> +#if __cplusplus > 201703L >> + bool >> + starts_with(basic_string_view<_CharT, _Traits> __x) const >> noexcept >> + { return __sv_type(this->data(), >> this->size()).starts_with(__x); } >> + >> + bool >> + starts_with(_CharT __x) const noexcept >> + { return __sv_type(this->data(), >> this->size()).starts_with(__x); } >> + >> + bool >> + starts_with(const _CharT* __x) const > > This can be noexcept. It isn't in the standard, because it has a > narrow contract (there's a precondition that __x is null-terminated). > But since we can't reliably detect whether __x is null-terminated, and > even if we could we wouldn't want to throw an exception, we can just > make it noexcept. Same for the ends_with(const _CharT*) one, and the > equivalent members in the COW basic_string and basic_string_view. > >> Index: include/std/string_view >> =================================================================== >> --- include/std/string_view (revision 266645) >> +++ include/std/string_view (working copy) >> @@ -227,7 +227,6 @@ >> __sv = __tmp; >> } >> >> - >> // [string.view.ops], string operations: >> >> size_type >> @@ -387,6 +386,36 @@ >> traits_type::length(__str)); >> } >> >> +#if __cplusplus > 201703L >> + constexpr bool >> + starts_with(basic_string_view __x) const noexcept >> + { return this->size() >= __x.size() >> + && this->compare(0, __x.size(), __x) == 0; } > > Please put the opening and closing braces on their own lines, as for > ends_with below: > >> + constexpr bool >> + ends_with(basic_string_view __x) const noexcept >> + { >> + return this->size() >= __x.size() >> + && this->compare(this->size() - __x.size(), npos, __x) == 0; >> + } > > OK with those changes, thanks Committed 266674. New patch attached. Ed 2018-11-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement P0457R2 String Prefix and Suffix Checking. * include/bits/basic_string.h: Add starts_with, ends_with members. * include/std/string_view: Ditto. * testsuite/21_strings/basic_string/operations/starts_with/ char/1.cc: New test. * testsuite/21_strings/basic_string/operations/starts_with/ wchar_t/1.cc: New test. * testsuite/21_strings/basic_string/operations/ends_with/ char/1.cc: New test. * testsuite/21_strings/basic_string/operations/ends_with/ wchar_t/1.cc: New test. * testsuite/21_strings/basic_string_view/operations/starts_with/ char/1.cc: New test. * testsuite/21_strings/basic_string_view/operations/starts_with/ wchar_t/1.cc: New test. * testsuite/21_strings/basic_string_view/operations/ends_with/ char/1.cc: New test. * testsuite/21_strings/basic_string_view/operations/ends_with/ wchar_t/1.cc: New test. Index: include/bits/basic_string.h =================================================================== --- include/bits/basic_string.h (revision 266671) +++ include/bits/basic_string.h (working copy) @@ -3038,6 +3038,32 @@ compare(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) const; +#if __cplusplus > 201703L + bool + starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + starts_with(_CharT __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + starts_with(const _CharT* __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } + + bool + ends_with(_CharT __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } + + bool + ends_with(const _CharT* __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } +#endif // C++20 + // Allow basic_stringbuf::__xfer_bufptrs to call _M_length: template<typename, typename, typename> friend class basic_stringbuf; }; @@ -5884,6 +5910,32 @@ compare(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) const; +#if __cplusplus > 201703L + bool + starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + starts_with(_CharT __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + starts_with(const _CharT* __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } + + bool + ends_with(_CharT __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } + + bool + ends_with(const _CharT* __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } +#endif // C++20 + # ifdef _GLIBCXX_TM_TS_INTERNAL friend void ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s, Index: include/std/string_view =================================================================== --- include/std/string_view (revision 266671) +++ include/std/string_view (working copy) @@ -227,7 +227,6 @@ __sv = __tmp; } - // [string.view.ops], string operations: size_type @@ -387,6 +386,38 @@ traits_type::length(__str)); } +#if __cplusplus > 201703L + constexpr bool + starts_with(basic_string_view __x) const noexcept + { + return this->size() >= __x.size() + && this->compare(0, __x.size(), __x) == 0; + } + + constexpr bool + starts_with(_CharT __x) const noexcept + { return this->starts_with(basic_string_view(&__x, 1)); } + + constexpr bool + starts_with(const _CharT* __x) const noexcept + { return this->starts_with(basic_string_view(__x)); } + + constexpr bool + ends_with(basic_string_view __x) const noexcept + { + return this->size() >= __x.size() + && this->compare(this->size() - __x.size(), npos, __x) == 0; + } + + constexpr bool + ends_with(_CharT __x) const noexcept + { return this->ends_with(basic_string_view(&__x, 1)); } + + constexpr bool + ends_with(const _CharT* __x) const noexcept + { return this->ends_with(basic_string_view(__x)); } +#endif // C++20 + constexpr size_type _M_check(size_type __pos, const char* __s) const noexcept(false) { Index: testsuite/21_strings/basic_string/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_dir[] = "slugs/"; + const std::string_view sv_dir("slugs/"); + const char cstr_dir2[] = "worms/"; + const std::string_view sv_dir2("worms/"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with('s'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with('w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_dir[] = L"slugs/"; + const std::wstring_view sv_dir(L"slugs/"); + const wchar_t cstr_dir2[] = L"worms/"; + const std::wstring_view sv_dir2(L"worms/"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with(L's'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with(L'w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_dir[] = "slugs/"; + const std::string_view sv_dir("slugs/"); + const char cstr_dir2[] = "worms/"; + const std::string_view sv_dir2("worms/"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with('s'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with('w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_dir[] = "slugs/"; + const std::string_view sv_dir("slugs/"); + const char cstr_dir2[] = "worms/"; + const std::string_view sv_dir2("worms/"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with('s'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with('w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_dir[] = L"slugs/"; + const std::wstring_view sv_dir(L"slugs/"); + const wchar_t cstr_dir2[] = L"worms/"; + const std::wstring_view sv_dir2(L"worms/"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with(L's'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with(L'w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_dir[] = L"slugs/"; + const std::wstring_view sv_dir(L"slugs/"); + const wchar_t cstr_dir2[] = L"worms/"; + const std::wstring_view sv_dir2(L"worms/"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with(L's'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with(L'w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_suf[] = ".jpg"; + const std::string_view sv_suf(".jpg"); + const char cstr_suf2[] = ".rgb"; + const std::string_view sv_suf2(".rgb"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with('g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with('b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_suf[] = L".jpg"; + const std::wstring_view sv_suf(L".jpg"); + const wchar_t cstr_suf2[] = L".rgb"; + const std::wstring_view sv_suf2(L".rgb"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with(L'g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with(L'b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_suf[] = ".jpg"; + const std::string_view sv_suf(".jpg"); + const char cstr_suf2[] = ".rgb"; + const std::string_view sv_suf2(".rgb"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with('g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with('b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_suf[] = ".jpg"; + const std::string_view sv_suf(".jpg"); + const char cstr_suf2[] = ".rgb"; + const std::string_view sv_suf2(".rgb"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with('g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with('b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_suf[] = L".jpg"; + const std::wstring_view sv_suf(L".jpg"); + const wchar_t cstr_suf2[] = L".rgb"; + const std::wstring_view sv_suf2(L".rgb"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with(L'g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with(L'b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_suf[] = L".jpg"; + const std::wstring_view sv_suf(L".jpg"); + const wchar_t cstr_suf2[] = L".rgb"; + const std::wstring_view sv_suf2(L".rgb"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with(L'g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with(L'b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_dir[] = "slugs/"; + constexpr std::string_view sv_dir("slugs/"); + constexpr char cstr_dir2[] = "worms/"; + constexpr std::string_view sv_dir2("worms/"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with('s'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with('w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_dir[] = L"slugs/"; + constexpr std::wstring_view sv_dir(L"slugs/"); + constexpr wchar_t cstr_dir2[] = L"worms/"; + constexpr std::wstring_view sv_dir2(L"worms/"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with(L's'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with(L'w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_dir[] = "slugs/"; + constexpr std::string_view sv_dir("slugs/"); + constexpr char cstr_dir2[] = "worms/"; + constexpr std::string_view sv_dir2("worms/"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with('s'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with('w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_dir[] = "slugs/"; + constexpr std::string_view sv_dir("slugs/"); + constexpr char cstr_dir2[] = "worms/"; + constexpr std::string_view sv_dir2("worms/"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with('s'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with('w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_dir[] = L"slugs/"; + constexpr std::wstring_view sv_dir(L"slugs/"); + constexpr wchar_t cstr_dir2[] = L"worms/"; + constexpr std::wstring_view sv_dir2(L"worms/"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with(L's'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with(L'w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_dir[] = L"slugs/"; + constexpr std::wstring_view sv_dir(L"slugs/"); + constexpr wchar_t cstr_dir2[] = L"worms/"; + constexpr std::wstring_view sv_dir2(L"worms/"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with(L's'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with(L'w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_suf[] = ".jpg"; + constexpr std::string_view sv_suf(".jpg"); + constexpr char cstr_suf2[] = ".rgb"; + constexpr std::string_view sv_suf2(".rgb"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with('g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with('b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_suf[] = L".jpg"; + constexpr std::wstring_view sv_suf(L".jpg"); + constexpr wchar_t cstr_suf2[] = L".rgb"; + constexpr std::wstring_view sv_suf2(L".rgb"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with(L'g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with(L'b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_suf[] = ".jpg"; + constexpr std::string_view sv_suf(".jpg"); + constexpr char cstr_suf2[] = ".rgb"; + constexpr std::string_view sv_suf2(".rgb"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with('g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with('b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_suf[] = ".jpg"; + constexpr std::string_view sv_suf(".jpg"); + constexpr char cstr_suf2[] = ".rgb"; + constexpr std::string_view sv_suf2(".rgb"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with('g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with('b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_suf[] = L".jpg"; + constexpr std::wstring_view sv_suf(L".jpg"); + constexpr wchar_t cstr_suf2[] = L".rgb"; + constexpr std::wstring_view sv_suf2(L".rgb"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with(L'g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with(L'b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_suf[] = L".jpg"; + constexpr std::wstring_view sv_suf(L".jpg"); + constexpr wchar_t cstr_suf2[] = L".rgb"; + constexpr std::wstring_view sv_suf2(L".rgb"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with(L'g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with(L'b'); + static_assert(!char_b); +}
Index: include/bits/basic_string.h =================================================================== --- include/bits/basic_string.h (revision 266645) +++ include/bits/basic_string.h (working copy) @@ -3038,6 +3038,32 @@ compare(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) const; +#if __cplusplus > 201703L + bool + starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + starts_with(_CharT __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + starts_with(const _CharT* __x) const + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } + + bool + ends_with(_CharT __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } + + bool + ends_with(const _CharT* __x) const + { return __sv_type(this->data(), this->size()).ends_with(__x); } +#endif // C++20 + // Allow basic_stringbuf::__xfer_bufptrs to call _M_length: template<typename, typename, typename> friend class basic_stringbuf; }; @@ -5884,6 +5910,32 @@ compare(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) const; +#if __cplusplus > 201703L + bool + starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + starts_with(_CharT __x) const noexcept + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + starts_with(const _CharT* __x) const + { return __sv_type(this->data(), this->size()).starts_with(__x); } + + bool + ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } + + bool + ends_with(_CharT __x) const noexcept + { return __sv_type(this->data(), this->size()).ends_with(__x); } + + bool + ends_with(const _CharT* __x) const + { return __sv_type(this->data(), this->size()).ends_with(__x); } +#endif // C++20 + # ifdef _GLIBCXX_TM_TS_INTERNAL friend void ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s, Index: include/std/string_view =================================================================== --- include/std/string_view (revision 266645) +++ include/std/string_view (working copy) @@ -227,7 +227,6 @@ __sv = __tmp; } - // [string.view.ops], string operations: size_type @@ -387,6 +386,36 @@ traits_type::length(__str)); } +#if __cplusplus > 201703L + constexpr bool + starts_with(basic_string_view __x) const noexcept + { return this->size() >= __x.size() + && this->compare(0, __x.size(), __x) == 0; } + + constexpr bool + starts_with(_CharT __x) const noexcept + { return this->starts_with(basic_string_view(&__x, 1)); } + + constexpr bool + starts_with(const _CharT* __x) const + { return this->starts_with(basic_string_view(__x)); } + + constexpr bool + ends_with(basic_string_view __x) const noexcept + { + return this->size() >= __x.size() + && this->compare(this->size() - __x.size(), npos, __x) == 0; + } + + constexpr bool + ends_with(_CharT __x) const noexcept + { return this->ends_with(basic_string_view(&__x, 1)); } + + constexpr bool + ends_with(const _CharT* __x) const + { return this->ends_with(basic_string_view(__x)); } +#endif // C++20 + constexpr size_type _M_check(size_type __pos, const char* __s) const noexcept(false) { Index: testsuite/21_strings/basic_string/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_dir[] = "slugs/"; + const std::string_view sv_dir("slugs/"); + const char cstr_dir2[] = "worms/"; + const std::string_view sv_dir2("worms/"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with('s'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with('w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_dir[] = L"slugs/"; + const std::wstring_view sv_dir(L"slugs/"); + const wchar_t cstr_dir2[] = L"worms/"; + const std::wstring_view sv_dir2(L"worms/"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with(L's'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with(L'w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_dir[] = "slugs/"; + const std::string_view sv_dir("slugs/"); + const char cstr_dir2[] = "worms/"; + const std::string_view sv_dir2("worms/"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with('s'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with('w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_dir[] = "slugs/"; + const std::string_view sv_dir("slugs/"); + const char cstr_dir2[] = "worms/"; + const std::string_view sv_dir2("worms/"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with('s'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with('w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_dir[] = L"slugs/"; + const std::wstring_view sv_dir(L"slugs/"); + const wchar_t cstr_dir2[] = L"worms/"; + const std::wstring_view sv_dir2(L"worms/"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with(L's'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with(L'w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string begins_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_dir[] = L"slugs/"; + const std::wstring_view sv_dir(L"slugs/"); + const wchar_t cstr_dir2[] = L"worms/"; + const std::wstring_view sv_dir2(L"worms/"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.starts_with(cstr_dir); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.starts_with(sv_dir); + VERIFY( sv_in_slugs ); + const auto char_s = s_test.starts_with(L's'); + VERIFY( char_s ); + + const auto cstr_in_worms = s_test.starts_with(cstr_dir2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.starts_with(sv_dir2); + VERIFY( !sv_in_worms ); + const auto char_w = s_test.starts_with(L'w'); + VERIFY( !char_w ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_suf[] = ".jpg"; + const std::string_view sv_suf(".jpg"); + const char cstr_suf2[] = ".rgb"; + const std::string_view sv_suf2(".rgb"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with('g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with('b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_suf[] = L".jpg"; + const std::wstring_view sv_suf(L".jpg"); + const wchar_t cstr_suf2[] = L".rgb"; + const std::wstring_view sv_suf2(L".rgb"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with(L'g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with(L'b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_suf[] = ".jpg"; + const std::string_view sv_suf(".jpg"); + const char cstr_suf2[] = ".rgb"; + const std::string_view sv_suf2(".rgb"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with('g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with('b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const char cstr_suf[] = ".jpg"; + const std::string_view sv_suf(".jpg"); + const char cstr_suf2[] = ".rgb"; + const std::string_view sv_suf2(".rgb"); + + const std::string s_test("slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with('g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with('b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_suf[] = L".jpg"; + const std::wstring_view sv_suf(L".jpg"); + const wchar_t cstr_suf2[] = L".rgb"; + const std::wstring_view sv_suf2(L".rgb"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with(L'g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with(L'b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string ends_with + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + const wchar_t cstr_suf[] = L".jpg"; + const std::wstring_view sv_suf(L".jpg"); + const wchar_t cstr_suf2[] = L".rgb"; + const std::wstring_view sv_suf2(L".rgb"); + + const std::wstring s_test(L"slugs/slimy.jpg"); + + const auto cstr_in_slugs = s_test.ends_with(cstr_suf); + VERIFY( cstr_in_slugs ); + const auto sv_in_slugs = s_test.ends_with(sv_suf); + VERIFY( sv_in_slugs ); + const auto char_g = s_test.ends_with(L'g'); + VERIFY( char_g ); + + const auto cstr_in_worms = s_test.ends_with(cstr_suf2); + VERIFY( !cstr_in_worms ); + const auto sv_in_worms = s_test.ends_with(sv_suf2); + VERIFY( !sv_in_worms ); + const auto char_b = s_test.ends_with(L'b'); + VERIFY( !char_b ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_dir[] = "slugs/"; + constexpr std::string_view sv_dir("slugs/"); + constexpr char cstr_dir2[] = "worms/"; + constexpr std::string_view sv_dir2("worms/"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with('s'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with('w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_dir[] = L"slugs/"; + constexpr std::wstring_view sv_dir(L"slugs/"); + constexpr wchar_t cstr_dir2[] = L"worms/"; + constexpr std::wstring_view sv_dir2(L"worms/"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with(L's'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with(L'w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_dir[] = "slugs/"; + constexpr std::string_view sv_dir("slugs/"); + constexpr char cstr_dir2[] = "worms/"; + constexpr std::string_view sv_dir2("worms/"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with('s'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with('w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_dir[] = "slugs/"; + constexpr std::string_view sv_dir("slugs/"); + constexpr char cstr_dir2[] = "worms/"; + constexpr std::string_view sv_dir2("worms/"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with('s'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with('w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_dir[] = L"slugs/"; + constexpr std::wstring_view sv_dir(L"slugs/"); + constexpr wchar_t cstr_dir2[] = L"worms/"; + constexpr std::wstring_view sv_dir2(L"worms/"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with(L's'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with(L'w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view begins_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_dir[] = L"slugs/"; + constexpr std::wstring_view sv_dir(L"slugs/"); + constexpr wchar_t cstr_dir2[] = L"worms/"; + constexpr std::wstring_view sv_dir2(L"worms/"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.starts_with(cstr_dir); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.starts_with(sv_dir); + static_assert(sv_in_slugs); + constexpr auto char_s = sv_test.starts_with(L's'); + static_assert(char_s); + + constexpr auto cstr_in_worms = sv_test.starts_with(cstr_dir2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.starts_with(sv_dir2); + static_assert(!sv_in_worms); + constexpr auto char_w = sv_test.starts_with(L'w'); + static_assert(!char_w); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_suf[] = ".jpg"; + constexpr std::string_view sv_suf(".jpg"); + constexpr char cstr_suf2[] = ".rgb"; + constexpr std::string_view sv_suf2(".rgb"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with('g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with('b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_suf[] = L".jpg"; + constexpr std::wstring_view sv_suf(L".jpg"); + constexpr wchar_t cstr_suf2[] = L".rgb"; + constexpr std::wstring_view sv_suf2(L".rgb"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with(L'g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with(L'b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_suf[] = ".jpg"; + constexpr std::string_view sv_suf(".jpg"); + constexpr char cstr_suf2[] = ".rgb"; + constexpr std::string_view sv_suf2(".rgb"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with('g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with('b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr char cstr_suf[] = ".jpg"; + constexpr std::string_view sv_suf(".jpg"); + constexpr char cstr_suf2[] = ".rgb"; + constexpr std::string_view sv_suf2(".rgb"); + + constexpr std::string_view sv_test("slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with('g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with('b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_suf[] = L".jpg"; + constexpr std::wstring_view sv_suf(L".jpg"); + constexpr wchar_t cstr_suf2[] = L".rgb"; + constexpr std::wstring_view sv_suf2(L".rgb"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with(L'g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with(L'b'); + static_assert(!char_b); +} Index: testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc =================================================================== --- testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (nonexistent) +++ testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc (working copy) @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// basic_string_view ends_with + +#include <string_view> + +void +test01() +{ + constexpr wchar_t cstr_suf[] = L".jpg"; + constexpr std::wstring_view sv_suf(L".jpg"); + constexpr wchar_t cstr_suf2[] = L".rgb"; + constexpr std::wstring_view sv_suf2(L".rgb"); + + constexpr std::wstring_view sv_test(L"slugs/slimy.jpg"); + + constexpr auto cstr_in_slugs = sv_test.ends_with(cstr_suf); + static_assert(cstr_in_slugs); + constexpr auto sv_in_slugs = sv_test.ends_with(sv_suf); + static_assert(sv_in_slugs); + constexpr auto char_g = sv_test.ends_with(L'g'); + static_assert(char_g); + + constexpr auto cstr_in_worms = sv_test.ends_with(cstr_suf2); + static_assert(!cstr_in_worms); + constexpr auto sv_in_worms = sv_test.ends_with(sv_suf2); + static_assert(!sv_in_worms); + constexpr auto char_b = sv_test.ends_with(L'b'); + static_assert(!char_b); +}