pub mod named_conf;
pub mod zone_file;
pub use named_conf::write_named_conf;
pub use zone_file::write_zone_file;
#[derive(Debug, Clone)]
pub struct WriteOptions {
pub indent: usize,
pub modern_keywords: bool,
pub explicit_class: bool,
pub blank_between_statements: bool,
}
impl Default for WriteOptions {
fn default() -> Self {
Self {
indent: 4,
modern_keywords: true,
explicit_class: false,
blank_between_statements: true,
}
}
}
pub(super) fn indent(out: &mut String, depth: usize, opts: &WriteOptions) {
for _ in 0..depth * opts.indent {
out.push(' ');
}
}
pub(super) fn escape(s: &str) -> String {
let mut out = String::with_capacity(s.len() + 2);
for c in s.chars() {
match c {
'"' => out.push_str("\\\""),
'\\' => out.push_str("\\\\"),
_ => out.push(c),
}
}
out
}
pub(super) fn quoted(s: &str) -> String {
format!("\"{}\"", escape(s))
}