blob: 939ba2fed8c2742503007331ee929b98b2a19083 [file] [log] [blame]
Manish Goregaokar361854c2025-03-05 15:02:28 -08001// Copyright (C) 2025 The Android Open Source Project
2// SPDX-License-Identifier: Apache-2.0
3
4#![allow(missing_docs)] // Not particularly useful to document these thin wrappers
5
6//! This is a thin wrapper around ICU4X for use in Bionic
7
8use icu_casemap::CaseMapper;
9use icu_collections::codepointtrie::TrieValue;
10use icu_properties::props::*;
11use icu_properties::{CodePointMapData, CodePointSetData};
12
13#[no_mangle]
14pub extern "C" fn __icu4x_bionic_general_category(ch: u32) -> u8 {
15 CodePointMapData::<GeneralCategory>::new().get32(ch) as u8
16}
17
18#[no_mangle]
19pub extern "C" fn __icu4x_bionic_east_asian_width(ch: u32) -> u8 {
20 CodePointMapData::<EastAsianWidth>::new().get32(ch).to_u32() as u8
21}
22
23#[no_mangle]
24pub extern "C" fn __icu4x_bionic_hangul_syllable_type(ch: u32) -> u8 {
25 CodePointMapData::<HangulSyllableType>::new().get32(ch).to_u32() as u8
26}
27
28#[no_mangle]
29pub extern "C" fn __icu4x_bionic_is_alphabetic(ch: u32) -> bool {
30 CodePointSetData::new::<Alphabetic>().contains32(ch)
31}
32
33#[no_mangle]
34pub extern "C" fn __icu4x_bionic_is_default_ignorable_code_point(ch: u32) -> bool {
35 CodePointSetData::new::<DefaultIgnorableCodePoint>().contains32(ch)
36}
37
38#[no_mangle]
39pub extern "C" fn __icu4x_bionic_is_lowercase(ch: u32) -> bool {
40 CodePointSetData::new::<Lowercase>().contains32(ch)
41}
42
43#[no_mangle]
44pub extern "C" fn __icu4x_bionic_is_alnum(ch: u32) -> bool {
45 CodePointSetData::new::<Alnum>().contains32(ch)
46}
47
48#[no_mangle]
49pub extern "C" fn __icu4x_bionic_is_blank(ch: u32) -> bool {
50 CodePointSetData::new::<Blank>().contains32(ch)
51}
52
53#[no_mangle]
54pub extern "C" fn __icu4x_bionic_is_graph(ch: u32) -> bool {
55 CodePointSetData::new::<Graph>().contains32(ch)
56}
57
58#[no_mangle]
59pub extern "C" fn __icu4x_bionic_is_print(ch: u32) -> bool {
60 CodePointSetData::new::<Print>().contains32(ch)
61}
62
63#[no_mangle]
64pub extern "C" fn __icu4x_bionic_is_xdigit(ch: u32) -> bool {
65 CodePointSetData::new::<Xdigit>().contains32(ch)
66}
67
68#[no_mangle]
69pub extern "C" fn __icu4x_bionic_is_white_space(ch: u32) -> bool {
70 CodePointSetData::new::<WhiteSpace>().contains32(ch)
71}
72
73#[no_mangle]
74pub extern "C" fn __icu4x_bionic_is_uppercase(ch: u32) -> bool {
75 CodePointSetData::new::<Uppercase>().contains32(ch)
76}
77
78/// Convert a code point to uppercase
79#[no_mangle]
80pub extern "C" fn __icu4x_bionic_to_upper(ch: u32) -> u32 {
81 let Ok(ch) = char::try_from(ch) else {
82 return ch;
83 };
84 let cm = CaseMapper::new();
85
86 cm.simple_uppercase(ch) as u32
87}
88
89/// Convert a code point to lowercase
90#[no_mangle]
91pub extern "C" fn __icu4x_bionic_to_lower(ch: u32) -> u32 {
92 let Ok(ch) = char::try_from(ch) else {
93 return ch;
94 };
95 let cm = CaseMapper::new();
96
97 cm.simple_lowercase(ch) as u32
98}