malachite_base/chars/constants.rs
1// Copyright © 2025 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::comparison::traits::{Max, Min};
10use crate::named::Named;
11
12/// The number of [Unicode scalar values](https://www.unicode.org/glossary/#unicode_scalar_value).
13/// $2^{20}+2^{16}-2^{11} = \mathrm{0x10\\,f800} = 1,\\!112,\\!064$.
14pub const NUMBER_OF_CHARS: u32 = (1 << 20) + (1 << 16) - NUMBER_OF_SURROGATE_CODE_POINTS;
15
16/// The number of [surrogate code points](https://www.unicode.org/glossary/#surrogate_code_point);
17/// these are code points that do not correspond to any valid [`char`].
18///
19/// $2^{11} = 2,\\!048$.
20pub const NUMBER_OF_SURROGATE_CODE_POINTS: u32 = 1 << 11;
21
22/// The first [surrogate code point](https://www.unicode.org/glossary/#surrogate_code_point).
23pub const FIRST_SURROGATE_CODE_POINT: u32 = 0xd800;
24
25/// The [`char`] that comes just before the surrogate range.
26///
27/// This happens to be an unassigned (as of Unicode 14.0) character in the [Hangul Jamo Extended-B
28/// block](https://www.unicode.org/charts/PDF/UD7B0.pdf).
29pub const CHAR_JUST_BELOW_SURROGATES: char = '\u{d7ff}';
30
31/// The [`char`] that comes just after the surrogate range.
32///
33/// This is a character in the [Private Use Area](https://www.unicode.org/charts/PDF/UE000.pdf).
34pub const CHAR_JUST_ABOVE_SURROGATES: char = '\u{e000}';
35
36impl Min for char {
37 /// The minimum value of a [`char`]: `'\u{0}'`.
38 ///
39 /// This is the famous NUL character, a [C0
40 /// control](https://www.unicode.org/charts/PDF/U0000.pdf).
41 const MIN: char = '\u{0}';
42}
43
44impl Max for char {
45 /// The maximum value of a [`char`]: `'\u{10ffff}'`.
46 ///
47 /// This is a character in [Supplementary Private Use
48 /// Area-B](https://www.unicode.org/charts/PDF/U10FF80.pdf).
49 const MAX: char = core::char::MAX;
50}
51impl_named!(char);