1.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // { dg-require-iconv "UCS-2BE" }
  2. // { dg-require-iconv "ISO-8859-15" }
  3. // 2003-02-06 Petur Runolfsson <peturr02@ru.is>
  4. // Copyright (C) 2003-2022 Free Software Foundation, Inc.
  5. //
  6. // This file is part of the GNU ISO C++ Library. This library is free
  7. // software; you can redistribute it and/or modify it under the
  8. // terms of the GNU General Public License as published by the
  9. // Free Software Foundation; either version 3, or (at your option)
  10. // any later version.
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. // You should have received a copy of the GNU General Public License along
  16. // with this library; see the file COPYING3. If not see
  17. // <http://www.gnu.org/licenses/>.
  18. // 22.2.1.5 - Template class codecvt [lib.locale.codecvt]
  19. #include <locale>
  20. #include <cstring>
  21. #include <testsuite_hooks.h>
  22. #include <ext/codecvt_specializations.h>
  23. // Partial specialization using encoding_state
  24. // codecvt<unicode_t, char, encoding_state>
  25. // UNICODE - UCS2 (big endian)
  26. void test01()
  27. {
  28. using namespace std;
  29. typedef unsigned short int_type;
  30. typedef char ext_type;
  31. typedef __gnu_cxx::encoding_state state_type;
  32. typedef codecvt<int_type, ext_type, state_type> unicode_codecvt;
  33. const ext_type* e_lit = "black pearl jasmine tea";
  34. int size = strlen(e_lit);
  35. // construct a locale object with the specialized facet.
  36. locale loc(locale::classic(), new unicode_codecvt);
  37. // sanity check the constructed locale has the specialized facet.
  38. VERIFY( has_facet<unicode_codecvt>(loc) );
  39. const unicode_codecvt& cvt = use_facet<unicode_codecvt>(loc);
  40. unicode_codecvt::state_type state04("UCS-2BE", "ISO-8859-15", 0xfeff, 0);
  41. cvt.length(state04, e_lit, e_lit + size, 5);
  42. }
  43. int main ()
  44. {
  45. test01();
  46. return 0;
  47. }