1 /* This file was converted by gperf_fold_key_conv.py
2       from gperf output file. */
3 /* ANSI-C code produced by gperf version 3.1 */
4 /* Command-line: gperf -n -C -T -c -t -j1 -L ANSI-C -F,-1 -N onigenc_unicode_fold3_key unicode_fold3_key.gperf  */
5 /* Computed positions: -k'3,6,9' */
6 
7 
8 
9 /* This gperf source file was generated by make_unicode_fold_data.py */
10 
11 /*-
12  * Copyright (c) 2017-2020  K.Kosako
13  * All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36 #include "regint.h"
37 
38 #define TOTAL_KEYWORDS 14
39 #define MIN_WORD_LENGTH 9
40 #define MAX_WORD_LENGTH 9
41 #define MIN_HASH_VALUE 0
42 #define MAX_HASH_VALUE 13
43 /* maximum key range = 14, duplicates = 0 */
44 
45 #ifdef __GNUC__
46 __inline
47 #else
48 #ifdef __cplusplus
49 inline
50 #endif
51 #endif
52 /*ARGSUSED*/
53 static unsigned int
hash(OnigCodePoint codes[])54 hash(OnigCodePoint codes[])
55 {
56   static const unsigned char asso_values[] =
57     {
58        6,  3, 14, 14, 14, 14, 14, 14,  1, 14,
59       14, 14, 14, 14, 14, 14, 14, 14, 14,  0,
60       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
61       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
62       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
63       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
64       14, 14, 14, 14, 14, 14,  0, 14, 14, 14,
65       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
66       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
67       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
68       14, 14,  4, 14, 14,  5, 14, 14,  4, 14,
69       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
70       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
71       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
72       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
73       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
74       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
75       14, 14, 14, 14, 14, 14, 14, 10, 14, 14,
76       14, 14, 14,  9, 14,  1, 14, 14, 14, 14,
77       14, 14, 14, 14, 14, 14, 14,  0, 14, 14,
78       14,  8, 14, 14, 14, 14, 14, 14, 14, 14,
79       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
80       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
81       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
82       14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
83       14, 14, 14, 14, 14, 14
84     };
85   return asso_values[(unsigned char)onig_codes_byte_at(codes, 8)] + asso_values[(unsigned char)onig_codes_byte_at(codes, 5)] + asso_values[(unsigned char)onig_codes_byte_at(codes, 2)];
86 }
87 
88 int
onigenc_unicode_fold2_key(OnigCodePoint codes[])89 onigenc_unicode_fold3_key(OnigCodePoint codes[])
90 {
91   static const short int wordlist[] =
92     {
93 
94       62,
95 
96       47,
97 
98       31,
99 
100       57,
101 
102       41,
103 
104       25,
105 
106       52,
107 
108       36,
109 
110       20,
111 
112       67,
113 
114       15,
115 
116       10,
117 
118       5,
119 
120       0
121     };
122 
123 
124     {
125       int key = hash(codes);
126 
127       if (key <= MAX_HASH_VALUE)
128         {
129           int index = wordlist[key];
130 
131           if (index >= 0 && onig_codes_cmp(codes, OnigUnicodeFolds3 + index, 3) == 0)
132             return index;
133         }
134     }
135   return -1;
136 }
137