15569331642446be05292e3e1f8a51218827168cdclaireho#include <stdlib.h>
25569331642446be05292e3e1f8a51218827168cdclaireho#include <stdint.h>
35569331642446be05292e3e1f8a51218827168cdclaireho
45569331642446be05292e3e1f8a51218827168cdclaireho#include <harfbuzz-external.h>
55569331642446be05292e3e1f8a51218827168cdclaireho
65569331642446be05292e3e1f8a51218827168cdclaireho#include "tables/category-properties.h"
75569331642446be05292e3e1f8a51218827168cdclaireho#include "tables/combining-properties.h"
85569331642446be05292e3e1f8a51218827168cdclaireho
95569331642446be05292e3e1f8a51218827168cdclairehoHB_LineBreakClass
105569331642446be05292e3e1f8a51218827168cdclairehoHB_GetLineBreakClass(HB_UChar32 ch) {
115569331642446be05292e3e1f8a51218827168cdclaireho  abort();
125569331642446be05292e3e1f8a51218827168cdclaireho  return 0;
135569331642446be05292e3e1f8a51218827168cdclaireho}
145569331642446be05292e3e1f8a51218827168cdclaireho
155569331642446be05292e3e1f8a51218827168cdclairehostatic int
165569331642446be05292e3e1f8a51218827168cdclairehocombining_property_cmp(const void *vkey, const void *vcandidate) {
175569331642446be05292e3e1f8a51218827168cdclaireho  const uint32_t key = (uint32_t) (intptr_t) vkey;
185569331642446be05292e3e1f8a51218827168cdclaireho  const struct combining_property *candidate = vcandidate;
195569331642446be05292e3e1f8a51218827168cdclaireho
205569331642446be05292e3e1f8a51218827168cdclaireho  if (key < candidate->range_start) {
215569331642446be05292e3e1f8a51218827168cdclaireho    return -1;
225569331642446be05292e3e1f8a51218827168cdclaireho  } else if (key > candidate->range_end) {
235569331642446be05292e3e1f8a51218827168cdclaireho    return 1;
245569331642446be05292e3e1f8a51218827168cdclaireho  } else {
255569331642446be05292e3e1f8a51218827168cdclaireho    return 0;
265569331642446be05292e3e1f8a51218827168cdclaireho  }
275569331642446be05292e3e1f8a51218827168cdclaireho}
285569331642446be05292e3e1f8a51218827168cdclaireho
295569331642446be05292e3e1f8a51218827168cdclairehostatic int
305569331642446be05292e3e1f8a51218827168cdclairehocode_point_to_combining_class(HB_UChar32 cp) {
315569331642446be05292e3e1f8a51218827168cdclaireho  const void *vprop = bsearch((void *) (intptr_t) cp, combining_properties,
325569331642446be05292e3e1f8a51218827168cdclaireho                              combining_properties_count,
335569331642446be05292e3e1f8a51218827168cdclaireho                              sizeof(struct combining_property),
345569331642446be05292e3e1f8a51218827168cdclaireho                              combining_property_cmp);
355569331642446be05292e3e1f8a51218827168cdclaireho  if (!vprop)
365569331642446be05292e3e1f8a51218827168cdclaireho    return 0;
375569331642446be05292e3e1f8a51218827168cdclaireho
385569331642446be05292e3e1f8a51218827168cdclaireho  return ((const struct combining_property *) vprop)->klass;
395569331642446be05292e3e1f8a51218827168cdclaireho}
405569331642446be05292e3e1f8a51218827168cdclaireho
415569331642446be05292e3e1f8a51218827168cdclairehoint
425569331642446be05292e3e1f8a51218827168cdclairehoHB_GetUnicodeCharCombiningClass(HB_UChar32 ch) {
435569331642446be05292e3e1f8a51218827168cdclaireho  return code_point_to_combining_class(ch);
445569331642446be05292e3e1f8a51218827168cdclaireho  return 0;
455569331642446be05292e3e1f8a51218827168cdclaireho}
465569331642446be05292e3e1f8a51218827168cdclaireho
475569331642446be05292e3e1f8a51218827168cdclairehostatic int
485569331642446be05292e3e1f8a51218827168cdclairehocategory_property_cmp(const void *vkey, const void *vcandidate) {
495569331642446be05292e3e1f8a51218827168cdclaireho  const uint32_t key = (uint32_t) (intptr_t) vkey;
505569331642446be05292e3e1f8a51218827168cdclaireho  const struct category_property *candidate = vcandidate;
515569331642446be05292e3e1f8a51218827168cdclaireho
525569331642446be05292e3e1f8a51218827168cdclaireho  if (key < candidate->range_start) {
535569331642446be05292e3e1f8a51218827168cdclaireho    return -1;
545569331642446be05292e3e1f8a51218827168cdclaireho  } else if (key > candidate->range_end) {
555569331642446be05292e3e1f8a51218827168cdclaireho    return 1;
565569331642446be05292e3e1f8a51218827168cdclaireho  } else {
575569331642446be05292e3e1f8a51218827168cdclaireho    return 0;
585569331642446be05292e3e1f8a51218827168cdclaireho  }
595569331642446be05292e3e1f8a51218827168cdclaireho}
605569331642446be05292e3e1f8a51218827168cdclaireho
615569331642446be05292e3e1f8a51218827168cdclairehostatic HB_CharCategory
625569331642446be05292e3e1f8a51218827168cdclairehocode_point_to_category(HB_UChar32 cp) {
635569331642446be05292e3e1f8a51218827168cdclaireho  const void *vprop = bsearch((void *) (intptr_t) cp, category_properties,
645569331642446be05292e3e1f8a51218827168cdclaireho                              category_properties_count,
655569331642446be05292e3e1f8a51218827168cdclaireho                              sizeof(struct category_property),
665569331642446be05292e3e1f8a51218827168cdclaireho                              category_property_cmp);
675569331642446be05292e3e1f8a51218827168cdclaireho  if (!vprop)
685569331642446be05292e3e1f8a51218827168cdclaireho    return HB_NoCategory;
695569331642446be05292e3e1f8a51218827168cdclaireho
705569331642446be05292e3e1f8a51218827168cdclaireho  return ((const struct category_property *) vprop)->category;
715569331642446be05292e3e1f8a51218827168cdclaireho}
725569331642446be05292e3e1f8a51218827168cdclaireho
735569331642446be05292e3e1f8a51218827168cdclairehovoid
745569331642446be05292e3e1f8a51218827168cdclairehoHB_GetUnicodeCharProperties(HB_UChar32 ch,
755569331642446be05292e3e1f8a51218827168cdclaireho                            HB_CharCategory *category,
765569331642446be05292e3e1f8a51218827168cdclaireho                            int *combiningClass) {
775569331642446be05292e3e1f8a51218827168cdclaireho  *category = code_point_to_category(ch);
785569331642446be05292e3e1f8a51218827168cdclaireho  *combiningClass = code_point_to_combining_class(ch);
795569331642446be05292e3e1f8a51218827168cdclaireho}
805569331642446be05292e3e1f8a51218827168cdclaireho
815569331642446be05292e3e1f8a51218827168cdclairehoHB_CharCategory
825569331642446be05292e3e1f8a51218827168cdclairehoHB_GetUnicodeCharCategory(HB_UChar32 ch) {
835569331642446be05292e3e1f8a51218827168cdclaireho  return code_point_to_category(ch);
845569331642446be05292e3e1f8a51218827168cdclaireho}
85