Skip to content

Commit

Permalink
Make use of jump_take!
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Aug 18, 2023
1 parent 712a4ad commit 1b0acf3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/compact1/font_set/character_name_keyed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ impl<'l> Walue<'l> for Record {

fn read<T: Tape>(tape: &mut T, (position, top_operations): Self::Parameter) -> Result<Self> {
let (size, offset) = get!(@double top_operations, Private);
tape.jump(position + offset as u64)?;
let chunk = tape.take_given::<Vec<u8>>(size as usize)?;
let chunk: Vec<u8> = jump_take_given!(@unwrap tape, position, offset, size as usize);
let operations = Cursor::new(chunk).take::<Operations>()?;
let subroutines = match get!(@try @single operations, Subrs) {
Some(another_offset) => {
tape.jump(position + offset as u64 + another_offset as u64)?;
tape.take()?
}
Some(another_offset) => jump_take!(@unwrap tape, position, offset + another_offset),
_ => Default::default(),
};
Ok(Self {
Expand Down
21 changes: 15 additions & 6 deletions src/compact1/font_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,27 @@ impl Value for FontSet {
let subroutines = tape.take::<Subroutines>()?;
let mut encodings = vec![];
let mut character_sets = vec![];
let mut character_strings = vec![];
let mut character_strings: Vec<CharacterStrings> = vec![];
let mut records = vec![];
for (i, operations) in operations.iter().enumerate() {
character_strings.push({
tape.jump(position + get!(@single operations, CharStrings) as u64)?;
tape.take_given::<CharacterStrings>(get!(@single operations, CharStringType))?
});
character_strings.push(jump_take_given!(
@unwrap
tape,
position,
get!(@single operations, CharStrings),
get!(@single operations, CharStringType)
));
character_sets.push(match get!(@single operations, CharSet) {
0 => CharacterSet::ISOAdobe,
1 => CharacterSet::Expert,
2 => CharacterSet::ExpertSubset,
offset => jump_take_given!(@unwrap tape, position, offset, character_strings[i].count as usize),
offset => jump_take_given!(
@unwrap
tape,
position,
offset,
character_strings[i].count as usize
),
});
encodings.push(match get!(@single operations, Encoding) {
0 => Encoding::Standard,
Expand Down

0 comments on commit 1b0acf3

Please sign in to comment.