pub struct CodePointInversionListBuilder {
intervals: Vec<u32>,
}
Expand description
A builder for CodePointInversionList
.
Provides exposure to builder functions and conversion to CodePointInversionList
Fields§
§intervals: Vec<u32>
Implementations§
source§impl CodePointInversionListBuilder
impl CodePointInversionListBuilder
sourcepub const fn new() -> Self
pub const fn new() -> Self
Returns empty CodePointInversionListBuilder
sourcepub fn build(self) -> CodePointInversionList<'static>
pub fn build(self) -> CodePointInversionList<'static>
Returns a CodePointInversionList
and consumes the CodePointInversionListBuilder
sourcefn add_remove_middle(&mut self, start: u32, end: u32, add: bool)
fn add_remove_middle(&mut self, start: u32, end: u32, add: bool)
Abstraction for adding/removing a range from start..end
If add is true add, else remove
sourcefn add(&mut self, start: u32, end: u32)
fn add(&mut self, start: u32, end: u32)
Add the range to the CodePointInversionListBuilder
Accomplishes this through binary search for the start and end indices and merges intervals
in between with inplace memory. Performs O(1)
operation if adding to end of list, and O(N)
otherwise,
where N
is the number of endpoints.
sourcepub fn add_char(&mut self, c: char)
pub fn add_char(&mut self, c: char)
Add the character to the CodePointInversionListBuilder
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add_char('a');
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('a'));
sourcepub fn add32(&mut self, c: u32)
pub fn add32(&mut self, c: u32)
Add the code point value to the CodePointInversionListBuilder
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.
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add32(0x41);
let check = builder.build();
assert!(check.contains32(0x41));
sourcepub fn add_u32(&mut self, c: u32)
👎Deprecated since 1.5.0: Use add32
pub fn add_u32(&mut self, c: u32)
add32
Same as Self::add32
.
sourcepub fn add_range(&mut self, range: &impl RangeBounds<char>)
pub fn add_range(&mut self, range: &impl RangeBounds<char>)
Add the range of characters to the CodePointInversionListBuilder
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add_range(&('A'..='Z'));
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('A'));
sourcepub fn add_range32(&mut self, range: &impl RangeBounds<u32>)
pub fn add_range32(&mut self, range: &impl RangeBounds<u32>)
Add the range of characters, represented as u32, to the CodePointInversionListBuilder
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add_range32(&(0xd800..=0xdfff));
let check = builder.build();
assert!(check.contains32(0xd900));
sourcepub fn add_range_u32(&mut self, range: &impl RangeBounds<u32>)
👎Deprecated since 1.5.0: Use add_range32
pub fn add_range_u32(&mut self, range: &impl RangeBounds<u32>)
add_range32
Same as Self::add_range32
.
sourcepub fn add_set(&mut self, set: &CodePointInversionList<'_>)
pub fn add_set(&mut self, set: &CodePointInversionList<'_>)
Add the CodePointInversionList
reference to the CodePointInversionListBuilder
§Examples
use icu::collections::codepointinvlist::{
CodePointInversionList, CodePointInversionListBuilder,
};
let mut builder = CodePointInversionListBuilder::new();
let set =
CodePointInversionList::try_from_inversion_list_slice(&[0x41, 0x4C])
.unwrap();
builder.add_set(&set);
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('A'));
sourcefn remove(&mut self, start: u32, end: u32)
fn remove(&mut self, start: u32, end: u32)
Removes the range from the CodePointInversionListBuilder
Performs binary search to find start and end affected intervals, then removes in an O(N)
fashion
where N
is the number of endpoints, with in-place memory.
sourcepub fn remove_char(&mut self, c: char)
pub fn remove_char(&mut self, c: char)
Remove the character from the CodePointInversionListBuilder
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add_range(&('A'..='Z'));
builder.remove_char('A');
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('B'));
sourcepub fn remove_range(&mut self, range: &impl RangeBounds<char>)
pub fn remove_range(&mut self, range: &impl RangeBounds<char>)
Remove the range of characters from the CodePointInversionListBuilder
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add_range(&('A'..='Z'));
builder.remove_range(&('A'..='C'));
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('D'));
sourcepub fn remove_range32(&mut self, range: &impl RangeBounds<u32>)
pub fn remove_range32(&mut self, range: &impl RangeBounds<u32>)
sourcepub fn remove_set(&mut self, set: &CodePointInversionList<'_>)
pub fn remove_set(&mut self, set: &CodePointInversionList<'_>)
Remove the CodePointInversionList
from the CodePointInversionListBuilder
§Examples
use icu::collections::codepointinvlist::{CodePointInversionList, CodePointInversionListBuilder};
let mut builder = CodePointInversionListBuilder::new();
let set = CodePointInversionList::try_from_inversion_list_slice(&[0x41, 0x46]).unwrap();
builder.add_range(&('A'..='Z'));
builder.remove_set(&set); // removes 'A'..='E'
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('F'));
sourcepub fn retain_char(&mut self, c: char)
pub fn retain_char(&mut self, c: char)
Retain the specified character in the CodePointInversionListBuilder
if it exists
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add_range(&('A'..='Z'));
builder.retain_char('A');
let set = builder.build();
let mut check = set.iter_chars();
assert_eq!(check.next(), Some('A'));
assert_eq!(check.next(), None);
sourcepub fn retain_range(&mut self, range: &impl RangeBounds<char>)
pub fn retain_range(&mut self, range: &impl RangeBounds<char>)
Retain the range of characters located within the CodePointInversionListBuilder
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add_range(&('A'..='Z'));
builder.retain_range(&('A'..='B'));
let set = builder.build();
let mut check = set.iter_chars();
assert_eq!(check.next(), Some('A'));
assert_eq!(check.next(), Some('B'));
assert_eq!(check.next(), None);
sourcepub fn retain_range32(&mut self, range: &impl RangeBounds<u32>)
pub fn retain_range32(&mut self, range: &impl RangeBounds<u32>)
sourcepub fn retain_set(&mut self, set: &CodePointInversionList<'_>)
pub fn retain_set(&mut self, set: &CodePointInversionList<'_>)
Retain the elements in the specified set within the CodePointInversionListBuilder
§Examples
use icu::collections::codepointinvlist::{
CodePointInversionList, CodePointInversionListBuilder,
};
let mut builder = CodePointInversionListBuilder::new();
let set = CodePointInversionList::try_from_inversion_list_slice(&[65, 70])
.unwrap();
builder.add_range(&('A'..='Z'));
builder.retain_set(&set); // retains 'A'..='E'
let check = builder.build();
assert!(check.contains('A'));
assert!(!check.contains('G'));
sourcefn complement_list(&mut self, set_iter: impl Iterator<Item = u32>)
fn complement_list(&mut self, set_iter: impl Iterator<Item = u32>)
Computes the complement of the argument, adding any elements that do not yet exist in the builder, and removing any elements that already exist in the builder. See public functions for examples.
Performs in O(B + S)
, where B
is the number of endpoints in the Builder, and S
is the number
of endpoints in the argument.
sourcepub fn complement(&mut self)
pub fn complement(&mut self)
Computes the complement of the builder, inverting the builder (any elements in the builder are removed, while any elements not in the builder are added)
§Examples
use icu::collections::codepointinvlist::{
CodePointInversionList, CodePointInversionListBuilder,
};
let mut builder = CodePointInversionListBuilder::new();
let set = CodePointInversionList::try_from_inversion_list_slice(&[
0x0,
0x41,
0x46,
(std::char::MAX as u32) + 1,
])
.unwrap();
builder.add_set(&set);
builder.complement();
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('A'));
sourcepub fn complement_char(&mut self, c: char)
pub fn complement_char(&mut self, c: char)
Complements the character in the builder, adding it if not in the builder, and removing it otherwise.
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add_range(&('A'..='D'));
builder.complement_char('A');
builder.complement_char('E');
let check = builder.build();
assert!(check.contains('E'));
assert!(!check.contains('A'));
sourcepub fn complement32(&mut self, c: u32)
pub fn complement32(&mut self, c: u32)
sourcepub fn complement_range(&mut self, range: &impl RangeBounds<char>)
pub fn complement_range(&mut self, range: &impl RangeBounds<char>)
Complements the range in the builder, adding any elements in the range if not in the builder, and removing them otherwise.
§Examples
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
let mut builder = CodePointInversionListBuilder::new();
builder.add_range(&('A'..='D'));
builder.complement_range(&('C'..='F'));
let check = builder.build();
assert!(check.contains('F'));
assert!(!check.contains('C'));
sourcepub fn complement_range32(&mut self, range: &impl RangeBounds<u32>)
pub fn complement_range32(&mut self, range: &impl RangeBounds<u32>)
sourcepub fn complement_set(&mut self, set: &CodePointInversionList<'_>)
pub fn complement_set(&mut self, set: &CodePointInversionList<'_>)
Complements the set in the builder, adding any elements in the set if not in the builder, and removing them otherwise.
§Examples
use icu::collections::codepointinvlist::{
CodePointInversionList, CodePointInversionListBuilder,
};
let mut builder = CodePointInversionListBuilder::new();
let set = CodePointInversionList::try_from_inversion_list_slice(&[
0x41, 0x46, 0x4B, 0x5A,
])
.unwrap();
builder.add_range(&('C'..='N')); // 67 - 78
builder.complement_set(&set);
let check = builder.build();
assert!(check.contains('Q')); // 81
assert!(!check.contains('N')); // 78