Imported Upstream version 8.2.2
[platform/upstream/harfbuzz.git] / src / hb-set.cc
index 204dbb5..a9386c5 100644 (file)
@@ -40,7 +40,7 @@
 
 
 /**
- * hb_set_create: (Xconstructor)
+ * hb_set_create:
  *
  * Creates a new, initially empty set.
  *
@@ -56,8 +56,6 @@ hb_set_create ()
   if (!(set = hb_object_create<hb_set_t> ()))
     return hb_set_get_empty ();
 
-  set->init_shallow ();
-
   return set;
 }
 
@@ -107,8 +105,6 @@ hb_set_destroy (hb_set_t *set)
 {
   if (!hb_object_destroy (set)) return;
 
-  set->fini_shallow ();
-
   hb_free (set);
 }
 
@@ -122,7 +118,7 @@ hb_set_destroy (hb_set_t *set)
  *
  * Attaches a user-data key/data pair to the specified set.
  *
- * Return value: %true if success, %false otherwise
+ * Return value: `true` if success, `false` otherwise
  *
  * Since: 0.9.2
  **/
@@ -149,7 +145,7 @@ hb_set_set_user_data (hb_set_t           *set,
  * Since: 0.9.2
  **/
 void *
-hb_set_get_user_data (hb_set_t           *set,
+hb_set_get_user_data (const hb_set_t     *set,
                      hb_user_data_key_t *key)
 {
   return hb_object_get_user_data (set, key);
@@ -162,7 +158,7 @@ hb_set_get_user_data (hb_set_t           *set,
  *
  * Tests whether memory allocation for a set was successful.
  *
- * Return value: %true if allocation succeeded, %false otherwise
+ * Return value: `true` if allocation succeeded, `false` otherwise
  *
  * Since: 0.9.2
  **/
@@ -178,7 +174,7 @@ hb_set_allocation_successful (const hb_set_t  *set)
  *
  * Allocate a copy of @set.
  *
- * Return value: Newly-allocated set.
+ * Return value: (transfer full): Newly-allocated set.
  *
  * Since: 2.8.2
  **/
@@ -186,6 +182,9 @@ hb_set_t *
 hb_set_copy (const hb_set_t *set)
 {
   hb_set_t *copy = hb_set_create ();
+  if (unlikely (copy->in_error ()))
+    return hb_set_get_empty ();
+
   copy->set (*set);
   return copy;
 }
@@ -201,7 +200,7 @@ hb_set_copy (const hb_set_t *set)
 void
 hb_set_clear (hb_set_t *set)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->clear ();
 }
 
@@ -211,7 +210,7 @@ hb_set_clear (hb_set_t *set)
  *
  * Tests whether a set is empty (contains no elements).
  *
- * Return value: %true if @set is empty
+ * Return value: `true` if @set is empty
  *
  * Since: 0.9.7
  **/
@@ -228,7 +227,7 @@ hb_set_is_empty (const hb_set_t *set)
  *
  * Tests whether @codepoint belongs to @set.
  *
- * Return value: %true if @codepoint is in @set, %false otherwise
+ * Return value: `true` if @codepoint is in @set, `false` otherwise
  *
  * Since: 0.9.2
  **/
@@ -252,11 +251,34 @@ void
 hb_set_add (hb_set_t       *set,
            hb_codepoint_t  codepoint)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->add (codepoint);
 }
 
 /**
+ * hb_set_add_sorted_array:
+ * @set: A set
+ * @sorted_codepoints: (array length=num_codepoints): Array of codepoints to add
+ * @num_codepoints: Length of @sorted_codepoints
+ *
+ * Adds @num_codepoints codepoints to a set at once.
+ * The codepoints array must be in increasing order,
+ * with size at least @num_codepoints.
+ *
+ * Since: 4.1.0
+ */
+HB_EXTERN void
+hb_set_add_sorted_array (hb_set_t             *set,
+                        const hb_codepoint_t *sorted_codepoints,
+                        unsigned int          num_codepoints)
+{
+  /* Immutable-safe. */
+  set->add_sorted_array (sorted_codepoints,
+                        num_codepoints,
+                        sizeof(hb_codepoint_t));
+}
+
+/**
  * hb_set_add_range:
  * @set: A set
  * @first: The first element to add to @set
@@ -272,7 +294,7 @@ hb_set_add_range (hb_set_t       *set,
                  hb_codepoint_t  first,
                  hb_codepoint_t  last)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->add_range (first, last);
 }
 
@@ -289,7 +311,7 @@ void
 hb_set_del (hb_set_t       *set,
            hb_codepoint_t  codepoint)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->del (codepoint);
 }
 
@@ -312,7 +334,7 @@ hb_set_del_range (hb_set_t       *set,
                  hb_codepoint_t  first,
                  hb_codepoint_t  last)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->del_range (first, last);
 }
 
@@ -324,7 +346,7 @@ hb_set_del_range (hb_set_t       *set,
  * Tests whether @set and @other are equal (contain the same
  * elements).
  *
- * Return value: %true if the two sets are equal, %false otherwise.
+ * Return value: `true` if the two sets are equal, `false` otherwise.
  *
  * Since: 0.9.7
  **/
@@ -336,13 +358,30 @@ hb_set_is_equal (const hb_set_t *set,
 }
 
 /**
+ * hb_set_hash:
+ * @set: A set
+ *
+ * Creates a hash representing @set.
+ *
+ * Return value:
+ * A hash of @set.
+ *
+ * Since: 4.4.0
+ **/
+HB_EXTERN unsigned int
+hb_set_hash (const hb_set_t *set)
+{
+  return set->hash ();
+}
+
+/**
  * hb_set_is_subset:
  * @set: A set
  * @larger_set: Another set
  *
  * Tests whether @set is a subset of @larger_set.
  *
- * Return value: %true if the @set is a subset of (or equal to) @larger_set, %false otherwise.
+ * Return value: `true` if the @set is a subset of (or equal to) @larger_set, `false` otherwise.
  *
  * Since: 1.8.1
  **/
@@ -366,7 +405,7 @@ void
 hb_set_set (hb_set_t       *set,
            const hb_set_t *other)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->set (*other);
 }
 
@@ -383,7 +422,7 @@ void
 hb_set_union (hb_set_t       *set,
              const hb_set_t *other)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->union_ (*other);
 }
 
