use crate::{XML, XMLVersion};
pub struct XMLBuilder {
version: XMLVersion,
encoding: Option<String>,
standalone: Option<bool>,
indent: bool,
sort_attributes: bool,
break_lines: bool,
expand_empty_tags: bool,
}
impl Default for XMLBuilder {
fn default() -> Self {
Self {
version: XMLVersion::XML1_0,
encoding: None,
standalone: None,
indent: true,
sort_attributes: false,
break_lines: true,
expand_empty_tags: false,
}
}
}
impl XMLBuilder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub const fn version(mut self, version: XMLVersion) -> Self {
self.version = version;
self
}
#[must_use]
pub fn encoding(mut self, encoding: String) -> Self {
self.encoding = Some(encoding);
self
}
#[must_use]
pub const fn standalone(mut self, standalone: Option<bool>) -> Self {
self.standalone = standalone;
self
}
#[must_use]
pub const fn indent(mut self, indent: bool) -> Self {
self.indent = indent;
self
}
#[must_use]
pub const fn sort_attributes(mut self, sort: bool) -> Self {
self.sort_attributes = sort;
self
}
#[must_use]
pub const fn break_lines(mut self, break_lines: bool) -> Self {
self.break_lines = break_lines;
self
}
#[must_use]
pub const fn expand_empty_tags(mut self, expand_empty_tags: bool) -> Self {
self.expand_empty_tags = expand_empty_tags;
self
}
#[must_use]
pub fn build(self) -> XML {
XML::new(
self.version,
self.encoding,
self.standalone,
self.indent,
self.sort_attributes,
self.break_lines,
self.expand_empty_tags,
)
}
}