brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 5585ec8 Raw
74 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <locale>10 11// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT -D_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT12 13// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>14 15// size_t converted() const;16 17// XFAIL: no-wide-characters18 19#include <locale>20#include <codecvt>21#include <cassert>22 23#include "test_macros.h"24 25template <class CharT, std::size_t = sizeof(CharT)>26struct TestHelper;27template <class CharT>28struct TestHelper<CharT, 2> {29  static void test();30};31template <class CharT>32struct TestHelper<CharT, 4> {33  static void test();34};35 36template <class CharT>37void TestHelper<CharT, 2>::test() {38  static_assert((std::is_same<CharT, wchar_t>::value), "");39  {40    typedef std::codecvt_utf8<CharT> Codecvt;41    typedef std::wstring_convert<Codecvt> Myconv;42    Myconv myconv;43    assert(myconv.converted() == 0);44    std::string bs = myconv.to_bytes(L"\u1005");45    assert(myconv.converted() == 1);46    bs = myconv.to_bytes(L"\u1005e");47    assert(myconv.converted() == 2);48    std::wstring ws = myconv.from_bytes("\xE1\x80\x85");49    assert(myconv.converted() == 3);50  }51}52 53template <class CharT>54void TestHelper<CharT, 4>::test() {55  static_assert((std::is_same<CharT, wchar_t>::value), "");56  {57    typedef std::codecvt_utf8<CharT> Codecvt;58    typedef std::wstring_convert<Codecvt> Myconv;59    Myconv myconv;60    assert(myconv.converted() == 0);61    std::string bs = myconv.to_bytes(L"\U00040003");62    assert(myconv.converted() == 1);63    bs = myconv.to_bytes(L"\U00040003e");64    assert(myconv.converted() == 2);65    std::wstring ws = myconv.from_bytes("\xF1\x80\x80\x83");66    assert(myconv.converted() == 4);67  }68}69 70int main(int, char**) {71  TestHelper<wchar_t>::test();72  return 0;73}74