Expand description
§trim-newlines — trim newlines from the start and end of a string
Remove leading and/or trailing newline characters (\r and \n only — not other
whitespace) from a string. A faithful Rust port of the widely-used
trim-newlines npm package.
use trim_newlines::{trim_newlines, trim_newlines_start, trim_newlines_end};
assert_eq!(trim_newlines("\n\nfoo\n\n"), "foo");
assert_eq!(trim_newlines_start("\r\nbar\r\n"), "bar\r\n");
assert_eq!(trim_newlines_end("\r\nbar\r\n"), "\r\nbar");Only \r and \n are trimmed, so surrounding spaces or tabs are preserved. The functions
return a borrowed slice of the input (no allocation).
Zero dependencies and #![no_std].
Functions§
- trim_
newlines - Trim newlines (
\rand\n) from both ends ofstring. - trim_
newlines_ end - Trim newlines (
\rand\n) from the end ofstring. - trim_
newlines_ start - Trim newlines (
\rand\n) from the start ofstring.