]> sourceware.org Git - glibc.git/blame - locale/weight.h
Use <> for include of kernel-features.h.
[glibc.git] / locale / weight.h
CommitLineData
f3a6cc0a 1/* Copyright (C) 1996,1997,1998,1999,2000,2003,2004,2011 Free Software Foundation, Inc.
6d52618b 2 This file is part of the GNU C Library.
5d08d218 3 Written by Ulrich Drepper, <drepper@cygnus.com>.
19bc17a9 4
6d52618b 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
19bc17a9 9
6d52618b
UD
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
41bdb6e2 13 Lesser General Public License for more details.
19bc17a9 14
41bdb6e2
AJ
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. */
19bc17a9 19
450bf66e 20/* Find index of weight. */
7090d3ca 21auto inline int32_t
dd9423a6 22__attribute ((always_inline))
f3a6cc0a 23findidx (const unsigned char **cpp, size_t len)
450bf66e
UD
24{
25 int_fast32_t i = table[*(*cpp)++];
26 const unsigned char *cp;
dbfdf944 27 const unsigned char *usrc;
19bc17a9 28
450bf66e
UD
29 if (i >= 0)
30 /* This is an index into the weight table. Cool. */
31 return i;
19bc17a9 32
450bf66e
UD
33 /* Oh well, more than one sequence starting with this byte.
34 Search for the correct one. */
35 cp = &extra[-i];
dbfdf944 36 usrc = *cpp;
f3a6cc0a 37 --len;
450bf66e 38 while (1)
0393dfd6 39 {
450bf66e 40 size_t nhere;
19bc17a9 41
450bf66e 42 /* The first thing is the index. */
8b6e6767 43 i = *((const int32_t *) cp);
450bf66e 44 cp += sizeof (int32_t);
19bc17a9 45
450bf66e
UD
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++;
19bc17a9 50
450bf66e 51 if (i >= 0)
19bc17a9 52 {
450bf66e
UD
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;
19bc17a9 59
f3a6cc0a 60 for (cnt = 0; cnt < nhere && cnt < len; ++cnt)
450bf66e
UD
61 if (cp[cnt] != usrc[cnt])
62 break;
19bc17a9 63
450bf66e
UD
64 if (cnt == nhere)
65 {
66 /* Found it. */
67 *cpp += nhere;
68 return i;
69 }
19bc17a9 70
450bf66e
UD
71 /* Up to the next entry. */
72 cp += nhere;
ee00109c
UD
73 if ((1 + nhere) % __alignof__ (int32_t) != 0)
74 cp += __alignof__ (int32_t) - (1 + nhere) % __alignof__ (int32_t);
19bc17a9 75 }
450bf66e
UD
76 else
77 {
78 /* This is a range of characters. First decide whether the
79 current byte sequence lies in the range. */
80 size_t cnt;
81 size_t offset = 0;
19bc17a9 82
f3a6cc0a 83 for (cnt = 0; cnt < nhere && cnt < len; ++cnt)
450bf66e
UD
84 if (cp[cnt] != usrc[cnt])
85 break;
19bc17a9 86
450bf66e
UD
87 if (cnt != nhere)
88 {
f3a6cc0a 89 if (cnt == len || cp[cnt] > usrc[cnt])
450bf66e
UD
90 {
91 /* Cannot be in this range. */
92 cp += 2 * nhere;
ee00109c
UD
93 if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
94 cp += (__alignof__ (int32_t)
95 - (1 + 2 * nhere) % __alignof__ (int32_t));
450bf66e
UD
96 continue;
97 }
19bc17a9 98
450bf66e
UD
99 /* Test against the end of the range. */
100 for (cnt = 0; cnt < nhere; ++cnt)
101 if (cp[nhere + cnt] != usrc[cnt])
102 break;
19bc17a9 103
450bf66e
UD
104 if (cnt != nhere && cp[nhere + cnt] < usrc[cnt])
105 {
106 /* Cannot be in this range. */
107 cp += 2 * nhere;
ee00109c
UD
108 if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
109 cp += (__alignof__ (int32_t)
110 - (1 + 2 * nhere) % __alignof__ (int32_t));
450bf66e
UD
111 continue;
112 }
19bc17a9 113
450bf66e
UD
114 /* This range matches the next characters. Now find
115 the offset in the indirect table. */
116 for (cnt = 0; cp[cnt] == usrc[cnt]; ++cnt);
117
118 do
119 {
120 offset <<= 8;
121 offset += usrc[cnt] - cp[cnt];
122 }
123 while (++cnt < nhere);
19bc17a9 124 }
19bc17a9 125
450bf66e 126 *cpp += nhere;
dbfdf944 127 return indirect[-i + offset];
450bf66e 128 }
19bc17a9 129 }
19bc17a9 130
450bf66e
UD
131 /* NOTREACHED */
132 return 0x43219876;
133}
This page took 0.306279 seconds and 5 git commands to generate.