🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internationalization
2 messages
2 total messages Started by Niels Mon, 09 Jan 2006 13:33
wstring to string in Danish?
#155
Author: Niels
Date: Mon, 09 Jan 2006 13:33
30 lines
1986 bytes
Hello,
Why does this function not translate the Danish characters "������" correctly from wide character to character format? Well, it does but only because I put the switch statement in there:

std::string StrNarrow(const std::wstring &source)
// From http://lists.boost.org/Archives/boost/2002/10/38018.php
{
  std::string result(source.size(), wchar_t(0));
  typedef std::ctype<wchar_t> ctype_t;
  const ctype_t& ct = std::use_facet<ctype_t>(std::locale("danish"));  // no effect!
  ct.narrow(source.data(), source.data() + source.size(),'@',&(*result.begin()));
  for (size_t i=0; i<source.size(); ++i)
    switch (source[i]){
      case L'�': result[i]='�'; break;
      case L'�': result[i]='�'; break;
      case L'�': result[i]='�'; break;
      case L'�': result[i]='�'; break;
      case L'�': result[i]='�'; break;
      case L'�': result[i]='�'; break;
      default: ;
    }
  return result;
}

Without the switch statement the call of StrNarrow(L"Bl�b�rgr�d") yield Bl@b@rgr@d. Incorrect!

With the switch statement the call of StrNarrow(L"Bl�b�rgr�d") yield "Bl�b�rgr�d". Correct!

I am using Builder 6.0.
Cheers, Niels
Re: wstring to string in Danish?
#156
Author: Darko Miletic
Date: Wed, 11 Jan 2006 01:48
17 lines
1809 bytes
Niels wrote:
> Hello,
> Why does this function not translate the Danish characters "������" correctly from wide character to character format? Well, it does but only because I put the switch statement in there:
> Without the switch statement the call of StrNarrow(L"Bl�b�rgr�d") yield Bl@b@rgr@d. Incorrect!
> 
> With the switch statement the call of StrNarrow(L"Bl�b�rgr�d") yield "Bl�b�rgr�d". Correct!
> 
> I am using Builder 6.0.

C++ Builder ships with two implementations of STL. One is "new" STLport
and another is rouge wave STL.

By default bcb 6 uses STLport. Just to be sure try to switch to older RW
STL and see what happens. You can do that by adding _USE_OLD_RW_STL
define to your project settings.

Darko
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads