views:

392

answers:

1

Hi,

I maintain an application written in Borland C++ 6. This app is using SQLite database.

I am now extending it, so it can be used by unprivileged users, and so I had to move the database file to the home user directory. Unfortunately some of users have Polish national characters in their names, such as ą,ć,ę and some more. The system codepage is cp1250, but SQLite requires me to pass an utf-8 encoded path.

So, basicly I need to convert a cp1250 encoded path:

String path = "c:\documents and settings\User Name like Zażółć gęślą Jaźń\Application Data\...\MyDb.sqlite"

to utf-8, and then pass it to sqlite with path.c_str();

Does C++ builder have any class to convert charsets, or should I just map the short set of polish national character codes to their utf-8 representations?

+1  A: 

I couldn't find the documentation for C++ Builder (the links on Borland's page seem to be broken), but from what I recall, you can directly convert from AnsiString to WideString.

Once you have a UTF-16 string, you can use WideCharToMultiByte Windows function, passing CP_UTF8 as a parameter.

avakar
Thanks, it worked for me.
SWilk
Assigning an AnsiString to a WideString uses the OS default Ansi codepage for the conversion. If you want to use a specific codepage, especially if it is different than the OS language, then you have to call MultiByteToWideChar() directly.
Remy Lebeau - TeamB