1.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // { dg-options "-std=gnu++17" }
  2. // Copyright (C) 2013-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License along
  14. // with this library; see the file COPYING3. If not see
  15. // <http://www.gnu.org/licenses/>.
  16. // basic_string_view::substr
  17. namespace operations_substr_1 {
  18. static void
  19. test01 ()
  20. {
  21. typedef gdb::string_view::size_type csize_type;
  22. typedef gdb::string_view::const_reference cref;
  23. typedef gdb::string_view::reference ref;
  24. csize_type csz01;
  25. const char str_lit01[] = "rockaway, pacifica";
  26. const gdb::string_view str01(str_lit01);
  27. gdb::string_view str02;
  28. // basic_string_view<charT, _Traits, _Alloc>
  29. // substr(size_type pos = 0, size_type n = npos) const;
  30. csz01 = str01.size();
  31. str02 = str01.substr(0, 1);
  32. VERIFY( str02 == "r" );
  33. str02 = str01.substr(10);
  34. VERIFY( str02 == "pacifica" );
  35. try
  36. {
  37. str02 = str01.substr(csz01 + 1);
  38. VERIFY( false );
  39. }
  40. catch(gdb_exception& fail)
  41. {
  42. VERIFY( true );
  43. }
  44. catch(...)
  45. {
  46. VERIFY( false );
  47. }
  48. try
  49. {
  50. str02 = str01.substr(csz01);
  51. VERIFY( str02.size() == 0 );
  52. VERIFY( str02.begin() == str01.end() );
  53. VERIFY( true );
  54. }
  55. catch(...)
  56. {
  57. VERIFY( false );
  58. }
  59. }
  60. static int
  61. main ()
  62. {
  63. test01();
  64. return 0;
  65. }
  66. } // namespace operations_substr_1