1c5f01b2fSopenharmony_ci//     __ _____ _____ _____
2c5f01b2fSopenharmony_ci//  __|  |   __|     |   | |  JSON for Modern C++
3c5f01b2fSopenharmony_ci// |  |  |__   |  |  | | | |  version 3.11.2
4c5f01b2fSopenharmony_ci// |_____|_____|_____|_|___|  https://github.com/nlohmann/json
5c5f01b2fSopenharmony_ci//
6c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
7c5f01b2fSopenharmony_ci// SPDX-License-Identifier: MIT
8c5f01b2fSopenharmony_ci
9c5f01b2fSopenharmony_ci#pragma once
10c5f01b2fSopenharmony_ci
11c5f01b2fSopenharmony_ci#include <cstring> // strlen
12c5f01b2fSopenharmony_ci#include <string> // string
13c5f01b2fSopenharmony_ci#include <utility> // forward
14c5f01b2fSopenharmony_ci
15c5f01b2fSopenharmony_ci#include <nlohmann/detail/meta/cpp_future.hpp>
16c5f01b2fSopenharmony_ci#include <nlohmann/detail/meta/detected.hpp>
17c5f01b2fSopenharmony_ci
18c5f01b2fSopenharmony_ciNLOHMANN_JSON_NAMESPACE_BEGIN
19c5f01b2fSopenharmony_cinamespace detail
20c5f01b2fSopenharmony_ci{
21c5f01b2fSopenharmony_ci
22c5f01b2fSopenharmony_ciinline std::size_t concat_length()
23c5f01b2fSopenharmony_ci{
24c5f01b2fSopenharmony_ci    return 0;
25c5f01b2fSopenharmony_ci}
26c5f01b2fSopenharmony_ci
27c5f01b2fSopenharmony_citemplate<typename... Args>
28c5f01b2fSopenharmony_ciinline std::size_t concat_length(const char* cstr, Args&& ... rest);
29c5f01b2fSopenharmony_ci
30c5f01b2fSopenharmony_citemplate<typename StringType, typename... Args>
31c5f01b2fSopenharmony_ciinline std::size_t concat_length(const StringType& str, Args&& ... rest);
32c5f01b2fSopenharmony_ci
33c5f01b2fSopenharmony_citemplate<typename... Args>
34c5f01b2fSopenharmony_ciinline std::size_t concat_length(const char /*c*/, Args&& ... rest)
35c5f01b2fSopenharmony_ci{
36c5f01b2fSopenharmony_ci    return 1 + concat_length(std::forward<Args>(rest)...);
37c5f01b2fSopenharmony_ci}
38c5f01b2fSopenharmony_ci
39c5f01b2fSopenharmony_citemplate<typename... Args>
40c5f01b2fSopenharmony_ciinline std::size_t concat_length(const char* cstr, Args&& ... rest)
41c5f01b2fSopenharmony_ci{
42c5f01b2fSopenharmony_ci    // cppcheck-suppress ignoredReturnValue
43c5f01b2fSopenharmony_ci    return ::strlen(cstr) + concat_length(std::forward<Args>(rest)...);
44c5f01b2fSopenharmony_ci}
45c5f01b2fSopenharmony_ci
46c5f01b2fSopenharmony_citemplate<typename StringType, typename... Args>
47c5f01b2fSopenharmony_ciinline std::size_t concat_length(const StringType& str, Args&& ... rest)
48c5f01b2fSopenharmony_ci{
49c5f01b2fSopenharmony_ci    return str.size() + concat_length(std::forward<Args>(rest)...);
50c5f01b2fSopenharmony_ci}
51c5f01b2fSopenharmony_ci
52c5f01b2fSopenharmony_citemplate<typename OutStringType>
53c5f01b2fSopenharmony_ciinline void concat_into(OutStringType& /*out*/)
54c5f01b2fSopenharmony_ci{}
55c5f01b2fSopenharmony_ci
56c5f01b2fSopenharmony_citemplate<typename StringType, typename Arg>
57c5f01b2fSopenharmony_ciusing string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg && > ()));
58c5f01b2fSopenharmony_ci
59c5f01b2fSopenharmony_citemplate<typename StringType, typename Arg>
60c5f01b2fSopenharmony_ciusing detect_string_can_append = is_detected<string_can_append, StringType, Arg>;
61c5f01b2fSopenharmony_ci
62c5f01b2fSopenharmony_citemplate<typename StringType, typename Arg>
63c5f01b2fSopenharmony_ciusing string_can_append_op = decltype(std::declval<StringType&>() += std::declval < Arg && > ());
64c5f01b2fSopenharmony_ci
65c5f01b2fSopenharmony_citemplate<typename StringType, typename Arg>
66c5f01b2fSopenharmony_ciusing detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;
67c5f01b2fSopenharmony_ci
68c5f01b2fSopenharmony_citemplate<typename StringType, typename Arg>
69c5f01b2fSopenharmony_ciusing string_can_append_iter = decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
70c5f01b2fSopenharmony_ci
71c5f01b2fSopenharmony_citemplate<typename StringType, typename Arg>
72c5f01b2fSopenharmony_ciusing detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;
73c5f01b2fSopenharmony_ci
74c5f01b2fSopenharmony_citemplate<typename StringType, typename Arg>
75c5f01b2fSopenharmony_ciusing string_can_append_data = decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
76c5f01b2fSopenharmony_ci
77c5f01b2fSopenharmony_citemplate<typename StringType, typename Arg>
78c5f01b2fSopenharmony_ciusing detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
79c5f01b2fSopenharmony_ci
80c5f01b2fSopenharmony_citemplate < typename OutStringType, typename Arg, typename... Args,
81c5f01b2fSopenharmony_ci           enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
82c5f01b2fSopenharmony_ci                         && detect_string_can_append_op<OutStringType, Arg>::value, int > = 0 >
83c5f01b2fSopenharmony_ciinline void concat_into(OutStringType& out, Arg && arg, Args && ... rest);
84c5f01b2fSopenharmony_ci
85c5f01b2fSopenharmony_citemplate < typename OutStringType, typename Arg, typename... Args,
86c5f01b2fSopenharmony_ci           enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
87c5f01b2fSopenharmony_ci                         && !detect_string_can_append_op<OutStringType, Arg>::value
88c5f01b2fSopenharmony_ci                         && detect_string_can_append_iter<OutStringType, Arg>::value, int > = 0 >
89c5f01b2fSopenharmony_ciinline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest);
90c5f01b2fSopenharmony_ci
91c5f01b2fSopenharmony_citemplate < typename OutStringType, typename Arg, typename... Args,
92c5f01b2fSopenharmony_ci           enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
93c5f01b2fSopenharmony_ci                         && !detect_string_can_append_op<OutStringType, Arg>::value
94c5f01b2fSopenharmony_ci                         && !detect_string_can_append_iter<OutStringType, Arg>::value
95c5f01b2fSopenharmony_ci                         && detect_string_can_append_data<OutStringType, Arg>::value, int > = 0 >
96c5f01b2fSopenharmony_ciinline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest);
97c5f01b2fSopenharmony_ci
98c5f01b2fSopenharmony_citemplate<typename OutStringType, typename Arg, typename... Args,
99c5f01b2fSopenharmony_ci         enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0>
100c5f01b2fSopenharmony_ciinline void concat_into(OutStringType& out, Arg && arg, Args && ... rest)
101c5f01b2fSopenharmony_ci{
102c5f01b2fSopenharmony_ci    out.append(std::forward<Arg>(arg));
103c5f01b2fSopenharmony_ci    concat_into(out, std::forward<Args>(rest)...);
104c5f01b2fSopenharmony_ci}
105c5f01b2fSopenharmony_ci
106c5f01b2fSopenharmony_citemplate < typename OutStringType, typename Arg, typename... Args,
107c5f01b2fSopenharmony_ci           enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
108c5f01b2fSopenharmony_ci                         && detect_string_can_append_op<OutStringType, Arg>::value, int > >
109c5f01b2fSopenharmony_ciinline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)
110c5f01b2fSopenharmony_ci{
111c5f01b2fSopenharmony_ci    out += std::forward<Arg>(arg);
112c5f01b2fSopenharmony_ci    concat_into(out, std::forward<Args>(rest)...);
113c5f01b2fSopenharmony_ci}
114c5f01b2fSopenharmony_ci
115c5f01b2fSopenharmony_citemplate < typename OutStringType, typename Arg, typename... Args,
116c5f01b2fSopenharmony_ci           enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
117c5f01b2fSopenharmony_ci                         && !detect_string_can_append_op<OutStringType, Arg>::value
118c5f01b2fSopenharmony_ci                         && detect_string_can_append_iter<OutStringType, Arg>::value, int > >
119c5f01b2fSopenharmony_ciinline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest)
120c5f01b2fSopenharmony_ci{
121c5f01b2fSopenharmony_ci    out.append(arg.begin(), arg.end());
122c5f01b2fSopenharmony_ci    concat_into(out, std::forward<Args>(rest)...);
123c5f01b2fSopenharmony_ci}
124c5f01b2fSopenharmony_ci
125c5f01b2fSopenharmony_citemplate < typename OutStringType, typename Arg, typename... Args,
126c5f01b2fSopenharmony_ci           enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
127c5f01b2fSopenharmony_ci                         && !detect_string_can_append_op<OutStringType, Arg>::value
128c5f01b2fSopenharmony_ci                         && !detect_string_can_append_iter<OutStringType, Arg>::value
129c5f01b2fSopenharmony_ci                         && detect_string_can_append_data<OutStringType, Arg>::value, int > >
130c5f01b2fSopenharmony_ciinline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest)
131c5f01b2fSopenharmony_ci{
132c5f01b2fSopenharmony_ci    out.append(arg.data(), arg.size());
133c5f01b2fSopenharmony_ci    concat_into(out, std::forward<Args>(rest)...);
134c5f01b2fSopenharmony_ci}
135c5f01b2fSopenharmony_ci
136c5f01b2fSopenharmony_citemplate<typename OutStringType = std::string, typename... Args>
137c5f01b2fSopenharmony_ciinline OutStringType concat(Args && ... args)
138c5f01b2fSopenharmony_ci{
139c5f01b2fSopenharmony_ci    OutStringType str;
140c5f01b2fSopenharmony_ci    str.reserve(concat_length(std::forward<Args>(args)...));
141c5f01b2fSopenharmony_ci    concat_into(str, std::forward<Args>(args)...);
142c5f01b2fSopenharmony_ci    return str;
143c5f01b2fSopenharmony_ci}
144c5f01b2fSopenharmony_ci
145c5f01b2fSopenharmony_ci}  // namespace detail
146c5f01b2fSopenharmony_ciNLOHMANN_JSON_NAMESPACE_END
147