use crate::error::Result;
use crate::shared_strings::SharedStrings;
use crate::xml;
use quick_xml::events::{BytesEnd, BytesStart, Event};
pub fn write<W: std::io::Write>(sink: W, strings: &SharedStrings) -> Result<()> {
let mut writer = xml::writer(sink);
let mut root = BytesStart::new("sst");
root.push_attribute(("xmlns", xml::NS_MAIN));
root.push_attribute(("count", strings.len().to_string().as_str()));
root.push_attribute(("uniqueCount", strings.len().to_string().as_str()));
writer.write_event(Event::Start(root))?;
for (_, s) in strings.iter() {
writer.write_event(Event::Start(BytesStart::new("si")))?;
writer.write_event(Event::Start(BytesStart::new("t")))?;
xml::write_text(&mut writer, s)?;
writer.write_event(Event::End(BytesEnd::new("t")))?;
writer.write_event(Event::End(BytesEnd::new("si")))?;
}
writer.write_event(Event::End(BytesEnd::new("sst")))?;
Ok(())
}