sudachi/dic/read/
mod.rs

1/*
2 *  Copyright (c) 2021-2024 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
17pub(crate) mod u16str;
18pub(crate) mod word_info;
19
20use nom::number::complete::{le_u32, le_u8};
21use nom::Parser;
22
23use crate::dic::word_id::WordId;
24use crate::error::SudachiNomResult;
25
26pub fn u32_array_parser(input: &[u8]) -> SudachiNomResult<&[u8], Vec<u32>> {
27    let (rest, length) = le_u8(input)?;
28    nom::multi::count(le_u32, length as usize)(rest)
29}
30
31pub fn u32_wid_array_parser(input: &[u8]) -> SudachiNomResult<&[u8], Vec<WordId>> {
32    let (rest, length) = le_u8(input)?;
33    nom::multi::count(le_u32.map(WordId::from_raw), length as usize)(rest)
34}
35
36pub fn skip_wid_array(input: &[u8]) -> SudachiNomResult<&[u8], Vec<WordId>> {
37    let (rest, length) = le_u8(input)?;
38    let num_bytes = length as usize * 4;
39    let next = &rest[num_bytes..];
40    Ok((next, Vec::new()))
41}
42
43pub fn skip_u32_array(input: &[u8]) -> SudachiNomResult<&[u8], Vec<u32>> {
44    let (rest, length) = le_u8(input)?;
45    let num_bytes = length as usize * 4;
46    let next = &rest[num_bytes..];
47    Ok((next, Vec::new()))
48}
49
50pub fn u32_parser(input: &[u8]) -> SudachiNomResult<&[u8], u32> {
51    le_u32(input)
52}