Sign in to follow this  
Decept

Unicode case conversion

Recommended Posts

Is there a function in C++ to change the case of a unicode string? The program I need this in is using MFC so if there are any such functions there it's also ok. I tried using the MakeUpper()/MakeLower() functions in the MFC CString class (the project is in Unicode). But they only change the case of the "standard" characters. For example, they just skip the "special" characters used in german. I'm using VC++ 2003

Share this post


Link to post
Share on other sites
have u tried _wcslwr and _wcsupr which are defined in <tchar.h>?

EDIT:
actually, nevermind... just checked MFC 8.0 (don't know about 7.0 which comes with VS 2003 though) source myself and saw MFC actually wraps the above functions. however, you might want to try messing with the locale versions of these functions, _wcslwr_l and _wcsupr_l. you can also try the Win32 API functions CharLower and CharUpper as well.

[Edited by - yadango on August 17, 2006 3:25:40 AM]

Share this post


Link to post
Share on other sites
The C++ functions for this are the toupper() member functions of the ctype locale facet. You'll need to create an appropriate locale for this though.

The standard C function for this is towupper(), but again the global locale needs to be set appropriately.

Share this post


Link to post
Share on other sites
If you're willing to Windows only and really care about getting things as right as you can the function to call is LCMapString. The problem with toupper and similiar functions is that they operate a character at a time and thus assume there's a one-to-one mapping between upper and lower case characters. In general this isn't true and it's possible for a string to end up being longer or shorter when you change it's case.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this