Make HB_DIRECTION_INVALID be zero

This changes all the HB_DIRECTION_* enum member values, but is
nicer, in preparation for making hb_segment_properties_t public.
This commit is contained in:
Behdad Esfahbod 2012-04-12 17:38:23 -04:00
parent d01402da9c
commit 4bf90f6483
3 changed files with 21 additions and 15 deletions

View File

@ -80,7 +80,7 @@ hb_direction_from_string (const char *str, int len)
char c = TOLOWER (str[0]);
for (unsigned int i = 0; i < ARRAY_LENGTH (direction_strings); i++)
if (c == direction_strings[i][0])
return (hb_direction_t) i;
return (hb_direction_t) (HB_DIRECTION_LTR + i);
return HB_DIRECTION_INVALID;
}
@ -88,8 +88,9 @@ hb_direction_from_string (const char *str, int len)
const char *
hb_direction_to_string (hb_direction_t direction)
{
if (likely ((unsigned int) direction < ARRAY_LENGTH (direction_strings)))
return direction_strings[direction];
if (likely ((unsigned int) (direction - HB_DIRECTION_LTR)
< ARRAY_LENGTH (direction_strings)))
return direction_strings[direction - HB_DIRECTION_LTR];
return "invalid";
}

View File

@ -93,31 +93,31 @@ typedef uint32_t hb_tag_t;
#define HB_TAG_NONE HB_TAG(0,0,0,0)
/* len=-1 means s is NUL-terminated */
hb_tag_t hb_tag_from_string (const char *s, int len);
/* len=-1 means str is NUL-terminated */
hb_tag_t hb_tag_from_string (const char *str, int len);
/* hb_direction_t */
typedef enum _hb_direction_t {
HB_DIRECTION_INVALID = -1,
HB_DIRECTION_LTR = 0,
HB_DIRECTION_INVALID = 0,
HB_DIRECTION_LTR = 4,
HB_DIRECTION_RTL,
HB_DIRECTION_TTB,
HB_DIRECTION_BTT
} hb_direction_t;
/* len=-1 means s is NUL-terminated */
/* len=-1 means str is NUL-terminated */
hb_direction_t
hb_direction_from_string (const char *str, int len);
const char *
hb_direction_to_string (hb_direction_t direction);
#define HB_DIRECTION_IS_HORIZONTAL(dir) ((((unsigned int) (dir)) & ~1U) == 0)
#define HB_DIRECTION_IS_VERTICAL(dir) ((((unsigned int) (dir)) & ~1U) == 2)
#define HB_DIRECTION_IS_FORWARD(dir) ((((unsigned int) (dir)) & ~2U) == 0)
#define HB_DIRECTION_IS_BACKWARD(dir) ((((unsigned int) (dir)) & ~2U) == 1)
#define HB_DIRECTION_IS_HORIZONTAL(dir) ((((unsigned int) (dir)) & ~1U) == 4)
#define HB_DIRECTION_IS_VERTICAL(dir) ((((unsigned int) (dir)) & ~1U) == 6)
#define HB_DIRECTION_IS_FORWARD(dir) ((((unsigned int) (dir)) & ~2U) == 4)
#define HB_DIRECTION_IS_BACKWARD(dir) ((((unsigned int) (dir)) & ~2U) == 5)
#define HB_DIRECTION_REVERSE(dir) ((hb_direction_t) (((unsigned int) (dir)) ^ 1))
@ -125,7 +125,7 @@ hb_direction_to_string (hb_direction_t direction);
typedef struct _hb_language_t *hb_language_t;
/* len=-1 means s is NUL-terminated */
/* len=-1 means str is NUL-terminated */
hb_language_t
hb_language_from_string (const char *str, int len);

View File

@ -51,33 +51,38 @@ test_types_int (void)
static void
test_types_direction (void)
{
g_assert_cmpint ((signed) HB_DIRECTION_INVALID, ==, -1);
g_assert_cmpint (HB_DIRECTION_LTR, ==, 0);
g_assert_cmpint ((signed) HB_DIRECTION_INVALID, ==, 0);
g_assert_cmpint (HB_DIRECTION_LTR, !=, 0);
g_assert (HB_DIRECTION_IS_HORIZONTAL (HB_DIRECTION_LTR));
g_assert (HB_DIRECTION_IS_HORIZONTAL (HB_DIRECTION_RTL));
g_assert (!HB_DIRECTION_IS_HORIZONTAL (HB_DIRECTION_TTB));
g_assert (!HB_DIRECTION_IS_HORIZONTAL (HB_DIRECTION_BTT));
g_assert (!HB_DIRECTION_IS_HORIZONTAL (HB_DIRECTION_INVALID));
g_assert (!HB_DIRECTION_IS_VERTICAL (HB_DIRECTION_LTR));
g_assert (!HB_DIRECTION_IS_VERTICAL (HB_DIRECTION_RTL));
g_assert (HB_DIRECTION_IS_VERTICAL (HB_DIRECTION_TTB));
g_assert (HB_DIRECTION_IS_VERTICAL (HB_DIRECTION_BTT));
g_assert (!HB_DIRECTION_IS_VERTICAL (HB_DIRECTION_INVALID));
g_assert (HB_DIRECTION_IS_FORWARD (HB_DIRECTION_LTR));
g_assert (HB_DIRECTION_IS_FORWARD (HB_DIRECTION_TTB));
g_assert (!HB_DIRECTION_IS_FORWARD (HB_DIRECTION_RTL));
g_assert (!HB_DIRECTION_IS_FORWARD (HB_DIRECTION_BTT));
g_assert (!HB_DIRECTION_IS_FORWARD (HB_DIRECTION_INVALID));
g_assert (!HB_DIRECTION_IS_BACKWARD (HB_DIRECTION_LTR));
g_assert (!HB_DIRECTION_IS_BACKWARD (HB_DIRECTION_TTB));
g_assert (HB_DIRECTION_IS_BACKWARD (HB_DIRECTION_RTL));
g_assert (HB_DIRECTION_IS_BACKWARD (HB_DIRECTION_BTT));
g_assert (!HB_DIRECTION_IS_BACKWARD (HB_DIRECTION_INVALID));
g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_LTR), ==, HB_DIRECTION_RTL);
g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_RTL), ==, HB_DIRECTION_LTR);
g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_TTB), ==, HB_DIRECTION_BTT);
g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_BTT), ==, HB_DIRECTION_TTB);
//g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_INVALID), ==, HB_DIRECTION_INVALID);
g_assert_cmpint (HB_DIRECTION_INVALID, ==, hb_direction_from_string (NULL, -1));
g_assert_cmpint (HB_DIRECTION_INVALID, ==, hb_direction_from_string ("", -1));