MCPcopy Create free account
hub / github.com/couchbase/fleece / writeDict

Method writeDict

Fleece/Support/JSONEncoder.cc:91–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90
91 void JSONEncoder::writeDict(const Dict *dict) {
92 beginDictionary();
93 if (_canonical) {
94 // In canonical mode, ensure the keys are written in sorted order:
95 struct kv {
96 slice key;
97 const Value *value;
98 bool operator< (const kv &other) const {return key < other.key;}
99 };
100 smallVector<kv, 4> items;
101 items.reserve(dict->count());
102 for (auto iter = dict->begin(); iter; ++iter)
103 items.push_back({iter.keyString(), iter.value()});
104 std::sort(items.begin(), items.end());
105 for (auto &item : items) {
106 writeKey(item.key);
107 writeValue(item.value);
108 }
109 } else {
110 for (auto iter = dict->begin(); iter; ++iter) {
111 slice keyStr = iter.keyString();
112 if (keyStr) {
113 writeKey(keyStr);
114 } else {
115 // non-string keys are possible...
116 comma();
117 _first = true;
118 writeValue(iter.key());
119 _out << ':';
120 _first = true;
121 }
122 writeValue(iter.value());
123 }
124 }
125 endDictionary();
126 }
127
128
129 void JSONEncoder::writeValue(const Value *v) {

Callers

nothing calls this directly

Calls 6

countMethod · 0.45
beginMethod · 0.45
keyStringMethod · 0.45
valueMethod · 0.45
endMethod · 0.45
keyMethod · 0.45

Tested by

no test coverage detected