1 | use crate::algorithm::{self, BeginToken, BreakToken, Breaks, Printer}; |
2 | use std::borrow::Cow; |
3 | |
4 | impl Printer { |
5 | pub fn ibox(&mut self, indent: isize) { |
6 | self.scan_begin(BeginToken { |
7 | offset: indent, |
8 | breaks: Breaks::Inconsistent, |
9 | }); |
10 | } |
11 | |
12 | pub fn cbox(&mut self, indent: isize) { |
13 | self.scan_begin(BeginToken { |
14 | offset: indent, |
15 | breaks: Breaks::Consistent, |
16 | }); |
17 | } |
18 | |
19 | pub fn end(&mut self) { |
20 | self.scan_end(); |
21 | } |
22 | |
23 | pub fn word<S: Into<Cow<'static, str>>>(&mut self, wrd: S) { |
24 | let s = wrd.into(); |
25 | self.scan_string(s); |
26 | } |
27 | |
28 | fn spaces(&mut self, n: usize) { |
29 | self.scan_break(BreakToken { |
30 | blank_space: n, |
31 | ..BreakToken::default() |
32 | }); |
33 | } |
34 | |
35 | pub fn zerobreak(&mut self) { |
36 | self.spaces(0); |
37 | } |
38 | |
39 | pub fn space(&mut self) { |
40 | self.spaces(1); |
41 | } |
42 | |
43 | pub fn nbsp(&mut self) { |
44 | self.word(" " ); |
45 | } |
46 | |
47 | pub fn hardbreak(&mut self) { |
48 | self.spaces(algorithm::SIZE_INFINITY as usize); |
49 | } |
50 | |
51 | pub fn space_if_nonempty(&mut self) { |
52 | self.scan_break(BreakToken { |
53 | blank_space: 1, |
54 | if_nonempty: true, |
55 | ..BreakToken::default() |
56 | }); |
57 | } |
58 | |
59 | pub fn hardbreak_if_nonempty(&mut self) { |
60 | self.scan_break(BreakToken { |
61 | blank_space: algorithm::SIZE_INFINITY as usize, |
62 | if_nonempty: true, |
63 | ..BreakToken::default() |
64 | }); |
65 | } |
66 | |
67 | pub fn trailing_comma(&mut self, is_last: bool) { |
68 | if is_last { |
69 | self.scan_break(BreakToken { |
70 | pre_break: Some(',' ), |
71 | ..BreakToken::default() |
72 | }); |
73 | } else { |
74 | self.word("," ); |
75 | self.space(); |
76 | } |
77 | } |
78 | |
79 | pub fn trailing_comma_or_space(&mut self, is_last: bool) { |
80 | if is_last { |
81 | self.scan_break(BreakToken { |
82 | blank_space: 1, |
83 | pre_break: Some(',' ), |
84 | ..BreakToken::default() |
85 | }); |
86 | } else { |
87 | self.word("," ); |
88 | self.space(); |
89 | } |
90 | } |
91 | |
92 | pub fn neverbreak(&mut self) { |
93 | self.scan_break(BreakToken { |
94 | never_break: true, |
95 | ..BreakToken::default() |
96 | }); |
97 | } |
98 | } |
99 | |