This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Re: Locale codecvt facet doesn't seem to return 'partial'



FYI Paolo here's the extension use to double check the UTF-8 encoding.


-benjamin



#include <locale>
#include <fstream>
#include <ext/codecvt_specializations.h>


int foo2()
{
  using namespace std;
  typedef codecvt_base::result                  result;
  typedef char                        		int_type;
  typedef char                                  ext_type;
  typedef __gnu_cxx::encoding_state                     state_type;
  typedef codecvt<int_type, ext_type, state_type>       utf8_codecvt;
  typedef char_traits<int_type>                 int_traits;
  typedef char_traits<ext_type>                 ext_traits;

  state_type state("ISO-8859-15", "UTF-8", 0, 0);
  string from("¡Hasta mañana!");
  static char to[256];
  ext_type*       eto_next;
  const int_type*       ifrom_next;

  locale                loc(locale::classic(), new utf8_codecvt);
  const utf8_codecvt& cvt = use_facet<utf8_codecvt>(loc); 

  result r = cvt.out(state, from.c_str(), from.c_str() + from.size(), 
		     ifrom_next, 
		     to, to + 256, eto_next);


  // write it out
  const char* filename = "test_utf8_output2";
  filebuf fb;
  string tmp(to);
  fb.open(filename, ios_base::out);
  fb.sputn(tmp.c_str(), tmp.size());
  fb.close();
}

int main()
{
  foo2();
}

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