objc2_core_foundation/generated/
CFNumberFormatter.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatterkey?language=objc)
13// NS_TYPED_ENUM
14pub type CFNumberFormatterKey = CFString;
15
16/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatter?language=objc)
17#[doc(alias = "CFNumberFormatterRef")]
18#[repr(C)]
19pub struct CFNumberFormatter {
20    inner: [u8; 0],
21    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
22}
23
24cf_type!(
25    unsafe impl CFNumberFormatter {}
26);
27#[cfg(feature = "objc2")]
28cf_objc2_type!(
29    unsafe impl RefEncode<"__CFNumberFormatter"> for CFNumberFormatter {}
30);
31
32unsafe impl ConcreteType for CFNumberFormatter {
33    #[doc(alias = "CFNumberFormatterGetTypeID")]
34    #[inline]
35    fn type_id() -> CFTypeID {
36        extern "C-unwind" {
37            fn CFNumberFormatterGetTypeID() -> CFTypeID;
38        }
39        unsafe { CFNumberFormatterGetTypeID() }
40    }
41}
42
43/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatterstyle?language=objc)
44// NS_ENUM
45#[repr(transparent)]
46#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
47pub struct CFNumberFormatterStyle(pub CFIndex);
48impl CFNumberFormatterStyle {
49    #[doc(alias = "kCFNumberFormatterNoStyle")]
50    pub const NoStyle: Self = Self(0);
51    #[doc(alias = "kCFNumberFormatterDecimalStyle")]
52    pub const DecimalStyle: Self = Self(1);
53    #[doc(alias = "kCFNumberFormatterCurrencyStyle")]
54    pub const CurrencyStyle: Self = Self(2);
55    #[doc(alias = "kCFNumberFormatterPercentStyle")]
56    pub const PercentStyle: Self = Self(3);
57    #[doc(alias = "kCFNumberFormatterScientificStyle")]
58    pub const ScientificStyle: Self = Self(4);
59    #[doc(alias = "kCFNumberFormatterSpellOutStyle")]
60    pub const SpellOutStyle: Self = Self(5);
61    #[doc(alias = "kCFNumberFormatterOrdinalStyle")]
62    pub const OrdinalStyle: Self = Self(6);
63    #[doc(alias = "kCFNumberFormatterCurrencyISOCodeStyle")]
64    pub const CurrencyISOCodeStyle: Self = Self(8);
65    #[doc(alias = "kCFNumberFormatterCurrencyPluralStyle")]
66    pub const CurrencyPluralStyle: Self = Self(9);
67    #[doc(alias = "kCFNumberFormatterCurrencyAccountingStyle")]
68    pub const CurrencyAccountingStyle: Self = Self(10);
69}
70
71#[cfg(feature = "objc2")]
72unsafe impl Encode for CFNumberFormatterStyle {
73    const ENCODING: Encoding = CFIndex::ENCODING;
74}
75
76#[cfg(feature = "objc2")]
77unsafe impl RefEncode for CFNumberFormatterStyle {
78    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
79}
80
81impl CFNumberFormatter {
82    /// # Safety
83    ///
84    /// - `allocator` might not allow `None`.
85    /// - `locale` might not allow `None`.
86    #[doc(alias = "CFNumberFormatterCreate")]
87    #[cfg(feature = "CFLocale")]
88    #[inline]
89    pub unsafe fn new(
90        allocator: Option<&CFAllocator>,
91        locale: Option<&CFLocale>,
92        style: CFNumberFormatterStyle,
93    ) -> Option<CFRetained<CFNumberFormatter>> {
94        extern "C-unwind" {
95            fn CFNumberFormatterCreate(
96                allocator: Option<&CFAllocator>,
97                locale: Option<&CFLocale>,
98                style: CFNumberFormatterStyle,
99            ) -> Option<NonNull<CFNumberFormatter>>;
100        }
101        let ret = unsafe { CFNumberFormatterCreate(allocator, locale, style) };
102        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
103    }
104
105    #[doc(alias = "CFNumberFormatterGetLocale")]
106    #[cfg(feature = "CFLocale")]
107    #[inline]
108    pub fn locale(&self) -> Option<CFRetained<CFLocale>> {
109        extern "C-unwind" {
110            fn CFNumberFormatterGetLocale(
111                formatter: &CFNumberFormatter,
112            ) -> Option<NonNull<CFLocale>>;
113        }
114        let ret = unsafe { CFNumberFormatterGetLocale(self) };
115        ret.map(|ret| unsafe { CFRetained::retain(ret) })
116    }
117
118    #[doc(alias = "CFNumberFormatterGetStyle")]
119    #[inline]
120    pub fn style(&self) -> CFNumberFormatterStyle {
121        extern "C-unwind" {
122            fn CFNumberFormatterGetStyle(formatter: &CFNumberFormatter) -> CFNumberFormatterStyle;
123        }
124        unsafe { CFNumberFormatterGetStyle(self) }
125    }
126
127    #[doc(alias = "CFNumberFormatterGetFormat")]
128    #[inline]
129    pub fn format(&self) -> Option<CFRetained<CFString>> {
130        extern "C-unwind" {
131            fn CFNumberFormatterGetFormat(
132                formatter: &CFNumberFormatter,
133            ) -> Option<NonNull<CFString>>;
134        }
135        let ret = unsafe { CFNumberFormatterGetFormat(self) };
136        ret.map(|ret| unsafe { CFRetained::retain(ret) })
137    }
138
139    /// # Safety
140    ///
141    /// `format_string` might not allow `None`.
142    #[doc(alias = "CFNumberFormatterSetFormat")]
143    #[inline]
144    pub unsafe fn set_format(&self, format_string: Option<&CFString>) {
145        extern "C-unwind" {
146            fn CFNumberFormatterSetFormat(
147                formatter: &CFNumberFormatter,
148                format_string: Option<&CFString>,
149            );
150        }
151        unsafe { CFNumberFormatterSetFormat(self, format_string) }
152    }
153
154    /// # Safety
155    ///
156    /// - `allocator` might not allow `None`.
157    /// - `formatter` might not allow `None`.
158    /// - `number` might not allow `None`.
159    #[doc(alias = "CFNumberFormatterCreateStringWithNumber")]
160    #[cfg(feature = "CFNumber")]
161    #[inline]
162    pub unsafe fn new_string_with_number(
163        allocator: Option<&CFAllocator>,
164        formatter: Option<&CFNumberFormatter>,
165        number: Option<&CFNumber>,
166    ) -> Option<CFRetained<CFString>> {
167        extern "C-unwind" {
168            fn CFNumberFormatterCreateStringWithNumber(
169                allocator: Option<&CFAllocator>,
170                formatter: Option<&CFNumberFormatter>,
171                number: Option<&CFNumber>,
172            ) -> Option<NonNull<CFString>>;
173        }
174        let ret = unsafe { CFNumberFormatterCreateStringWithNumber(allocator, formatter, number) };
175        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
176    }
177
178    /// # Safety
179    ///
180    /// - `allocator` might not allow `None`.
181    /// - `formatter` might not allow `None`.
182    /// - `value_ptr` must be a valid pointer.
183    #[doc(alias = "CFNumberFormatterCreateStringWithValue")]
184    #[cfg(feature = "CFNumber")]
185    #[inline]
186    pub unsafe fn new_string_with_value(
187        allocator: Option<&CFAllocator>,
188        formatter: Option<&CFNumberFormatter>,
189        number_type: CFNumberType,
190        value_ptr: *const c_void,
191    ) -> Option<CFRetained<CFString>> {
192        extern "C-unwind" {
193            fn CFNumberFormatterCreateStringWithValue(
194                allocator: Option<&CFAllocator>,
195                formatter: Option<&CFNumberFormatter>,
196                number_type: CFNumberType,
197                value_ptr: *const c_void,
198            ) -> Option<NonNull<CFString>>;
199        }
200        let ret = unsafe {
201            CFNumberFormatterCreateStringWithValue(allocator, formatter, number_type, value_ptr)
202        };
203        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
204    }
205}
206
207/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatteroptionflags?language=objc)
208// NS_OPTIONS
209#[repr(transparent)]
210#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
211pub struct CFNumberFormatterOptionFlags(pub CFOptionFlags);
212bitflags::bitflags! {
213    impl CFNumberFormatterOptionFlags: CFOptionFlags {
214        #[doc(alias = "kCFNumberFormatterParseIntegersOnly")]
215        const ParseIntegersOnly = 1;
216    }
217}
218
219#[cfg(feature = "objc2")]
220unsafe impl Encode for CFNumberFormatterOptionFlags {
221    const ENCODING: Encoding = CFOptionFlags::ENCODING;
222}
223
224#[cfg(feature = "objc2")]
225unsafe impl RefEncode for CFNumberFormatterOptionFlags {
226    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
227}
228
229impl CFNumberFormatter {
230    /// # Safety
231    ///
232    /// - `allocator` might not allow `None`.
233    /// - `formatter` might not allow `None`.
234    /// - `string` might not allow `None`.
235    /// - `rangep` must be a valid pointer.
236    #[doc(alias = "CFNumberFormatterCreateNumberFromString")]
237    #[cfg(feature = "CFNumber")]
238    #[inline]
239    pub unsafe fn new_number_from_string(
240        allocator: Option<&CFAllocator>,
241        formatter: Option<&CFNumberFormatter>,
242        string: Option<&CFString>,
243        rangep: *mut CFRange,
244        options: CFOptionFlags,
245    ) -> Option<CFRetained<CFNumber>> {
246        extern "C-unwind" {
247            fn CFNumberFormatterCreateNumberFromString(
248                allocator: Option<&CFAllocator>,
249                formatter: Option<&CFNumberFormatter>,
250                string: Option<&CFString>,
251                rangep: *mut CFRange,
252                options: CFOptionFlags,
253            ) -> Option<NonNull<CFNumber>>;
254        }
255        let ret = unsafe {
256            CFNumberFormatterCreateNumberFromString(allocator, formatter, string, rangep, options)
257        };
258        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
259    }
260
261    /// # Safety
262    ///
263    /// - `string` might not allow `None`.
264    /// - `rangep` must be a valid pointer.
265    /// - `value_ptr` must be a valid pointer.
266    #[doc(alias = "CFNumberFormatterGetValueFromString")]
267    #[cfg(feature = "CFNumber")]
268    #[inline]
269    pub unsafe fn value_from_string(
270        &self,
271        string: Option<&CFString>,
272        rangep: *mut CFRange,
273        number_type: CFNumberType,
274        value_ptr: *mut c_void,
275    ) -> bool {
276        extern "C-unwind" {
277            fn CFNumberFormatterGetValueFromString(
278                formatter: &CFNumberFormatter,
279                string: Option<&CFString>,
280                rangep: *mut CFRange,
281                number_type: CFNumberType,
282                value_ptr: *mut c_void,
283            ) -> Boolean;
284        }
285        let ret = unsafe {
286            CFNumberFormatterGetValueFromString(self, string, rangep, number_type, value_ptr)
287        };
288        ret != 0
289    }
290
291    /// # Safety
292    ///
293    /// - `key` might not allow `None`.
294    /// - `value` should be of the correct type.
295    /// - `value` might not allow `None`.
296    #[doc(alias = "CFNumberFormatterSetProperty")]
297    #[inline]
298    pub unsafe fn set_property(&self, key: Option<&CFNumberFormatterKey>, value: Option<&CFType>) {
299        extern "C-unwind" {
300            fn CFNumberFormatterSetProperty(
301                formatter: &CFNumberFormatter,
302                key: Option<&CFNumberFormatterKey>,
303                value: Option<&CFType>,
304            );
305        }
306        unsafe { CFNumberFormatterSetProperty(self, key, value) }
307    }
308
309    /// # Safety
310    ///
311    /// `key` might not allow `None`.
312    #[doc(alias = "CFNumberFormatterCopyProperty")]
313    #[inline]
314    pub unsafe fn property(
315        &self,
316        key: Option<&CFNumberFormatterKey>,
317    ) -> Option<CFRetained<CFType>> {
318        extern "C-unwind" {
319            fn CFNumberFormatterCopyProperty(
320                formatter: &CFNumberFormatter,
321                key: Option<&CFNumberFormatterKey>,
322            ) -> Option<NonNull<CFType>>;
323        }
324        let ret = unsafe { CFNumberFormatterCopyProperty(self, key) };
325        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
326    }
327}
328
329extern "C" {
330    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattercurrencycode?language=objc)
331    pub static kCFNumberFormatterCurrencyCode: Option<&'static CFNumberFormatterKey>;
332}
333
334extern "C" {
335    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterdecimalseparator?language=objc)
336    pub static kCFNumberFormatterDecimalSeparator: Option<&'static CFNumberFormatterKey>;
337}
338
339extern "C" {
340    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattercurrencydecimalseparator?language=objc)
341    pub static kCFNumberFormatterCurrencyDecimalSeparator: Option<&'static CFNumberFormatterKey>;
342}
343
344extern "C" {
345    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatteralwaysshowdecimalseparator?language=objc)
346    pub static kCFNumberFormatterAlwaysShowDecimalSeparator: Option<&'static CFNumberFormatterKey>;
347}
348
349extern "C" {
350    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattergroupingseparator?language=objc)
351    pub static kCFNumberFormatterGroupingSeparator: Option<&'static CFNumberFormatterKey>;
352}
353
354extern "C" {
355    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterusegroupingseparator?language=objc)
356    pub static kCFNumberFormatterUseGroupingSeparator: Option<&'static CFNumberFormatterKey>;
357}
358
359extern "C" {
360    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpercentsymbol?language=objc)
361    pub static kCFNumberFormatterPercentSymbol: Option<&'static CFNumberFormatterKey>;
362}
363
364extern "C" {
365    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterzerosymbol?language=objc)
366    pub static kCFNumberFormatterZeroSymbol: Option<&'static CFNumberFormatterKey>;
367}
368
369extern "C" {
370    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatternansymbol?language=objc)
371    pub static kCFNumberFormatterNaNSymbol: Option<&'static CFNumberFormatterKey>;
372}
373
374extern "C" {
375    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterinfinitysymbol?language=objc)
376    pub static kCFNumberFormatterInfinitySymbol: Option<&'static CFNumberFormatterKey>;
377}
378
379extern "C" {
380    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterminussign?language=objc)
381    pub static kCFNumberFormatterMinusSign: Option<&'static CFNumberFormatterKey>;
382}
383
384extern "C" {
385    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterplussign?language=objc)
386    pub static kCFNumberFormatterPlusSign: Option<&'static CFNumberFormatterKey>;
387}
388
389extern "C" {
390    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattercurrencysymbol?language=objc)
391    pub static kCFNumberFormatterCurrencySymbol: Option<&'static CFNumberFormatterKey>;
392}
393
394extern "C" {
395    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterexponentsymbol?language=objc)
396    pub static kCFNumberFormatterExponentSymbol: Option<&'static CFNumberFormatterKey>;
397}
398
399extern "C" {
400    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterminintegerdigits?language=objc)
401    pub static kCFNumberFormatterMinIntegerDigits: Option<&'static CFNumberFormatterKey>;
402}
403
404extern "C" {
405    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermaxintegerdigits?language=objc)
406    pub static kCFNumberFormatterMaxIntegerDigits: Option<&'static CFNumberFormatterKey>;
407}
408
409extern "C" {
410    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterminfractiondigits?language=objc)
411    pub static kCFNumberFormatterMinFractionDigits: Option<&'static CFNumberFormatterKey>;
412}
413
414extern "C" {
415    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermaxfractiondigits?language=objc)
416    pub static kCFNumberFormatterMaxFractionDigits: Option<&'static CFNumberFormatterKey>;
417}
418
419extern "C" {
420    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattergroupingsize?language=objc)
421    pub static kCFNumberFormatterGroupingSize: Option<&'static CFNumberFormatterKey>;
422}
423
424extern "C" {
425    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattersecondarygroupingsize?language=objc)
426    pub static kCFNumberFormatterSecondaryGroupingSize: Option<&'static CFNumberFormatterKey>;
427}
428
429extern "C" {
430    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterroundingmode?language=objc)
431    pub static kCFNumberFormatterRoundingMode: Option<&'static CFNumberFormatterKey>;
432}
433
434extern "C" {
435    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterroundingincrement?language=objc)
436    pub static kCFNumberFormatterRoundingIncrement: Option<&'static CFNumberFormatterKey>;
437}
438
439extern "C" {
440    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterformatwidth?language=objc)
441    pub static kCFNumberFormatterFormatWidth: Option<&'static CFNumberFormatterKey>;
442}
443
444extern "C" {
445    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpaddingposition?language=objc)
446    pub static kCFNumberFormatterPaddingPosition: Option<&'static CFNumberFormatterKey>;
447}
448
449extern "C" {
450    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpaddingcharacter?language=objc)
451    pub static kCFNumberFormatterPaddingCharacter: Option<&'static CFNumberFormatterKey>;
452}
453
454extern "C" {
455    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterdefaultformat?language=objc)
456    pub static kCFNumberFormatterDefaultFormat: Option<&'static CFNumberFormatterKey>;
457}
458
459extern "C" {
460    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermultiplier?language=objc)
461    pub static kCFNumberFormatterMultiplier: Option<&'static CFNumberFormatterKey>;
462}
463
464extern "C" {
465    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpositiveprefix?language=objc)
466    pub static kCFNumberFormatterPositivePrefix: Option<&'static CFNumberFormatterKey>;
467}
468
469extern "C" {
470    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpositivesuffix?language=objc)
471    pub static kCFNumberFormatterPositiveSuffix: Option<&'static CFNumberFormatterKey>;
472}
473
474extern "C" {
475    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatternegativeprefix?language=objc)
476    pub static kCFNumberFormatterNegativePrefix: Option<&'static CFNumberFormatterKey>;
477}
478
479extern "C" {
480    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatternegativesuffix?language=objc)
481    pub static kCFNumberFormatterNegativeSuffix: Option<&'static CFNumberFormatterKey>;
482}
483
484extern "C" {
485    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpermillsymbol?language=objc)
486    pub static kCFNumberFormatterPerMillSymbol: Option<&'static CFNumberFormatterKey>;
487}
488
489extern "C" {
490    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterinternationalcurrencysymbol?language=objc)
491    pub static kCFNumberFormatterInternationalCurrencySymbol: Option<&'static CFNumberFormatterKey>;
492}
493
494extern "C" {
495    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattercurrencygroupingseparator?language=objc)
496    pub static kCFNumberFormatterCurrencyGroupingSeparator: Option<&'static CFNumberFormatterKey>;
497}
498
499extern "C" {
500    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterislenient?language=objc)
501    pub static kCFNumberFormatterIsLenient: Option<&'static CFNumberFormatterKey>;
502}
503
504extern "C" {
505    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterusesignificantdigits?language=objc)
506    pub static kCFNumberFormatterUseSignificantDigits: Option<&'static CFNumberFormatterKey>;
507}
508
509extern "C" {
510    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterminsignificantdigits?language=objc)
511    pub static kCFNumberFormatterMinSignificantDigits: Option<&'static CFNumberFormatterKey>;
512}
513
514extern "C" {
515    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermaxsignificantdigits?language=objc)
516    pub static kCFNumberFormatterMaxSignificantDigits: Option<&'static CFNumberFormatterKey>;
517}
518
519extern "C" {
520    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermingroupingdigits?language=objc)
521    pub static kCFNumberFormatterMinGroupingDigits: Option<&'static CFNumberFormatterKey>;
522}
523
524/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatterroundingmode?language=objc)
525// NS_ENUM
526#[repr(transparent)]
527#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
528pub struct CFNumberFormatterRoundingMode(pub CFIndex);
529impl CFNumberFormatterRoundingMode {
530    #[doc(alias = "kCFNumberFormatterRoundCeiling")]
531    pub const RoundCeiling: Self = Self(0);
532    #[doc(alias = "kCFNumberFormatterRoundFloor")]
533    pub const RoundFloor: Self = Self(1);
534    #[doc(alias = "kCFNumberFormatterRoundDown")]
535    pub const RoundDown: Self = Self(2);
536    #[doc(alias = "kCFNumberFormatterRoundUp")]
537    pub const RoundUp: Self = Self(3);
538    #[doc(alias = "kCFNumberFormatterRoundHalfEven")]
539    pub const RoundHalfEven: Self = Self(4);
540    #[doc(alias = "kCFNumberFormatterRoundHalfDown")]
541    pub const RoundHalfDown: Self = Self(5);
542    #[doc(alias = "kCFNumberFormatterRoundHalfUp")]
543    pub const RoundHalfUp: Self = Self(6);
544}
545
546#[cfg(feature = "objc2")]
547unsafe impl Encode for CFNumberFormatterRoundingMode {
548    const ENCODING: Encoding = CFIndex::ENCODING;
549}
550
551#[cfg(feature = "objc2")]
552unsafe impl RefEncode for CFNumberFormatterRoundingMode {
553    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
554}
555
556/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatterpadposition?language=objc)
557// NS_ENUM
558#[repr(transparent)]
559#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
560pub struct CFNumberFormatterPadPosition(pub CFIndex);
561impl CFNumberFormatterPadPosition {
562    #[doc(alias = "kCFNumberFormatterPadBeforePrefix")]
563    pub const BeforePrefix: Self = Self(0);
564    #[doc(alias = "kCFNumberFormatterPadAfterPrefix")]
565    pub const AfterPrefix: Self = Self(1);
566    #[doc(alias = "kCFNumberFormatterPadBeforeSuffix")]
567    pub const BeforeSuffix: Self = Self(2);
568    #[doc(alias = "kCFNumberFormatterPadAfterSuffix")]
569    pub const AfterSuffix: Self = Self(3);
570}
571
572#[cfg(feature = "objc2")]
573unsafe impl Encode for CFNumberFormatterPadPosition {
574    const ENCODING: Encoding = CFIndex::ENCODING;
575}
576
577#[cfg(feature = "objc2")]
578unsafe impl RefEncode for CFNumberFormatterPadPosition {
579    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
580}
581
582impl CFNumberFormatter {
583    /// # Safety
584    ///
585    /// - `currency_code` might not allow `None`.
586    /// - `default_fraction_digits` must be a valid pointer.
587    /// - `rounding_increment` must be a valid pointer.
588    #[doc(alias = "CFNumberFormatterGetDecimalInfoForCurrencyCode")]
589    #[inline]
590    pub unsafe fn decimal_info_for_currency_code(
591        currency_code: Option<&CFString>,
592        default_fraction_digits: *mut i32,
593        rounding_increment: *mut c_double,
594    ) -> bool {
595        extern "C-unwind" {
596            fn CFNumberFormatterGetDecimalInfoForCurrencyCode(
597                currency_code: Option<&CFString>,
598                default_fraction_digits: *mut i32,
599                rounding_increment: *mut c_double,
600            ) -> Boolean;
601        }
602        let ret = unsafe {
603            CFNumberFormatterGetDecimalInfoForCurrencyCode(
604                currency_code,
605                default_fraction_digits,
606                rounding_increment,
607            )
608        };
609        ret != 0
610    }
611}
612
613#[cfg(feature = "CFLocale")]
614#[deprecated = "renamed to `CFNumberFormatter::new`"]
615#[inline]
616pub unsafe extern "C-unwind" fn CFNumberFormatterCreate(
617    allocator: Option<&CFAllocator>,
618    locale: Option<&CFLocale>,
619    style: CFNumberFormatterStyle,
620) -> Option<CFRetained<CFNumberFormatter>> {
621    extern "C-unwind" {
622        fn CFNumberFormatterCreate(
623            allocator: Option<&CFAllocator>,
624            locale: Option<&CFLocale>,
625            style: CFNumberFormatterStyle,
626        ) -> Option<NonNull<CFNumberFormatter>>;
627    }
628    let ret = unsafe { CFNumberFormatterCreate(allocator, locale, style) };
629    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
630}
631
632#[cfg(feature = "CFLocale")]
633#[deprecated = "renamed to `CFNumberFormatter::locale`"]
634#[inline]
635pub extern "C-unwind" fn CFNumberFormatterGetLocale(
636    formatter: &CFNumberFormatter,
637) -> Option<CFRetained<CFLocale>> {
638    extern "C-unwind" {
639        fn CFNumberFormatterGetLocale(formatter: &CFNumberFormatter) -> Option<NonNull<CFLocale>>;
640    }
641    let ret = unsafe { CFNumberFormatterGetLocale(formatter) };
642    ret.map(|ret| unsafe { CFRetained::retain(ret) })
643}
644
645#[deprecated = "renamed to `CFNumberFormatter::style`"]
646#[inline]
647pub extern "C-unwind" fn CFNumberFormatterGetStyle(
648    formatter: &CFNumberFormatter,
649) -> CFNumberFormatterStyle {
650    extern "C-unwind" {
651        fn CFNumberFormatterGetStyle(formatter: &CFNumberFormatter) -> CFNumberFormatterStyle;
652    }
653    unsafe { CFNumberFormatterGetStyle(formatter) }
654}
655
656#[deprecated = "renamed to `CFNumberFormatter::format`"]
657#[inline]
658pub extern "C-unwind" fn CFNumberFormatterGetFormat(
659    formatter: &CFNumberFormatter,
660) -> Option<CFRetained<CFString>> {
661    extern "C-unwind" {
662        fn CFNumberFormatterGetFormat(formatter: &CFNumberFormatter) -> Option<NonNull<CFString>>;
663    }
664    let ret = unsafe { CFNumberFormatterGetFormat(formatter) };
665    ret.map(|ret| unsafe { CFRetained::retain(ret) })
666}
667
668extern "C-unwind" {
669    #[deprecated = "renamed to `CFNumberFormatter::set_format`"]
670    pub fn CFNumberFormatterSetFormat(
671        formatter: &CFNumberFormatter,
672        format_string: Option<&CFString>,
673    );
674}
675
676#[cfg(feature = "CFNumber")]
677#[deprecated = "renamed to `CFNumberFormatter::new_string_with_number`"]
678#[inline]
679pub unsafe extern "C-unwind" fn CFNumberFormatterCreateStringWithNumber(
680    allocator: Option<&CFAllocator>,
681    formatter: Option<&CFNumberFormatter>,
682    number: Option<&CFNumber>,
683) -> Option<CFRetained<CFString>> {
684    extern "C-unwind" {
685        fn CFNumberFormatterCreateStringWithNumber(
686            allocator: Option<&CFAllocator>,
687            formatter: Option<&CFNumberFormatter>,
688            number: Option<&CFNumber>,
689        ) -> Option<NonNull<CFString>>;
690    }
691    let ret = unsafe { CFNumberFormatterCreateStringWithNumber(allocator, formatter, number) };
692    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
693}
694
695#[cfg(feature = "CFNumber")]
696#[deprecated = "renamed to `CFNumberFormatter::new_string_with_value`"]
697#[inline]
698pub unsafe extern "C-unwind" fn CFNumberFormatterCreateStringWithValue(
699    allocator: Option<&CFAllocator>,
700    formatter: Option<&CFNumberFormatter>,
701    number_type: CFNumberType,
702    value_ptr: *const c_void,
703) -> Option<CFRetained<CFString>> {
704    extern "C-unwind" {
705        fn CFNumberFormatterCreateStringWithValue(
706            allocator: Option<&CFAllocator>,
707            formatter: Option<&CFNumberFormatter>,
708            number_type: CFNumberType,
709            value_ptr: *const c_void,
710        ) -> Option<NonNull<CFString>>;
711    }
712    let ret = unsafe {
713        CFNumberFormatterCreateStringWithValue(allocator, formatter, number_type, value_ptr)
714    };
715    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
716}
717
718#[cfg(feature = "CFNumber")]
719#[deprecated = "renamed to `CFNumberFormatter::new_number_from_string`"]
720#[inline]
721pub unsafe extern "C-unwind" fn CFNumberFormatterCreateNumberFromString(
722    allocator: Option<&CFAllocator>,
723    formatter: Option<&CFNumberFormatter>,
724    string: Option<&CFString>,
725    rangep: *mut CFRange,
726    options: CFOptionFlags,
727) -> Option<CFRetained<CFNumber>> {
728    extern "C-unwind" {
729        fn CFNumberFormatterCreateNumberFromString(
730            allocator: Option<&CFAllocator>,
731            formatter: Option<&CFNumberFormatter>,
732            string: Option<&CFString>,
733            rangep: *mut CFRange,
734            options: CFOptionFlags,
735        ) -> Option<NonNull<CFNumber>>;
736    }
737    let ret = unsafe {
738        CFNumberFormatterCreateNumberFromString(allocator, formatter, string, rangep, options)
739    };
740    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
741}
742
743#[cfg(feature = "CFNumber")]
744#[deprecated = "renamed to `CFNumberFormatter::value_from_string`"]
745#[inline]
746pub unsafe extern "C-unwind" fn CFNumberFormatterGetValueFromString(
747    formatter: &CFNumberFormatter,
748    string: Option<&CFString>,
749    rangep: *mut CFRange,
750    number_type: CFNumberType,
751    value_ptr: *mut c_void,
752) -> bool {
753    extern "C-unwind" {
754        fn CFNumberFormatterGetValueFromString(
755            formatter: &CFNumberFormatter,
756            string: Option<&CFString>,
757            rangep: *mut CFRange,
758            number_type: CFNumberType,
759            value_ptr: *mut c_void,
760        ) -> Boolean;
761    }
762    let ret = unsafe {
763        CFNumberFormatterGetValueFromString(formatter, string, rangep, number_type, value_ptr)
764    };
765    ret != 0
766}
767
768extern "C-unwind" {
769    #[deprecated = "renamed to `CFNumberFormatter::set_property`"]
770    pub fn CFNumberFormatterSetProperty(
771        formatter: &CFNumberFormatter,
772        key: Option<&CFNumberFormatterKey>,
773        value: Option<&CFType>,
774    );
775}
776
777#[deprecated = "renamed to `CFNumberFormatter::property`"]
778#[inline]
779pub unsafe extern "C-unwind" fn CFNumberFormatterCopyProperty(
780    formatter: &CFNumberFormatter,
781    key: Option<&CFNumberFormatterKey>,
782) -> Option<CFRetained<CFType>> {
783    extern "C-unwind" {
784        fn CFNumberFormatterCopyProperty(
785            formatter: &CFNumberFormatter,
786            key: Option<&CFNumberFormatterKey>,
787        ) -> Option<NonNull<CFType>>;
788    }
789    let ret = unsafe { CFNumberFormatterCopyProperty(formatter, key) };
790    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
791}
792
793#[deprecated = "renamed to `CFNumberFormatter::decimal_info_for_currency_code`"]
794#[inline]
795pub unsafe extern "C-unwind" fn CFNumberFormatterGetDecimalInfoForCurrencyCode(
796    currency_code: Option<&CFString>,
797    default_fraction_digits: *mut i32,
798    rounding_increment: *mut c_double,
799) -> bool {
800    extern "C-unwind" {
801        fn CFNumberFormatterGetDecimalInfoForCurrencyCode(
802            currency_code: Option<&CFString>,
803            default_fraction_digits: *mut i32,
804            rounding_increment: *mut c_double,
805        ) -> Boolean;
806    }
807    let ret = unsafe {
808        CFNumberFormatterGetDecimalInfoForCurrencyCode(
809            currency_code,
810            default_fraction_digits,
811            rounding_increment,
812        )
813    };
814    ret != 0
815}