Struct icu_uniset::UnicodeSetBuilder[][src]

pub struct UnicodeSetBuilder { /* fields omitted */ }
Expand description

A builder for UnicodeSet.

Provides exposure to builder functions and conversion to UnicodeSet

Implementations

Returns empty UnicodeSetBuilder

Returns a UnicodeSet and consumes the UnicodeSetBuilder

Add the character to the UnicodeSetBuilder

Examples

use icu::uniset::UnicodeSetBuilder;
let mut builder = UnicodeSetBuilder::new();
builder.add_char('a');
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('a'));

Add the code point value to the UnicodeSetBuilder

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::uniset::UnicodeSetBuilder;
let mut builder = UnicodeSetBuilder::new();
builder.add_u32(0x41);
let check = builder.build();
assert_eq!(check.contains_u32(0x41), true);

Add the range of characters to the UnicodeSetBuilder

Examples

use icu::uniset::UnicodeSetBuilder;
let mut builder = UnicodeSetBuilder::new();
builder.add_range(&('A'..='Z'));
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('A'));

Add the UnicodeSet reference to the UnicodeSetBuilder

Examples

use icu::uniset::{UnicodeSet, UnicodeSetBuilder};
let mut builder = UnicodeSetBuilder::new();
let set = UnicodeSet::from_inversion_list(vec![0x41, 0x4C]).unwrap();
builder.add_set(&set);
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('A'));

Remove the character from the UnicodeSetBuilder

Examples

use icu::uniset::UnicodeSetBuilder;
let mut builder = UnicodeSetBuilder::new();
builder.add_range(&('A'..='Z'));
builder.remove_char('A');
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('B'));

Remove the range of characters from the UnicodeSetBuilder

Examples

use icu::uniset::UnicodeSetBuilder;
let mut builder = UnicodeSetBuilder::new();
builder.add_range(&('A'..='Z'));
builder.remove_range(&('A'..='C'));
let check = builder.build();
assert_eq!(check.iter_chars().next(), Some('D'));

Remove the UnicodeSet from the UnicodeSetBuilder

Examples

use icu::uniset::{UnicodeSet, UnicodeSetBuilder};
let mut builder = UnicodeSetBuilder::new();
let set = UnicodeSet::from_inversion_list(vec![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'));

Retain the specified character in the UnicodeSetBuilder if it exists

Examples

use icu::uniset::UnicodeSetBuilder;
let mut builder = UnicodeSetBuilder::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);

Retain the range of characters located within the UnicodeSetBuilder

Examples

use icu::uniset::UnicodeSetBuilder;
let mut builder = UnicodeSetBuilder::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);

Retain the elements in the specified set within the UnicodeSetBuilder

Examples

use icu::uniset::{UnicodeSetBuilder, UnicodeSet};
let mut builder = UnicodeSetBuilder::new();
let set = UnicodeSet::from_inversion_list(vec![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'));

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::uniset::{UnicodeSetBuilder, UnicodeSet};
let mut builder = UnicodeSetBuilder::new();
let set = UnicodeSet::from_inversion_list(vec![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'));

Complements the character in the builder, adding it if not in the builder, and removing it otherwise.

Examples

use icu::uniset::UnicodeSetBuilder;
let mut builder = UnicodeSetBuilder::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'));

Complements the range in the builder, adding any elements in the range if not in the builder, and removing them otherwise.

Examples

use icu::uniset::UnicodeSetBuilder;
let mut builder = UnicodeSetBuilder::new();
builder.add_range(&('A'..='D'));
builder.complement_range(&('C'..='F'));
let check = builder.build();
assert!(check.contains('F'));
assert!(!check.contains('C'));

Complements the set in the builder, adding any elements in the set if not in the builder, and removing them otherwise.

Examples

use icu::uniset::{UnicodeSetBuilder, UnicodeSet};
let mut builder = UnicodeSetBuilder::new();
let set = UnicodeSet::from_inversion_list(vec![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

Returns whether the build is empty.

Examples

use icu::uniset::{UnicodeSetBuilder, UnicodeSet};
let mut builder = UnicodeSetBuilder::new();
let check = builder.build();
assert!(check.is_empty());

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Clone this trait object reference, returning a boxed trait object.

Return this boxed trait object as Box<dyn Any>. Read more

Return this trait object reference as &dyn Any. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.