Remove unnecessary lifetimes.
This commit is contained in:
parent
fafd85fb30
commit
192a4a2891
@ -3,7 +3,7 @@ use std::borrow::Cow;
|
|||||||
/// Removes all whitespace from a string if any line breaks are present.
|
/// Removes all whitespace from a string if any line breaks are present.
|
||||||
///
|
///
|
||||||
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foobar".
|
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foobar".
|
||||||
pub(crate) fn remove_whitespace_if_line_break<'s>(input: &'s str) -> Cow<'s, str> {
|
pub(crate) fn remove_whitespace_if_line_break(input: &str) -> Cow<'_, str> {
|
||||||
let mut state = RemoveWhitespaceIfLineBreakState::Normal;
|
let mut state = RemoveWhitespaceIfLineBreakState::Normal;
|
||||||
for (offset, c) in input.char_indices() {
|
for (offset, c) in input.char_indices() {
|
||||||
match (&mut state, c) {
|
match (&mut state, c) {
|
||||||
@ -49,7 +49,7 @@ enum RemoveWhitespaceIfLineBreakState {
|
|||||||
/// Removes all line breaks from a string
|
/// Removes all line breaks from a string
|
||||||
///
|
///
|
||||||
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foo bar".
|
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foo bar".
|
||||||
pub(crate) fn remove_line_break<'s>(input: &'s str) -> Cow<'s, str> {
|
pub(crate) fn remove_line_break(input: &str) -> Cow<'_, str> {
|
||||||
let mut state = RemoveLineBreakState::Normal;
|
let mut state = RemoveLineBreakState::Normal;
|
||||||
for (offset, c) in input.char_indices() {
|
for (offset, c) in input.char_indices() {
|
||||||
match (&mut state, c) {
|
match (&mut state, c) {
|
||||||
@ -79,7 +79,7 @@ enum RemoveLineBreakState {
|
|||||||
/// Removes all whitespace from a string if any line breaks are present.
|
/// Removes all whitespace from a string if any line breaks are present.
|
||||||
///
|
///
|
||||||
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foobar".
|
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foobar".
|
||||||
pub(crate) fn coalesce_whitespace_if_line_break<'s>(input: &'s str) -> Cow<'s, str> {
|
pub(crate) fn coalesce_whitespace_if_line_break(input: &str) -> Cow<'_, str> {
|
||||||
let mut state = CoalesceWhitespaceIfLineBreakState::Normal;
|
let mut state = CoalesceWhitespaceIfLineBreakState::Normal;
|
||||||
for (offset, c) in input.char_indices() {
|
for (offset, c) in input.char_indices() {
|
||||||
match (&mut state, c) {
|
match (&mut state, c) {
|
||||||
@ -202,7 +202,7 @@ enum CoalesceWhitespaceIfLineBreakState {
|
|||||||
///
|
///
|
||||||
/// Example: "foo bar" => "foobar" and "foo \n bar" => "foobar".
|
/// Example: "foo bar" => "foobar" and "foo \n bar" => "foobar".
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn coalesce_whitespace<'s>(input: &'s str) -> Cow<'s, str> {
|
pub(crate) fn coalesce_whitespace(input: &str) -> Cow<'_, str> {
|
||||||
let mut state = CoalesceWhitespace::Normal;
|
let mut state = CoalesceWhitespace::Normal;
|
||||||
for (offset, c) in input.char_indices() {
|
for (offset, c) in input.char_indices() {
|
||||||
match (&mut state, c) {
|
match (&mut state, c) {
|
||||||
@ -248,18 +248,18 @@ enum CoalesceWhitespace {
|
|||||||
/// Removes all whitespace from a string and handle escaping characters.
|
/// Removes all whitespace from a string and handle escaping characters.
|
||||||
///
|
///
|
||||||
/// Example: "foo bar" => "foobar" and "foo \n bar" => "foobar" but if the escape character is backslash and comma is an escapable character than "foo\,bar" becomes "foo,bar".
|
/// Example: "foo bar" => "foobar" and "foo \n bar" => "foobar" but if the escape character is backslash and comma is an escapable character than "foo\,bar" becomes "foo,bar".
|
||||||
pub(crate) fn coalesce_whitespace_escaped<'c, C: Fn(char) -> bool>(
|
pub(crate) fn coalesce_whitespace_escaped<C: Fn(char) -> bool>(
|
||||||
escape_character: char,
|
escape_character: char,
|
||||||
escapable_characters: C,
|
escapable_characters: C,
|
||||||
) -> impl for<'s> Fn(&'s str) -> Cow<'s, str> {
|
) -> impl for<'s> Fn(&'s str) -> Cow<'s, str> {
|
||||||
move |input| impl_coalesce_whitespace_escaped(input, escape_character, &escapable_characters)
|
move |input| impl_coalesce_whitespace_escaped(input, escape_character, &escapable_characters)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impl_coalesce_whitespace_escaped<'s, C: Fn(char) -> bool>(
|
fn impl_coalesce_whitespace_escaped<C: Fn(char) -> bool>(
|
||||||
input: &'s str,
|
input: &str,
|
||||||
escape_character: char,
|
escape_character: char,
|
||||||
escapable_characters: C,
|
escapable_characters: C,
|
||||||
) -> Cow<'s, str> {
|
) -> Cow<'_, str> {
|
||||||
let mut state = CoalesceWhitespaceEscaped::Normal {
|
let mut state = CoalesceWhitespaceEscaped::Normal {
|
||||||
in_whitespace: false,
|
in_whitespace: false,
|
||||||
};
|
};
|
||||||
@ -451,7 +451,7 @@ enum CoalesceWhitespaceEscaped {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn to_lowercase<'s>(input: &'s str) -> Cow<'s, str> {
|
pub(crate) fn to_lowercase(input: &str) -> Cow<'_, str> {
|
||||||
if input.chars().any(|c| !c.is_lowercase()) {
|
if input.chars().any(|c| !c.is_lowercase()) {
|
||||||
Cow::Owned(input.to_lowercase())
|
Cow::Owned(input.to_lowercase())
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user