Make hb_language_t typesafe
This commit is contained in:
parent
2f2f448af3
commit
3cbdf70e0a
|
@ -51,6 +51,10 @@ hb_tag_from_string (const char *s)
|
||||||
|
|
||||||
/* hb_language_t */
|
/* hb_language_t */
|
||||||
|
|
||||||
|
struct _hb_language_t {
|
||||||
|
const char s[1];
|
||||||
|
};
|
||||||
|
|
||||||
static const char canon_map[256] = {
|
static const char canon_map[256] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
@ -99,7 +103,7 @@ hb_language_from_string (const char *str)
|
||||||
{
|
{
|
||||||
static unsigned int num_langs;
|
static unsigned int num_langs;
|
||||||
static unsigned int num_alloced;
|
static unsigned int num_alloced;
|
||||||
static const char **langs;
|
static hb_language_t *langs;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
|
|
||||||
|
@ -109,31 +113,31 @@ hb_language_from_string (const char *str)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (i = 0; i < num_langs; i++)
|
for (i = 0; i < num_langs; i++)
|
||||||
if (lang_equal (str, langs[i]))
|
if (lang_equal (str, langs[i]->s))
|
||||||
return langs[i];
|
return langs[i];
|
||||||
|
|
||||||
if (unlikely (num_langs == num_alloced)) {
|
if (unlikely (num_langs == num_alloced)) {
|
||||||
unsigned int new_alloced = 2 * (8 + num_alloced);
|
unsigned int new_alloced = 2 * (8 + num_alloced);
|
||||||
const char **new_langs = realloc (langs, new_alloced * sizeof (langs[0]));
|
hb_language_t *new_langs = realloc (langs, new_alloced * sizeof (langs[0]));
|
||||||
if (!new_langs)
|
if (!new_langs)
|
||||||
return NULL;
|
return NULL;
|
||||||
num_alloced = new_alloced;
|
num_alloced = new_alloced;
|
||||||
langs = new_langs;
|
langs = new_langs;
|
||||||
}
|
}
|
||||||
|
|
||||||
langs[i] = strdup (str);
|
langs[i] = (hb_language_t) strdup (str);
|
||||||
for (p = (unsigned char *) langs[i]; *p; p++)
|
for (p = (unsigned char *) langs[i]->s; *p; p++)
|
||||||
*p = canon_map[*p];
|
*p = canon_map[*p];
|
||||||
|
|
||||||
num_langs++;
|
num_langs++;
|
||||||
|
|
||||||
return (hb_language_t) langs[i];
|
return langs[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
hb_language_to_string (hb_language_t language)
|
hb_language_to_string (hb_language_t language)
|
||||||
{
|
{
|
||||||
return (const char *) language;
|
return language->s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ typedef enum _hb_direction_t {
|
||||||
|
|
||||||
/* hb_language_t */
|
/* hb_language_t */
|
||||||
|
|
||||||
typedef const void *hb_language_t;
|
typedef struct _hb_language_t *hb_language_t;
|
||||||
|
|
||||||
hb_language_t
|
hb_language_t
|
||||||
hb_language_from_string (const char *str);
|
hb_language_from_string (const char *str);
|
||||||
|
|
Loading…
Reference in New Issue