rust_macios/foundation/
ns_character_set.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{object, 
4    objective_c_runtime::{
5        macros::{interface_impl},
6        traits::{FromId, PNSObject},
7    },
8    utils::to_bool,
9};
10
11use super::{unichar, NSCoder, NSData, NSRange, NSString, UInt8};
12
13object! {
14    /// A character set containing the characters in Unicode General Categories L*, M*, and N*.
15    unsafe pub struct NSCharacterSet;
16}
17
18#[interface_impl(NSObject)]
19impl NSCharacterSet {
20    /* Getting Standard Character Sets
21     */
22
23    /// A character set containing the characters in Unicode General Categories L*, M*, and N*.
24    #[property]
25    pub fn alphanumeric_character_set() -> NSCharacterSet {
26        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), alphanumericCharacterSet]) }
27    }
28
29    /// A character set containing the characters in Unicode General Category Lt.
30    #[property]
31    pub fn capitalized_letter_character_set() -> NSCharacterSet {
32        unsafe {
33            NSCharacterSet::from_id(msg_send![Self::m_class(), capitalizedLetterCharacterSet])
34        }
35    }
36
37    /// A character set containing the characters in Unicode General Category Cc and Cf.
38    #[property]
39    pub fn control_character_set() -> NSCharacterSet {
40        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), controlCharacterSet]) }
41    }
42
43    /// A character set containing the characters in the category of Decimal Numbers.
44    #[property]
45    pub fn decimal_digit_character_set() -> NSCharacterSet {
46        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), decimalDigitCharacterSet]) }
47    }
48
49    /// A character set containing individual Unicode characters that can also be represented as composed character sequences (such as for letters with accents), by the definition of “standard decomposition” in version 3.2 of the Unicode character encoding standard.
50    #[property]
51    pub fn decomposable_character_set() -> NSCharacterSet {
52        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), decomposableCharacterSet]) }
53    }
54
55    /// A character set containing values in the category of Non-Characters or that have not yet been defined in version 3.2 of the Unicode standard.
56    #[property]
57    pub fn illegal_character_set() -> NSCharacterSet {
58        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), illegalCharacterSet]) }
59    }
60
61    /// A character set containing the characters in Unicode General Category L* & M*.
62    #[property]
63    pub fn letter_character_set() -> NSCharacterSet {
64        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), letterCharacterSet]) }
65    }
66
67    /// A character set containing the characters in Unicode General Category Ll.
68    #[property]
69    pub fn lowercase_letter_character_set() -> NSCharacterSet {
70        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), lowercaseLetterCharacterSet]) }
71    }
72
73    /// A character set containing the newline characters (U+000A ~ U+000D, U+0085, U+2028, and U+2029).
74    #[property]
75    pub fn newline_character_set() -> NSCharacterSet {
76        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), newlineCharacterSet]) }
77    }
78
79    /// A character set containing the characters in Unicode General Category M*.
80    #[property]
81    pub fn non_base_character_set() -> NSCharacterSet {
82        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), nonBaseCharacterSet]) }
83    }
84
85    /// A character set containing the characters in Unicode General Category P*.
86    #[property]
87    pub fn punctuation_character_set() -> NSCharacterSet {
88        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), punctuationCharacterSet]) }
89    }
90
91    /// A character set containing the characters in Unicode General Category S*.
92    #[property]
93    pub fn symbol_character_set() -> NSCharacterSet {
94        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), symbolCharacterSet]) }
95    }
96
97    /// A character set containing the characters in Unicode General Category Lu and Lt.
98    #[property]
99    pub fn uppercase_letter_character_set() -> NSCharacterSet {
100        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), uppercaseLetterCharacterSet]) }
101    }
102
103    /// A character set containing characters in Unicode General Category Z*, U+000A ~ U+000D, and U+0085.
104    #[property]
105    pub fn whitespace_and_newline_character_set() -> NSCharacterSet {
106        unsafe {
107            NSCharacterSet::from_id(msg_send![Self::m_class(), whitespaceAndNewlineCharacterSet])
108        }
109    }
110
111    /// A character set containing the characters in Unicode General Category Zs and CHARACTER TABULATION (U+0009).
112    #[property]
113    pub fn whitespace_character_set() -> NSCharacterSet {
114        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), whitespaceCharacterSet]) }
115    }
116
117    /* Getting Character Sets for URL Encoding
118     */
119
120    /// Returns the character set for characters allowed in a fragment URL component.
121    #[property]
122    pub fn url_fragment_allowed_character_set() -> NSCharacterSet {
123        unsafe {
124            NSCharacterSet::from_id(msg_send![Self::m_class(), URLFragmentAllowedCharacterSet])
125        }
126    }
127
128    /// Returns the character set for characters allowed in a host URL subcomponent.
129    #[property]
130    pub fn url_host_allowed_character_set() -> NSCharacterSet {
131        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), URLHostAllowedCharacterSet]) }
132    }
133
134    /// Returns the character set for characters allowed in a password URL subcomponent.
135    #[property]
136    pub fn url_password_allowed_character_set() -> NSCharacterSet {
137        unsafe {
138            NSCharacterSet::from_id(msg_send![Self::m_class(), URLPasswordAllowedCharacterSet])
139        }
140    }
141
142    /// Returns the character set for characters allowed in a path URL component.
143    #[property]
144    pub fn url_path_allowed_character_set() -> NSCharacterSet {
145        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), URLPathAllowedCharacterSet]) }
146    }
147
148    /// Returns the character set for characters allowed in a query URL component.
149    #[property]
150    pub fn url_query_allowed_character_set() -> NSCharacterSet {
151        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), URLQueryAllowedCharacterSet]) }
152    }
153
154    /// Returns the character set for characters allowed in a user URL subcomponent.
155    #[property]
156    pub fn url_user_allowed_character_set() -> NSCharacterSet {
157        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), URLUserAllowedCharacterSet]) }
158    }
159
160    /* Creating a Custom Character Set
161     */
162
163    /// Initializing with coder
164    #[method]
165    pub fn init_with_coder(mut self, coder: NSCoder) -> Self
166    where
167        Self: Sized + FromId,
168    {
169        unsafe { Self::from_id(msg_send![self.m_self(), initWithCoder: coder]) }
170    }
171
172    /// Returns a character set containing the characters in a given string.
173    #[method]
174    pub fn character_set_with_characters_in_string(string: NSString) -> NSCharacterSet {
175        unsafe {
176            NSCharacterSet::from_id(msg_send![
177                Self::m_class(),
178                characterSetWithCharactersInString: string
179            ])
180        }
181    }
182
183    /// Returns a character set containing characters with Unicode values in a given range.
184    #[method]
185    pub fn character_set_with_range(range: NSRange) -> NSCharacterSet {
186        unsafe { NSCharacterSet::from_id(msg_send![Self::m_class(), characterSetWithRange: range]) }
187    }
188
189    /* Creating and Managing Character Sets as Bitmap Representations
190     */
191
192    /// Returns a character set containing characters determined by a given bitmap representation.
193    #[method]
194    pub fn character_set_with_bitmap_representation(data: NSData) -> NSCharacterSet {
195        unsafe {
196            NSCharacterSet::from_id(msg_send![
197                Self::m_class(),
198                characterSetWithBitmapRepresentation: data
199            ])
200        }
201    }
202
203    /// Returns a character set read from the bitmap representation stored in the file a given path.
204    #[method]
205    pub fn character_set_with_contents_of_file(path: NSString) -> NSCharacterSet {
206        unsafe {
207            NSCharacterSet::from_id(msg_send![
208                Self::m_class(),
209                characterSetWithContentsOfFile: path
210            ])
211        }
212    }
213
214    /// An NSData object encoding the receiver in binary format.
215    #[property]
216    pub fn bitmap_representation(&self) -> NSData {
217        unsafe { NSData::from_id(msg_send![self.m_self(), bitmapRepresentation]) }
218    }
219
220    /// A character set containing only characters that don’t exist in the receiver.
221    #[property]
222    pub fn inverted_set(&self) -> NSCharacterSet {
223        unsafe { NSCharacterSet::from_id(msg_send![self.m_self(), invertedSet]) }
224    }
225
226    /* Testing Set Membership
227     */
228
229    /// Returns a Boolean value that indicates whether a given character is in the receiver.
230    #[method]
231    pub fn character_is_member(&self, character: unichar) -> bool {
232        unsafe { to_bool(msg_send![self.m_self(), characterIsMember: character]) }
233    }
234
235    /// Returns a Boolean value that indicates whether the receiver has at least one member in a given character plane.
236    #[method]
237    pub fn has_member_in_plane(&self, plane: UInt8) -> bool {
238        unsafe { to_bool(msg_send![self.m_self(), hasMemberInPlane: plane]) }
239    }
240
241    /// Returns a Boolean value that indicates whether the receiver is a superset of another given character set.
242    #[method]
243    pub fn is_superset_of_set(&self, other: NSCharacterSet) -> bool {
244        unsafe { to_bool(msg_send![self.m_self(), isSupersetOfSet: other]) }
245    }
246
247    /// Returns a Boolean value that indicates whether a given long character is a member of the receiver.
248    #[method]
249    pub fn long_character_is_member(&self, long_char: u32) -> bool {
250        unsafe { to_bool(msg_send![self.m_self(), longCharacterIsMember: long_char]) }
251    }
252}