diff -r bfef9f34e438 -r 2d2eaba76d70 rust/parameter-lister/src/xmlmodule.rs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/parameter-lister/src/xmlmodule.rs Sat Oct 01 16:19:20 2016 +0200 @@ -0,0 +1,58 @@ +/** + * parameter-lister (Rust implementation) + * Copyright © 2016 Vojtěch Král + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +use std::io; + +use outputmodule::*; + +pub static MOD_NAME: &'static str = "xml"; + + +trait XMLEscape { + fn xml_escape(self) -> Self; +} + +impl XMLEscape for String { + fn xml_escape(self) -> String { + self.replace("&", "&").replace("<", "<").replace(">", ">") + } +} + + +pub struct XMLModule; + +impl XMLModule { + pub fn new() -> XMLModule { XMLModule } + + fn process_io(&self, output: &mut Write, parameters: Vec) -> io::Result<()> { + try!(write!(output, "\n")); + for p in parameters { + try!(write!(output, "\t{}\n", p.xml_escape())); + } + try!(write!(output, "\n")); + Ok(()) + } +} + +impl OutputModule for XMLModule { + fn process(&self, output: &mut Write, parameters: Vec) -> Result<(), String> { + match self.process_io(output, parameters) { + Ok(()) => Ok(()), + Err(err) => Err(format!("{}", err)), + } + } +}