(INTDEFX): Define to get correct expansion order.
[glibc.git] / locale / weightwc.h
blob7eb72187f6133f4b563353b7fd2932db0ed5c1e7
1 /* Copyright (C) 1996-2000, 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Ulrich Drepper, <drepper@cygnus.com>.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 /* Find index of weight. */
21 static inline int32_t
22 findidx (const wint_t **cpp)
24 int32_t i;
25 const wint_t *cp;
26 wint_t ch;
28 ch = *(*cpp)++;
29 i = collidx_table_lookup ((const char *) table, ch);
31 if (i >= 0)
32 /* This is an index into the weight table. Cool. */
33 return i;
35 /* Oh well, more than one sequence starting with this byte.
36 Search for the correct one. */
37 cp = &extra[-i];
38 while (1)
40 size_t nhere;
41 const wint_t *usrc = *cpp;
43 /* The first thing is the index. */
44 i = *cp++;
46 /* Next is the length of the byte sequence. These are always
47 short byte sequences so there is no reason to call any
48 function (even if they are inlined). */
49 nhere = *cp++;
51 if (i >= 0)
53 /* It is a single character. If it matches we found our
54 index. Note that at the end of each list there is an
55 entry of length zero which represents the single byte
56 sequence. The first (and here only) byte was tested
57 already. */
58 size_t cnt;
60 for (cnt = 0; cnt < nhere; ++cnt)
61 if (cp[cnt] != usrc[cnt])
62 break;
64 if (cnt == nhere)
66 /* Found it. */
67 *cpp += nhere;
68 return i;
71 /* Up to the next entry. */
72 cp += nhere;
74 else
76 /* This is a range of characters. First decide whether the
77 current byte sequence lies in the range. */
78 size_t cnt;
79 size_t offset;
81 for (cnt = 0; cnt < nhere - 1; ++cnt)
82 if (cp[cnt] != usrc[cnt])
83 break;
85 if (cnt < nhere - 1)
87 cp += 2 * nhere;
88 continue;
91 if (cp[nhere - 1] > usrc[nhere -1])
93 cp += 2 * nhere;
94 continue;
97 if (cp[2 * nhere - 1] < usrc[nhere -1])
99 cp += 2 * nhere;
100 continue;
103 /* This range matches the next characters. Now find
104 the offset in the indirect table. */
105 offset = usrc[nhere - 1] - cp[nhere - 1];
106 *cpp += nhere;
108 return indirect[-i + offset];
112 /* NOTREACHED */
113 return 0x43219876;