1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use crate::formatter::*;
use core::cmp;
#[derive(Debug, Default, Copy, Clone)]
pub struct NumberFormattingOptions<'a> {
pub prefix: &'a str,
pub suffix: &'a str,
pub digit_separator: &'a str,
pub digit_group_size: u8,
pub number_base: NumberBase,
pub uppercase_hex: bool,
pub small_hex_numbers_in_decimal: bool,
pub add_leading_zero_to_hex_numbers: bool,
pub leading_zeros: bool,
pub signed_number: bool,
pub displacement_leading_zeros: bool,
}
impl<'a> NumberFormattingOptions<'a> {
#[inline]
#[must_use]
pub fn with_immediate(options: &'a FormatterOptions) -> Self {
NumberFormattingOptions::new(options, options.leading_zeros(), options.signed_immediate_operands(), false)
}
#[inline]
#[must_use]
pub fn with_displacement(options: &'a FormatterOptions) -> Self {
NumberFormattingOptions::new(options, options.leading_zeros(), options.signed_memory_displacements(), options.displacement_leading_zeros())
}
#[inline]
#[must_use]
pub fn with_branch(options: &'a FormatterOptions) -> Self {
NumberFormattingOptions::new(options, options.branch_leading_zeros(), false, false)
}
#[inline]
#[must_use]
#[allow(clippy::missing_inline_in_public_items)]
pub fn new(options: &'a FormatterOptions, leading_zeros: bool, signed_number: bool, displacement_leading_zeros: bool) -> Self {
let (digit_group_size, prefix, suffix) = match options.number_base() {
NumberBase::Hexadecimal => (options.hex_digit_group_size(), options.hex_prefix(), options.hex_suffix()),
NumberBase::Decimal => (options.decimal_digit_group_size(), options.decimal_prefix(), options.decimal_suffix()),
NumberBase::Octal => (options.octal_digit_group_size(), options.octal_prefix(), options.octal_suffix()),
NumberBase::Binary => (options.binary_digit_group_size(), options.binary_prefix(), options.binary_suffix()),
};
Self {
prefix,
suffix,
digit_separator: options.digit_separator(),
digit_group_size: cmp::min(u8::MAX as u32, digit_group_size) as u8,
number_base: options.number_base(),
uppercase_hex: options.uppercase_hex(),
small_hex_numbers_in_decimal: options.small_hex_numbers_in_decimal(),
add_leading_zero_to_hex_numbers: options.add_leading_zero_to_hex_numbers(),
leading_zeros,
signed_number,
displacement_leading_zeros,
}
}
}