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

Method WriteJsonValue

library/cpp/json/ordered_maps/json_ordered.cpp:389–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

GetStringRobustMethod · 0.45
TJsonValue>Method · 0.45
WriteMethod · 0.45
Y_UNIT_TESTFunction · 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