| 1134 | |
| 1135 | template <typename StringType> |
| 1136 | NodeType* atPointerImpl(const GenericJsonPointer<StringType>& pointer) const { |
| 1137 | const NodeType* re = downCast(); |
| 1138 | for (auto& node : pointer) { |
| 1139 | if (node.IsStr()) { |
| 1140 | if (re->IsObject()) { |
| 1141 | auto m = re->FindMember(node.GetStr()); |
| 1142 | if (m != re->MemberEnd()) { |
| 1143 | re = &(m->value); |
| 1144 | continue; |
| 1145 | } |
| 1146 | } |
| 1147 | return nullptr; |
| 1148 | } else { // Json Pointer node is number |
| 1149 | if (re->IsArray()) { |
| 1150 | int idx = node.GetNum(); |
| 1151 | if (idx >= 0 && idx < static_cast<int>(re->Size())) { |
| 1152 | re = &(re->operator[]((size_t)idx)); |
| 1153 | continue; |
| 1154 | } |
| 1155 | } |
| 1156 | return nullptr; |
| 1157 | } |
| 1158 | } |
| 1159 | return const_cast<NodeType*>(re); |
| 1160 | } |
| 1161 | }; |
| 1162 | |
| 1163 | } // namespace sonic_json |