From 4c5083dd3faead800a93609648e784d7cddd56bb Mon Sep 17 00:00:00 2001 From: zel1b08a Date: Tue, 19 Nov 2024 17:22:17 +0700 Subject: [PATCH 1/3] Use OS independent utf8 string representation of std_fs::path at to_json conversions. --- include/nlohmann/detail/conversions/to_json.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index 18c4493e75..f1c876584a 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -435,7 +435,7 @@ inline void to_json(BasicJsonType& j, const T& t) template inline void to_json(BasicJsonType& j, const std_fs::path& p) { - j = p.string(); + j = p.u8string(); } #endif From efac3b36abb56e1e7fddf2a0985bf3dc10edb407 Mon Sep 17 00:00:00 2001 From: zel1b08a Date: Sat, 7 Dec 2024 20:56:08 +0700 Subject: [PATCH 2/3] Add char8_t feature guard. --- include/nlohmann/detail/conversions/to_json.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index f1c876584a..c5f4ce8347 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -435,7 +435,12 @@ inline void to_json(BasicJsonType& j, const T& t) template inline void to_json(BasicJsonType& j, const std_fs::path& p) { +#if defined __cpp_lib_char8_t + j = reinterpret_cast(p.u8string().data()); +#else j = p.u8string(); +#endif + } #endif From e41bfbcf06b7d2754477454d635f651c6964caf0 Mon Sep 17 00:00:00 2001 From: zel1b08a Date: Sat, 7 Dec 2024 20:56:50 +0700 Subject: [PATCH 3/3] Remove empty line. --- include/nlohmann/detail/conversions/to_json.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index c5f4ce8347..32d58e255b 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -440,7 +440,6 @@ inline void to_json(BasicJsonType& j, const std_fs::path& p) #else j = p.u8string(); #endif - } #endif