tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

collections_sets.rs (9286B)


      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 #[diplomat::bridge]
      6 #[diplomat::abi_rename = "icu4x_{0}_mv1"]
      7 #[diplomat::attr(auto, namespace = "icu4x")]
      8 pub mod ffi {
      9    use alloc::boxed::Box;
     10 
     11    use crate::unstable::properties_sets::ffi::CodePointSetData;
     12 
     13    #[diplomat::opaque]
     14    #[diplomat::rust_link(
     15        icu::collections::codepointinvlist::CodePointInversionListBuilder,
     16        Struct
     17    )]
     18    pub struct CodePointSetBuilder(
     19        pub icu_collections::codepointinvlist::CodePointInversionListBuilder,
     20    );
     21 
     22    impl CodePointSetBuilder {
     23        /// Make a new set builder containing nothing
     24        #[diplomat::rust_link(
     25            icu::collections::codepointinvlist::CodePointInversionListBuilder::new,
     26            FnInStruct
     27        )]
     28        #[diplomat::attr(auto, constructor)]
     29        pub fn create() -> Box<Self> {
     30            Box::new(Self(
     31                icu_collections::codepointinvlist::CodePointInversionListBuilder::new(),
     32            ))
     33        }
     34 
     35        /// Build this into a set
     36        ///
     37        /// This object is repopulated with an empty builder
     38        #[diplomat::rust_link(
     39            icu::collections::codepointinvlist::CodePointInversionListBuilder::build,
     40            FnInStruct
     41        )]
     42        #[diplomat::rust_link(
     43            icu::properties::CodePointSetData::from_code_point_inversion_list,
     44            FnInStruct,
     45            hidden
     46        )]
     47        pub fn build(&mut self) -> Box<CodePointSetData> {
     48            let inner = core::mem::take(&mut self.0);
     49            let built = inner.build();
     50            let set = icu_properties::CodePointSetData::from_code_point_inversion_list(built);
     51            Box::new(CodePointSetData(set))
     52        }
     53 
     54        /// Complements this set
     55        ///
     56        /// (Elements in this set are removed and vice versa)
     57        #[diplomat::rust_link(
     58            icu::collections::codepointinvlist::CodePointInversionListBuilder::complement,
     59            FnInStruct
     60        )]
     61        pub fn complement(&mut self) {
     62            self.0.complement()
     63        }
     64 
     65        /// Returns whether this set is empty
     66        #[diplomat::rust_link(
     67            icu::collections::codepointinvlist::CodePointInversionListBuilder::is_empty,
     68            FnInStruct
     69        )]
     70        #[diplomat::attr(auto, getter)]
     71        pub fn is_empty(&self) -> bool {
     72            self.0.is_empty()
     73        }
     74 
     75        /// Add a single character to the set
     76        #[diplomat::rust_link(
     77            icu::collections::codepointinvlist::CodePointInversionListBuilder::add_char,
     78            FnInStruct
     79        )]
     80        #[diplomat::rust_link(
     81            icu::collections::codepointinvlist::CodePointInversionListBuilder::add32,
     82            FnInStruct,
     83            hidden
     84        )]
     85        pub fn add_char(&mut self, ch: DiplomatChar) {
     86            self.0.add32(ch)
     87        }
     88 
     89        /// Add an inclusive range of characters to the set
     90        #[diplomat::rust_link(
     91            icu::collections::codepointinvlist::CodePointInversionListBuilder::add_range,
     92            FnInStruct
     93        )]
     94        #[diplomat::rust_link(
     95            icu::collections::codepointinvlist::CodePointInversionListBuilder::add_range32,
     96            FnInStruct,
     97            hidden
     98        )]
     99        pub fn add_inclusive_range(&mut self, start: DiplomatChar, end: DiplomatChar) {
    100            self.0.add_range32(start..=end)
    101        }
    102 
    103        /// Add all elements that belong to the provided set to the set
    104        #[diplomat::rust_link(
    105            icu::collections::codepointinvlist::CodePointInversionListBuilder::add_set,
    106            FnInStruct
    107        )]
    108        #[diplomat::rust_link(
    109            icu::properties::CodePointSetData::as_code_point_inversion_list,
    110            FnInStruct,
    111            hidden
    112        )]
    113        #[diplomat::rust_link(
    114            icu::properties::CodePointSetData::to_code_point_inversion_list,
    115            FnInStruct,
    116            hidden
    117        )]
    118        pub fn add_set(&mut self, data: &CodePointSetData) {
    119            // This is a ZeroFrom and always cheap for a CPIL, may be expensive
    120            // for other impls. In the future we can make this builder support multiple impls
    121            // if we ever add them
    122            let list = data.0.to_code_point_inversion_list();
    123            self.0.add_set(&list);
    124        }
    125 
    126        /// Remove a single character to the set
    127        #[diplomat::rust_link(
    128            icu::collections::codepointinvlist::CodePointInversionListBuilder::remove_char,
    129            FnInStruct
    130        )]
    131        #[diplomat::rust_link(
    132            icu::collections::codepointinvlist::CodePointInversionListBuilder::remove32,
    133            FnInStruct,
    134            hidden
    135        )]
    136        pub fn remove_char(&mut self, ch: DiplomatChar) {
    137            self.0.remove32(ch)
    138        }
    139 
    140        /// Remove an inclusive range of characters from the set
    141        #[diplomat::rust_link(
    142            icu::collections::codepointinvlist::CodePointInversionListBuilder::remove_range,
    143            FnInStruct
    144        )]
    145        #[diplomat::rust_link(
    146            icu::collections::codepointinvlist::CodePointInversionListBuilder::remove_range32,
    147            FnInStruct,
    148            hidden
    149        )]
    150        pub fn remove_inclusive_range(&mut self, start: DiplomatChar, end: DiplomatChar) {
    151            self.0.remove_range32(start..=end)
    152        }
    153 
    154        /// Remove all elements that belong to the provided set from the set
    155        #[diplomat::rust_link(
    156            icu::collections::codepointinvlist::CodePointInversionListBuilder::remove_set,
    157            FnInStruct
    158        )]
    159        pub fn remove_set(&mut self, data: &CodePointSetData) {
    160            // (see comment in add_set)
    161            let list = data.0.to_code_point_inversion_list();
    162            self.0.remove_set(&list);
    163        }
    164 
    165        /// Removes all elements from the set except a single character
    166        #[diplomat::rust_link(
    167            icu::collections::codepointinvlist::CodePointInversionListBuilder::retain_char,
    168            FnInStruct
    169        )]
    170        #[diplomat::rust_link(
    171            icu::collections::codepointinvlist::CodePointInversionListBuilder::retain32,
    172            FnInStruct,
    173            hidden
    174        )]
    175        pub fn retain_char(&mut self, ch: DiplomatChar) {
    176            self.0.retain32(ch)
    177        }
    178 
    179        /// Removes all elements from the set except an inclusive range of characters f
    180        #[diplomat::rust_link(
    181            icu::collections::codepointinvlist::CodePointInversionListBuilder::retain_range,
    182            FnInStruct
    183        )]
    184        #[diplomat::rust_link(
    185            icu::collections::codepointinvlist::CodePointInversionListBuilder::retain_range32,
    186            FnInStruct,
    187            hidden
    188        )]
    189        pub fn retain_inclusive_range(&mut self, start: DiplomatChar, end: DiplomatChar) {
    190            self.0.retain_range32(start..=end)
    191        }
    192 
    193        /// Removes all elements from the set except all elements in the provided set
    194        #[diplomat::rust_link(
    195            icu::collections::codepointinvlist::CodePointInversionListBuilder::retain_set,
    196            FnInStruct
    197        )]
    198        pub fn retain_set(&mut self, data: &CodePointSetData) {
    199            // (see comment in add_set)
    200            let list = data.0.to_code_point_inversion_list();
    201            self.0.retain_set(&list);
    202        }
    203 
    204        /// Complement a single character to the set
    205        ///
    206        /// (Characters which are in this set are removed and vice versa)
    207        #[diplomat::rust_link(
    208            icu::collections::codepointinvlist::CodePointInversionListBuilder::complement_char,
    209            FnInStruct
    210        )]
    211        #[diplomat::rust_link(
    212            icu::collections::codepointinvlist::CodePointInversionListBuilder::complement32,
    213            FnInStruct,
    214            hidden
    215        )]
    216        pub fn complement_char(&mut self, ch: DiplomatChar) {
    217            self.0.complement32(ch)
    218        }
    219 
    220        /// Complement an inclusive range of characters from the set
    221        ///
    222        /// (Characters which are in this set are removed and vice versa)
    223        #[diplomat::rust_link(
    224            icu::collections::codepointinvlist::CodePointInversionListBuilder::complement_range,
    225            FnInStruct
    226        )]
    227        #[diplomat::rust_link(
    228            icu::collections::codepointinvlist::CodePointInversionListBuilder::complement_range32,
    229            FnInStruct,
    230            hidden
    231        )]
    232        pub fn complement_inclusive_range(&mut self, start: DiplomatChar, end: DiplomatChar) {
    233            self.0.complement_range32(start..=end)
    234        }
    235 
    236        /// Complement all elements that belong to the provided set from the set
    237        ///
    238        /// (Characters which are in this set are removed and vice versa)
    239        #[diplomat::rust_link(
    240            icu::collections::codepointinvlist::CodePointInversionListBuilder::complement_set,
    241            FnInStruct
    242        )]
    243        pub fn complement_set(&mut self, data: &CodePointSetData) {
    244            // (see comment in add_set)
    245            let list = data.0.to_code_point_inversion_list();
    246            self.0.complement_set(&list);
    247        }
    248    }
    249 }