1 | #[doc (hidden)] |
2 | #[macro_export ] |
3 | macro_rules! __for_range{ |
4 | ( $var:ident in $range:expr => $($for_body:tt)* )=>({ |
5 | let $crate::pmr::Range{start: mut $var, end} = $range; |
6 | while $var < end { |
7 | {$($for_body)*} |
8 | $var+=1; |
9 | } |
10 | }) |
11 | } |
12 | |
13 | macro_rules! identity { |
14 | ($($tt:tt)*) => { $($tt)* }; |
15 | } |
16 | |
17 | #[doc (hidden)] |
18 | #[macro_export ] |
19 | macro_rules! iter_copy_slice{ |
20 | ( $var:ident in $array:expr => $($for_body:tt)* )=>({ |
21 | let mut array: &[_] = &$array; |
22 | while let [$var, ref rem @ ..] = *array { |
23 | {$($for_body)*} |
24 | array = rem; |
25 | } |
26 | }) |
27 | } |
28 | |
29 | #[doc (hidden)] |
30 | #[macro_export ] |
31 | macro_rules! __write_pvariant { |
32 | (char, $parg:expr, $elem:ident => $out:ident) => {{ |
33 | let encoded = $elem.encoded(); |
34 | let len = $elem.len(); |
35 | |
36 | let mut start = 0; |
37 | while start < len { |
38 | $out.array[$out.len] = encoded[start]; |
39 | $out.len += 1; |
40 | start += 1; |
41 | } |
42 | }}; |
43 | (int, $parg:expr, $elem:ident => $out:ident) => {{ |
44 | let wrapper = $crate::pmr::PWrapper($elem); |
45 | |
46 | let debug_display; |
47 | let bin; |
48 | let hex; |
49 | |
50 | let sa: &$crate::pmr::StartAndArray<[_]> = match $parg.fmt { |
51 | $crate::pmr::Formatting::Display => { |
52 | debug_display = wrapper.to_start_array_display(); |
53 | &debug_display |
54 | } |
55 | $crate::pmr::Formatting::Debug => match $parg.fmt_flags.num_fmt() { |
56 | $crate::pmr::NumberFormatting::Decimal => { |
57 | debug_display = wrapper.to_start_array_debug(); |
58 | &debug_display |
59 | } |
60 | $crate::pmr::NumberFormatting::Binary => { |
61 | bin = wrapper.to_start_array_binary($parg.fmt_flags); |
62 | &bin |
63 | } |
64 | $crate::pmr::NumberFormatting::Hexadecimal => { |
65 | hex = wrapper.to_start_array_hexadecimal($parg.fmt_flags); |
66 | &hex |
67 | } |
68 | }, |
69 | }; |
70 | |
71 | let mut start = sa.start; |
72 | while start < sa.array.len() { |
73 | $out.array[$out.len] = sa.array[start]; |
74 | $out.len += 1; |
75 | start += 1; |
76 | } |
77 | }}; |
78 | (str, $parg:expr, $elem:ident => $out:ident) => {{ |
79 | let str = $elem.as_bytes(); |
80 | let is_display = $parg.fmt.is_display(); |
81 | let mut i = 0; |
82 | if is_display { |
83 | while i < str.len() { |
84 | $out.array[$out.len] = str[i]; |
85 | $out.len += 1; |
86 | i += 1; |
87 | } |
88 | } else { |
89 | $out.array[$out.len] = b'"' ; |
90 | $out.len += 1; |
91 | while i < str.len() { |
92 | use $crate::pmr::{hex_as_ascii, ForEscaping, FOR_ESCAPING}; |
93 | |
94 | let c = str[i]; |
95 | let mut written_c = c; |
96 | if c < 128 { |
97 | let shifted = 1 << c; |
98 | |
99 | if (FOR_ESCAPING.is_escaped & shifted) != 0 { |
100 | $out.array[$out.len] = b' \\' ; |
101 | $out.len += 1; |
102 | if (FOR_ESCAPING.is_backslash_escaped & shifted) == 0 { |
103 | $out.array[$out.len] = b'x' ; |
104 | $out.array[$out.len + 1] = |
105 | hex_as_ascii(c >> 4, $crate::pmr::HexFormatting::Upper); |
106 | $out.len += 2; |
107 | written_c = hex_as_ascii(c & 0b1111, $crate::pmr::HexFormatting::Upper); |
108 | } else { |
109 | written_c = ForEscaping::get_backslash_escape(c); |
110 | }; |
111 | } |
112 | } |
113 | $out.array[$out.len] = written_c; |
114 | $out.len += 1; |
115 | i += 1; |
116 | } |
117 | $out.array[$out.len] = b'"' ; |
118 | $out.len += 1; |
119 | } |
120 | }}; |
121 | } |
122 | |