* sysdeps/m68k/fpu/bits/mathinline.h (isgreater, isgreaterequal)
[glibc.git] / locale / weight.h
blob439accdcaa4697bb09519b9fd9e18b11b14adab1
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 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 unsigned char **cpp)
24 int_fast32_t i = table[*(*cpp)++];
25 const unsigned char *cp;
26 const unsigned char *usrc;
28 if (i >= 0)
29 /* This is an index into the weight table. Cool. */
30 return i;
32 /* Oh well, more than one sequence starting with this byte.
33 Search for the correct one. */
34 cp = &extra[-i];
35 usrc = *cpp;
36 while (1)
38 size_t nhere;
40 /* The first thing is the index. */
41 i = *((const int32_t *) cp);
42 cp += sizeof (int32_t);
44 /* Next is the length of the byte sequence. These are always
45 short byte sequences so there is no reason to call any
46 function (even if they are inlined). */
47 nhere = *cp++;
49 if (i >= 0)
51 /* It is a single character. If it matches we found our
52 index. Note that at the end of each list there is an
53 entry of length zero which represents the single byte
54 sequence. The first (and here only) byte was tested
55 already. */
56 size_t cnt;
58 for (cnt = 0; cnt < nhere; ++cnt)
59 if (cp[cnt] != usrc[cnt])
60 break;
62 if (cnt == nhere)
64 /* Found it. */
65 *cpp += nhere;
66 return i;
69 /* Up to the next entry. */
70 cp += nhere;
71 if ((1 + nhere) % __alignof__ (int32_t) != 0)
72 cp += __alignof__ (int32_t) - (1 + nhere) % __alignof__ (int32_t);
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 = 0;
81 for (cnt = 0; cnt < nhere; ++cnt)
82 if (cp[cnt] != usrc[cnt])
83 break;
85 if (cnt != nhere)
87 if (cp[cnt] > usrc[cnt])
89 /* Cannot be in this range. */
90 cp += 2 * nhere;
91 if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
92 cp += (__alignof__ (int32_t)
93 - (1 + 2 * nhere) % __alignof__ (int32_t));
94 continue;
97 /* Test against the end of the range. */
98 for (cnt = 0; cnt < nhere; ++cnt)
99 if (cp[nhere + cnt] != usrc[cnt])
100 break;
102 if (cnt != nhere && cp[nhere + cnt] < usrc[cnt])
104 /* Cannot be in this range. */
105 cp += 2 * nhere;
106 if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
107 cp += (__alignof__ (int32_t)
108 - (1 + 2 * nhere) % __alignof__ (int32_t));
109 continue;
112 /* This range matches the next characters. Now find
113 the offset in the indirect table. */
114 for (cnt = 0; cp[cnt] == usrc[cnt]; ++cnt);
118 offset <<= 8;
119 offset += usrc[cnt] - cp[cnt];
121 while (++cnt < nhere);
124 *cpp += nhere;
125 return indirect[-i + offset];
129 /* NOTREACHED */
130 return 0x43219876;