[−][src]Trait textwrap::WordSplitter
The WordSplitter
trait describes where words can be split.
If the textwrap crate has been compiled with the hyphenation
feature enabled, you will find an implementation of WordSplitter
by the [hyphenation::Standard
] struct. Use this struct for
language-aware hyphenation. See the hyphenation documentation
for details.
Required methods
pub fn split_points(&self, word: &str) -> Vec<usize>
[src]
Return all possible indices where word
can be split.
The indices returned must be in range 0..word.len()
. They
should point to the index after the split point, i.e., after
-
if splitting on hyphens. This way, word.split_at(idx)
will break the word into two well-formed pieces.
Examples
use textwrap::{HyphenSplitter, NoHyphenation, WordSplitter}; assert_eq!(NoHyphenation.split_points("cannot-be-split"), vec![]); assert_eq!(HyphenSplitter.split_points("can-be-split"), vec![4, 7]);
Implementations on Foreign Types
impl WordSplitter for Box<dyn WordSplitter>
[src]
pub fn split_points(&self, word: &str) -> Vec<usize>
[src]
impl<T: ?Sized + WordSplitter, '_> WordSplitter for &'_ T
[src]
pub fn split_points(&self, word: &str) -> Vec<usize>
[src]
impl WordSplitter for Standard
[src]
A hyphenation dictionary can be used to do language-specific hyphenation using patterns from the hyphenation crate.
Note: Only available when the hyphenation
feature is
enabled.
pub fn split_points(&self, word: &str) -> Vec<usize>
[src]
Implementors
impl WordSplitter for HyphenSplitter
[src]
HyphenSplitter
is the default WordSplitter
used by
Options::new
. It will split words on any
existing hyphens in the word.
It will only use hyphens that are surrounded by alphanumeric
characters, which prevents a word like "--foo-bar"
from being
split into "--"
and "foo-bar"
.
pub fn split_points(&self, word: &str) -> Vec<usize>
[src]
impl WordSplitter for NoHyphenation
[src]
NoHyphenation
implements WordSplitter
by not splitting the
word at all.