pub struct Splitter { /* private fields */ }
Expand description
A struct for splitting texts into segments based on the most desirable separator found.
§Examples
use semchunk_rs::Splitter;
let splitter = Splitter::default();
let text = "Hello World\nGoodbye World";
let (separator, is_whitespace, segments) = splitter.split_text(text);
assert_eq!(separator, "\n");
assert!(is_whitespace);
assert_eq!(segments, vec!["Hello World", "Goodbye World"]);
Implementations§
Source§impl Splitter
impl Splitter
Sourcepub fn split_text<'a>(&self, text: &'a str) -> (&'a str, bool, Vec<&'a str>)
pub fn split_text<'a>(&self, text: &'a str) -> (&'a str, bool, Vec<&'a str>)
Splits the given text into segments based on the most desirable separator found.
The method prioritizes separators in the following order:
- The largest sequence of newlines and/or carriage returns.
- The largest sequence of tabs.
- The largest sequence of whitespace characters.
- A semantically meaningful non-whitespace separator.
If no semantically meaningful separator is found, the text is split into individual characters.
§Arguments
text
- A string slice that holds the text to be split.
§Returns
A tuple containing:
- The separator used for splitting the text.
- A boolean indicating whether the separator is whitespace.
- A vector of string slices representing the segments of the split text.
§Examples
use semchunk_rs::Splitter;
let splitter = Splitter::default();
let text = "Hello World\nGoodbye World";
let (separator, is_whitespace, segments) = splitter.split_text(text);
assert_eq!(separator, "\n");
assert!(is_whitespace);
assert_eq!(segments, vec!["Hello World", "Goodbye World"]);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Splitter
impl RefUnwindSafe for Splitter
impl Send for Splitter
impl Sync for Splitter
impl Unpin for Splitter
impl UnwindSafe for Splitter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more