I'm trying to build a Python extension with C++ 14. When the module is initialized in Python, I ask caller giving me a callback function which take a string as input.
When a function in the module is called, I want to do is reading a text file from disk, which may contain non-English characters. So I read it into memory as wstring in C++ code.
The next step is to pass this wstring to Python code. Should I define the user callback function like below:
typedef std::string (*UserCallbackFunc)(std::string);
and handle wstring to utf-8 string conversion like below:
string wstring2utf8string(wstring input)
{
wstring_convert<codecvt_utf8<wchar_t>> converter;
return converter.to_bytes(input);
}
or I could simply define the callback like
typedef std::wstring (*UserCallbackFunc)(std::wstring);
and pass in what I read from disk directly?