| 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 = ¤tJson->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 { |
nothing calls this directly
no test coverage detected