MCPcopy Create free account
hub / github.com/GJDuck/e9patch / entryToInt

Function entryToInt

src/e9tool/e9csv.cpp:61–85  ·  view source on GitHub ↗

* Convert an entry into an integer. */

Source from the content-addressed store, hash-verified

59 * Convert an entry into an integer.
60 */
61static bool entryToInt(const char *entry, intptr_t *val)
62{
63 const char *s = entry;
64 while (isspace(*s))
65 s++;
66 bool neg = false;
67 if (s[0] == '+')
68 s++;
69 else if (s[0] == '-')
70 {
71 neg = true;
72 s++;
73 }
74 int base = (s[0] == '0' && s[1] == 'x'? 16: 10);
75 char *end = nullptr;
76 intptr_t x = (intptr_t)strtoull(s, &end, base);
77 if (end == nullptr || end == s)
78 return false;
79 while (isspace(*end))
80 end++;
81 if (*end != '\0')
82 return false;
83 *val = (neg? -x: x);
84 return true;
85}
86
87/*
88 * Checked getc.

Callers 1

parseEntryFunction · 0.85

Calls 2

isspaceFunction · 0.85
strtoullFunction · 0.85

Tested by

no test coverage detected