Skip to main content

CharFilter

Enum CharFilter 

Source
pub enum CharFilter {
    HTMLStrip,
    CJKWidth,
    Mapping {
        mapping: BTreeMap<String, String>,
    },
    PatternReplace {
        pattern: String,
        replacement: String,
    },
}

Variants§

§

HTMLStrip

§

CJKWidth

Fold fullwidth ASCII and halfwidth Katakana, preserving original source spans.

use uqa_analysis::CharFilter;
let filtered = CharFilter::CJKWidth.filter_with_offsets("ガA①")?;
assert_eq!(filtered.as_str(), "ガA①");
assert_eq!(filtered.source_offsets(0..3)?.utf16, 0..2);
§

Mapping

Fields

§

PatternReplace

Fields

§pattern: String
§replacement: String

Implementations§

Source§

impl CharFilter

Source

pub fn validate(&self) -> AnalysisResult<()>

Validate configuration without filtering input.

Source

pub fn filter(&self, text: &str) -> AnalysisResult<String>

Source

pub fn filter_with_offsets<'a>( &self, text: &'a str, ) -> AnalysisResult<FilteredText<'a>>

Transform text while retaining source coordinates for the result.

Source

pub fn filter_mapped<'a>( &self, text: FilteredText<'a>, ) -> AnalysisResult<FilteredText<'a>>

Apply this stage to previously filtered text without losing its original source.

Source

pub fn filter_with_offsets_budgeted<'a>( &self, text: &'a str, budget: &MemoryBudget, poll: &mut dyn FnMut() -> AnalysisResult<()>, ) -> AnalysisResult<FilteredText<'a>>

Transform a borrowed input while retaining source buffers and regex search workspace under the caller’s byte allowance. Immutable configuration preparation is separate. Literal, built-in HTML, regex range and capture searches, source copying, and coordinate construction poll during execution. Search scratch is released before returning the retained source result.

use uqa_analysis::CharFilter;
use uqa_core::memory::MemoryBudget;
let budget = MemoryBudget::new(16 * 1024);
let filtered = CharFilter::HTMLStrip.filter_with_offsets_budgeted(
    "<b>한&amp;🙂</b>", &budget, &mut || Ok(()),
)?;
let retained = filtered.clone();
drop(filtered);
assert_eq!(retained.as_str(), " 한&🙂 ");
assert_eq!(retained.source_offsets(1..4)?.utf8, 3..6);
assert!(budget.used() > 0);
drop(retained);
assert_eq!(budget.used(), 0);
Source

pub fn filter_mapped_budgeted<'a>( &self, text: FilteredText<'a>, budget: &MemoryBudget, poll: &mut dyn FnMut() -> AnalysisResult<()>, ) -> AnalysisResult<FilteredText<'a>>

New source, edit, and coordinate buffers use budget; retained input allocations keep their original shared leases.

Trait Implementations§

Source§

impl Clone for CharFilter

Source§

fn clone(&self) -> CharFilter

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 Debug for CharFilter

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CharFilter

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CharFilter

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.