Skip to content

Commit

Permalink
print bounded depth partial strings correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed Feb 7, 2022
1 parent 33a6c81 commit e4ea547
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/heap_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,15 +1188,19 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
self.state_stack.push(TokenOrRedirect::HeadTailSeparator);
}

for (char_count, c) in pstr.chars().rev().enumerate() {
let state_stack_len = self.state_stack.len();

for (char_count, c) in pstr.chars().enumerate() {
if max_depth > 0 && char_count + 1 >= max_depth {
break;
}

self.state_stack.push(TokenOrRedirect::Char(c));
self.state_stack.push(TokenOrRedirect::Comma);
self.state_stack.push(TokenOrRedirect::Char(c));
}

self.state_stack[state_stack_len ..].reverse();

if let Some(TokenOrRedirect::Comma) = self.state_stack.last() {
self.state_stack.pop();
}
Expand Down

0 comments on commit e4ea547

Please sign in to comment.