diff options
Diffstat (limited to 'src/parser/conversion.rs')
| -rw-r--r-- | src/parser/conversion.rs | 17 | 
1 files changed, 17 insertions, 0 deletions
| diff --git a/src/parser/conversion.rs b/src/parser/conversion.rs index 5154f40..32461bf 100644 --- a/src/parser/conversion.rs +++ b/src/parser/conversion.rs @@ -72,6 +72,23 @@ pub fn convert_document(pairs: Pairs<Rule>) -> Result<e::Document, Error> {  	Ok(e::Document::with_children(toplevel))  } +/// Normalizes a name in terms of whitespace. Equivalent to docutils's +/// `docutils.nodes.whitespace_normalize_name`. +pub fn whitespace_normalize_name(name: &str) -> String { +	// Python's string.split() defines whitespace differently than Rust does. +	let split_iter = name.split( +		|ch: char| ch.is_whitespace() || (ch >= '\x1C' && ch <= '\x1F') +	).filter(|split| !split.is_empty()); +	let mut ret = String::new(); +	for split in split_iter { +		if !ret.is_empty() { +			ret.push(' '); +		} +		ret.push_str(split); +	} +	ret +} +  #[cfg(test)]  mod tests { | 
