Welcome to mirror list, hosted at ThFree Co, Russian Federation.

categories.c « ctype « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c237324ecfaefd3abc44a587fc8d86db6b332073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <wctype.h>
#include "categories.h"

struct _category {
  enum category cat: 8;
  unsigned int first: 24;
  unsigned short delta;
} __attribute__((packed));

static const struct _category categories[] = {
#include "categories.t"
};

static enum category
bisearch_cat(wint_t ucs, const struct _category *table, int max)
{
  int min = 0;
  int mid;

  if (ucs < table[0].first || ucs > table[max].first + table[max].delta)
    return 0;
  while (max >= min)
    {
      mid = (min + max) / 2;
      if (ucs > table[mid].first + table[mid].delta)
	min = mid + 1;
      else if (ucs < table[mid].first)
	max = mid - 1;
      else
	return table[mid].cat;
    }
  return -1;
}

enum category category(wint_t ucs)
{
  return bisearch_cat(ucs, categories,
		      sizeof(categories) / sizeof(*categories) - 1);
}