]>
git.saurik.com Git - apple/dyld.git/blob - dyld3/JSONWriter.h
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
36 std::map
<std::string
, Node
> map
;
37 std::vector
<Node
> array
;
40 static inline std::string
hex(uint64_t value
) {
42 sprintf(buff
, "0x%llX", value
);
46 static inline std::string
hex4(uint64_t value
) {
48 sprintf(buff
, "0x%04llX", value
);
52 static inline std::string
hex8(uint64_t value
) {
54 sprintf(buff
, "0x%08llX", value
);
58 static inline std::string
decimal(uint64_t value
) {
60 sprintf(buff
, "%llu", value
);
64 static inline void indentBy(uint32_t spaces
, FILE* out
) {
65 for (int i
=0; i
< spaces
; ++i
) {
70 static inline void printJSON(const Node
& node
, uint32_t indent
, FILE* out
)
72 if ( !node
.map
.empty() ) {
74 bool needComma
= false;
75 for (const auto& entry
: node
.map
) {
79 indentBy(indent
+2, out
);
80 fprintf(out
, "\"%s\": ", entry
.first
.c_str());
81 printJSON(entry
.second
, indent
+2, out
);
85 indentBy(indent
, out
);
88 else if ( !node
.array
.empty() ) {
90 bool needComma
= false;
91 for (const auto& entry
: node
.array
) {
95 indentBy(indent
+2, out
);
96 printJSON(entry
, indent
+2, out
);
100 indentBy(indent
, out
);
104 fprintf(out
, "\"%s\"", node
.value
.c_str());