use crate::format::{
FormatCalendarStyle, FormatNumberStyle, FormatPart, FormatPartType, ValueFormatTrait,
};
use icu_locale_core::Locale;
#[derive(Debug)]
pub struct PartNumberBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartNumberBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Number),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn decimal_places(mut self, decimal_places: u8) -> Self {
self.part
.set_attr("number:decimal-places", decimal_places.to_string());
self
}
#[must_use]
pub fn fixed_decimal_places(mut self, decimal_places: u8) -> Self {
self.part
.set_attr("number:decimal-places", decimal_places.to_string());
self.part
.set_attr("number:min-decimal-places", decimal_places.to_string());
self
}
#[must_use]
pub fn grouping(mut self) -> Self {
self.part.set_attr("number:grouping", String::from("true"));
self
}
#[must_use]
pub fn min_decimal_places(mut self, min_decimal_places: u8) -> Self {
self.part
.set_attr("number:min-decimal-places", min_decimal_places.to_string());
self
}
#[must_use]
pub fn min_integer_digits(mut self, mininteger_digits: u8) -> Self {
self.part
.set_attr("number:min-integer-digits", mininteger_digits.to_string());
self
}
#[must_use]
pub fn display_factor(mut self, display_factor: f64) -> Self {
self.part
.set_attr("number:display-factor", display_factor.to_string());
self
}
#[must_use]
pub fn decimal_replacement(mut self, decimal_replacement: char) -> Self {
self.part.set_attr(
"number:decimal-replacement",
decimal_replacement.to_string(),
);
self
}
#[must_use]
pub fn embedded_text<S: Into<String>>(mut self, text: S, pos: i32) -> Self {
self.part.position = Some(pos);
self.part.content = Some(text.into());
self
}
}
#[derive(Debug)]
pub struct PartFillCharacterBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartFillCharacterBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::FillCharacter),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn fill_char(mut self, c: char) -> Self {
self.part.set_content(c.to_string());
self
}
}
#[derive(Debug)]
pub struct PartScientificBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartScientificBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::ScientificNumber),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn decimal_places(mut self, v: u8) -> Self {
self.part.set_attr("number:decimal-places", v.to_string());
self
}
#[must_use]
pub fn expontent_interval(mut self, v: u8) -> Self {
self.part
.set_attr("number:exponent-interval", v.to_string());
self
}
#[must_use]
pub fn forced_exponent_sign(mut self, v: bool) -> Self {
self.part
.set_attr("number:forced-exponent-sign", v.to_string());
self
}
#[must_use]
pub fn grouping(mut self) -> Self {
self.part.set_attr("number:grouping", String::from("true"));
self
}
#[must_use]
pub fn min_decimal_places(mut self, v: u8) -> Self {
self.part
.set_attr("number:min-decimal-places", v.to_string());
self
}
#[must_use]
pub fn min_exponent_digits(mut self, v: u8) -> Self {
self.part
.set_attr("number:min-exponent-digits", v.to_string());
self
}
#[must_use]
pub fn min_integer_digits(mut self, v: u8) -> Self {
self.part
.set_attr("number:min-integer-digits", v.to_string());
self
}
}
#[derive(Debug)]
pub struct PartFractionBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartFractionBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Fraction),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn denominator(mut self, v: i64) -> Self {
self.part
.set_attr("number:denominator-value", v.to_string());
self
}
#[must_use]
pub fn grouping(mut self) -> Self {
self.part.set_attr("number:grouping", String::from("true"));
self
}
#[must_use]
pub fn max_denominator(mut self, v: i64) -> Self {
self.part
.set_attr("number:max-denominator-value", v.to_string());
self
}
#[must_use]
pub fn min_denominator_digits(mut self, v: u8) -> Self {
self.part
.set_attr("number:min-denominator-digits", v.to_string());
self
}
#[must_use]
pub fn min_integer_digits(mut self, v: u8) -> Self {
self.part
.set_attr("number:min-numerator-digits", v.to_string());
self
}
#[must_use]
pub fn min_numerator_digits(mut self, v: u8) -> Self {
self.part
.set_attr("number:min-numerator-digits", v.to_string());
self
}
}
#[derive(Debug)]
pub struct PartCurrencySymbolBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartCurrencySymbolBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::CurrencySymbol),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn locale(mut self, v: Locale) -> Self {
self.part
.set_attr("number:language", v.id.language.to_string());
if let Some(region) = v.id.region {
self.part.set_attr("number:country", region.to_string());
}
if let Some(script) = v.id.script {
self.part.set_attr("number:script", script.to_string());
}
self
}
#[must_use]
pub fn symbol<S: Into<String>>(mut self, v: S) -> Self {
self.part.set_content(v.into());
self
}
}
#[derive(Debug)]
pub struct PartDayBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartDayBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Day),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn long_style(mut self) -> Self {
self.part.set_attr("number:style", "long".to_string());
self
}
#[must_use]
pub fn short_style(mut self) -> Self {
self.part.set_attr("number:style", "short".to_string());
self
}
#[must_use]
pub fn style(mut self, style: FormatNumberStyle) -> Self {
self.part.set_attr("number:style", style.to_string());
self
}
#[must_use]
pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
self.part.set_attr("number:calendar", calendar.to_string());
self
}
}
#[derive(Debug)]
pub struct PartMonthBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartMonthBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Month),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn long_style(mut self) -> Self {
self.part.set_attr("number:style", "long".to_string());
self
}
#[must_use]
pub fn short_style(mut self) -> Self {
self.part.set_attr("number:style", "short".to_string());
self
}
#[must_use]
pub fn style(mut self, style: FormatNumberStyle) -> Self {
self.part.set_attr("number:style", style.to_string());
self
}
#[must_use]
pub fn textual(mut self) -> Self {
self.part.set_attr("number:textual", true.to_string());
self
}
#[must_use]
pub fn possessive_form(mut self) -> Self {
self.part
.set_attr("number:possessive-form", true.to_string());
self
}
#[must_use]
pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
self.part.set_attr("number:calendar", calendar.to_string());
self
}
}
#[derive(Debug)]
pub struct PartYearBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartYearBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Year),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn long_style(mut self) -> Self {
self.part.set_attr("number:style", "long".to_string());
self
}
#[must_use]
pub fn short_style(mut self) -> Self {
self.part.set_attr("number:style", "short".to_string());
self
}
#[must_use]
pub fn style(mut self, style: FormatNumberStyle) -> Self {
self.part.set_attr("number:style", style.to_string());
self
}
#[must_use]
pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
self.part.set_attr("number:calendar", calendar.to_string());
self
}
}
#[derive(Debug)]
pub struct PartEraBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartEraBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Era),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn long_style(mut self) -> Self {
self.part.set_attr("number:style", "long".to_string());
self
}
#[must_use]
pub fn short_style(mut self) -> Self {
self.part.set_attr("number:style", "short".to_string());
self
}
#[must_use]
pub fn style(mut self, style: FormatNumberStyle) -> Self {
self.part.set_attr("number:style", style.to_string());
self
}
#[must_use]
pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
self.part.set_attr("number:calendar", calendar.to_string());
self
}
}
#[derive(Debug)]
pub struct PartDayOfWeekBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartDayOfWeekBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::DayOfWeek),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn long_style(mut self) -> Self {
self.part.set_attr("number:style", "long".to_string());
self
}
#[must_use]
pub fn short_style(mut self) -> Self {
self.part.set_attr("number:style", "short".to_string());
self
}
#[must_use]
pub fn style(mut self, style: FormatNumberStyle) -> Self {
self.part.set_attr("number:style", style.to_string());
self
}
#[must_use]
pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
self.part.set_attr("number:calendar", calendar.to_string());
self
}
}
#[derive(Debug)]
pub struct PartWeekOfYearBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartWeekOfYearBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::WeekOfYear),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
self.part.set_attr("number:calendar", calendar.to_string());
self
}
}
#[derive(Debug)]
pub struct PartQuarterBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartQuarterBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Quarter),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn long_style(mut self) -> Self {
self.part.set_attr("number:style", "long".to_string());
self
}
#[must_use]
pub fn short_style(mut self) -> Self {
self.part.set_attr("number:style", "short".to_string());
self
}
#[must_use]
pub fn style(mut self, style: FormatNumberStyle) -> Self {
self.part.set_attr("number:style", style.to_string());
self
}
#[must_use]
pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
self.part.set_attr("number:calendar", calendar.to_string());
self
}
}
#[derive(Debug)]
pub struct PartHoursBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartHoursBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Hours),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn long_style(mut self) -> Self {
self.part.set_attr("number:style", "long".to_string());
self
}
#[must_use]
pub fn short_style(mut self) -> Self {
self.part.set_attr("number:style", "short".to_string());
self
}
#[must_use]
pub fn style(mut self, style: FormatNumberStyle) -> Self {
self.part.set_attr("number:style", style.to_string());
self
}
}
#[derive(Debug)]
pub struct PartMinutesBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartMinutesBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Minutes),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn long_style(mut self) -> Self {
self.part.set_attr("number:style", "long".to_string());
self
}
#[must_use]
pub fn short_style(mut self) -> Self {
self.part.set_attr("number:style", "short".to_string());
self
}
#[must_use]
pub fn style(mut self, style: FormatNumberStyle) -> Self {
self.part.set_attr("number:style", style.to_string());
self
}
}
#[derive(Debug)]
pub struct PartSecondsBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartSecondsBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Seconds),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn decimal_places(mut self, decimal_places: u8) -> Self {
self.part
.set_attr("number:decimal-places", decimal_places.to_string());
self
}
#[must_use]
pub fn long_style(mut self) -> Self {
self.part.set_attr("number:style", "long".to_string());
self
}
#[must_use]
pub fn short_style(mut self) -> Self {
self.part.set_attr("number:style", "short".to_string());
self
}
#[must_use]
pub fn style(mut self, style: FormatNumberStyle) -> Self {
self.part.set_attr("number:style", style.to_string());
self
}
}
#[derive(Debug)]
pub struct PartAmPmBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartAmPmBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::AmPm),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
}
#[derive(Debug)]
pub struct PartBooleanBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartBooleanBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Boolean),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
}
#[derive(Debug)]
pub struct PartTextBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartTextBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::Text),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
#[must_use]
pub fn if_then<F>(self, test: bool, build: F) -> Self
where
F: Fn(Self) -> Self,
{
if test {
build(self)
} else {
self
}
}
#[must_use]
pub fn text<S: Into<String>>(mut self, txt: S) -> Self {
self.part.set_content(txt.into());
self
}
}
#[derive(Debug)]
pub struct PartTextContentBuilder<'vf, T: ValueFormatTrait> {
part: FormatPart,
valueformat: &'vf mut T,
}
impl<'vf, T: ValueFormatTrait> PartTextContentBuilder<'vf, T> {
pub fn new<'a>(valueformat: &'a mut T) -> Self
where
'a: 'vf,
{
Self {
part: FormatPart::new(FormatPartType::TextContent),
valueformat,
}
}
pub fn build(self) {
self.valueformat.push_part(self.part);
}
}