Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2005-09-19 05:33:05


Vladimir Prus wrote:
>Reece Dunn wrote:
> > WRT the MFC/ATL/WTL libraries, they use the Win32 API calls
> > WideCharToMultiByte (WC2MB) and MultiByteToWideChar (MB2WC) to do the
> > conversion using the current thread's codepage. Likewise, their
> > CA2W/CW2A helper classes do a similar thing.
> >
> > The WC2MB/MB2WC API allow you to pass in a specific codepage (not just
> > the current thread/user's). Some of these include:
> > UTF7 = 65000
> > UTF8 = 65001
> > UTF16 (Little Endian) = 1200
> > UTF16 (Big Endian) = 1200
> >
> > So, you could say something like:
> >
> > std::cout << unicode_cast< std::string >( russian_text, unicode::utf8 );
>
>Sure, but there's no "std::" in front of "unicode_cast". In fact, I don't
>know what the "unicode_cast" comes from. My points is not that you cannot
>implement all the missing functionality for std::string. The point is that
>std:: namespace does not have this functionality.

I was proposing unicode_cast as a standard/Boost replacement for the
CA2W/CW2A functionality in MFC/ATL in the same way that boost::lexical_cast,
et. al. work.

I agree that this functionality is lacking in the current standard.

> > I am not sure about how this would work for Linux, Mac and other
> > operating systems, though.
>
>Assuming unicode_cast is from MFC/ATL/WTL -- then well, none for Linux.

I was suggesting unicode_cast initially as a Boost library (I should have
made this clearer). Then, you would have:

   namespace boost { namespace unicode {
      enum encoding
      {
         utf8, utf16le, utf16be, ... // values implementation defined
      };

      class basic_*fstream{}; // unicode aware file streams

      unicode_cast< To >( From from, unicode::encoding to_unicode_encoding )
   }}
   using boost::unicode::unicode_cast;

This would most likely complement the current work for Unicode support in
boost.

- Reece


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