C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

_wcsupr () with german characters

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Ajey
Guest





PostPosted: Wed Mar 30, 2005 8:35 am    Post subject: _wcsupr () with german characters Reply with quote



Hi,
I have a string which contains some german characters e.g
'Menü'. I am converting it to upper case using wcsupr (). But ü is
not converted to Ü. There are other characters too. I can use the
_wsetlocale () function before using _wcsupr (). I cannot use the
current machines locale setting. The strings have to be converted to
upper case based on the locale of the target machine which is a SQL
Server. What's the most efficient way of converting
the string to upper case considering the language specific characters.
I tried using the _wsetlocale (LC_CTYPE , L".OCP"); which uses the OEM
code page. This seems to be working. What's the difference in OEM code
page and language specific code page?

Thanks in advance

Ajey


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ron Natalie
Guest





PostPosted: Wed Mar 30, 2005 11:27 pm    Post subject: Re: _wcsupr () with german characters Reply with quote



Ajey wrote:
Quote:
Hi,
I have a string which contains some german characters e.g
'Menü'. I am converting it to upper case using wcsupr (). But ü is
not converted to Ü. There are other characters too.

All of the functions you mention are Microsoft specific. You need
to ask in a microsoft group.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Alberto Barbati
Guest





PostPosted: Wed Mar 30, 2005 11:28 pm    Post subject: Re: _wcsupr () with german characters Reply with quote



Ajey wrote:
Quote:
Hi,
I have a string which contains some german characters e.g
'Menü'. I am converting it to upper case using wcsupr (). But ü is
not converted to Ü. There are other characters too. I can use the
_wsetlocale () function before using _wcsupr (). I cannot use the
current machines locale setting. The strings have to be converted to
upper case based on the locale of the target machine which is a SQL
Server. What's the most efficient way of converting
the string to upper case considering the language specific characters.
I tried using the _wsetlocale (LC_CTYPE , L".OCP"); which uses the OEM
code page. This seems to be working. What's the difference in OEM code
page and language specific code page?


First of all, neither _wcsupr() nor _wsetlocale() are C++ standard
functions. They are not even C standard functions. Therefore I won't
discuss those, because this is a C++ newsgroup. If you want to stick
with those functions, you should post your question to a more relevant
newsgroup (probably microsoft.public.vc.* as you are clearly referring
to the VC++ platform and the use of such functions is platform-specific).

The correct way to address localizazion issues in C++ is through the
std::locale object. In order to convert a string to uppercase you have
to create a std::locale, extract the std::ctype<wchar_t> facet and call
method toupper(). In practice:

std::locale de("German");
const std::ctype<wchar_t>& fac
= std::use_facet<std::ctype(de);

wchar_t menu[] = L"Menü";
fac.toupper(menu, menu + 4);

Two words of warning:

1) the string "German" up there is platform-specific. It means the
German locale on the Windows platform. Different strings might be needed
on other platforms (for example "de", "de_DE", ecc.). You have to check
which convention your SQL server is using, if you want to be consistent.

2) although every implementation of std::locale must provide a
ctype<char> facet, the availability of the ctype<wchar_t> facet is not
guaranteed, so the call to use_facet may fail with an std::bad_cast
exception. Fortunately, on VC7.1 it works as it should.

HTH,

Alberto

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Ray Lischner
Guest





PostPosted: Thu Mar 31, 2005 8:44 am    Post subject: Re: _wcsupr () with german characters Reply with quote

On Wednesday 30 March 2005 06:28 pm, Alberto Barbati wrote:

Quote:
although every implementation of std::locale must provide a
ctype<char> facet, the availability of the ctype<wchar_t> facet is not
guaranteed

Table 51, in section 22.1.1.1.1 shows ctype<wchar_t> specialization. See
also 22.2.1.1/2. Perhaps you were confused by 22.2.1.3, which specifies
a particular implementation of ctype<char> but not ctype<wchar_t>. It
has no bearing on ctype<wchar_t>.
--
Ray Lischner, author of C++ in a Nutshell
http://www.tempest-sw.com/cpp

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Thu Mar 31, 2005 8:50 am    Post subject: Re: _wcsupr () with german characters Reply with quote

