MCPcopy Create free account
hub / github.com/catboost/catboost / WriteJsonValue

Method WriteJsonValue

library/cpp/json/writer/json.cpp:382–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380 }
381
382 TValueContext TBuf::WriteJsonValue(const NJson::TJsonValue* v, bool sortKeys, EFloatToStringMode mode, int ndigits) {
383 using namespace NJson;
384 switch (v->GetType()) {
385 default:
386 case JSON_NULL:
387 WriteNull();
388 break;
389 case JSON_BOOLEAN:
390 WriteBool(v->GetBoolean());
391 break;
392 case JSON_DOUBLE:
393 WriteDouble(v->GetDouble(), mode, ndigits);
394 break;
395 case JSON_INTEGER:
396 WriteLongLong(v->GetInteger());
397 break;
398 case JSON_UINTEGER:
399 WriteULongLong(v->GetUInteger());
400 break;
401 case JSON_STRING:
402 WriteString(v->GetString());
403 break;
404 case JSON_ARRAY: {
405 BeginList();
406 const TJsonValue::TArray& arr = v->GetArray();
407 for (const auto& it : arr) {
408 WriteJsonValue(&it, sortKeys, mode, ndigits);
409 }
410 EndList();
411 break;
412 }
413 case JSON_MAP: {
414 BeginObject();
415 const TJsonValue::TMapType& map = v->GetMap();
416 if (sortKeys) {
417 const size_t oldsz = Keys.size();
418 Keys.reserve(map.size() + oldsz);
419 for (const auto& it : map) {
420 Keys.push_back(&(it.first));
421 }
422 Sort(Keys.begin() + oldsz, Keys.end(), LessStrPtr);
423 for (size_t i = oldsz, sz = Keys.size(); i < sz; ++i) {
424 TJsonValue::TMapType::const_iterator kv = map.find(*Keys[i]);
425 WriteKey(kv->first);
426 WriteJsonValue(&kv->second, sortKeys, mode, ndigits);
427 }
428 Keys.resize(oldsz);
429 } else {
430 for (const auto& it : map) {
431 WriteKey(it.first);
432 WriteJsonValue(&it.second, sortKeys, mode, ndigits);
433 }
434 }
435 EndObject();
436 break;
437 }
438 }
439 return TValueContext(*this);

Callers 7

WriteMethod · 0.45
Y_UNIT_TESTFunction · 0.45
Y_UNIT_TESTFunction · 0.45
GetStringRobustMethod · 0.45
TJsonValue>Method · 0.45
ToJsonStrFunction · 0.45
TraceMethod · 0.45

Calls 15

WriteBoolFunction · 0.85
WriteJsonValueFunction · 0.85
TValueContextClass · 0.70
WriteDoubleFunction · 0.50
WriteStringFunction · 0.50
SortFunction · 0.50
GetTypeMethod · 0.45
GetBooleanMethod · 0.45
GetDoubleMethod · 0.45
GetIntegerMethod · 0.45
GetUIntegerMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected