Move hb_codepoint_parse to hb_parse_uint

This commit is contained in:
Ebrahim Byagowi 2019-09-03 14:49:14 +04:30
parent 43372fbb5a
commit a77bb7eb41
6 changed files with 36 additions and 16 deletions

View File

@ -32,6 +32,7 @@
#include "hb.hh"
#include "hb-meta.hh"
#include "hb-null.hh"
#include "hb-number.hh"
/* Encodes three unsigned integers in one 64-bit number. If the inputs have more than 21 bits,
@ -896,17 +897,14 @@ hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *))
static inline hb_bool_t
hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *out)
{
/* Pain because we don't know whether s is nul-terminated. */
char buf[64];
len = hb_min (ARRAY_LENGTH (buf) - 1, len);
strncpy (buf, s, len);
buf[len] = '\0';
unsigned int v;
const char *p = s;
const char *end = p + len;
if (!hb_parse_uint (&p, p + len, &v, base))
return false;
if (end != p && *p) return false;
char *end;
errno = 0;
unsigned long v = strtoul (buf, &end, base);
if (errno) return false;
if (*end) return false;
*out = v;
return true;
}

View File

@ -25,7 +25,6 @@
*/
#include "hb.hh"
#include "hb-number.hh"
#ifndef HB_NO_BUFFER_SERIALIZE

View File

@ -28,7 +28,6 @@
#include "hb.hh"
#include "hb-machinery.hh"
#include "hb-number.hh"
#include <locale.h>
#ifdef HAVE_XLOCALE_H

View File

@ -25,7 +25,6 @@
#include "hb.hh"
#include "hb-machinery.hh"
#include "hb-number.hh"
#include <locale.h>
#ifdef HAVE_XLOCALE_H
@ -46,14 +45,35 @@ hb_parse_int (const char **pp, const char *end, int *pv)
errno = 0;
v = strtol (p, &pend, 10);
if (errno || p == pend)
return false;
if (unlikely (errno || p == pend)) return false;
*pv = v;
*pp += pend - p;
return true;
}
bool
hb_parse_uint (const char **pp, const char *end, unsigned int *pv, int base)
{
char buf[32];
unsigned int len = hb_min (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - *pp));
strncpy (buf, *pp, len);
buf[len] = '\0';
char *p = buf;
char *pend = p;
int v;
errno = 0;
v = strtol (p, &pend, 10);
if (unlikely (errno || p == pend)) return false;
*pv = v;
*pp += pend - p;
return true;
}
#if defined (HAVE_NEWLOCALE) && defined (HAVE_STRTOD_L)
#define USE_XLOCALE 1
#define HB_LOCALE_T locale_t

View File

@ -29,6 +29,9 @@
HB_INTERNAL bool
hb_parse_int (const char **pp, const char *end, int *pv);
HB_INTERNAL bool
hb_parse_uint (const char **pp, const char *end, unsigned int *pv, int base=10);
HB_INTERNAL bool
hb_parse_float (const char **pp, const char *end, float *pv);

View File

@ -594,9 +594,10 @@ struct BEInt<Type, 4>
* them directly.*/
#include "hb-meta.hh"
#include "hb-mutex.hh"
#include "hb-number.hh"
#include "hb-atomic.hh" // Requires: hb-meta
#include "hb-null.hh" // Requires: hb-meta
#include "hb-algs.hh" // Requires: hb-meta hb-null
#include "hb-algs.hh" // Requires: hb-meta hb-null hb-number
#include "hb-iter.hh" // Requires: hb-algs hb-meta
#include "hb-debug.hh" // Requires: hb-algs hb-atomic
#include "hb-array.hh" // Requires: hb-algs hb-iter hb-null