MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / parse_number

Method parse_number

lite/load_and_run/src/helpers/json_loader.cpp:206–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206std::unique_ptr<JsonLoader::Value> JsonLoader::parse_number() {
207 const char* p = m_buf;
208
209 auto loop_digit = [this](const char*& p) {
210 if (not std::isdigit(*p)) {
211 m_state = State::BAD_DIGIT;
212 return;
213 }
214 while (std::isdigit(*p)) {
215 p++;
216 }
217 return;
218 };
219
220 if ('-' == *p)
221 p++;
222 if ('0' == *p)
223 p++;
224 else {
225 loop_digit(std::ref(p));
226 }
227 if ('.' == *p) {
228 p++;
229 loop_digit(std::ref(p));
230 }
231
232 if ('e' == *p || 'E' == *p) {
233 p++;
234 if ('+' == *p || '-' == *p)
235 p++;
236 loop_digit(std::ref(p));
237 }
238 std::unique_ptr<JsonLoader::NumberValue> pNum =
239 std::make_unique<JsonLoader::NumberValue>();
240 pNum->m_value = strtod(m_buf, nullptr);
241
242 m_buf = p;
243
244 std::unique_ptr<JsonLoader::Value> ret = std::move(pNum);
245 return ret;
246}
247
248std::unique_ptr<JsonLoader::Value> JsonLoader::parse_value() {
249 switch (*m_buf) {

Callers

nothing calls this directly

Calls 1

refFunction · 0.50

Tested by

no test coverage detected