summaryrefslogtreecommitdiff
path: root/dev-cpp/nlohmann_json
diff options
context:
space:
mode:
Diffstat (limited to 'dev-cpp/nlohmann_json')
-rw-r--r--dev-cpp/nlohmann_json/Manifest2
-rw-r--r--dev-cpp/nlohmann_json/files/nlohmann_json-3.12.0-fallback-missing-char8_t.patch141
-rw-r--r--dev-cpp/nlohmann_json/metadata.xml9
-rw-r--r--dev-cpp/nlohmann_json/nlohmann_json-3.12.0-r1.ebuild68
4 files changed, 220 insertions, 0 deletions
diff --git a/dev-cpp/nlohmann_json/Manifest b/dev-cpp/nlohmann_json/Manifest
new file mode 100644
index 000000000000..ec3508287207
--- /dev/null
+++ b/dev-cpp/nlohmann_json/Manifest
@@ -0,0 +1,2 @@
+DIST nlohmann_json-3.12.0.tar.gz 9678593 BLAKE2B db4310eeecee130a73f6dd774367104d0631e25af8bf507185c708598f2b9af67fc8387fe2b93bb27b91859518bf6c81c91dbde301e3c1a717aae6866e257e3d SHA512 6cc1e86261f8fac21cc17a33da3b6b3c3cd5c116755651642af3c9e99bb3538fd42c1bd50397a77c8fb6821bc62d90e6b91bcdde77a78f58f2416c62fc53b97d
+DIST nlohmann_json-testdata-3.1.0.tar.gz 115036393 BLAKE2B 809be0728a0b9d007fcc752911bdf6f7e548d6e3ec59871ea2b16d87d8248ca4dd2f681a1d0f82c618463294188ad41d6d965b8bdc39c70fdcf4b939d4121e9c SHA512 db6c411b37f2154f5dd1ed90f4e8fa0907f4a736cd0ff79943bcacf9da422285ff142bb6a7dc6022b236090083166ac1ab197be3f480d8dc50b26a91a9477821
diff --git a/dev-cpp/nlohmann_json/files/nlohmann_json-3.12.0-fallback-missing-char8_t.patch b/dev-cpp/nlohmann_json/files/nlohmann_json-3.12.0-fallback-missing-char8_t.patch
new file mode 100644
index 000000000000..afb1491e10af
--- /dev/null
+++ b/dev-cpp/nlohmann_json/files/nlohmann_json-3.12.0-fallback-missing-char8_t.patch
@@ -0,0 +1,141 @@
+From 756ca22ec5b0d89b5d107b4c30891d1293650c87 Mon Sep 17 00:00:00 2001
+From: Sergiu Deitsch <sergiud@users.noreply.github.com>
+Date: Wed, 23 Apr 2025 18:36:41 +0200
+Subject: [PATCH] Provide fallback for missing `char8_t` support (#4736)
+
+---
+ .../nlohmann/detail/conversions/from_json.hpp | 5 +++-
+ .../nlohmann/detail/conversions/to_json.hpp | 21 ++++++++++-----
+ single_include/nlohmann/json.hpp | 26 +++++++++++++------
+ tests/src/unit-deserialization.cpp | 5 ++--
+ 4 files changed, 39 insertions(+), 18 deletions(-)
+
+diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp
+index 797f714dfa..3a24a6f4d2 100644
+--- a/include/nlohmann/detail/conversions/from_json.hpp
++++ b/include/nlohmann/detail/conversions/from_json.hpp
+@@ -539,7 +539,10 @@ inline void from_json(const BasicJsonType& j, std_fs::path& p)
+ JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
+ }
+ const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
+-#ifdef JSON_HAS_CPP_20
++ // Checking for C++20 standard or later can be insufficient in case the
++ // library support for char8_t is either incomplete or was disabled
++ // altogether. Use the __cpp_lib_char8_t feature test instead.
++#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
+ p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size()));
+ #else
+ p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20
+diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp
+index f8413850d5..8b910dd161 100644
+--- a/include/nlohmann/detail/conversions/to_json.hpp
++++ b/include/nlohmann/detail/conversions/to_json.hpp
+@@ -15,7 +15,8 @@
+
+ #include <algorithm> // copy
+ #include <iterator> // begin, end
+-#include <string> // string
++#include <memory> // allocator_traits
++#include <string> // basic_string, char_traits
+ #include <tuple> // tuple, get
+ #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
+ #include <utility> // move, forward, declval, pair
+@@ -440,15 +441,21 @@ inline void to_json(BasicJsonType& j, const T& t)
+ }
+
+ #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
++#if defined(__cpp_lib_char8_t)
++template<typename BasicJsonType, typename Tr, typename Allocator>
++inline void to_json(BasicJsonType& j, const std::basic_string<char8_t, Tr, Allocator>& s)
++{
++ using OtherAllocator = typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
++ j = std::basic_string<char, std::char_traits<char>, OtherAllocator>(s.begin(), s.end(), s.get_allocator());
++}
++#endif
++
+ template<typename BasicJsonType>
+ inline void to_json(BasicJsonType& j, const std_fs::path& p)
+ {
+-#ifdef JSON_HAS_CPP_20
+- const std::u8string s = p.u8string();
+- j = std::string(s.begin(), s.end());
+-#else
+- j = p.u8string(); // returns std::string in C++17
+-#endif
++ // Returns either a std::string or a std::u8string depending whether library
++ // support for char8_t is enabled.
++ j = p.u8string();
+ }
+ #endif
+
+diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
+index 13b07c0fbc..93e5983cf1 100644
+--- a/single_include/nlohmann/json.hpp
++++ b/single_include/nlohmann/json.hpp
+@@ -5324,7 +5324,10 @@ inline void from_json(const BasicJsonType& j, std_fs::path& p)
+ JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
+ }
+ const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
+-#ifdef JSON_HAS_CPP_20
++ // Checking for C++20 standard or later can be insufficient in case the
++ // library support for char8_t is either incomplete or was disabled
++ // altogether. Use the __cpp_lib_char8_t feature test instead.
++#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
+ p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size()));
+ #else
+ p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20
+@@ -5379,7 +5382,8 @@ NLOHMANN_JSON_NAMESPACE_END
+
+ #include <algorithm> // copy
+ #include <iterator> // begin, end
+-#include <string> // string
++#include <memory> // allocator_traits
++#include <string> // basic_string, char_traits
+ #include <tuple> // tuple, get
+ #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
+ #include <utility> // move, forward, declval, pair
+@@ -6086,15 +6090,21 @@ inline void to_json(BasicJsonType& j, const T& t)
+ }
+
+ #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
++#if defined(__cpp_lib_char8_t)
++template<typename BasicJsonType, typename Tr, typename Allocator>
++inline void to_json(BasicJsonType& j, const std::basic_string<char8_t, Tr, Allocator>& s)
++{
++ using OtherAllocator = typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
++ j = std::basic_string<char, std::char_traits<char>, OtherAllocator>(s.begin(), s.end(), s.get_allocator());
++}
++#endif
++
+ template<typename BasicJsonType>
+ inline void to_json(BasicJsonType& j, const std_fs::path& p)
+ {
+-#ifdef JSON_HAS_CPP_20
+- const std::u8string s = p.u8string();
+- j = std::string(s.begin(), s.end());
+-#else
+- j = p.u8string(); // returns std::string in C++17
+-#endif
++ // Returns either a std::string or a std::u8string depending whether library
++ // support for char8_t is enabled.
++ j = p.u8string();
+ }
+ #endif
+
+diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp
+index 84a970a183..5c450c23d3 100644
+--- a/tests/src/unit-deserialization.cpp
++++ b/tests/src/unit-deserialization.cpp
+@@ -1134,9 +1134,10 @@ TEST_CASE("deserialization")
+ }
+ }
+
+-// select the types to test - char8_t is only available in C++20
++// select the types to test - char8_t is only available since C++20 if and only
++// if __cpp_char8_t is defined.
+ #define TYPE_LIST(...) __VA_ARGS__
+-#ifdef JSON_HAS_CPP_20
++#if defined(__cpp_char8_t) && (__cpp_char8_t >= 201811L)
+ #define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t, char8_t)
+ #else
+ #define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t)
diff --git a/dev-cpp/nlohmann_json/metadata.xml b/dev-cpp/nlohmann_json/metadata.xml
new file mode 100644
index 000000000000..2d659d311a25
--- /dev/null
+++ b/dev-cpp/nlohmann_json/metadata.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "https://docs.baldeagleos.com/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="project">
+ <email>media-video@gentoo.org</email>
+ <name>Gentoo Video project</name>
+ </maintainer>
+ <origin>baldeagleos-repo</origin>
+</pkgmetadata>
diff --git a/dev-cpp/nlohmann_json/nlohmann_json-3.12.0-r1.ebuild b/dev-cpp/nlohmann_json/nlohmann_json-3.12.0-r1.ebuild
new file mode 100644
index 000000000000..e9bb529175ae
--- /dev/null
+++ b/dev-cpp/nlohmann_json/nlohmann_json-3.12.0-r1.ebuild
@@ -0,0 +1,68 @@
+# Copyright 1999-2026 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+#DOCS_BUILDER="mkdocs"
+# Needs unpackaged plantuml-markdown too
+# ... but plantuml (Python bindings anyway) need network access to generate bits at runtime.
+#DOCS_DEPEND="dev-python/mkdocs-material-extensions dev-python/mkdocs-minify-plugin"
+#DOCS_DIR="doc/mkdocs"
+inherit cmake
+
+# Check https://github.com/nlohmann/json/blob/develop/cmake/download_test_data.cmake to find test archive version
+TEST_VERSION="3.1.0"
+DESCRIPTION="JSON for Modern C++"
+HOMEPAGE="https://github.com/nlohmann/json https://nlohmann.github.io/json/"
+SRC_URI="
+ https://github.com/nlohmann/json/archive/v${PV}.tar.gz -> ${P}.tar.gz
+ test? ( https://github.com/nlohmann/json_test_data/archive/v${TEST_VERSION}.tar.gz -> ${PN}-testdata-${TEST_VERSION}.tar.gz )
+"
+S="${WORKDIR}/json-${PV}"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="amd64 arm arm64 ~hppa ~loong ppc ppc64 ~riscv ~sparc x86"
+IUSE="test"
+RESTRICT="!test? ( test )"
+
+DOCS=( ChangeLog.md README.md )
+
+PATCHES=( "${FILESDIR}/${PN}-3.12.0-fallback-missing-char8_t.patch" )
+
+src_prepare() {
+ if use test ; then
+ ln -s "${WORKDIR}"/json_test_data-${TEST_VERSION} "${S}"/json_test_data || die
+ fi
+
+ cmake_src_prepare
+}
+
+src_configure() {
+ # Tests are built by default so we can't group the test logic below
+ local mycmakeargs=(
+ -DJSON_MultipleHeaders=ON
+ -DJSON_BuildTests=$(usex test)
+ )
+
+ # Define test data directory here to avoid unused var QA warning, bug #747826
+ use test && mycmakeargs+=( -DJSON_TestDataDirectory="${S}"/json_test_data )
+
+ cmake_src_configure
+}
+
+src_test() {
+ cd "${BUILD_DIR}"/tests || die
+
+ # git_required:
+ # Skip certain tests needing git per upstream
+ # https://github.com/nlohmann/json/issues/2189
+ #
+ # cmake_fetch_content_configure, cmake_fetch_content2_configure:
+ # Needs network (bug #865027, bug #865105)
+ local myctestargs=(
+ -E "(git_required|cmake_fetch_content_configure|cmake_fetch_content2_configure|cmake_fetch_content_build|cmake_fetch_content2_build)"
+ )
+
+ cmake_src_test
+}