Enable non-ascii chars (#1669)

* Enable non-ascii chars

* Follow file naming policy

* Use stream read and write methods

* Remove obsolete close() calls

* Revert "Remove obsolete close() calls"

This reverts commit 7006bcb038.

* Revert "Use stream read and write methods"

This reverts commit ec06a1a05b.
This commit is contained in:
stefansjfw
2020-03-25 11:11:27 +01:00
committed by GitHub
parent 8156279025
commit 1476395829

View File

@@ -9,11 +9,12 @@ namespace json
{
try
{
std::wifstream file(file_name.data(), std::ios::binary);
std::ifstream file(file_name.data(), std::ios::binary);
if (file.is_open())
{
using isbi = std::istreambuf_iterator<wchar_t>;
return JsonValue::Parse(std::wstring{ isbi{ file }, isbi{} }).GetObjectW();
using isbi = std::istreambuf_iterator<char>;
std::string obj_str{ isbi{ file }, isbi{} };
return JsonValue::Parse(winrt::to_hstring(obj_str)).GetObjectW();
}
return std::nullopt;
}
@@ -25,6 +26,7 @@ namespace json
void to_file(std::wstring_view file_name, const JsonObject& obj)
{
std::wofstream{ file_name.data(), std::ios::binary } << obj.Stringify().c_str();
std::wstring obj_str{ obj.Stringify().c_str() };
std::ofstream{ file_name.data(), std::ios::binary } << winrt::to_string(obj_str);
}
}