1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! This module provides necessary functionality for highly efficient querying of sets of Unicode characters.
//!
//! It is an implementation of the code point portion of the existing
//! [ICU4C UnicodeSet API](https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1UnicodeSet.html).
//!
//! # Architecture
//! ICU4X [`CodePointInversionList`] is split up into independent levels, with [`CodePointInversionList`] representing the membership/query API,
//! and [`CodePointInversionListBuilder`] representing the builder API.
//!
//! # Examples:
//!
//! ## Creating a `CodePointInversionList`
//!
//! `CodePointSets` are created from either serialized [`CodePointSets`](CodePointInversionList),
//! represented by [inversion lists](http://userguide.icu-project.org/strings/properties),
//! the [`CodePointInversionListBuilder`], or from the Properties API.
//!
//! ```
//! use icu::collections::codepointinvlist::{
//!     CodePointInversionList, CodePointInversionListBuilder,
//! };
//!
//! let mut builder = CodePointInversionListBuilder::new();
//! builder.add_range('A'..='Z');
//! let set: CodePointInversionList = builder.build();
//!
//! assert!(set.contains('A'));
//! ```
//!
//! ## Querying a `CodePointInversionList`
//!
//! Currently, you can check if a character/range of characters exists in the [`CodePointInversionList`], or iterate through the characters.
//!
//! ```
//! use icu::collections::codepointinvlist::{
//!     CodePointInversionList, CodePointInversionListBuilder,
//! };
//!
//! let mut builder = CodePointInversionListBuilder::new();
//! builder.add_range('A'..='Z');
//! let set: CodePointInversionList = builder.build();
//!
//! assert!(set.contains('A'));
//! assert!(set.contains_range('A'..='C'));
//! assert_eq!(set.iter_chars().next(), Some('A'));
//! ```
//!
//! [`ICU4X`]: ../icu/index.html

#![warn(missing_docs)]

extern crate alloc;

#[macro_use]
mod builder;
mod conversions;
mod cpinvlist;
mod utils;

use alloc::vec::Vec;

pub use builder::CodePointInversionListBuilder;
pub use cpinvlist::CodePointInversionList;
pub use cpinvlist::CodePointInversionListULE;
use displaydoc::Display;

#[derive(Display, Debug)]
/// A CodePointInversionList was constructed with an invalid inversion list
#[displaydoc("Invalid set: {0:?}")]
pub struct InvalidSetError(pub Vec<potential_utf::PotentialCodePoint>);

/// A CodePointInversionList was constructed from an invalid range
#[derive(Display, Debug)]
#[displaydoc("Invalid range: {0}..{1}")]
pub struct RangeError(pub u32, pub u32);