blob: 853207af4f3de8f150a839694e546f9cbd71a33e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/*
* Common tokenization functions
*/
#include <sys/types.h>
#include "tokenizers.h"
struct tokenizer tokenizers[] = {
{"osb-text", osb_tokenize_text, get_next_word },
};
struct tokenizer*
get_tokenizer (char *name)
{
int i;
for (i = 0; i < sizeof (tokenizers) / sizeof (tokenizers[0]); i ++) {
if (strcmp (tokenizers[i].name, name) == 0) {
return &tokenizers[i];
}
}
return NULL;
}
int
token_node_compare_func (gconstpointer a, gconstpointer b)
{
const token_node_t *aa = a, *bb = b;
if (aa->h1 == bb->h1) {
return aa->h2 - bb->h2;
}
return aa->h1 - bb->h1;
}
/* Get next word from specified f_str_t buf */
f_str_t *
get_next_word (f_str_t *buf, f_str_t *token)
{
size_t remain;
char *pos;
if (buf == NULL) {
return NULL;
}
if (token->begin == NULL) {
token->begin = buf->begin;
}
remain = buf->len - (token->begin - buf->begin);
if (remain <= 0) {
return NULL;
}
token->begin = token->begin + token->len;
token->len = 0;
pos = token->begin;
/* Skip non graph symbols */
while (remain-- && !g_ascii_isgraph (*pos ++)) {
token->begin ++;
}
while (remain-- && g_ascii_isgraph (*pos ++)) {
token->len ++;
}
return token;
}
/*
* vi:ts=4
*/
|