]> git.ipfire.org Git - thirdparty/glibc.git/blame - locale/weightwc.h
Update.
[thirdparty/glibc.git] / locale / weightwc.h
CommitLineData
dd9423a6 1/* Copyright (C) 1996-2000, 2001, 2003 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. */
21static inline int32_t
dd9423a6 22__attribute ((always_inline))
9eb157c8
UD
23findidx (const wint_t **cpp)
24{
a529b416 25 int32_t i;
9eb157c8
UD
26 const wint_t *cp;
27 wint_t ch;
9eb157c8
UD
28
29 ch = *(*cpp)++;
4c7d276e 30 i = collidx_table_lookup ((const char *) table, ch);
9eb157c8
UD
31
32 if (i >= 0)
33 /* This is an index into the weight table. Cool. */
34 return i;
35
36 /* Oh well, more than one sequence starting with this byte.
37 Search for the correct one. */
38 cp = &extra[-i];
39 while (1)
40 {
41 size_t nhere;
42 const wint_t *usrc = *cpp;
43
44 /* The first thing is the index. */
46661856 45 i = *cp++;
9eb157c8
UD
46
47 /* Next is the length of the byte sequence. These are always
48 short byte sequences so there is no reason to call any
49 function (even if they are inlined). */
50 nhere = *cp++;
51
52 if (i >= 0)
53 {
54 /* It is a single character. If it matches we found our
55 index. Note that at the end of each list there is an
56 entry of length zero which represents the single byte
57 sequence. The first (and here only) byte was tested
58 already. */
59 size_t cnt;
60
61 for (cnt = 0; cnt < nhere; ++cnt)
62 if (cp[cnt] != usrc[cnt])
63 break;
64
65 if (cnt == nhere)
66 {
67 /* Found it. */
68 *cpp += nhere;
69 return i;
70 }
71
72 /* Up to the next entry. */
73 cp += nhere;
74 }
75 else
76 {
77 /* This is a range of characters. First decide whether the
78 current byte sequence lies in the range. */
79 size_t cnt;
740c2239 80 size_t offset;
9eb157c8 81
740c2239 82 for (cnt = 0; cnt < nhere - 1; ++cnt)
9eb157c8
UD
83 if (cp[cnt] != usrc[cnt])
84 break;
85
740c2239
UD
86 if (cnt < nhere - 1)
87 {
88 cp += 2 * nhere;
89 continue;
90 }
91
92 if (cp[nhere - 1] > usrc[nhere -1])
9eb157c8 93 {
740c2239
UD
94 cp += 2 * nhere;
95 continue;
9eb157c8
UD
96 }
97
740c2239
UD
98 if (cp[2 * nhere - 1] < usrc[nhere -1])
99 {
100 cp += 2 * nhere;
101 continue;
102 }
103
104 /* This range matches the next characters. Now find
105 the offset in the indirect table. */
106 offset = usrc[nhere - 1] - cp[nhere - 1];
9eb157c8 107 *cpp += nhere;
740c2239
UD
108
109 return indirect[-i + offset];
9eb157c8
UD
110 }
111 }
112
113 /* NOTREACHED */
114 return 0x43219876;
115}