1 #ifndef SCORER_H
2 #define SCORER_H
3 #include <limits.h>
4 
5 struct scorer_query {
6 	const char *pattern;
7 	int right_match;
8 };
9 
10 struct filter_result {
11 	int index;
12 	int score;
13 	int dirscore;
14 	short last_match_pos;
15 	short first_dir_match_pos;
16 };
17 
18 struct prepared_pattern {
19 	char *translated_pattern;
20 	char *start_of_pattern_word;
21 	unsigned pat_length;
22 	char first_chars[8];
23 	char fc_count;
24 };
25 
26 extern int scorer_utf8_mode; // on by default
27 
28 static inline
utf8_continuation_p(char p)29 int utf8_continuation_p(char p)
30 {
31 	return (p & 0xc0) == 0x80;
32 }
33 
34 // signals that there are no highlight-able match in this pattern position
35 #define SCORER_MATCH_NONE UINT_MAX
36 
37 int score_string(const char *string, const struct scorer_query *query, const unsigned string_length, unsigned* match);
38 int score_simple_string(const char *string, const char *pattern, unsigned *match);
39 
40 struct prepared_pattern *prepare_pattern(const struct scorer_query *query);
41 void free_prepared_pattern(struct prepared_pattern *p);
42 
43 int score_string_prepared(const char *string,
44 			  const struct scorer_query *query,
45 			  const struct prepared_pattern *prepared_pattern,
46 			  const unsigned string_length,
47 			  unsigned* match);
48 
49 void prepare_scorer(void);
50 
51 
52 #endif
53