Commit 8cb89529bd52ab40f5cf93024f6fbf6c0ef52f56

Authored by m-holger
1 parent 75e74679

Use early returns in JSONHandler::handle

Showing 1 changed file with 13 additions and 15 deletions
libqpdf/JSONHandler.cc
@@ -117,24 +117,24 @@ JSONHandler::handle(std::string const& path, JSON j) @@ -117,24 +117,24 @@ JSONHandler::handle(std::string const& path, JSON j)
117 m->h.any_handler(path, j); 117 m->h.any_handler(path, j);
118 return; 118 return;
119 } 119 }
120 - bool handled = false; 120 +
121 bool bvalue = false; 121 bool bvalue = false;
122 std::string s_value; 122 std::string s_value;
123 if (m->h.null_handler && j.isNull()) { 123 if (m->h.null_handler && j.isNull()) {
124 m->h.null_handler(path); 124 m->h.null_handler(path);
125 - handled = true; 125 + return;
126 } 126 }
127 if (m->h.string_handler && j.getString(s_value)) { 127 if (m->h.string_handler && j.getString(s_value)) {
128 m->h.string_handler(path, s_value); 128 m->h.string_handler(path, s_value);
129 - handled = true; 129 + return;
130 } 130 }
131 if (m->h.number_handler && j.getNumber(s_value)) { 131 if (m->h.number_handler && j.getNumber(s_value)) {
132 m->h.number_handler(path, s_value); 132 m->h.number_handler(path, s_value);
133 - handled = true; 133 + return;
134 } 134 }
135 if (m->h.bool_handler && j.getBool(bvalue)) { 135 if (m->h.bool_handler && j.getBool(bvalue)) {
136 m->h.bool_handler(path, bvalue); 136 m->h.bool_handler(path, bvalue);
137 - handled = true; 137 + return;
138 } 138 }
139 if (m->h.dict_start_handler && j.isDictionary()) { 139 if (m->h.dict_start_handler && j.isDictionary()) {
140 m->h.dict_start_handler(path, j); 140 m->h.dict_start_handler(path, j);
@@ -156,7 +156,7 @@ JSONHandler::handle(std::string const& path, JSON j) @@ -156,7 +156,7 @@ JSONHandler::handle(std::string const& path, JSON j)
156 } 156 }
157 }); 157 });
158 m->h.dict_end_handler(path); 158 m->h.dict_end_handler(path);
159 - handled = true; 159 + return;
160 } 160 }
161 if (m->h.array_start_handler && j.isArray()) { 161 if (m->h.array_start_handler && j.isArray()) {
162 m->h.array_start_handler(path, j); 162 m->h.array_start_handler(path, j);
@@ -166,15 +166,13 @@ JSONHandler::handle(std::string const& path, JSON j) @@ -166,15 +166,13 @@ JSONHandler::handle(std::string const& path, JSON j)
166 ++i; 166 ++i;
167 }); 167 });
168 m->h.array_end_handler(path); 168 m->h.array_end_handler(path);
169 - handled = true; 169 + return;
170 } 170 }
171 171
172 - if (!handled) {  
173 - // It would be nice to include information about what type the object was and what types  
174 - // were allowed, but we're relying on schema validation to make sure input is properly  
175 - // structured before calling the handlers. It would be different if this code were trying to  
176 - // be part of a general-purpose JSON package.  
177 - QTC::TC("libtests", "JSONHandler unhandled value");  
178 - usage("JSON handler: value at " + path + " is not of expected type");  
179 - } 172 + // It would be nice to include information about what type the object was and what types were
  173 + // allowed, but we're relying on schema validation to make sure input is properly structured
  174 + // before calling the handlers. It would be different if this code were trying to be part of a
  175 + // general-purpose JSON package.
  176 + QTC::TC("libtests", "JSONHandler unhandled value");
  177 + usage("JSON handler: value at " + path + " is not of expected type");
180 } 178 }