]> git.ipfire.org Git - thirdparty/glibc.git/blame - locale/weightwc.h
Add new locale yuw_PG [BZ #20952]
[thirdparty/glibc.git] / locale / weightwc.h
CommitLineData
bfff8b1b 1/* Copyright (C) 1996-2017 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 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
9eb157c8 18
8c0ab919
RM
19#ifndef _WEIGHTWC_H_
20#define _WEIGHTWC_H_ 1
21
9090848d 22#include <libc-diag.h>
bb5badf1 23
9eb157c8 24/* Find index of weight. */
8c0ab919
RM
25static inline int32_t __attribute__ ((always_inline))
26findidx (const int32_t *table,
27 const int32_t *indirect,
28 const wint_t *extra,
29 const wint_t **cpp, size_t len)
9eb157c8 30{
1c99f950
UD
31 wint_t ch = *(*cpp)++;
32 int32_t i = __collidx_table_lookup ((const char *) table, ch);
9eb157c8
UD
33
34 if (i >= 0)
35 /* This is an index into the weight table. Cool. */
36 return i;
37
38 /* Oh well, more than one sequence starting with this byte.
39 Search for the correct one. */
701666b7 40 const int32_t *cp = (const int32_t *) &extra[-i];
f3a6cc0a 41 --len;
9eb157c8
UD
42 while (1)
43 {
44 size_t nhere;
1c99f950 45 const int32_t *usrc = (const int32_t *) *cpp;
9eb157c8
UD
46
47 /* The first thing is the index. */
46661856 48 i = *cp++;
9eb157c8
UD
49
50 /* Next is the length of the byte sequence. These are always
51 short byte sequences so there is no reason to call any
52 function (even if they are inlined). */
53 nhere = *cp++;
54
55 if (i >= 0)
56 {
57 /* It is a single character. If it matches we found our
58 index. Note that at the end of each list there is an
59 entry of length zero which represents the single byte
60 sequence. The first (and here only) byte was tested
61 already. */
62 size_t cnt;
63
93fe09cb
CD
64 /* With GCC 5.3 when compiling with -Os the compiler warns
65 that seq2.back_us, which becomes usrc, might be used
66 uninitialized. This can't be true because we pass a length
67 of -1 for len at the same time which means that this loop
68 never executes. */
69 DIAG_PUSH_NEEDS_COMMENT;
70 DIAG_IGNORE_Os_NEEDS_COMMENT (5, "-Wmaybe-uninitialized");
f3a6cc0a 71 for (cnt = 0; cnt < nhere && cnt < len; ++cnt)
9eb157c8
UD
72 if (cp[cnt] != usrc[cnt])
73 break;
93fe09cb 74 DIAG_POP_NEEDS_COMMENT;
9eb157c8
UD
75
76 if (cnt == nhere)
77 {
78 /* Found it. */
79 *cpp += nhere;
80 return i;
81 }
82
83 /* Up to the next entry. */
84 cp += nhere;
85 }
86 else
87 {
88 /* This is a range of characters. First decide whether the
89 current byte sequence lies in the range. */
90 size_t cnt;
740c2239 91 size_t offset;
9eb157c8 92
f3a6cc0a 93 for (cnt = 0; cnt < nhere - 1 && cnt < len; ++cnt)
9eb157c8
UD
94 if (cp[cnt] != usrc[cnt])
95 break;
96
740c2239
UD
97 if (cnt < nhere - 1)
98 {
99 cp += 2 * nhere;
100 continue;
101 }
102
103 if (cp[nhere - 1] > usrc[nhere -1])
9eb157c8 104 {
740c2239
UD
105 cp += 2 * nhere;
106 continue;
9eb157c8
UD
107 }
108
740c2239
UD
109 if (cp[2 * nhere - 1] < usrc[nhere -1])
110 {
111 cp += 2 * nhere;
112 continue;
113 }
114
115 /* This range matches the next characters. Now find
116 the offset in the indirect table. */
117 offset = usrc[nhere - 1] - cp[nhere - 1];
9eb157c8 118 *cpp += nhere;
740c2239
UD
119
120 return indirect[-i + offset];
9eb157c8
UD
121 }
122 }
123
124 /* NOTREACHED */
125 return 0x43219876;
126}
8c0ab919
RM
127
128#endif /* weightwc.h */