sudachi/input_text/mod.rs
1/*
2 * Copyright (c) 2021 Works Applications Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17mod buffer;
18
19use crate::dic::category_type::CategoryType;
20use std::ops::Range;
21
22pub use self::buffer::InputBuffer;
23pub use self::buffer::InputEditor;
24
25/// Provides fast indexed access into the input text
26pub trait InputTextIndex {
27 /// Common character category inside the range. Indexed by chars.
28 fn cat_of_range(&self, range: Range<usize>) -> CategoryType;
29
30 /// Character category at char offset
31 fn cat_at_char(&self, offset: usize) -> CategoryType;
32
33 /// Number of chars to the right of the offset with the same character category
34 ///
35 /// Java name: getCharCategoryContinuousLength
36 fn cat_continuous_len(&self, offset: usize) -> usize;
37
38 /// Distance in chars between the char indexed by `index`
39 /// and the char, relative to it by `offset`.
40 /// Java name: getCodePointsOffsetLength
41 fn char_distance(&self, index: usize, offset: usize) -> usize;
42
43 /// Returns substring of original text by indices from the current text
44 fn orig_slice(&self, range: Range<usize>) -> &str;
45
46 /// Returns substring of the current (modified) text by indices from the current text
47 fn curr_slice(&self, range: Range<usize>) -> &str;
48
49 /// Translate range from current state to original. Byte-indexed.
50 fn to_orig(&self, range: Range<usize>) -> Range<usize>;
51}