brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · ec4c8a0 Raw
43 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// <iostream>10 11// wostream wcerr;12 13// UNSUPPORTED: no-wide-characters14 15// RUN: %{build}16// RUN: %{exec} %t.exe 2> %t.actual17// RUN: echo -n zzzz > %t.expected18// RUN: diff %t.expected %t.actual19 20#include <iostream>21 22struct custom_codecvt : std::codecvt<wchar_t, char, std::mbstate_t> {23  using base = std::codecvt<wchar_t, char, std::mbstate_t>;24protected:25  result do_out(std::mbstate_t&, const wchar_t *from, const wchar_t *from_end,26                const wchar_t *&from_next, char *to, char *to_end, char *&to_next) const {27    while (from != from_end && to != to_end) {28      ++from;29      *to++ = 'z';30    }31    from_next = from;32    to_next = to;33    return ok;34  }35};36 37int main(int, char**) {38    std::locale loc(std::locale::classic(), new custom_codecvt);39    std::wcerr.imbue(loc);40    std::wcerr << L"1234";41    return 0;42}43