pub struct OffsetMapping {
pub transformations: Vec<Transformation>,
/* private fields */
}Expand description
Offset mapping structure for tracking position changes during text filtering.
This structure maintains a list of all text transformations that occurred during character filtering, enabling accurate position mapping between filtered and original text.
§Usage Pattern
- Record transformations during filtering:
let mut mapping = OffsetMapping::new();
// When "㍑" → "リットル" transformation occurs:
mapping.add_transformation(Transformation::new(6, 9, 2, 14));- Correct positions from filtered to original:
let original_pos = mapping.correct_offset(filtered_pos, text.len());§Multi-Filter Support
When multiple character filters are applied, their mappings are composed:
let combined_mapping = mapping1.compose(mapping2);This ensures accurate position tracking through complex filter chains.
Fields§
§transformations: Vec<Transformation>List of transformations applied to the text
Implementations§
Source§impl OffsetMapping
impl OffsetMapping
pub fn new() -> Self
pub fn with_transformations(transformations: Vec<Transformation>) -> Self
Sourcepub fn add_transformation(&mut self, transformation: Transformation)
pub fn add_transformation(&mut self, transformation: Transformation)
Add a transformation to the mapping
Sourcepub fn correct_offset(&self, offset: usize, text_len: usize) -> usize
pub fn correct_offset(&self, offset: usize, text_len: usize) -> usize
Correct a position in filtered text to the corresponding position in original text.
This method maps a byte position in the filtered text back to the corresponding byte position in the original text, accounting for all recorded transformations.
§Arguments
offset- Byte position in the filtered texttext_len- Length of the filtered text (used for boundary validation)
§Returns
The corresponding byte position in the original text.
§Algorithm
- If no transformations exist, return the offset unchanged
- Find the transformation whose filtered range contains the offset
- Map the offset to the corresponding position in the original range
- If offset is outside all transformation ranges, adjust by cumulative differences
§Example
// For "10㍑" → "10リットル" with transformations recorded
let mut mapping = OffsetMapping::new();
mapping.add_transformation(Transformation::new(6, 9, 2, 14));
// Position 2 in "10リットル" ("リットル" start)
let original_pos = mapping.correct_offset(2, 14); // returns 6
// This maps to position 6 in "10㍑" ("㍑" start)Sourcepub fn compose(self, other: OffsetMapping) -> OffsetMapping
pub fn compose(self, other: OffsetMapping) -> OffsetMapping
Compose this mapping with another mapping (for chaining filters)
Trait Implementations§
Source§impl Clone for OffsetMapping
impl Clone for OffsetMapping
Source§fn clone(&self) -> OffsetMapping
fn clone(&self) -> OffsetMapping
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OffsetMapping
impl Debug for OffsetMapping
Source§impl Default for OffsetMapping
impl Default for OffsetMapping
Source§fn default() -> OffsetMapping
fn default() -> OffsetMapping
Source§impl PartialEq for OffsetMapping
impl PartialEq for OffsetMapping
impl StructuralPartialEq for OffsetMapping
Auto Trait Implementations§
impl Freeze for OffsetMapping
impl RefUnwindSafe for OffsetMapping
impl Send for OffsetMapping
impl Sync for OffsetMapping
impl Unpin for OffsetMapping
impl UnsafeUnpin for OffsetMapping
impl UnwindSafe for OffsetMapping
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.