From 248ad3bce5b5e7190e174929bf1892f1a2bafb44 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 Aug 2021 10:17:51 -0600 Subject: [PATCH] [bit-set-invertible] Implement next/previous This makes invertible set functionality complete. --- src/hb-bit-set-invertible.hh | 48 +++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/hb-bit-set-invertible.hh b/src/hb-bit-set-invertible.hh index 8f4b7f865..aaa1840f7 100644 --- a/src/hb-bit-set-invertible.hh +++ b/src/hb-bit-set-invertible.hh @@ -177,16 +177,53 @@ struct hb_bit_set_invertible_t bool next (hb_codepoint_t *codepoint) const { - /*XXX(inverted)*/ - return s.next (codepoint); + if (likely (!inverted)) + return s.next (codepoint); + + auto old = *codepoint; + do + { + auto v = old; + s.next (&v); + if (old + 1 < v) + { + *codepoint = old + 1; + return true; + } + old++; + } + while (old != INVALID); + + *codepoint = INVALID; + return false; } bool previous (hb_codepoint_t *codepoint) const { - /*XXX(inverted)*/ - return s.previous (codepoint); + if (likely (!inverted)) + return s.previous (codepoint); + + auto old = *codepoint; + do + { + auto v = old; + s.previous (&v); + if (old - 1 > v) + { + *codepoint = old - 1; + return true; + } + old--; + } + while (old != INVALID); + + *codepoint = INVALID; + return false; } bool next_range (hb_codepoint_t *first, hb_codepoint_t *last) const { + if (likely (!inverted)) + return s.next_range (first, last); + hb_codepoint_t i; i = *last; @@ -205,6 +242,9 @@ struct hb_bit_set_invertible_t } bool previous_range (hb_codepoint_t *first, hb_codepoint_t *last) const { + if (likely (!inverted)) + return s.previous_range (first, last); + hb_codepoint_t i; i = *first;