@@ -400,7 +439,7 @@ void
 hb_set_intersect (hb_set_t       *set,
                  const hb_set_t *other)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->intersect (*other);
 }
 
@@ -417,7 +456,7 @@ void
 hb_set_subtract (hb_set_t       *set,
                 const hb_set_t *other)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->subtract (*other);
 }
 
@@ -435,7 +474,7 @@ void
 hb_set_symmetric_difference (hb_set_t       *set,
                             const hb_set_t *other)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   set->symmetric_difference (*other);
 }
 
@@ -450,11 +489,27 @@ hb_set_symmetric_difference (hb_set_t       *set,
 void
 hb_set_invert (hb_set_t *set)
 {
-  /* Immutible-safe. */
+  /* Immutable-safe. */
   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: 7.0.0
+ **/
+hb_bool_t
+hb_set_is_inverted (const hb_set_t *set)
+{
+  return set->is_inverted ();
+}
+
+/**
  * hb_set_get_population:
  * @set: A set
  *
@@ -512,7 +567,7 @@ hb_set_get_max (const hb_set_t *set)
  *
  * Set @codepoint to #HB_SET_VALUE_INVALID to get started.
  *
- * Return value: %true if there was a next value, %false otherwise
+ * Return value: `true` if there was a next value, `false` otherwise
  *
  * Since: 0.9.2
  **/
@@ -533,7 +588,7 @@ hb_set_next (const hb_set_t *set,
  *
  * Set @codepoint to #HB_SET_VALUE_INVALID to get started.
  *
- * Return value: %true if there was a previous value, %false otherwise
+ * Return value: `true` if there was a previous value, `false` otherwise
  *
  * Since: 1.8.0
  **/
@@ -556,7 +611,7 @@ hb_set_previous (const hb_set_t *set,
  *
  * Set @last to #HB_SET_VALUE_INVALID to get started.
  *
- * Return value: %true if there was a next range, %false otherwise
+ * Return value: `true` if there was a next range, `false` otherwise
  *
  * Since: 0.9.7
  **/
@@ -580,7 +635,7 @@ hb_set_next_range (const hb_set_t *set,
  *
  * Set @first to #HB_SET_VALUE_INVALID to get started.
  *
- * Return value: %true if there was a previous range, %false otherwise
+ * Return value: `true` if there was a previous range, `false` otherwise
  *
  * Since: 1.8.0
  **/
@@ -591,3 +646,28 @@ hb_set_previous_range (const hb_set_t *set,
 {
   return set->previous_range (first, last);
 }
+
+/**
+ * hb_set_next_many:
+ * @set: A set
+ * @codepoint: Outputting codepoints starting after this one.
+ *             Use #HB_SET_VALUE_INVALID to get started.
+ * @out: (array length=size): An array of codepoints to write to.
+ * @size: The maximum number of codepoints to write out.
+ *
+ * Finds the next element in @set that is greater than @codepoint. Writes out
+ * codepoints to @out, until either the set runs out of elements, or @size
+ * codepoints are written, whichever comes first.
+ *
+ * Return value: the number of values written.
+ *
+ * Since: 4.2.0
+ **/
+unsigned int
+hb_set_next_many (const hb_set_t *set,
+                 hb_codepoint_t  codepoint,
+                 hb_codepoint_t *out,
+                 unsigned int    size)
+{
+  return set->next_many (codepoint, out, size);
+}