- As you know, native narrow encoding for Windows is not utf-8, so when I`m trying to serialize std::string in native Windows encoding (like cp1251) I'm getting crash. In fact, I can't use the same serialization code for Linux and Windows and I can't use rfl with WinAPI narrow functions easily. I think rfl::json::write should consider native narrow encoding.
- Ok, I thought I can resolve my problems using std::wstring or std::filesystem::path (I got crash for path returned by SHGetFolderPathA). I tried to use SHGetFolderPathW and std::wstring or std::filesystem::path, but I also got crash! From other side, if I'm constructing std::filesystem::path from utf-8, then rfl::json::write works, but std::filesystem::path variable contains broken path. If I'm converting this path from utf-8 to std::wstring, then I'm getting crash again.
Version https://vcpkg.link/ports/reflectcpp/v/0.19.0/0
Windows any, Visual Studio any
Minimal code to reproduce:
std::ifstream infile("cp1251.txt", std::ios::binary);
std::string data;
std::getline(infile, data);
std::filesystem::path path{ data };
auto json{ rfl::json::write(path) };
or
std::wstring utf8_to_wstring(const std::string& str)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
return converter.from_bytes(str);
}
...
std::ifstream infile("utf8.txt", std::ios::binary);
std::string data;
std::getline(infile, data);
auto ws{ utf8_to_wstring(data) };
auto json{ rfl::json::write(ws) };
cp1251.txt
utf8.txt
Version https://vcpkg.link/ports/reflectcpp/v/0.19.0/0
Windows any, Visual Studio any
Minimal code to reproduce:
or
cp1251.txt
utf8.txt