1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
45//! This module provides necessary functionality for highly efficient querying of sets of Unicode characters.
6//!
7//! It is an implementation of the code point portion of the existing
8//! [ICU4C UnicodeSet API](https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1UnicodeSet.html).
9//!
10//! # Architecture
11//! ICU4X [`CodePointInversionList`] is split up into independent levels, with [`CodePointInversionList`] representing the membership/query API,
12//! and [`CodePointInversionListBuilder`] representing the builder API.
13//!
14//! # Examples:
15//!
16//! ## Creating a `CodePointInversionList`
17//!
18//! `CodePointSets` are created from either serialized [`CodePointSets`](CodePointInversionList),
19//! represented by [inversion lists](http://userguide.icu-project.org/strings/properties),
20//! the [`CodePointInversionListBuilder`], or from the Properties API.
21//!
22//! ```
23//! use icu::collections::codepointinvlist::{
24//! CodePointInversionList, CodePointInversionListBuilder,
25//! };
26//!
27//! let mut builder = CodePointInversionListBuilder::new();
28//! builder.add_range('A'..='Z');
29//! let set: CodePointInversionList = builder.build();
30//!
31//! assert!(set.contains('A'));
32//! ```
33//!
34//! ## Querying a `CodePointInversionList`
35//!
36//! Currently, you can check if a character/range of characters exists in the [`CodePointInversionList`], or iterate through the characters.
37//!
38//! ```
39//! use icu::collections::codepointinvlist::{
40//! CodePointInversionList, CodePointInversionListBuilder,
41//! };
42//!
43//! let mut builder = CodePointInversionListBuilder::new();
44//! builder.add_range('A'..='Z');
45//! let set: CodePointInversionList = builder.build();
46//!
47//! assert!(set.contains('A'));
48//! assert!(set.contains_range('A'..='C'));
49//! assert_eq!(set.iter_chars().next(), Some('A'));
50//! ```
51//!
52//! [`ICU4X`]: ../icu/index.html
5354#![warn(missing_docs)]
5556#[cfg(feature = "alloc")]
57#[macro_use]
58mod builder;
59#[cfg(feature = "alloc")]
60mod conversions;
61mod cpinvlist;
62mod utils;
6364#[cfg(feature = "alloc")]
65pub use builder::CodePointInversionListBuilder;
66pub use cpinvlist::CodePointInversionList;
67pub use cpinvlist::CodePointInversionListULE;
68use displaydoc::Display;
6970#[derive(#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () =
{
impl ::core::fmt::Display for InvalidSetError {
fn fmt(&self, formatter: &mut ::core::fmt::Formatter)
-> ::core::fmt::Result {
#[allow(unused_variables)]
let Self() = self;
formatter.write_fmt(format_args!("A CodePointInversionList was constructed with an invalid inversion list"))
}
}
};Display, #[automatically_derived]
impl ::core::fmt::Debug for InvalidSetError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "InvalidSetError")
}
}Debug)]
71/// A CodePointInversionList was constructed with an invalid inversion list
72#[cfg_attr(feature = "alloc", displaydoc("Invalid set: {0:?}"))]
73pub struct InvalidSetError(
74#[cfg(feature = "alloc")] pub alloc::vec::Vec<potential_utf::PotentialCodePoint>,
75);
7677/// A CodePointInversionList was constructed from an invalid range
78#[derive(#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () =
{
impl ::core::fmt::Display for RangeError {
fn fmt(&self, formatter: &mut ::core::fmt::Formatter)
-> ::core::fmt::Result {
#[allow(unused_variables)]
let Self(_0, _1) = self;
formatter.write_fmt(format_args!("Invalid range: {0}..{1}",
_0, _1))
}
}
};Display, #[automatically_derived]
impl ::core::fmt::Debug for RangeError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field2_finish(f, "RangeError",
&self.0, &&self.1)
}
}Debug)]
79#[displaydoc("Invalid range: {0}..{1}")]
80pub struct RangeError(pub u32, pub u32);