Expand description

An easy to use library for manipulating multiple newlines.

Create an Editor with one of the six factory functions to suit your line editing needs. Or create one directly with Editor::new.

Examples

General

Replace all newlines with spaces.

let editor = factory::replacer(" ", 1);
let output = editor.edit("foo\nbar");
assert_eq!("foo bar", output);

Add a tab after every double newline.

let editor = factory::appender("\t", 2);
let output = editor.edit("foo \n bar \n\n baz");
assert_eq!("foo \n bar \n\n\t baz", output);

Working with CRLF

Insert dahes before every CRLF newline.

let editor = factory::inserter_crlf("---", 1);
let output = editor.edit("foo\r\nbar");
assert_eq!("foo---\r\nbar", output);

Replace CRLF with a LF.

let editor = factory::replacer_crlf("\n", 1);
let output = editor.edit("foo\r\nbar");
assert_eq!("foo\nbar", output);

Working with buffered streams

Add double lines from stdin to stdout.

let editor = factory::appender("\n", 1);
let mut input = BufReader::new(stdin());
editor.edit_buffered(&mut input, &mut stdout())?;

Add an extra line of dashes to every 2 newlines. Using a Cursor as input (type that implments BufRead). Output is a Vec<u8> (type that implements Write).

let editor = factory::appender("---\n", 2);
let mut input = Cursor::new("foo\n\nbar");
let mut output = Vec::new();
editor.edit_buffered(&mut input, &mut output)?;
assert_eq!("foo\n\n---\nbar", from_utf8(&output)?);

Modules

Convenience functions for creating a configuired Editor. Variations are based on the desired type of edit: append, insert, or replace. Each has a CRLF version.

Structs

Line-ending text editor

Enums

The two types of newline.