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

Function GetValuePtrByPath

library/cpp/json/writer/json_value.cpp:819–855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

817
818 template <bool Create, class TJsonPtr>
819 TJsonPtr GetValuePtrByPath(TJsonPtr currentJson, TStringBuf path, char delimiter) noexcept(!Create) {
820 static_assert(
821 !(Create && std::is_const<std::remove_pointer_t<TJsonPtr>>::value),
822 "TJsonPtr must be a `TJsonValue*` if `Create` is true");
823 constexpr std::integral_constant<bool, Create> create_tag{};
824
825 while (!path.empty()) {
826 i64 index = 0;
827 const TStringBuf step = path.NextTok(delimiter);
828 if (step.size() > 2 && *step.begin() == '[' && step.back() == ']' && TryFromString(step.substr(1, step.size() - 2), index)) {
829 if (index < 0) {
830 if constexpr (Create) {
831 currentJson->SetType(JSON_ARRAY);
832 TJsonArray::TArray& dst = currentJson->GetArraySafe();
833 while (i64(dst.size()) < -index) {
834 dst.push_front({JSON_NULL});
835 }
836 }
837 index = i64(currentJson->GetArray().size()) - (-index);
838 }
839 if (index < 0) {
840 return nullptr;
841 }
842 currentJson = CreateOrNullptr(currentJson, index, create_tag);
843 } else if (Create && step == "[]") {
844 if constexpr (Create) {
845 currentJson = &currentJson->AppendValue({});
846 }
847 } else {
848 currentJson = CreateOrNullptr(currentJson, step, create_tag);
849 }
850 if (!currentJson) {
851 return nullptr;
852 }
853 }
854 return currentJson;
855 }
856 } // anonymous namespace
857
858 bool TJsonValue::GetValueByPath(const TStringBuf path, TJsonValue& result, char delimiter) const {

Callers

nothing calls this directly

Calls 12

TryFromStringFunction · 0.85
AppendValueMethod · 0.80
CreateOrNullptrFunction · 0.70
emptyMethod · 0.45
NextTokMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
backMethod · 0.45
substrMethod · 0.45
SetTypeMethod · 0.45
push_frontMethod · 0.45
GetArrayMethod · 0.45

Tested by

no test coverage detected