From: Behdad Esfahbod Date: Mon, 6 Aug 2018 11:32:51 +0000 (-0700) Subject: Move some more code around X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=be336dadc07460a53de51be32dd5d1f218b398b6;p=platform%2Fupstream%2FlibHarfBuzzSharp.git Move some more code around --- diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index fc7d1f0..36395db 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -232,6 +232,18 @@ hb_ctz (T v) * Tiny stuff. */ +/* ASCII tag/character handling */ +static inline bool ISALPHA (unsigned char c) +{ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } +static inline bool ISALNUM (unsigned char c) +{ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); } +static inline bool ISSPACE (unsigned char c) +{ return c == ' ' || c =='\f'|| c =='\n'|| c =='\r'|| c =='\t'|| c =='\v'; } +static inline unsigned char TOUPPER (unsigned char c) +{ return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; } +static inline unsigned char TOLOWER (unsigned char c) +{ return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; } + #undef MIN template static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; } @@ -262,6 +274,37 @@ hb_ceil_to_4 (unsigned int v) return ((v - 1) | 3) + 1; } +template class hb_assert_unsigned_t; +template <> class hb_assert_unsigned_t {}; +template <> class hb_assert_unsigned_t {}; +template <> class hb_assert_unsigned_t {}; +template <> class hb_assert_unsigned_t {}; + +template static inline bool +hb_in_range (T u, T lo, T hi) +{ + /* The sizeof() is here to force template instantiation. + * I'm sure there are better ways to do this but can't think of + * one right now. Declaring a variable won't work as HB_UNUSED + * is unusable on some platforms and unused types are less likely + * to generate a warning than unused variables. */ + static_assert ((sizeof (hb_assert_unsigned_t) >= 0), ""); + + /* The casts below are important as if T is smaller than int, + * the subtract results will become a signed int! */ + return (T)(u - lo) <= (T)(hi - lo); +} +template static inline bool +hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2) +{ + return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2); +} +template static inline bool +hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) +{ + return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2) || hb_in_range (u, lo3, hi3); +} + /* * Sort and search. diff --git a/src/hb-private.hh b/src/hb-private.hh index d912fe3..98a2118 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -435,20 +435,6 @@ struct CrapOrNull { #define CrapOrNull(Type) CrapOrNull::get () -/* ASCII tag/character handling */ - -static inline bool ISALPHA (unsigned char c) -{ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } -static inline bool ISALNUM (unsigned char c) -{ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); } -static inline bool ISSPACE (unsigned char c) -{ return c == ' ' || c =='\f'|| c =='\n'|| c =='\r'|| c =='\t'|| c =='\v'; } -static inline unsigned char TOUPPER (unsigned char c) -{ return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; } -static inline unsigned char TOLOWER (unsigned char c) -{ return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; } - - /* HB_NDEBUG disables some sanity checks that are very safe to disable and * should be disabled in production systems. If NDEBUG is defined, enable * HB_NDEBUG; but if it's desirable that normal assert()s (which are very @@ -459,41 +445,7 @@ static inline unsigned char TOLOWER (unsigned char c) #endif -/* Misc */ - -template class hb_assert_unsigned_t; -template <> class hb_assert_unsigned_t {}; -template <> class hb_assert_unsigned_t {}; -template <> class hb_assert_unsigned_t {}; -template <> class hb_assert_unsigned_t {}; - -template static inline bool -hb_in_range (T u, T lo, T hi) -{ - /* The sizeof() is here to force template instantiation. - * I'm sure there are better ways to do this but can't think of - * one right now. Declaring a variable won't work as HB_UNUSED - * is unusable on some platforms and unused types are less likely - * to generate a warning than unused variables. */ - static_assert ((sizeof (hb_assert_unsigned_t) >= 0), ""); - - /* The casts below are important as if T is smaller than int, - * the subtract results will become a signed int! */ - return (T)(u - lo) <= (T)(hi - lo); -} - -template static inline bool -hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2) -{ - return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2); -} - -template static inline bool -hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) -{ - return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2) || hb_in_range (u, lo3, hi3); -} - +/* Flags */ /* Enable bitwise ops on enums marked as flags_t */ /* To my surprise, looks like the function resolver is happy to silently cast @@ -517,7 +469,6 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) static inline T& operator ^= (T& l, T r) { l = l ^ r; return l; } \ } - /* Useful for set-operations on small enums. * For example, for testing "x ∈ {x1, x2, x3}" use: * (FLAG_UNSAFE(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3)))