blob: 59a0af46ed476155a0d4237088fe46e8ffd63349 [file] [log] [blame]
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -04001/*
2 * Copyright © 2012 Google, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
27#include "hb-set-private.hh"
28
29
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -040030/* Public API */
31
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040032
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -040033/**
Behdad Esfahbod085d4292013-09-12 17:14:33 -040034 * hb_set_create: (Xconstructor)
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -040035 *
36 * Return value: (transfer full):
37 *
38 * Since: 1.0
39 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040040hb_set_t *
Behdad Esfahbodaec89de2012-11-15 16:15:42 -080041hb_set_create (void)
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040042{
43 hb_set_t *set;
44
45 if (!(set = hb_object_create<hb_set_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -040046 return hb_set_get_empty ();
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040047
48 set->clear ();
49
50 return set;
51}
52
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -040053/**
54 * hb_set_get_empty:
55 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -040056 * Return value: (transfer full):
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -040057 *
58 * Since: 1.0
59 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040060hb_set_t *
61hb_set_get_empty (void)
62{
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -040063 static const hb_set_t _hb_set_nil = {
64 HB_OBJECT_HEADER_STATIC,
Behdad Esfahbod8165f272013-01-02 22:50:36 -060065 true, /* in_error */
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -040066
67 {0} /* elts */
68 };
69
70 return const_cast<hb_set_t *> (&_hb_set_nil);
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040071}
72
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -040073/**
74 * hb_set_reference: (skip)
75 * @set: a set.
76 *
77 * Return value: (transfer full):
78 *
79 * Since: 1.0
80 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040081hb_set_t *
82hb_set_reference (hb_set_t *set)
83{
84 return hb_object_reference (set);
85}
86
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -040087/**
88 * hb_set_destroy: (skip)
89 * @set: a set.
90 *
91 * Since: 1.0
92 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040093void
94hb_set_destroy (hb_set_t *set)
95{
96 if (!hb_object_destroy (set)) return;
97
Behdad Esfahboda5e39fe2012-04-25 00:14:46 -040098 set->fini ();
99
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400100 free (set);
101}
102
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400103/**
104 * hb_set_set_user_data: (skip)
105 * @set: a set.
106 * @key:
107 * @data:
108 * @destroy (closure data):
109 * @replace:
110 *
111 * Return value:
112 *
113 * Since: 1.0
114 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400115hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800116hb_set_set_user_data (hb_set_t *set,
117 hb_user_data_key_t *key,
118 void * data,
119 hb_destroy_func_t destroy,
120 hb_bool_t replace)
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400121{
122 return hb_object_set_user_data (set, key, data, destroy, replace);
123}
124
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400125/**
126 * hb_set_get_user_data: (skip)
127 * @set: a set.
128 * @key:
129 *
130 * Return value: (transfer none):
131 *
132 * Since: 1.0
133 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400134void *
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800135hb_set_get_user_data (hb_set_t *set,
136 hb_user_data_key_t *key)
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400137{
138 return hb_object_get_user_data (set, key);
139}
140
141
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400142/**
143 * hb_set_allocation_successful:
144 * @set: a set.
145 *
146 *
147 *
148 * Return value:
149 *
150 * Since: 1.0
151 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400152hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800153hb_set_allocation_successful (const hb_set_t *set HB_UNUSED)
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400154{
Behdad Esfahbod8165f272013-01-02 22:50:36 -0600155 return !set->in_error;
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400156}
157
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400158/**
159 * hb_set_clear:
160 * @set: a set.
161 *
162 *
163 *
164 * Since: 1.0
165 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400166void
167hb_set_clear (hb_set_t *set)
168{
169 set->clear ();
170}
171
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400172/**
173 * hb_set_is_empty:
174 * @set: a set.
175 *
176 *
177 *
178 * Return value:
179 *
180 * Since: 1.0
181 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400182hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800183hb_set_is_empty (const hb_set_t *set)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400184{
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800185 return set->is_empty ();
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400186}
187
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400188/**
189 * hb_set_has:
190 * @set: a set.
191 * @codepoint:
192 *
193 *
194 *
195 * Return value:
196 *
197 * Since: 1.0
198 **/
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400199hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800200hb_set_has (const hb_set_t *set,
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400201 hb_codepoint_t codepoint)
202{
203 return set->has (codepoint);
204}
205
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400206/**
207 * hb_set_add:
208 * @set: a set.
209 * @codepoint:
210 *
211 *
212 *
213 * Since: 1.0
214 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400215void
216hb_set_add (hb_set_t *set,
217 hb_codepoint_t codepoint)
218{
219 set->add (codepoint);
220}
221
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400222/**
223 * hb_set_add_range:
224 * @set: a set.
225 * @first:
226 * @last:
227 *
228 *
229 *
230 * Since: 1.0
231 **/
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400232void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800233hb_set_add_range (hb_set_t *set,
234 hb_codepoint_t first,
235 hb_codepoint_t last)
236{
237 set->add_range (first, last);
238}
239
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400240/**
241 * hb_set_del:
242 * @set: a set.
243 * @codepoint:
244 *
245 *
246 *
247 * Since: 1.0
248 **/
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800249void
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400250hb_set_del (hb_set_t *set,
251 hb_codepoint_t codepoint)
252{
253 set->del (codepoint);
254}
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400255
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400256/**
257 * hb_set_del_range:
258 * @set: a set.
259 * @first:
260 * @last:
261 *
262 *
263 *
264 * Since: 1.0
265 **/
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800266void
267hb_set_del_range (hb_set_t *set,
268 hb_codepoint_t first,
269 hb_codepoint_t last)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400270{
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800271 set->del_range (first, last);
272}
273
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400274/**
275 * hb_set_is_equal:
276 * @set: a set.
277 * @other:
278 *
279 *
280 *
281 * Return value:
282 *
283 * Since: 1.0
284 **/
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800285hb_bool_t
286hb_set_is_equal (const hb_set_t *set,
287 const hb_set_t *other)
288{
289 return set->is_equal (other);
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400290}
291
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400292/**
293 * hb_set_set:
294 * @set: a set.
295 * @other:
296 *
297 *
298 *
299 * Since: 1.0
300 **/
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400301void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800302hb_set_set (hb_set_t *set,
303 const hb_set_t *other)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400304{
305 set->set (other);
306}
307
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400308/**
309 * hb_set_union:
310 * @set: a set.
311 * @other:
312 *
313 *
314 *
315 * Since: 1.0
316 **/
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400317void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800318hb_set_union (hb_set_t *set,
319 const hb_set_t *other)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400320{
321 set->union_ (other);
322}
323
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400324/**
325 * hb_set_intersect:
326 * @set: a set.
327 * @other:
328 *
329 *
330 *
331 * Since: 1.0
332 **/
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400333void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800334hb_set_intersect (hb_set_t *set,
335 const hb_set_t *other)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400336{
337 set->intersect (other);
338}
339
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400340/**
341 * hb_set_subtract:
342 * @set: a set.
343 * @other:
344 *
345 *
346 *
347 * Since: 1.0
348 **/
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400349void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800350hb_set_subtract (hb_set_t *set,
351 const hb_set_t *other)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400352{
353 set->subtract (other);
354}
355
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400356/**
357 * hb_set_symmetric_difference:
358 * @set: a set.
359 * @other:
360 *
361 *
362 *
363 * Since: 1.0
364 **/
Behdad Esfahbod62c3e112012-05-25 13:48:00 -0400365void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800366hb_set_symmetric_difference (hb_set_t *set,
367 const hb_set_t *other)
Behdad Esfahbod62c3e112012-05-25 13:48:00 -0400368{
369 set->symmetric_difference (other);
370}
371
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400372/**
373 * hb_set_invert:
374 * @set: a set.
375 *
376 *
377 *
378 * Since: 1.0
379 **/
Behdad Esfahbod8165f272013-01-02 22:50:36 -0600380void
381hb_set_invert (hb_set_t *set)
382{
383 set->invert ();
384}
385
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400386/**
387 * hb_set_get_population:
388 * @set: a set.
389 *
390 * Returns the number of numbers in the set.
391 *
392 * Return value: set population.
393 *
394 * Since: 1.0
395 **/
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800396unsigned int
Behdad Esfahbodac064a22012-11-21 01:14:19 -0500397hb_set_get_population (const hb_set_t *set)
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800398{
399 return set->get_population ();
400}
401
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400402/**
403 * hb_set_get_min:
404 * @set: a set.
405 *
406 * Finds the minimum number in the set.
407 *
408 * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
409 *
410 * Since: 1.0
411 **/
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400412hb_codepoint_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800413hb_set_get_min (const hb_set_t *set)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400414{
Behdad Esfahbodf039e792012-05-17 20:55:12 -0400415 return set->get_min ();
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400416}
417
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400418/**
419 * hb_set_get_max:
420 * @set: a set.
421 *
422 * Finds the maximum number in the set.
423 *
424 * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
425 *
426 * Since: 1.0
427 **/
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400428hb_codepoint_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800429hb_set_get_max (const hb_set_t *set)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400430{
Behdad Esfahbodf039e792012-05-17 20:55:12 -0400431 return set->get_max ();
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400432}
Behdad Esfahbod29ce4462012-05-25 14:17:54 -0400433
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400434/**
435 * hb_set_next:
436 * @set: a set.
437 * @codepoint: (inout):
438 *
439 *
440 *
441 * Return value: whether there was a next value.
442 *
443 * Since: 1.0
444 **/
Behdad Esfahbod29ce4462012-05-25 14:17:54 -0400445hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800446hb_set_next (const hb_set_t *set,
Behdad Esfahbod29ce4462012-05-25 14:17:54 -0400447 hb_codepoint_t *codepoint)
448{
449 return set->next (codepoint);
450}
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800451
Behdad Esfahbod20cbc1f2013-09-06 15:29:22 -0400452/**
453 * hb_set_next_range:
454 * @set: a set.
455 * @first: (out): output first codepoint in the range.
456 * @last: (inout): input current last and output last codepoint in the range.
457 *
458 * Gets the next consecutive range of numbers in @set that
459 * are greater than current value of @last.
460 *
461 * Return value: whether there was a next range.
462 *
463 * Since: 1.0
464 **/
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800465hb_bool_t
466hb_set_next_range (const hb_set_t *set,
467 hb_codepoint_t *first,
468 hb_codepoint_t *last)
469{
470 return set->next_range (first, last);
471}