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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! Common types and constants shared across the extension.
//!
//! This module defines the fundamental types and constants used for FFI communication
//! between Rust and SQLite's C API.
use TryFrom;
use ;
use Tokenizer;
// sqlite3.h
/// SQLite success status code.
///
/// Returned by functions to indicate successful completion.
/// Value: 0
pub const SQLITE_OK: c_int = 0;
/// SQLite internal error status code.
///
/// Indicates an internal error in SQLite or the extension.
/// Used when unexpected errors occur during tokenization or initialization.
/// Value: 2
pub const SQLITE_INTERNAL: c_int = 2;
/// SQLite misuse error status code.
///
/// Indicates the library is being used incorrectly.
/// Used when version requirements are not met.
/// Value: 21
pub const SQLITE_MISUSE: c_int = 21;
/// Wrapper for Lindera tokenizer used in FTS5.
///
/// This structure wraps the Lindera [`Tokenizer`] for use in the FTS5 tokenizer API.
/// Each FTS5 table using the Lindera tokenizer will have its own instance of this struct.
///
/// # Memory Management
///
/// Instances are heap-allocated in [`fts5_create_lindera_tokenizer`](crate::extension::fts5_create_lindera_tokenizer)
/// and deallocated in [`fts5_delete_lindera_tokenizer`](crate::extension::fts5_delete_lindera_tokenizer).
/// Convenience wrapper around SQLite's token callback.
///
/// This helper keeps the unsafe FFI boundary localized and provides
/// clear intent when emitting tokens from Rust back into SQLite.
/// Runs an operation behind a panic boundary suitable for the SQLite FFI.
///
/// Any panic is translated to [`SQLITE_INTERNAL`], mirroring SQLite's
/// expectation that FFI callbacks never unwind across the boundary.
/// Token callback function type.
///
/// This type represents the callback function provided by SQLite FTS5 for each token
/// produced during tokenization. The extension calls this function once per token.
///
/// # Parameters
///
/// - `p_ctx` - Context pointer passed through from the tokenization call
/// - `t_flags` - Token flags (currently always 0 in this implementation)
/// - `p_token` - Pointer to the token text (UTF-8 encoded)
/// - `n_token` - Length of the token in bytes
/// - `i_start` - Byte offset where the token starts in the original text
/// - `i_end` - Byte offset where the token ends in the original text
///
/// # Returns
///
/// - [`SQLITE_OK`] - Token processed successfully, continue tokenization
/// - Other codes - Error occurred, stop tokenization
///
/// # Example Flow
///
/// ```text
/// Input: "日本語" (9 bytes in UTF-8)
///
/// Callback 1: token="日本", n_token=6, i_start=0, i_end=6
/// Callback 2: token="語", n_token=3, i_start=6, i_end=9
/// ```
pub type TokenFunction = extern "C" fn ;