Article View: borland.public.cppbuilder.internationalization
Article #155wstring to string in Danish?
From: Niels
Date: Mon, 09 Jan 2006 13:33
Date: Mon, 09 Jan 2006 13:33
30 lines
1986 bytes
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
Technical Details
Message-ID:
<43c2742d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10297d,fca0b7b205899cc1,start X-Google-Attributes: gid10297d,public X-Google-Language: ENGLISH,ASCII From: "Niels" <niels.holst@agrsci.dk> Sender: "Niels" <niels.holst@agrsci.dk> Reply-To: "Niels" <niels.holst@agrsci.dk> Subject: wstring to string in Danish? Newsgroups: borland.public.cppbuilder.internationalization X-User-Info: 130.226.173.129 NNTP-Posting-Host: 207.105.83.66 Message-ID: <43c2742d$1@newsgroups.borland.com> Date: 9 Jan 2006 06:33:17 -0700 X-Trace: newsgroups.borland.com 1136817197 207.105.83.66 (9 Jan 2006 06:33:17 -0700) Lines: 30 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail