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

Function GetValuePtrByPath

library/cpp/json/ordered_maps/json_value_ordered.cpp:894–931  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

892
893 template <bool Create, class TJsonPtr>
894 TJsonPtr GetValuePtrByPath(TJsonPtr currentJson, TStringBuf path, char delimiter) noexcept(!Create) {
895 static_assert(
896 !(Create && std::is_const<std::remove_pointer_t<TJsonPtr>>::value),
897 "TJsonPtr must be a `TJsonValue*` if `Create` is true");
898 constexpr std::integral_constant<bool, Create> create_tag{};
899
900
901 while (!path.empty()) {
902 i64 index = 0;
903 const TStringBuf step = path.NextTok(delimiter);
904 if (step.size() > 2 && *step.begin() == '[' && step.back() == ']' && TryFromString(step.substr(1, step.size() - 2), index)) {
905 if (index < 0) {
906 if constexpr (Create) {
907 currentJson->SetType(JSON_ARRAY);
908 TJsonArray::TArray& dst = currentJson->GetArraySafe();
909 while (i64(dst.size()) < -index) {
910 dst.push_front({JSON_NULL});
911 }
912 }
913 index = i64(currentJson->GetArray().size()) - (-index);
914 }
915 if (index < 0) {
916 return nullptr;
917 }
918 currentJson = CreateOrNullptr(currentJson, index, create_tag);
919 } else if (Create && step == "[]") {
920 if constexpr (Create) {
921 currentJson = &currentJson->AppendValue({});
922 }
923 } else {
924 currentJson = CreateOrNullptr(currentJson, step, create_tag);
925 }
926 if (!currentJson) {
927 return nullptr;
928 }
929 }
930 return currentJson;
931 }
932 } // anonymous namespace
933
934 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