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-2019  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 <string.h>
37 #include "regenc.h"
38 
39 #define TOTAL_KEYWORDS 14
40 #define MIN_WORD_LENGTH 9
41 #define MAX_WORD_LENGTH 9
42 #define MIN_HASH_VALUE 0
43 #define MAX_HASH_VALUE 13
44 /* maximum key range = 14, duplicates = 0 */
45 
46 #ifdef __GNUC__
47 __inline
48 #else
49 #ifdef __cplusplus
50 inline
51 #endif
52 #endif
53 /*ARGSUSED*/
54 static unsigned int
hash(OnigCodePoint codes[])55 hash(OnigCodePoint codes[])
56 {
57   static const unsigned char asso_values[] =
58     {
59        6,  3, 14, 14, 14, 14, 14, 14,  1, 14,
60       14, 14, 14, 14, 14, 14, 14, 14, 14,  0,
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, 14, 14, 14, 14,
65       14, 14, 14, 14, 14, 14,  0, 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, 14, 14, 14, 14, 14, 14, 14, 14,
69       14, 14,  4, 14, 14,  5, 14, 14,  4, 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, 14, 14, 14,
76       14, 14, 14, 14, 14, 14, 14, 10, 14, 14,
77       14, 14, 14,  9, 14,  1, 14, 14, 14, 14,
78       14, 14, 14, 14, 14, 14, 14,  0, 14, 14,
79       14,  8, 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, 14, 14, 14, 14,
84       14, 14, 14, 14, 14, 14
85     };
86   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)];
87 }
88 
89 int
onigenc_unicode_fold3_key(OnigCodePoint codes[])90 onigenc_unicode_fold3_key(OnigCodePoint codes[])
91 {
92   static const short int wordlist[] =
93     {
94 
95       62,
96 
97       47,
98 
99       31,
100 
101       57,
102 
103       41,
104 
105       25,
106 
107       52,
108 
109       36,
110 
111       20,
112 
113       67,
114 
115       15,
116 
117       10,
118 
119       5,
120 
121       0
122     };
123 
124 
125     {
126       int key = hash(codes);
127 
128       if (key <= MAX_HASH_VALUE)
129         {
130           int index = wordlist[key];
131 
132           if (index >= 0 && onig_codes_cmp(codes, OnigUnicodeFolds3 + index, 3) == 0)
133             return index;
134         }
135     }
136   return -1;
137 }
138