| 44 | } |
| 45 | |
| 46 | Result<std::string> GetString(const char* key) { |
| 47 | document_.rewind(); |
| 48 | |
| 49 | auto object = document_.get_object(); |
| 50 | |
| 51 | auto field = object.find_field(key); |
| 52 | |
| 53 | if (field.error() == simdjson::NO_SUCH_FIELD) { |
| 54 | return Status::KeyError("Key '", key, "' does not exist"); |
| 55 | } |
| 56 | if (field.error()) { |
| 57 | return Status::Invalid("Error accessing key '", key, |
| 58 | "': ", simdjson::error_message(field.error())); |
| 59 | } |
| 60 | |
| 61 | auto str_result = field.get_string(); |
| 62 | if (str_result.error() == simdjson::INCORRECT_TYPE) { |
| 63 | return Status::TypeError("Key '", key, "' is not a string"); |
| 64 | } |
| 65 | if (str_result.error()) { |
| 66 | return Status::Invalid("Error getting string for key '", key, |
| 67 | "': ", simdjson::error_message(str_result.error())); |
| 68 | } |
| 69 | |
| 70 | std::string_view str; |
| 71 | if (auto error = std::move(str_result).get(str)) { |
| 72 | return Status::Invalid("Error getting string for key '", key, |
| 73 | "': ", simdjson::error_message(error)); |
| 74 | } |
| 75 | return std::string(str); |
| 76 | } |
| 77 | |
| 78 | Result<std::unordered_map<std::string, std::string>> GetStringMap() { |
| 79 | std::unordered_map<std::string, std::string> map; |
nothing calls this directly
no test coverage detected