Debian Codegraph @

lib/fstrcmp.h

raw symbols SCIP
1 /*
2 * fstrcmp - fuzzy string compare library
3 * Copyright (C) 2009 Peter Miller
4 * Written by Peter Miller <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef FSTRCMP_H
21 #define FSTRCMP_H
22
23 #include <stddef.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /**
30 * The FSTRCMP_IDENTICAL constant may be used where the upper bound of
31 * the fstrcmp result is required.
32 */
33 #define FSTRCMP_IDENTICAL 1.0
34
35 /**
36 * The FSTRCMP_THRESHOLD constant may be used to decide "usefully
37 * similar" questions. Pairs of strings that return and fstrcmp result
38 * larger than this threshold are what humans would consider "similar".
39 */
40 #define FSTRCMP_THRESHOLD (FSTRCMP_IDENTICAL * 3 / 5)
41
42 /**
43 * The FSTRCMP_ERROR constant msy be used to test whether or not the
44 * fstrcmp function has returned an error. (Actually, any value < 0
45 * indicates and error, and < 0 can be a faster test.)
46 */
47 #define FSTRCMP_ERROR -1
48
49 /**
50 * The FSTRCMPI_IDENTICAL constant may be used where the upper bound of
51 * the fstrcmpi result is required.
52 *
53 * Don't assume the value will always be the one you see here. Always
54 * use the defined symbols. You can assume it will always be positive.
55 */
56 #define FSTRCMPI_IDENTICAL 10000
57
58 /**
59 * The FSTRCMPI_THRESHOLD constant may be used to decide "usefully
60 * similar" questions. Pairs of strings that return and fstrcmpi result
61 * larger than this threshold are what humans would consider "similar".
62 */
63 #define FSTRCMPI_THRESHOLD (FSTRCMPI_IDENTICAL * 3 / 5)
64
65 /**
66 * The FSTRCMPI_ERROR constant msy be used to test whether or not the
67 * fstrcmpi function has returned an error. (Actually, any value < 0
68 * indicates and error, and < 0 can be a faster test.)
69 */
70 #define FSTRCMPI_ERROR -1
71
72 /**
73 * The fstrcmp function may be used to make a fuzzy comparison between
74 * two strings. Note that this function's units of operation are
75 * bytes, not characters.
76 *
77 * This function is very useful in reducing "cascade" or "secondary"
78 * errors in compilers or other situations where symbol tables occur.
79 *
80 * @param string1
81 * The first string to be compared.
82 * @param string2
83 * The first string to be compared.
84 * @returns
85 * a number between 0.0 and FSTRCMP_IDENTICAL. The value 0.0 means
86 * the strings are utterly un-alike, and FSTRCMP_IDENTICAL means the
87 * strings are identical. A value of FSTRCMP_ERROR indicates an
88 * error (malloc failure).
89 */
90 double fstrcmp(const char *string1, const char *string2);
91
92 /**
93 * The fstrcmpi function may be used to make a fuzzy comparison between
94 * two strings. Note that this function's units of operation are
95 * bytes, not characters.
96 *
97 * This function is very useful in reducing "cascade" or "secondary"
98 * errors in compilers or other situations where symbol tables occur.
99 * Return values in excess of FSTRFCMPI_THRESHOLD are "similar".
100 *
101 * @param string1
102 * The first string to be compared.
103 * @param string2
104 * The first string to be compared.
105 * @returns
106 * a number between 0 and FSTRFCMPI_IDENTICAL. The value 0 means
107 * the strings are utterly un-alike, and FSTRFCMPI_IDENTICAL means
108 * the strings are identical. A value of FSTRFCMPI_ERROR indicates
109 * an error (malloc failure).
110 */
111 int fstrcmpi(const char *string1, const char *string2);
112
113 /**
114 * The fstrcasecmp function may be used to make a fuzzy comparison
115 * between two strings, while ignoring the case of the characters.
116 * Note that this function's units of operation are bytes, not
117 * characters.
118 *
119 * @param s1
120 * The first string to be compared.
121 * @param s2
122 * The second string to be compared.
123 * @returns
124 * a number between 0.0 and 1.0. The value 0.0 means the strings
125 * are utterly un-alike, and 1.0 means the strings are identical. A
126 * value of -1 indicates and error (malloc failure).
127 */
128 double fstrcasecmp(const char *s1, const char *s2);
129
130 /**
131 * The fstrcasecmpi function may be used to make a fuzzy comparison
132 * between two strings, while ignoring the case of the characters.
133 * Note that this function's units of operation are bytes, not
134 * characters.
135 *
136 * @param s1
137 * The first string to be compared.
138 * @param s2
139 * The second string to be compared.
140 * @returns
141 * a number between 0.0 and FSTRCMPI_IDENTICAL. The value 0 means
142 * the strings are utterly un-alike, and FSTRCMPI_IDENTICAL means
143 * the strings are identical. A value of FSTRCMPI_ERROR indicates
144 * and error (malloc failure).
145 */
146 int fstrcasecmpi(const char *s1, const char *s2);
147
148 /**
149 * The fmemcmp function may be used to make a fuzzy comparison between
150 * two arrays of bytes.
151 *
152 * @param data1
153 * The first array to be compared.
154 * @param size1
155 * The size in bytes of the first array to be compared.
156 * @param data2
157 * The first array to be compared.
158 * @param size2
159 * The size in bytes of the second array to be compared.
160 * @returns
161 * a number between 0.0 and 1.0. The value 0.0 means the arrays
162 * are utterly un-alike, and 1.0 means the strings are identical.
163 * A value of -1 indicates and error (malloc failure).
164 */
165 double fmemcmp(const void *data1, size_t size1, const void *data2,
166 size_t size2);
167
168 /**
169 * The fmemcmpi function may be used to make a fuzzy comparison between
170 * two arrays of bytes.
171 *
172 * @param data1
173 * The first array to be compared.
174 * @param size1
175 * The size in bytes of the first array to be compared.
176 * @param data2
177 * The first array to be compared.
178 * @param size2
179 * The size in bytes of the second array to be compared.
180 * @returns
181 * a number between 0 and FSTRFCMPI_IDENTICAL. The value 0 means
182 * the strings are utterly un-alike, and FSTRFCMPI_IDENTICAL means
183 * the strings are identical. A value of FSTRFCMPI_ERROR indicates
184 * an error (malloc failure).
185 */
186 int fmemcmpi(const void *data1, size_t size1, const void *data2,
187 size_t size2);
188
189 /**
190 * The fwcscmp function may be used to make a fuzzy comparison between
191 * two wide-character strings.
192 *
193 * @param string1
194 * The first string to be compared.
195 * @param string2
196 * The first string to be compared.
197 * @returns
198 * a number between 0.0 and FSTRCMP_IDENTICAL. The value 0.0 means
199 * the strings are utterly un-alike, and FSTRCMP_IDENTICAL means the
200 * strings are identical. A value of FSTRCMP_ERROR indicates an
201 * error (malloc failure).
202 */
203 double fwcscmp(const wchar_t *string1, const wchar_t *string2);
204
205 /**
206 * The fwcscmpi function may be used to make a fuzzy comparison between
207 * two wide-character strings.
208 *
209 * @param string1
210 * The first string to be compared.
211 * @param string2
212 * The first string to be compared.
213 * @returns
214 * a number between 0 and FSTRCMPI_IDENTICAL. The value 0 means the
215 * strings are utterly un-alike, and FSTRCMPI_IDENTICAL means the
216 * strings are identical. A value of FSTRCMPI_ERROR indicates an
217 * error (malloc failure).
218 */
219 int fwcscmpi(const wchar_t *string1, const wchar_t *string2);
220
221 /**
222 * The fstrcoll function may be used to make a fuzzy comparison
223 * between two multi-byte-character strings. Note that this function's
224 * units of operation are characters, possibly multi-byte characters.
225 *
226 * The behavior of fstrcoll() depends on the LC_CTYPE category of the
227 * current locale.
228 *
229 * @param string1
230 * The first string to be compared.
231 * @param string2
232 * The first string to be compared.
233 * @returns
234 * a number between 0.0 and FSTRCMP_IDENTICAL. The value 0.0 means
235 * the strings are utterly un-alike, and FSTRCMP_IDENTICAL means the
236 * strings are identical. A value of FSTRCMP_ERROR indicates an
237 * error, either a malloc() failure or a mbstowcs() failure.
238 */
239 double fstrcoll(const char *string1, const char *string2);
240
241 /**
242 * The fstrcolli function may be used to make a fuzzy comparison
243 * between two multi-byte-character strings. Note that this function's
244 * units of operation are characters, possibly multi-byte characters.
245 *
246 * The behavior of fstrcolli() depends on the LC_CTYPE category of the
247 * current locale.
248 *
249 * @param string1
250 * The first string to be compared.
251 * @param string2
252 * The first string to be compared.
253 * @returns
254 * a number between 0 and FSTRCMPI_IDENTICAL. The value 0 means
255 * the strings are utterly un-alike, and FSTRCMPI_IDENTICAL means the
256 * strings are identical. A value of FSTRCMPI_ERROR indicates an
257 * error, either a malloc() failure or a mbstowcs() failure.
258 */
259 int fstrcolli(const char *string1, const char *string2);
260
261 #ifdef __cplusplus
262 }
263 #endif
264
265 #endif /* FSTRCMP_H */