Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Locale] [Boost.Iostreams] Example with code converter does not work with clang
From: Jesse Beder (beder_at_[hidden])
Date: 2012-03-27 01:06:05

I'm trying the example on the "Character Set Conversions" page of the
Boost.Locale documentation:

(the full code I'm running is at the end of this message).

When compiling with gcc:

g++ -o test -lboost_locale test.cpp

It run correctly - it prints "שלום" to standard output.

However, when compiling with clang:

clang++ -o test -lboost_locale test.cpp

It produces, as far as I can tell, gibberish - it prints "של×" to
standard output. The hex values of the output are:

0xc3 0x97 0xc2 0xa9 0xc3 0x97 0xc2 0x9c 0xc3 0x97 0xc2 0x95 0xc3 0x97 0xc2 0x9d


What I'd like is to have a stream that accepts wide strings in the
current locale and produces narrow strings in UTF-8 - am I completely
off the track? If so, what should I do instead, and if not, what am I
doing wrong?


- Jesse Beder


(code follows)

#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/code_converter.hpp>
#include <boost/locale.hpp>
#include <iostream>

namespace io = boost::iostreams;

class consumer {
    typedef char char_type;
    typedef io::sink_tag category;
    std::streamsize write(const char* s, std::streamsize n)
        return n;

int main()
    typedef io::code_converter<consumer> converter_device;
    typedef io::stream<converter_device> converter_stream;

    consumer cons;
    converter_device dev;
    boost::locale::generator gen;
    converter_stream stream;;
    stream << L"שלום";
    return 0;

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at