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,
}
}
}