Crates.io | linurgy |
lib.rs | linurgy |
version | 0.6.0 |
source | src |
created_at | 2019-07-29 10:41:10.234706 |
updated_at | 2022-10-20 10:32:22.147102 |
description | Manipulate the output of multiple newlines. Replace/Insert/Append newlines with text. Input and output from stdio/files/buffers. |
homepage | |
repository | https://github.com/sonro/linurgy |
max_upload_size | |
id | 152607 |
size | 62,817 |
Rust library to manipulate multiple newlines.
Create a new String
with your edited text, or use buffers to pipe input and output into the
Editor
. This library has no additional dependencies.
Build a reusable Editor
with one of the convenient factory
functions. Use the edit
method to
create a new String
.
use linurgy::factory;
// appends an underscore "_" every 2 newlines "\n\n" => "\n\n_"
let editor = factory::appender("_", 2);
let output = editor.edit("foo\n\n");
assert_eq!("foo\n\n_", output);
Manipulate stdin
into stdout
by using the edit_buffered
method. This also works on files,
Cursor
s, or anything else that implements
BufRead
.
use linurgy::factory;
use std::io::{BufReader, Result, stdin, stdout};
// doubles every newline "\n" => "\n\n"
let editor = factory::appender("\n", 1);
// create a buffer over stdin
let mut input = BufReader::new(stdin());
// pipe input into editor and output to stdout
editor.edit_buffered(&mut input, &mut stdout())?;
Work with LF \n
or CRLF \r\n
line-endings. There are factory
functions for CRLF inputs.
use linurgy::factory;
// inserts a "*" before 2 newlines "\r\n\r\n" => "*\r\n\r\n"
let editor = factory::inserter_crlf("*", 2);
let output = editor.edit("foo\r\nbar\r\n\r\n");
// notice there is only an asterisk before the double newline
assert_eq!("foo\r\nbar*\r\n\r\n", output);
Thank you very much for considering to contribute to this project!
We welcome any form of contribution:
Note: Before you take the time to open a pull request, please open an issue first.
See CONTRIBUTING.md for details.
Linurgy is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.