Alberto Barbati wrote:
Quote:
Ajey wrote:

I have a string which contains some german characters
e.g 'Menü'. I am converting it to upper case using wcsupr
(). But ü is not converted to Ü. There are other characters
too. I can use the _wsetlocale () function before using
_wcsupr (). I cannot use the current machines locale
setting. The strings have to be converted to upper case
based on the locale of the target machine which is a SQL
Server. What's the most efficient way of converting the
string to upper case considering the language specific
characters. I tried using the _wsetlocale (LC_CTYPE ,
L".OCP"); which uses the OEM code page. This seems to be
working. What's the difference in OEM code page and language
specific code page?

First of all, neither _wcsupr() nor _wsetlocale() are C++
standard functions. They are not even C standard functions.
Therefore I won't discuss those, because this is a C++
newsgroup. If you want to stick with those functions, you
should post your question to a more relevant newsgroup
(probably microsoft.public.vc.* as you are clearly referring
to the VC++ platform and the use of such functions is
platform-specific).

The correct way to address localizazion issues in C++ is
through the std::locale object. In order to convert a string
to uppercase you have to create a std::locale, extract the
std::ctype<wchar_t> facet and call method toupper(). In
practice:

std::locale de("German");
const std::ctype<wchar_t>& fac
= std::use_facet<std::ctype(de);

wchar_t menu[] = L"Menü";
fac.toupper(menu, menu + 4);

Two words of warning:

1) the string "German" up there is platform-specific. It means
the German locale on the Windows platform. Different strings
might be needed on other platforms (for example "de", "de_DE",
ecc.). You have to check which convention your SQL server is
using, if you want to be consistent.

2) although every implementation of std::locale must provide a
ctype<char> facet, the availability of the ctype<wchar_t
facet is not guaranteed, so the call to use_facet may fail
with an std::bad_cast exception. Fortunately, on VC7.1 it
works as it should.

All implementations are required to provide both ctype ctype<wchar_t>. On the other hand, the only required locale is
"C", which won't help him much.

It's also important to point out that the std::ctype interface
is useless for converting lower to upper -- it supposes a one to
one matching, which just doesn't hold. Particularly in German,
where "ß" should map to "SS". The problem has been thrashed out
here several times, but the final conclusion is always the same:
in the general case (and in the specific case of German), you
have to reimplement everything yourself, or count on some
non-standard library.

I don't know whether _wcsupr handles this correctly or not.
I've never heard of the function, and it isn't present on my
machines. If it does, more power to him; he has a third party
library which does something right:-). With regards to what's
in the code pages, of course, he'll have to find some system
specific documentation. If the interface to _wsetlocale is
anything like that of setlocale, however, he's dealing with
global state, with all of the precautions that entails: saving
and restoring the original state, as a minimum, not to mention
threading issues.

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Alberto Barbati
Guest





PostPosted: Fri Apr 01, 2005 2:05 am    Post subject: Re: _wcsupr () with german characters Reply with quote

Ray Lischner wrote:
Quote:
On Wednesday 30 March 2005 06:28 pm, Alberto Barbati wrote:

although every implementation of std::locale must provide a
ctype<char> facet, the availability of the ctype<wchar_t> facet is not
guaranteed

Table 51, in section 22.1.1.1.1 shows ctype<wchar_t> specialization. See
also 22.2.1.1/2. Perhaps you were confused by 22.2.1.3, which specifies
a particular implementation of ctype<char> but not ctype<wchar_t>. It
has no bearing on ctype<wchar_t>.

You're right. I was confused by 22.2.1.3 and did not look at table 51.
So the ctype<wchar_t> facet must exist and use_facet<ctype()
should not fail on a conforming implementation. Thanks for correcting me.

Alberto

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.