Struct icu::collections::codepointinvlist::CodePointInversionList
source · [−]pub struct CodePointInversionList<'data> { /* private fields */ }
Expand description
A membership wrapper for CodePointInversionList
.
Provides exposure to membership functions and constructors from serialized CodePointSets
and predefined ranges.
Implementations
sourceimpl<'data> CodePointInversionList<'data>
impl<'data> CodePointInversionList<'data>
sourcepub fn from_inversion_list(
inv_list: ZeroVec<'data, u32>
) -> Result<CodePointInversionList<'data>, CodePointSetError>
pub fn from_inversion_list(
inv_list: ZeroVec<'data, u32>
) -> Result<CodePointInversionList<'data>, CodePointSetError>
Returns a new CodePointInversionList
from an inversion list
represented as a [ZeroVec
]<
u32
>
of code points.
The inversion list must be of even length, sorted ascending non-overlapping,
and within the bounds of 0x0 -> 0x10FFFF
inclusive, and end points being exclusive.
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
use icu_collections::codepointinvlist::CodePointSetError;
use zerovec::ZeroVec;
let valid = [0x0, 0x10000];
let inv_list: ZeroVec<u32> = ZeroVec::from_slice_or_alloc(&valid);
let result = CodePointInversionList::from_inversion_list(inv_list);
assert!(matches!(result, CodePointInversionList));
let invalid: Vec<u32> = vec![0x0, 0x80, 0x3];
let inv_list: ZeroVec<u32> = ZeroVec::from_slice_or_alloc(&invalid);
let result = CodePointInversionList::from_inversion_list(inv_list);
assert!(matches!(result, Err(CodePointSetError::InvalidSet(_))));
if let Err(CodePointSetError::InvalidSet(actual)) = result {
assert_eq!(&invalid, &actual);
}
sourcepub fn from_inversion_list_slice(
inv_list: &'data [u32]
) -> Result<CodePointInversionList<'data>, CodePointSetError>
pub fn from_inversion_list_slice(
inv_list: &'data [u32]
) -> Result<CodePointInversionList<'data>, CodePointSetError>
Returns a new CodePointInversionList
by borrowing an inversion list
represented as a slice of u32
code points.
The inversion list must be of even length, sorted ascending non-overlapping,
and within the bounds of 0x0 -> 0x10FFFF
inclusive, and end points being exclusive.
Note: The slice may be cloned on certain platforms; for more information, see [ZeroVec::from_slice_or_alloc
].
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
use icu_collections::codepointinvlist::CodePointSetError;
use zerovec::ZeroVec;
let valid = [0x0, 0x10000];
let result = CodePointInversionList::from_inversion_list_slice(&valid);
assert!(matches!(result, CodePointInversionList));
let invalid: Vec<u32> = vec![0x0, 0x80, 0x3];
let result = CodePointInversionList::from_inversion_list_slice(&invalid);
assert!(matches!(result, Err(CodePointSetError::InvalidSet(_))));
if let Err(CodePointSetError::InvalidSet(actual)) = result {
assert_eq!(&invalid, &actual);
}
sourcepub fn clone_from_inversion_list_slice(
inv_list: &[u32]
) -> Result<CodePointInversionList<'data>, CodePointSetError>
pub fn clone_from_inversion_list_slice(
inv_list: &[u32]
) -> Result<CodePointInversionList<'data>, CodePointSetError>
Returns a new, fully-owned CodePointInversionList
by cloning an inversion list
represented as a slice of u32
code points.
The inversion list must be of even length, sorted ascending non-overlapping,
and within the bounds of 0x0 -> 0x10FFFF
inclusive, and end points being exclusive.
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
use icu_collections::codepointinvlist::CodePointSetError;
use zerovec::ZeroVec;
use std::vec::Vec;
fn inv_list_to_owned_codepointinversionlist(inv_list: &[u32]) -> CodePointInversionList {
CodePointInversionList::clone_from_inversion_list_slice(inv_list).unwrap()
}
let bmp_list: [u32; 2] = [0x0, 0x10000];
let smp_list: Vec<u32> = vec![0x10000, 0x20000];
let sip_list: &[u32] = &vec![0x20000, 0x30000];
let inv_lists: [&[u32]; 3] = [&bmp_list, &smp_list, sip_list];
let codepointinversionlists: Vec<CodePointInversionList> = inv_lists
.iter()
.map(|il| inv_list_to_owned_codepointinversionlist(il))
.collect();
let bmp = &codepointinversionlists.get(0).unwrap();
assert!(bmp.contains_u32(0xFFFF));
assert!(!bmp.contains_u32(0x10000));
assert!(!&codepointinversionlists.iter().any(|set| set.contains_u32(0x40000)));
sourcepub fn get_inversion_list_vec(&self) -> Vec<u32, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn get_inversion_list_vec(&self) -> Vec<u32, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns an owned inversion list representing the current CodePointInversionList
sourcepub fn all() -> CodePointInversionList<'data>
pub fn all() -> CodePointInversionList<'data>
Returns CodePointInversionList
spanning entire Unicode range
The range spans from 0x0 -> 0x10FFFF
inclusive.
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
use zerovec::ZeroVec;
let expected = vec![0x0, (char::MAX as u32) + 1];
assert_eq!(CodePointInversionList::all().get_inversion_list_vec(), expected);
assert_eq!(
CodePointInversionList::all().size(),
(expected[1] - expected[0]) as usize
);
sourcepub fn bmp() -> CodePointInversionList<'data>
pub fn bmp() -> CodePointInversionList<'data>
Returns CodePointInversionList
spanning BMP range
The range spans from 0x0 -> 0xFFFF
inclusive.
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
use zerovec::ZeroVec;
const BMP_MAX: u32 = 0xFFFF;
let expected = vec![0x0, BMP_MAX + 1];
assert_eq!(CodePointInversionList::bmp().get_inversion_list_vec(), expected);
assert_eq!(
CodePointInversionList::bmp().size(),
(expected[1] - expected[0]) as usize
);
sourcepub fn iter_chars(&self) -> impl Iterator<Item = char>
pub fn iter_chars(&self) -> impl Iterator<Item = char>
Yields an Iterator
going through the character set in the CodePointInversionList
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
let example_list = [0x41, 0x44, 0x45, 0x46];
let example = CodePointInversionList::from_inversion_list_slice(&example_list).unwrap();
let mut ex_iter_chars = example.iter_chars();
assert_eq!(Some('A'), ex_iter_chars.next());
assert_eq!(Some('B'), ex_iter_chars.next());
assert_eq!(Some('C'), ex_iter_chars.next());
assert_eq!(Some('E'), ex_iter_chars.next());
assert_eq!(None, ex_iter_chars.next());
sourcepub fn iter_ranges(&self) -> impl ExactSizeIterator
pub fn iter_ranges(&self) -> impl ExactSizeIterator
Yields an Iterator
returning the ranges of the code points that are
included in the CodePointInversionList
Ranges are returned as RangeInclusive
, which is inclusive of its
end
bound value. An end-inclusive behavior matches the ICU4C/J
behavior of ranges, ex: CodePointInversionList::contains(UChar32 start, UChar32 end)
.
Example
use icu_collections::codepointinvlist::CodePointInversionList;
let example_list = [0x41, 0x44, 0x45, 0x46];
let example = CodePointInversionList::from_inversion_list_slice(&example_list).unwrap();
let mut example_iter_ranges = example.iter_ranges();
assert_eq!(Some(0x41..=0x43), example_iter_ranges.next());
assert_eq!(Some(0x45..=0x45), example_iter_ranges.next());
assert_eq!(None, example_iter_ranges.next());
sourcepub fn get_range_count(&self) -> usize
pub fn get_range_count(&self) -> usize
Returns the number of ranges contained in this CodePointInversionList
sourcepub fn get_nth_range(&self, idx: usize) -> Option<RangeInclusive<u32>>
pub fn get_nth_range(&self, idx: usize) -> Option<RangeInclusive<u32>>
Returns a specific range contained in this CodePointInversionList
by index.
Intended for use in FFI.
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the number of elements of the CodePointInversionList
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether or not the CodePointInversionList
is empty
sourcepub fn contains(&self, query: char) -> bool
pub fn contains(&self, query: char) -> bool
Checks to see the query is in the CodePointInversionList
Runs a binary search in O(log(n))
where n
is the number of start and end points
in the set using core
implementation
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
let example_list = [0x41, 0x43, 0x44, 0x45];
let example = CodePointInversionList::from_inversion_list_slice(&example_list).unwrap();
assert!(example.contains('A'));
assert!(!example.contains('C'));
sourcepub fn contains_u32(&self, query: u32) -> bool
pub fn contains_u32(&self, query: u32) -> bool
Checks to see the unsigned int is in the CodePointInversionList::all()
Note: Even though u32
and char
in Rust are non-negative 4-byte
values, there is an important difference. A u32
can take values up to
a very large integer value, while a char
in Rust is defined to be in
the range from 0 to the maximum valid Unicode Scalar Value.
Runs a binary search in O(log(n))
where n
is the number of start and end points
in the set using core
implementation
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
let example_list = [0x41, 0x43, 0x44, 0x45];
let example = CodePointInversionList::from_inversion_list_slice(&example_list).unwrap();
assert!(example.contains_u32(0x41));
assert!(!example.contains_u32(0x43));
sourcepub fn contains_range(&self, range: &impl RangeBounds<char>) -> bool
pub fn contains_range(&self, range: &impl RangeBounds<char>) -> bool
Checks to see if the range is in the CodePointInversionList
Runs a binary search in O(log(n))
where n
is the number of start and end points
in the set using Vec
implementation. Only runs the search once on the start
parameter, while the end
parameter is checked in a single O(1)
step.
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
let example_list = [0x41, 0x43, 0x44, 0x45];
let example = CodePointInversionList::from_inversion_list_slice(&example_list).unwrap();
assert!(example.contains_range(&('A'..'C')));
assert!(example.contains_range(&('A'..='B')));
assert!(!example.contains_range(&('A'..='C')));
Surrogate points (0xD800 -> 0xDFFF
) will return false
if the Range contains them but the
CodePointInversionList
does not.
Note: when comparing to ICU4C/J, keep in mind that Range
s in Rust are
constructed inclusive of start boundary and exclusive of end boundary.
The ICU4C/J CodePointInversionList::contains(UChar32 start, UChar32 end)
method
differs by including the end boundary.
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
use std::char;
let check = char::from_u32(0xD7FE).unwrap()..char::from_u32(0xE001).unwrap();
let example_list = [0xD7FE, 0xD7FF, 0xE000, 0xE001];
let example = CodePointInversionList::from_inversion_list_slice(&example_list).unwrap();
assert!(!example.contains_range(&(check)));
sourcepub fn contains_set(&self, set: &CodePointInversionList<'data>) -> bool
pub fn contains_set(&self, set: &CodePointInversionList<'data>) -> bool
Check if the calling CodePointInversionList
contains all the characters of the given CodePointInversionList
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
let example_list = [0x41, 0x46, 0x55, 0x5B]; // A - E, U - Z
let example = CodePointInversionList::from_inversion_list_slice(&example_list).unwrap();
let a_to_d = CodePointInversionList::from_inversion_list_slice(&[0x41, 0x45]).unwrap();
let f_to_t = CodePointInversionList::from_inversion_list_slice(&[0x46, 0x55]).unwrap();
let r_to_x = CodePointInversionList::from_inversion_list_slice(&[0x52, 0x58]).unwrap();
assert!(example.contains_set(&a_to_d)); // contains all
assert!(!example.contains_set(&f_to_t)); // contains none
assert!(!example.contains_set(&r_to_x)); // contains some
sourcepub fn span(&self, span_str: &str, contained: bool) -> usize
pub fn span(&self, span_str: &str, contained: bool) -> usize
Returns the end of the initial substring where the characters are either contained/not contained in the set.
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
let example_list = [0x41, 0x44]; // {A, B, C}
let example = CodePointInversionList::from_inversion_list_slice(&example_list).unwrap();
assert_eq!(example.span("CABXYZ", true), 3);
assert_eq!(example.span("XYZC", false), 3);
assert_eq!(example.span("XYZ", true), 0);
assert_eq!(example.span("ABC", false), 0);
sourcepub fn span_back(&self, span_str: &str, contained: bool) -> usize
pub fn span_back(&self, span_str: &str, contained: bool) -> usize
Returns the start of the trailing substring (starting from end of string) where the characters are either contained/not contained in the set. Returns the length of the string if no valid return.
Examples
use icu_collections::codepointinvlist::CodePointInversionList;
let example_list = [0x41, 0x44]; // {A, B, C}
let example = CodePointInversionList::from_inversion_list_slice(&example_list).unwrap();
assert_eq!(example.span_back("XYZCAB", true), 3);
assert_eq!(example.span_back("ABCXYZ", true), 6);
assert_eq!(example.span_back("CABXYZ", false), 3);
Trait Implementations
sourceimpl<'data> Clone for CodePointInversionList<'data>
impl<'data> Clone for CodePointInversionList<'data>
sourcefn clone(&self) -> CodePointInversionList<'data>
fn clone(&self) -> CodePointInversionList<'data>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'data> Debug for CodePointInversionList<'data>
impl<'data> Debug for CodePointInversionList<'data>
sourceimpl<'de, 'a> Deserialize<'de> for CodePointInversionList<'a> where
'de: 'a,
impl<'de, 'a> Deserialize<'de> for CodePointInversionList<'a> where
'de: 'a,
sourcefn deserialize<D>(
deserializer: D
) -> Result<CodePointInversionList<'a>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<CodePointInversionList<'a>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl FromIterator<RangeInclusive<u32>> for CodePointInversionList<'_>
impl FromIterator<RangeInclusive<u32>> for CodePointInversionList<'_>
sourcefn from_iter<I>(iter: I) -> CodePointInversionList<'_> where
I: IntoIterator<Item = RangeInclusive<u32>>,
fn from_iter<I>(iter: I) -> CodePointInversionList<'_> where
I: IntoIterator<Item = RangeInclusive<u32>>,
Creates a value from an iterator. Read more
sourceimpl<'data> PartialEq<CodePointInversionList<'data>> for CodePointInversionList<'data>
impl<'data> PartialEq<CodePointInversionList<'data>> for CodePointInversionList<'data>
sourcefn eq(&self, other: &CodePointInversionList<'data>) -> bool
fn eq(&self, other: &CodePointInversionList<'data>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &CodePointInversionList<'data>) -> bool
fn ne(&self, other: &CodePointInversionList<'data>) -> bool
This method tests for !=
.
sourceimpl<'data> Serialize for CodePointInversionList<'data>
impl<'data> Serialize for CodePointInversionList<'data>
sourcefn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
sourceimpl<'data> TryFrom<&Range<char>> for CodePointInversionList<'data>
impl<'data> TryFrom<&Range<char>> for CodePointInversionList<'data>
type Error = CodePointSetError
type Error = CodePointSetError
The type returned in the event of a conversion error.
sourceimpl<'data> TryFrom<&RangeFrom<char>> for CodePointInversionList<'data>
impl<'data> TryFrom<&RangeFrom<char>> for CodePointInversionList<'data>
type Error = CodePointSetError
type Error = CodePointSetError
The type returned in the event of a conversion error.
sourceimpl<'data> TryFrom<&RangeFull> for CodePointInversionList<'data>
impl<'data> TryFrom<&RangeFull> for CodePointInversionList<'data>
type Error = CodePointSetError
type Error = CodePointSetError
The type returned in the event of a conversion error.
sourcefn try_from(
&RangeFull
) -> Result<CodePointInversionList<'data>, <CodePointInversionList<'data> as TryFrom<&RangeFull>>::Error>
fn try_from(
&RangeFull
) -> Result<CodePointInversionList<'data>, <CodePointInversionList<'data> as TryFrom<&RangeFull>>::Error>
Performs the conversion.
sourceimpl<'data> TryFrom<&RangeInclusive<char>> for CodePointInversionList<'data>
impl<'data> TryFrom<&RangeInclusive<char>> for CodePointInversionList<'data>
type Error = CodePointSetError
type Error = CodePointSetError
The type returned in the event of a conversion error.
sourcefn try_from(
range: &RangeInclusive<char>
) -> Result<CodePointInversionList<'data>, <CodePointInversionList<'data> as TryFrom<&RangeInclusive<char>>>::Error>
fn try_from(
range: &RangeInclusive<char>
) -> Result<CodePointInversionList<'data>, <CodePointInversionList<'data> as TryFrom<&RangeInclusive<char>>>::Error>
Performs the conversion.
sourceimpl<'data> TryFrom<&RangeTo<char>> for CodePointInversionList<'data>
impl<'data> TryFrom<&RangeTo<char>> for CodePointInversionList<'data>
type Error = CodePointSetError
type Error = CodePointSetError
The type returned in the event of a conversion error.
sourceimpl<'data> TryFrom<&RangeToInclusive<char>> for CodePointInversionList<'data>
impl<'data> TryFrom<&RangeToInclusive<char>> for CodePointInversionList<'data>
type Error = CodePointSetError
type Error = CodePointSetError
The type returned in the event of a conversion error.
sourcefn try_from(
range: &RangeToInclusive<char>
) -> Result<CodePointInversionList<'data>, <CodePointInversionList<'data> as TryFrom<&RangeToInclusive<char>>>::Error>
fn try_from(
range: &RangeToInclusive<char>
) -> Result<CodePointInversionList<'data>, <CodePointInversionList<'data> as TryFrom<&RangeToInclusive<char>>>::Error>
Performs the conversion.
sourceimpl<'a> Yokeable<'a> for CodePointInversionList<'static>
impl<'a> Yokeable<'a> for CodePointInversionList<'static>
type Output = CodePointInversionList<'a>
type Output = CodePointInversionList<'a>
This type MUST be Self
with the 'static
replaced with 'a
, i.e. Self<'a>
sourcefn transform(
&'a self
) -> &'a <CodePointInversionList<'static> as Yokeable<'a>>::Output
fn transform(
&'a self
) -> &'a <CodePointInversionList<'static> as Yokeable<'a>>::Output
This method must cast self
between &'a Self<'static>
and &'a Self<'a>
. Read more
sourcefn transform_owned(
self
) -> <CodePointInversionList<'static> as Yokeable<'a>>::Output
fn transform_owned(
self
) -> <CodePointInversionList<'static> as Yokeable<'a>>::Output
This method must cast self
between Self<'static>
and Self<'a>
. Read more
sourceunsafe fn make(
this: <CodePointInversionList<'static> as Yokeable<'a>>::Output
) -> CodePointInversionList<'static>
unsafe fn make(
this: <CodePointInversionList<'static> as Yokeable<'a>>::Output
) -> CodePointInversionList<'static>
This method can be used to cast away Self<'a>
’s lifetime. Read more
sourcefn transform_mut<F>(&'a mut self, f: F) where
F: 'static + for<'b> FnOnce(&'b mut <CodePointInversionList<'static> as Yokeable<'a>>::Output),
fn transform_mut<F>(&'a mut self, f: F) where
F: 'static + for<'b> FnOnce(&'b mut <CodePointInversionList<'static> as Yokeable<'a>>::Output),
This method must cast self
between &'a mut Self<'static>
and &'a mut Self<'a>
,
and pass it to f
. Read more
sourceimpl<'zf, 'zf_inner> ZeroFrom<'zf, CodePointInversionList<'zf_inner>> for CodePointInversionList<'zf>
impl<'zf, 'zf_inner> ZeroFrom<'zf, CodePointInversionList<'zf_inner>> for CodePointInversionList<'zf>
sourcefn zero_from(
this: &'zf CodePointInversionList<'zf_inner>
) -> CodePointInversionList<'zf>
fn zero_from(
this: &'zf CodePointInversionList<'zf_inner>
) -> CodePointInversionList<'zf>
Clone the other C
into a struct that may retain references into C
.
impl<'data> Eq for CodePointInversionList<'data>
impl<'a> IsCovariant<'a> for CodePointInversionList<'a>
impl<'data> StructuralEq for CodePointInversionList<'data>
impl<'data> StructuralPartialEq for CodePointInversionList<'data>
Auto Trait Implementations
impl<'data> RefUnwindSafe for CodePointInversionList<'data>
impl<'data> Send for CodePointInversionList<'data>
impl<'data> Sync for CodePointInversionList<'data>
impl<'data> Unpin for CodePointInversionList<'data>
impl<'data> UnwindSafe for CodePointInversionList<'data>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more