Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-09-10 11:44:23


"George M. Garner Jr." <gmgarner_at_[hidden]> wrote in message
news:chr8dl$8rr$1_at_sea.gmane.org...
> Johnathan,
>
> How do I do locale specific Unicode-to-Multibyte conversion. As I
> understand the current design I need to do something like this:
>
> filtering_wostream out;
> out.push(unicode_to_multibyte_output_filter<__wchar_t>(locale));
> out.push(cout);
> out << L"This gets converted to multibyte characters according to the
> current locale." << endl;

The problem is really that I haven't finished writing the components that make
this easy. For this, I apologize. (See User's Guide-->Code Conversion.)

The *easiest* way to do what you want should be this:

    converting_ostream out;
    out.push(std::cout);
    out.imbue( some_locale );
    out << L"This gets converted to multibyte characters";

This will also allow any number of wide- and narrow- character filters before
cout, as long as all the wide ones come first. But as I said, this component is
not ready yet.

The current way to do this is extremely verbose:

 typedef converter< reference_wrapper<std::ostream> > my_converter;
 stream_facade<my_converter> out;
 out.open(my_converter(ref(std::cout), whatever_locale));
 out << L"Hello Wide World!\n";

Reference wrapper is required here because std::ostream is non-copyable. The
above code really should be

 typedef converter<std::ostream> my_converter;
 stream_facade<my_converter> out;
 out.open(my_converter(std::cout, whatever_locale));
 out << L"Hello Wide World!\n";

but I forgot to make the template converter do the reference-wrapping
automatically. (I'll fix this.)

There's one last problem. The file
boost/io/detail/streambufs/indirect_streambufs contains this code:

    enum {
        f_open = 1,
        f_input_closed = f_open << 1,
        f_output_closed = f_input_closed << 1,
        f_output_buffered = f_output_closed
    };

This should be

    enum {
        f_open = 1,
        f_input_closed = f_open << 1,
        f_output_closed = f_input_closed << 1,
        f_output_buffered = f_output_closed << 1
    };

I'm not sure if it will make a difference in the above case.

To summarize: what you want to do is perfectly resonable and should be easy, but
I haven't finished developing all the components. The current method is
unnecessarily verbose, but should work.

Thanks again!

Jonathan

>
> But the second to last line will generate an error with the present design
> because I am attaching a narrow character stream to a wide character
> filtering ostream. Do I need to use the boost::io::copy() paradigm? :(-
>
> Regards,
>
> George.
>
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk