tags:

views:

296

answers:

1

Hello!

I'm writing an application, and I'm currently using libcurl. The libcurl callback function works fine when I implement it for the Ansi charset, but I fail to get it working when working with Unicode characters.

int CURLConnectorAnsi::BufferWriter(char* data, size_t size, size_t nmemb, std::string* buffer)
{
    int ReadBytes = 0;
    if (buffer != NULL)
    {
        buffer->append(data, size * nmemb);
        ReadBytes = size * nmemb;
    }

    return ReadBytes;
}

This snippet works fine, and returns the contents of the website that I website that I've read. Does anyone know how I can pass the data correctly into a wstring instead of a string?

EDIT: I'm trying to manage to get the data in a correct wchar_t* buffer instead (first parameter which is a void* according to curl) of the character buffer, I don't want to know how to add Ansi data into a Unicode buffer.

Thanks!

+1  A: 

Basically, it has nothing to do with curl and you're facing the problem of converting utf-8 to wide string. You can use something like Glib::ustring class or implement it on your own, or take a look at this code.

Michael Krelin - hacker
It's not the converting thats my problem, its receiving the data in the first place; the first parameter is a void* and can be cast into anything; but this only works for a char*.
Chaoz
No, it *is* converting. You receive the stream of bytes, which are likely encoded using `UTF-8` (it actually depends on the server and you can find this information in `HTTP` headers). You can not just cast the pointer to make the data change, you need to convert it.
Michael Krelin - hacker
Worked smoothly, thanks!
Chaoz