[number] Minor tweak on parser related codes

This commit is contained in:
Ebrahim Byagowi 2019-09-03 15:23:40 +04:30
parent e2cecf1f34
commit b5e6805ee7
4 changed files with 13 additions and 19 deletions

View File

@ -900,10 +900,10 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o
unsigned int v;
const char *p = s;
const char *end = p + len;
if (!hb_parse_uint (&p, p + len, &v, base))
return false;
if (unlikely (!hb_parse_uint (&p, end, &v, base))) return false;
if (end != p && *p) return false;
/* Pain because we don't know whether s is nul-terminated. */
if (unlikely (p != end && *p)) return false;
*out = v;
return true;

View File

@ -384,12 +384,10 @@ parse_int (const char *pp, const char *end, int32_t *pv)
{
int v;
const char *p = pp;
if (!hb_parse_int (&p, end, &v))
return false;
if (unlikely (!hb_parse_int (&p, end, &v))) return false;
/* Check if parser consumed all of the buffer */
if (p != end)
return false;
if (unlikely (p != end)) return false;
*pv = v;
return true;

View File

@ -721,11 +721,10 @@ parse_char (const char **pp, const char *end, char c)
static bool
parse_uint (const char **pp, const char *end, unsigned int *pv)
{
/* Intentionally use strtol inside instead of strtoul, such that
* -1 turns into "big number"... */
/* Intentionally use hb_parse_int inside instead of hb_parse_uint,
* such that -1 turns into "big number"... */
int v;
if (!hb_parse_int (pp, end, &v))
return false;
if (unlikely (!hb_parse_int (pp, end, &v))) return false;
*pv = v;
return true;
@ -734,11 +733,10 @@ parse_uint (const char **pp, const char *end, unsigned int *pv)
static bool
parse_uint32 (const char **pp, const char *end, uint32_t *pv)
{
/* Intentionally use strtol inside instead of strtoul, such that
* -1 turns into "big number"... */
/* Intentionally use hb_parse_int inside instead of hb_parse_uint,
* such that -1 turns into "big number"... */
int v;
if (!hb_parse_int (pp, end, &v))
return false;
if (unlikely (!hb_parse_int (pp, end, &v))) return false;
*pv = v;
return true;

View File

@ -32,7 +32,7 @@
#endif
template<typename T, typename Func>
static inline bool
static bool
_parse_number (const char **pp, const char *end, T *pv, Func f)
{
char buf[32];
@ -42,13 +42,11 @@ _parse_number (const char **pp, const char *end, T *pv, Func f)
char *p = buf;
char *pend = p;
T v;
errno = 0;
v = f (p, &pend);
*pv = f (p, &pend);
if (unlikely (errno || p == pend)) return false;
*pv = v;
*pp += pend - p;
return true;
}