icu_collections/codepointinvlist/
mod.rs

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 ).
4
5//! 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
53
54#![warn(missing_docs)]
55
56extern crate alloc;
57
58#[cfg(feature = "alloc")]
59#[macro_use]
60mod builder;
61#[cfg(feature = "alloc")]
62mod conversions;
63mod cpinvlist;
64mod utils;
65
66#[cfg(feature = "alloc")]
67pub use builder::CodePointInversionListBuilder;
68pub use cpinvlist::CodePointInversionList;
69pub use cpinvlist::CodePointInversionListULE;
70use displaydoc::Display;
71
72#[derive(Display, Debug)]
73/// A CodePointInversionList was constructed with an invalid inversion list
74#[cfg_attr(feature = "alloc", displaydoc("Invalid set: {0:?}"))]
75pub struct InvalidSetError(
76    #[cfg(feature = "alloc")] pub alloc::vec::Vec<potential_utf::PotentialCodePoint>,
77);
78
79/// A CodePointInversionList was constructed from an invalid range
80#[derive(Display, Debug)]
81#[displaydoc("Invalid range: {0}..{1}")]
82pub struct RangeError(pub u32, pub u32);