From 5153218b41a5984673900d080daf4e3273e1d117 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 5 Jan 2023 16:26:41 -0700 Subject: [PATCH] [set] Add hb_set_is_inverted() --- docs/harfbuzz-sections.txt | 1 + src/hb-bit-set-invertible.hh | 5 +++++ src/hb-set.cc | 16 ++++++++++++++++ src/hb-set.h | 3 +++ src/hb-set.hh | 1 + src/test-set.cc | 3 ++- 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 7a6848be7..78158dfa0 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -750,6 +750,7 @@ hb_set_intersect hb_set_union hb_set_symmetric_difference hb_set_invert +hb_set_is_inverted hb_set_is_equal hb_set_is_subset hb_set_next diff --git a/src/hb-bit-set-invertible.hh b/src/hb-bit-set-invertible.hh index ff8aecc60..1eb1b1c20 100644 --- a/src/hb-bit-set-invertible.hh +++ b/src/hb-bit-set-invertible.hh @@ -74,6 +74,11 @@ struct hb_bit_set_invertible_t inverted = !inverted; } + bool is_inverted () const + { + return inverted; + } + bool is_empty () const { hb_codepoint_t v = INVALID; diff --git a/src/hb-set.cc b/src/hb-set.cc index 0270b2199..4496120fe 100644 --- a/src/hb-set.cc +++ b/src/hb-set.cc @@ -491,6 +491,22 @@ hb_set_invert (hb_set_t *set) set->invert (); } +/** + * hb_set_is_inverted: + * @set: A set + * + * Returns whether the set is inverted. + * + * Return value: `true` if the set is inverted, `false` otherwise + * + * Since: REPLACEME + **/ +hb_bool_t +hb_set_is_inverted (const hb_set_t *set) +{ + return set->is_inverted (); +} + /** * hb_set_get_population: * @set: A set diff --git a/src/hb-set.h b/src/hb-set.h index 93636ab5d..de5323103 100644 --- a/src/hb-set.h +++ b/src/hb-set.h @@ -97,6 +97,9 @@ hb_set_is_empty (const hb_set_t *set); HB_EXTERN void hb_set_invert (hb_set_t *set); +HB_EXTERN hb_bool_t +hb_set_is_inverted (const hb_set_t *set); + HB_EXTERN hb_bool_t hb_set_has (const hb_set_t *set, hb_codepoint_t codepoint); diff --git a/src/hb-set.hh b/src/hb-set.hh index b13d5372c..604802381 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -79,6 +79,7 @@ struct hb_sparseset_t void reset () { s.reset (); } void clear () { s.clear (); } void invert () { s.invert (); } + bool is_inverted () const { return s.is_inverted (); } bool is_empty () const { return s.is_empty (); } uint32_t hash () const { return s.hash (); } diff --git a/src/test-set.cc b/src/test-set.cc index a0b7ac9ea..9fe319da6 100644 --- a/src/test-set.cc +++ b/src/test-set.cc @@ -132,7 +132,8 @@ main (int argc, char **argv) assert (last == 4); assert (!s.previous_range (&start, &last)); - /* Inverted set returns true for invalid value. */ + assert (s.is_inverted ()); + /* Inverted set returns true for invalid value; oh well. */ assert (s.has (HB_SET_VALUE_INVALID)); }