[number] Minor tweak on parser related codes
This commit is contained in:
parent
e2cecf1f34
commit
b5e6805ee7
|
@ -900,10 +900,10 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o
|
||||||
unsigned int v;
|
unsigned int v;
|
||||||
const char *p = s;
|
const char *p = s;
|
||||||
const char *end = p + len;
|
const char *end = p + len;
|
||||||
if (!hb_parse_uint (&p, p + len, &v, base))
|
if (unlikely (!hb_parse_uint (&p, end, &v, base))) return false;
|
||||||
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;
|
*out = v;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -384,12 +384,10 @@ parse_int (const char *pp, const char *end, int32_t *pv)
|
||||||
{
|
{
|
||||||
int v;
|
int v;
|
||||||
const char *p = pp;
|
const char *p = pp;
|
||||||
if (!hb_parse_int (&p, end, &v))
|
if (unlikely (!hb_parse_int (&p, end, &v))) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
/* Check if parser consumed all of the buffer */
|
/* Check if parser consumed all of the buffer */
|
||||||
if (p != end)
|
if (unlikely (p != end)) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
*pv = v;
|
*pv = v;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -721,11 +721,10 @@ parse_char (const char **pp, const char *end, char c)
|
||||||
static bool
|
static bool
|
||||||
parse_uint (const char **pp, const char *end, unsigned int *pv)
|
parse_uint (const char **pp, const char *end, unsigned int *pv)
|
||||||
{
|
{
|
||||||
/* Intentionally use strtol inside instead of strtoul, such that
|
/* Intentionally use hb_parse_int inside instead of hb_parse_uint,
|
||||||
* -1 turns into "big number"... */
|
* such that -1 turns into "big number"... */
|
||||||
int v;
|
int v;
|
||||||
if (!hb_parse_int (pp, end, &v))
|
if (unlikely (!hb_parse_int (pp, end, &v))) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
*pv = v;
|
*pv = v;
|
||||||
return true;
|
return true;
|
||||||
|
@ -734,11 +733,10 @@ parse_uint (const char **pp, const char *end, unsigned int *pv)
|
||||||
static bool
|
static bool
|
||||||
parse_uint32 (const char **pp, const char *end, uint32_t *pv)
|
parse_uint32 (const char **pp, const char *end, uint32_t *pv)
|
||||||
{
|
{
|
||||||
/* Intentionally use strtol inside instead of strtoul, such that
|
/* Intentionally use hb_parse_int inside instead of hb_parse_uint,
|
||||||
* -1 turns into "big number"... */
|
* such that -1 turns into "big number"... */
|
||||||
int v;
|
int v;
|
||||||
if (!hb_parse_int (pp, end, &v))
|
if (unlikely (!hb_parse_int (pp, end, &v))) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
*pv = v;
|
*pv = v;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename T, typename Func>
|
template<typename T, typename Func>
|
||||||
static inline bool
|
static bool
|
||||||
_parse_number (const char **pp, const char *end, T *pv, Func f)
|
_parse_number (const char **pp, const char *end, T *pv, Func f)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
@ -42,13 +42,11 @@ _parse_number (const char **pp, const char *end, T *pv, Func f)
|
||||||
|
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
char *pend = p;
|
char *pend = p;
|
||||||
T v;
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
v = f (p, &pend);
|
*pv = f (p, &pend);
|
||||||
if (unlikely (errno || p == pend)) return false;
|
if (unlikely (errno || p == pend)) return false;
|
||||||
|
|
||||||
*pv = v;
|
|
||||||
*pp += pend - p;
|
*pp += pend - p;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue