pub trait StringExt {
// Required methods
fn trim(&mut self);
fn trim_matches(&mut self, rem: &str);
fn trim_start(&mut self);
fn trim_start_matches(&mut self, rem: &str);
fn trim_end(&mut self);
fn trim_end_matches(&mut self, rem: &str);
}Expand description
An extension to
String
allowing for inline trimming.
Required Methods§
Sourcefn trim(&mut self)
fn trim(&mut self)
Mutates a string in place with leading and trailing whitespace removed.
‘Whitespace’ is defined according to the terms of the Unicode Derived
Core Property White_Space.
§Examples
use fenn::StringExt;
let mut test = String::from(" Hello World! ");
test.trim();
assert_eq!(test, String::from("Hello World!"));Sourcefn trim_matches(&mut self, rem: &str)
fn trim_matches(&mut self, rem: &str)
Mutates a string in place with all suffixes that match a pattern repeatedly removed.
§Examples
use fenn::StringExt;
let mut test = String::from("blahHello World!blah");
test.trim_matches("blah");
assert_eq!(test, String::from("Hello World!"));§Note
Once the Pattern API (#27721) becomes stable this will be changed to accept a pattern.
Sourcefn trim_start(&mut self)
fn trim_start(&mut self)
Mutates a string in place with leading whitespace removed.
‘Whitespace’ is defined according to the terms of the Unicode Derived
Core Property White_Space.
§Text directionality
A string is a sequence of bytes. start in this context means the first
position of that byte string; for a left-to-right language like English or
Russian, this will be left side, and for right-to-left languages like
Arabic or Hebrew, this will be the right side.
§Examples
use fenn::StringExt;
let mut test = String::from(" Hello World!");
test.trim_start();
assert_eq!(test, String::from("Hello World!"));Sourcefn trim_start_matches(&mut self, rem: &str)
fn trim_start_matches(&mut self, rem: &str)
Mutates a string in place with all suffixes that match a pattern repeatedly removed.
§Text directionality
A string is a sequence of bytes. start in this context means the first
position of that byte string; for a left-to-right language like English or
Russian, this will be left side, and for right-to-left languages like
Arabic or Hebrew, this will be the right side.
§Examples
use fenn::StringExt;
let mut test = String::from("blahHello World!");
test.trim_start_matches("blah");
assert_eq!(test, String::from("Hello World!"));§Note
Once the Pattern API (#27721) becomes stable this will be changed to accept a pattern.
Sourcefn trim_end(&mut self)
fn trim_end(&mut self)
Mutates a string in place with trailing whitespace removed.
‘Whitespace’ is defined according to the terms of the Unicode Derived
Core Property White_Space.
§Text directionality
A string is a sequence of bytes. ‘Left’ in this context means the first position of that byte string; for a language like Arabic or Hebrew which are ‘right to left’ rather than ‘left to right’, this will be the right side, not the left.
§Examples
use fenn::StringExt;
let mut test = String::from("Hello World! ");
test.trim_end();
assert_eq!(test, String::from("Hello World!"));Sourcefn trim_end_matches(&mut self, rem: &str)
fn trim_end_matches(&mut self, rem: &str)
Mutates a string in place with all suffixes that match a pattern repeatedly removed.
§Text directionality
A string is a sequence of bytes. ‘Left’ in this context means the first position of that byte string; for a language like Arabic or Hebrew which are ‘right to left’ rather than ‘left to right’, this will be the right side, not the left.
use fenn::StringExt;
let mut test = String::from("Hello World!blah");
test.trim_end_matches("blah");
assert_eq!(test, String::from("Hello World!"));§Note
Once the Pattern API (#27721) becomes stable this will be changed to accept a pattern.