1use nom::number::complete::le_i16;
18
19use crate::error::SudachiResult;
20
21use super::read::utf16_string::utf16_string;
22
23pub const POS_DEPTH: usize = 6;
24
25#[allow(clippy::upper_case_acronyms)]
29type POS = Vec<String>;
30
31#[derive(Clone, Debug, Default)]
32pub struct PosList(Vec<POS>);
33
34impl From<PosList> for Vec<POS> {
35 fn from(val: PosList) -> Self {
36 val.0
37 }
38}
39
40impl std::ops::Deref for PosList {
41 type Target = Vec<POS>;
42 fn deref(&self) -> &Vec<POS> {
43 &self.0
44 }
45}
46
47impl std::ops::DerefMut for PosList {
48 fn deref_mut(&mut self) -> &mut Vec<POS> {
49 &mut self.0
50 }
51}
52
53impl IntoIterator for PosList {
54 type Item = POS;
55 type IntoIter = std::vec::IntoIter<Self::Item>;
56 fn into_iter(self) -> Self::IntoIter {
57 self.0.into_iter()
58 }
59}
60
61impl PosList {
62 pub fn from_bytes(buf: &[u8]) -> SudachiResult<Self> {
63 let (rest, num_pos) = le_i16(buf)?;
64 let (_rest, pos_list) =
65 nom::multi::count(nom::multi::count(utf16_string, POS_DEPTH), num_pos as usize)(rest)?;
66 Ok(PosList(pos_list))
67 }
68}