Skip to main content
gamedev.net
🔒 Locked

Unicode case conversion

Started by Decept 4 replies 1.8k views
Original Post
Decept
Decept
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
yadango
yadango
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]
Decept
Decept

The functions CharLower()/CharUpper() works

Thanks!
SiCrane
SiCrane
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.
Anon Mike
Anon Mike
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.
-Mike

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.