[][src]Function gpp::process_line

pub fn process_line(line: &str, context: &mut Context) -> Result<String, Error>

Process a string line of input.

This is the smallest processing function, and all other processing functions are wrappers around it. It only processes singular lines, and will not work on any string that contains newlines unless that newline is at the end.

It returns a Result<String, Error>. If an error occurs, then the Result will be that error. Otherwise, the returned string is the output. If the input did not contain a newline at the end, then this function will add it.

Examples

let mut context = gpp::Context::new();
context.macros.insert("Foo".to_string(), "Two".to_string());

assert_eq!(gpp::process_line("One Foo Three", &mut context).unwrap(), "One Two Three\n");
let mut context = gpp::Context::new();

assert_eq!(gpp::process_line("#define Foo Bar", &mut context).unwrap(), "");
assert_eq!(context.macros.get("Foo").unwrap(), "Bar");