[−][src]Struct textwrap::word_separators::UnicodeBreakProperties
Find words using the Unicode line breaking algorithm.
Trait Implementations
impl Clone for UnicodeBreakProperties
[src]
fn clone(&self) -> UnicodeBreakProperties
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for UnicodeBreakProperties
[src]
impl Debug for UnicodeBreakProperties
[src]
impl Default for UnicodeBreakProperties
[src]
fn default() -> UnicodeBreakProperties
[src]
impl WordSeparator for UnicodeBreakProperties
[src]
Split line
into words using Unicode break properties.
This word separator uses the Unicode line breaking algorithm
described in Unicode Standard Annex
#14 to find legal places
to break lines. There is a small difference in that the U+002D
(Hyphen-Minus) and U+00AD (Soft Hyphen) don’t create a line break:
to allow a line break at a hyphen, use the
HyphenSplitter
. Soft
hyphens are not currently supported.
Examples
Unlike AsciiSpace
, the Unicode line breaking algorithm will
find line break opportunities between some characters with no
intervening whitespace:
#[cfg(feature = "unicode-linebreak")] { use textwrap::word_separators::{WordSeparator, UnicodeBreakProperties}; use textwrap::core::Word; assert_eq!(UnicodeBreakProperties.find_words("Emojis: 😂😍").collect::<Vec<_>>(), vec![Word::from("Emojis: "), Word::from("😂"), Word::from("😍")]); assert_eq!(UnicodeBreakProperties.find_words("CJK: 你好").collect::<Vec<_>>(), vec![Word::from("CJK: "), Word::from("你"), Word::from("好")]); }
A U+2060 (Word Joiner) character can be inserted if you want to manually override the defaults and keep the characters together:
#[cfg(feature = "unicode-linebreak")] { use textwrap::word_separators::{UnicodeBreakProperties, WordSeparator}; use textwrap::core::Word; assert_eq!(UnicodeBreakProperties.find_words("Emojis: 😂\u{2060}😍").collect::<Vec<_>>(), vec![Word::from("Emojis: "), Word::from("😂\u{2060}😍")]); }
The Unicode line breaking algorithm will also automatically suppress break breaks around certain punctuation characters::
#[cfg(feature = "unicode-linebreak")] { use textwrap::word_separators::{UnicodeBreakProperties, WordSeparator}; use textwrap::core::Word; assert_eq!(UnicodeBreakProperties.find_words("[ foo ] bar !").collect::<Vec<_>>(), vec![Word::from("[ foo ] "), Word::from("bar !")]); }
Auto Trait Implementations
impl RefUnwindSafe for UnicodeBreakProperties
impl Send for UnicodeBreakProperties
impl Sync for UnicodeBreakProperties
impl Unpin for UnicodeBreakProperties
impl UnwindSafe for UnicodeBreakProperties
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,