This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/14623] New: UTF-8 encoding, wcout vs. file


This is taken from the FC1 / Red Hat bug tracking system. It's #112192

For the following program:

#include <fstream>
#include <iostream>
#include <locale>
#include <string>
#include <cstdlib>
#include <cerrno>

using namespace std;

int main()
{
  wchar_t dst[256];
  unsigned char *ptr = (unsigned char *) dst;

  char *src = "Tämä on öäåÃ&#150;Ã&#132;Ã&#133; testi\n";

  locale::global(locale("en_US.UTF-8"));
  cout << locale().name() << endl;
  wcout.imbue(locale());
  cout.imbue(locale());

  //typedef std::codecvt_byname<wchar_t, char, std::mbstate_t> Cvt;
  //const std::locale unicode(std::locale ("C"), new Cvt("UTF-8")); 

  int i = mbstowcs(dst, src, 255);
  printf(">%d< %d\n", i, sizeof(dst));

  for (int x=0; x<i*4+1; x++) 
    printf("%02hx ", ptr[x]);
  printf("\n===\n%s%ls===\n", src, dst);

  wofstream myfile;
  myfile.imbue(locale());
  myfile.open("log.log");

  perror("0");
  wcout  << L"Testi " << endl << dst << endl;
  perror("1");
  errno=0;
  myfile << L"Rivi 1 " << endl << dst << endl;
  perror("2");

  myfile.close();
}


On FC1, I'm getting:
----------------start
en_US.UTF-8
>21< 1024
54 00 00 00 e4 00 00 00 6d 00 00 00 e4 00 00 00 20 00 00 00 6f 00 00 00 6e 00 00
00 20 00 00 00 f6 00 00 00 e4 00 00 00 e5 00 00 00 d6 00 00 00 c4 00 00 00 c5 00
00 00 20 00 00 00 74 00 00 00 65 00 00 00 73 00 00 00 74 00 00 00 69 00 00 00 0a
00 00 00 00
===
Tämä on öäåÃ&#150;Ã&#132;Ã&#133; testi
Tämä on öäåÃ&#150;Ã&#132;Ã&#133; testi
===
0: Success
Testi
Tämä on öäåÖÄÅ testi
 
1: Illegal seek
2: Success
-------------------------------finish

Where 

0: Success
Testi
Tämä on öäåÖÄÅ testi

should match

Tämä on öäåÃ&#150;Ã&#132;Ã&#133; testi

but does not.

The wofstream bits, do, indeed, work as expected.

-benjamin

-- 
           Summary: UTF-8 encoding, wcout vs. file
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bkoz at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14623


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]