OLD | NEW |
1 /* | 1 /* |
2 ** 2006 Oct 10 | 2 ** 2006 Oct 10 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 11 matching lines...) Expand all Loading... |
22 ** * The FTS2 module is being built into the core of | 22 ** * The FTS2 module is being built into the core of |
23 ** SQLite (in which case SQLITE_ENABLE_FTS2 is defined). | 23 ** SQLite (in which case SQLITE_ENABLE_FTS2 is defined). |
24 */ | 24 */ |
25 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) | 25 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) |
26 | 26 |
27 | 27 |
28 #include <assert.h> | 28 #include <assert.h> |
29 #include <stdlib.h> | 29 #include <stdlib.h> |
30 #include <stdio.h> | 30 #include <stdio.h> |
31 #include <string.h> | 31 #include <string.h> |
32 #include <ctype.h> | |
33 | 32 |
34 #include "fts2_tokenizer.h" | 33 #include "fts2_tokenizer.h" |
35 | 34 |
36 typedef struct simple_tokenizer { | 35 typedef struct simple_tokenizer { |
37 sqlite3_tokenizer base; | 36 sqlite3_tokenizer base; |
38 char delim[128]; /* flag ASCII delimiters */ | 37 char delim[128]; /* flag ASCII delimiters */ |
39 } simple_tokenizer; | 38 } simple_tokenizer; |
40 | 39 |
41 typedef struct simple_tokenizer_cursor { | 40 typedef struct simple_tokenizer_cursor { |
42 sqlite3_tokenizer_cursor base; | 41 sqlite3_tokenizer_cursor base; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 if( ch>=0x80 ){ | 81 if( ch>=0x80 ){ |
83 sqlite3_free(t); | 82 sqlite3_free(t); |
84 return SQLITE_ERROR; | 83 return SQLITE_ERROR; |
85 } | 84 } |
86 t->delim[ch] = 1; | 85 t->delim[ch] = 1; |
87 } | 86 } |
88 } else { | 87 } else { |
89 /* Mark non-alphanumeric ASCII characters as delimiters */ | 88 /* Mark non-alphanumeric ASCII characters as delimiters */ |
90 int i; | 89 int i; |
91 for(i=1; i<0x80; i++){ | 90 for(i=1; i<0x80; i++){ |
92 t->delim[i] = !isalnum(i); | 91 t->delim[i] = !((i>='0' && i<='9') || (i>='A' && i<='Z') || |
| 92 (i>='a' && i<='z')); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 *ppTokenizer = &t->base; | 96 *ppTokenizer = &t->base; |
97 return SQLITE_OK; | 97 return SQLITE_OK; |
98 } | 98 } |
99 | 99 |
100 /* | 100 /* |
101 ** Destroy a tokenizer | 101 ** Destroy a tokenizer |
102 */ | 102 */ |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 if( n>c->nTokenAllocated ){ | 184 if( n>c->nTokenAllocated ){ |
185 c->nTokenAllocated = n+20; | 185 c->nTokenAllocated = n+20; |
186 c->pToken = sqlite3_realloc(c->pToken, c->nTokenAllocated); | 186 c->pToken = sqlite3_realloc(c->pToken, c->nTokenAllocated); |
187 if( c->pToken==NULL ) return SQLITE_NOMEM; | 187 if( c->pToken==NULL ) return SQLITE_NOMEM; |
188 } | 188 } |
189 for(i=0; i<n; i++){ | 189 for(i=0; i<n; i++){ |
190 /* TODO(shess) This needs expansion to handle UTF-8 | 190 /* TODO(shess) This needs expansion to handle UTF-8 |
191 ** case-insensitivity. | 191 ** case-insensitivity. |
192 */ | 192 */ |
193 unsigned char ch = p[iStartOffset+i]; | 193 unsigned char ch = p[iStartOffset+i]; |
194 c->pToken[i] = (ch>='A' && ch<='Z') ? (ch-'A'+'a') : ch; | 194 c->pToken[i] = (ch>='A' && ch<='Z') ? (ch - 'A' + 'a') : ch; |
195 } | 195 } |
196 *ppToken = c->pToken; | 196 *ppToken = c->pToken; |
197 *pnBytes = n; | 197 *pnBytes = n; |
198 *piStartOffset = iStartOffset; | 198 *piStartOffset = iStartOffset; |
199 *piEndOffset = c->iOffset; | 199 *piEndOffset = c->iOffset; |
200 *piPosition = c->iToken++; | 200 *piPosition = c->iToken++; |
201 | 201 |
202 return SQLITE_OK; | 202 return SQLITE_OK; |
203 } | 203 } |
204 } | 204 } |
(...skipping 16 matching lines...) Expand all Loading... |
221 ** Allocate a new simple tokenizer. Return a pointer to the new | 221 ** Allocate a new simple tokenizer. Return a pointer to the new |
222 ** tokenizer in *ppModule | 222 ** tokenizer in *ppModule |
223 */ | 223 */ |
224 void sqlite3Fts2SimpleTokenizerModule( | 224 void sqlite3Fts2SimpleTokenizerModule( |
225 sqlite3_tokenizer_module const**ppModule | 225 sqlite3_tokenizer_module const**ppModule |
226 ){ | 226 ){ |
227 *ppModule = &simpleTokenizerModule; | 227 *ppModule = &simpleTokenizerModule; |
228 } | 228 } |
229 | 229 |
230 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) */ | 230 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) */ |
OLD | NEW |