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