Update.
[glibc.git] / locale / weightwc.h
blobd0ca018e704dc708276736d07c197f04cc5e0ce9
1 /* Copyright (C) 1996, 1997, 1998, 1999, 2000 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* Find index of weight. */
21 static inline int32_t
22 findidx (const wint_t **cpp)
24 int_fast32_t i;
25 const wint_t *cp;
26 wint_t ch;
27 size_t idx;
28 size_t cnt = 0;
30 ch = *(*cpp)++;
31 idx = ch % size;
32 while (names[idx] != ch)
34 if (++cnt == layers)
35 /* We didn't find the name. It is case for UNDEFINED. */
36 return 0;
37 idx += size;
39 i = table[idx];
41 if (i >= 0)
42 /* This is an index into the weight table. Cool. */
43 return i;
45 /* Oh well, more than one sequence starting with this byte.
46 Search for the correct one. */
47 cp = &extra[-i];
48 while (1)
50 size_t nhere;
51 const wint_t *usrc = *cpp;
53 /* The first thing is the index. */
54 i = *cp++;
56 /* Next is the length of the byte sequence. These are always
57 short byte sequences so there is no reason to call any
58 function (even if they are inlined). */
59 nhere = *cp++;
61 if (i >= 0)
63 /* It is a single character. If it matches we found our
64 index. Note that at the end of each list there is an
65 entry of length zero which represents the single byte
66 sequence. The first (and here only) byte was tested
67 already. */
68 size_t cnt;
70 for (cnt = 0; cnt < nhere; ++cnt)
71 if (cp[cnt] != usrc[cnt])
72 break;
74 if (cnt == nhere)
76 /* Found it. */
77 *cpp += nhere;
78 return i;
81 /* Up to the next entry. */
82 cp += nhere;
84 else
86 /* This is a range of characters. First decide whether the
87 current byte sequence lies in the range. */
88 size_t cnt;
89 size_t offset;
91 for (cnt = 0; cnt < nhere - 1; ++cnt)
92 if (cp[cnt] != usrc[cnt])
93 break;
95 if (cnt < nhere - 1)
97 cp += 2 * nhere;
98 continue;
101 if (cp[nhere - 1] > usrc[nhere -1])
103 cp += 2 * nhere;
104 continue;
107 if (cp[2 * nhere - 1] < usrc[nhere -1])
109 cp += 2 * nhere;
110 continue;
113 /* This range matches the next characters. Now find
114 the offset in the indirect table. */
115 offset = usrc[nhere - 1] - cp[nhere - 1];
116 *cpp += nhere;
118 return indirect[-i + offset];
122 /* NOTREACHED */
123 return 0x43219876;