Sign in to follow this  
SirLuthor

Unicode + Standard Library

Recommended Posts

SirLuthor    364
Hiya guys, back from ugly router problems, I have 2 days worth of questions, in regards to Unicode, and the standard library. Or, well, I exaggerate, but, the point is, I have a query, and as always, I call upon you good souls to help me out [smile] Tell me honestly, is it a bad thing that I ramble on like this before getting into my material? It's because I like being polite, but is this just considered annoying? Anyway, my point. Yerr... I've been porting my code to (restarting my core with) MSVC 2003 (HURRAY!), and in the meantime, I've been working in support for both ASCII and unicode. This is all well and good, and with the help of a few useful typedefs it fits right into my design and all. But I'm having some problems. Particularly when it comes to places where either ASCII or Unicode (thankfully haven't found one of those yet..) is required, as a parameter, for example. Now, this would be all well and good, but I've googled, and searched MSDN, for a good method to translate one to the other, and vice-versa, but I have yet to find anything that looks like it could be used anywhere near performance code, nor anywhere near readable code, for that matter. I'm using std::string and std::wstring right now as strings, and they have the c_str() function to get a char * or wchar_t *, but only one of the other. And the open function of std::ifstreams takes only a const char *, but not the unicode equivalent. I could of course solve the problem by using my own file streams and hacking in unicode functionality like I had before, which I will no doubt integrate and use again soon once I have some core functionality down, but this would be a case of smashing the fly with a sledgehammer, a gross uber-solution. So I need a good solid way to translate unicode to ASCII and vice-versa. If anyone could enlighten me as to the answer to this problem, I'd be obliged. Thanks!

Share this post


Link to post
Share on other sites
SiCrane    11839
Try looking up mbstowcs(), wcstombs() and, if you're feeling adventurous, the ctype::widen() and ctype::narrow() member functions of the ctype locale facet.

Share this post


Link to post
Share on other sites
Kiput    100
Quote:
Original post by SiCrane
Try looking up mbstowcs(), wcstombs()


Correct me if I'm wrong, but these are windows specific routines. If you would like some cross-platform capabilities you could try libiconv.

Share this post


Link to post
Share on other sites
SiCrane    11839
Quote:
Original post by Kiput
Correct me if I'm wrong, but these are windows specific routines. If you would like some cross-platform capabilities you could try libiconv.

You're wrong. mbstowcs() and wcstombs() are part of the C Standard Library, defined in stdlib.h (and included by reference in the C++ Standard Library in header cstdlib).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
This information may also be useful to you in your future:

http://www.codeproject.com/vcpp/stl/upgradingstlappstounicode.asp

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