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
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct TextBlock {
pub offset: usize,
pub length: usize,
}
impl TextBlock {
pub fn get_text(&self, text: &str) -> String {
let mut res: Vec<u16> = Vec::with_capacity(self.length);
for (i, point) in text.encode_utf16().enumerate() {
if (self.offset + self.length) <= i {
break;
}
if self.offset <= i {
res.push(point)
}
}
String::from_utf16_lossy(res.as_slice())
}
}