Skip to main content

FilteredText

Struct FilteredText 

Source
pub struct FilteredText<'a> { /* private fields */ }
Expand description

Filtered text retaining its original input and the provenance of every edit.

Replacement output covers the replaced source range. Insertions map to an empty source range. An empty output range uses the following source boundary, including trailing deletions at the end of the input.

use uqa_analysis::CharFilter;
let input = "<b>한&amp;🙂</b>";
let filtered = CharFilter::HTMLStrip.filter_with_offsets(input)?;
assert_eq!(filtered.as_str(), " 한&🙂 ");
let entity = filtered.source_offsets(4..5)?;
assert_eq!(&input[entity.utf8], "&amp;");
assert_eq!(entity.utf16, 4..9);

Implementations§

Source§

impl<'a> FilteredText<'a>

Source

pub fn new(text: &'a str) -> Self

Source

pub fn as_str(&self) -> &str

Source

pub fn original(&self) -> &'a str

Source

pub fn into_string(self) -> String

Source

pub fn source_offsets( &self, range: Range<usize>, ) -> AnalysisResult<SourceOffsets>

Project a filtered UTF-8 range into the covering original source range.

Source

pub fn source_offsets_utf16( &self, range: Range<usize>, ) -> AnalysisResult<SourceOffsets>

Project filtered UTF-16 coordinates without accepting a split surrogate pair.

Source

pub fn source_covering_offsets_utf16( &self, range: Range<usize>, ) -> AnalysisResult<SourceOffsets>

Project exact filtered UTF-16 units, preserving split pairs through every edit map.

The returned original UTF-16 range stays exact; UTF-8 covers the original scalars. Replacements cover their source and insertions retain their source boundary, as in strict projection.

use uqa_analysis::CharFilter;
let filtered = CharFilter::HTMLStrip.filter_with_offsets("<b>🙂a</b>")?;
let source = filtered.source_covering_offsets_utf16(2..3)?;
assert_eq!(source.utf16, 4..5);
assert_eq!(source.utf8, 3..7);
assert_eq!(&filtered.original()[source.utf8], "🙂");
Source

pub fn final_offsets(&self) -> SourceOffsets

The final input boundary, even when filters remove all source characters.

Trait Implementations§

Source§

impl<'a> Clone for FilteredText<'a>

Source§

fn clone(&self) -> FilteredText<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for FilteredText<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for FilteredText<'a>

§

impl<'a> !RefUnwindSafe for FilteredText<'a>

§

impl<'a> !Sync for FilteredText<'a>

§

impl<'a> Send for FilteredText<'a>

§

impl<'a> Unpin for FilteredText<'a>

§

impl<'a> UnsafeUnpin for FilteredText<'a>

§

impl<'a> UnwindSafe for FilteredText<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.