]> git.ipfire.org Git - thirdparty/glibc.git/blame - locale/weightwc.h
Use <> for include of kernel-features.h.
[thirdparty/glibc.git] / locale / weightwc.h
CommitLineData
f3a6cc0a 1/* Copyright (C) 1996-2001,2003,2004,2005,2007,2011 Free Software Foundation, Inc.
9eb157c8
UD
2 This file is part of the GNU C Library.
3 Written by Ulrich Drepper, <drepper@cygnus.com>.
4
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.
9eb157c8
UD
9
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.
9eb157c8 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. */
9eb157c8
UD
19
20/* Find index of weight. */
7090d3ca 21auto inline int32_t
dd9423a6 22__attribute ((always_inline))
f3a6cc0a 23findidx (const wint_t **cpp, size_t len)
9eb157c8 24{
1c99f950
UD
25 wint_t ch = *(*cpp)++;
26 int32_t i = __collidx_table_lookup ((const char *) table, ch);
9eb157c8
UD
27
28 if (i >= 0)
29 /* This is an index into the weight table. Cool. */
30 return i;
31
32 /* Oh well, more than one sequence starting with this byte.
33 Search for the correct one. */
701666b7 34 const int32_t *cp = (const int32_t *) &extra[-i];
f3a6cc0a 35 --len;
9eb157c8
UD
36 while (1)
37 {
38 size_t nhere;
1c99f950 39 const int32_t *usrc = (const int32_t *) *cpp;
9eb157c8
UD
40
41 /* The first thing is the index. */
46661856 42 i = *cp++;
9eb157c8
UD
43
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++;
48
49 if (i >= 0)
50 {
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;
57
f3a6cc0a 58 for (cnt = 0; cnt < nhere && cnt < len; ++cnt)
9eb157c8
UD
59 if (cp[cnt] != usrc[cnt])
60 break;
61
62 if (cnt == nhere)
63 {
64 /* Found it. */
65 *cpp += nhere;
66 return i;
67 }
68
69 /* Up to the next entry. */
70 cp += nhere;
71 }
72 else
73 {
74 /* This is a range of characters. First decide whether the
75 current byte sequence lies in the range. */
76 size_t cnt;
740c2239 77 size_t offset;
9eb157c8 78
f3a6cc0a 79 for (cnt = 0; cnt < nhere - 1 && cnt < len; ++cnt)
9eb157c8
UD
80 if (cp[cnt] != usrc[cnt])
81 break;
82
740c2239
UD
83 if (cnt < nhere - 1)
84 {
85 cp += 2 * nhere;
86 continue;
87 }
88
89 if (cp[nhere - 1] > usrc[nhere -1])
9eb157c8 90 {
740c2239
UD
91 cp += 2 * nhere;
92 continue;
9eb157c8
UD
93 }
94
740c2239
UD
95 if (cp[2 * nhere - 1] < usrc[nhere -1])
96 {
97 cp += 2 * nhere;
98 continue;
99 }
100
101 /* This range matches the next characters. Now find
102 the offset in the indirect table. */
103 offset = usrc[nhere - 1] - cp[nhere - 1];
9eb157c8 104 *cpp += nhere;
740c2239
UD
105
106 return indirect[-i + offset];
9eb157c8
UD
107 }
108 }
109
110 /* NOTREACHED */
111 return 0x43219876;
112}