| 1 |
// Copyright 2023 The Servo Project Developers. See the COPYRIGHT |
| 2 |
// file at the top-level directory of this distribution. |
| 3 |
// |
| 4 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 5 |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 6 |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 7 |
// option. This file may not be copied, modified, or distributed |
| 8 |
// except according to those terms. |
| 9 |
|
| 10 |
use std::os::raw::{c_double, c_void}; |
| 11 |
|
| 12 |
use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFRange, CFTypeID, CFTypeRef}; |
| 13 |
use crate::locale::CFLocaleRef; |
| 14 |
use crate::number::{CFNumberRef, CFNumberType}; |
| 15 |
use crate::string::CFStringRef; |
| 16 |
|
| 17 |
#[repr(C)] |
| 18 |
pub struct __CFNumberFormatter(c_void); |
| 19 |
|
| 20 |
pub type CFNumberFormatterRef = *mut __CFNumberFormatter; |
| 21 |
|
| 22 |
pub type CFNumberFormatterKey = CFStringRef; |
| 23 |
pub type CFNumberFormatterStyle = CFIndex; |
| 24 |
pub type CFNumberFormatterOptionFlags = CFOptionFlags; |
| 25 |
pub type CFNumberFormatterRoundingMode = CFIndex; |
| 26 |
pub type CFNumberFormatterPadPosition = CFIndex; |
| 27 |
|
| 28 |
/* Number Formatter Styles */ |
| 29 |
pub const kCFNumberFormatterNoStyle: CFNumberFormatterStyle = 0; |
| 30 |
pub const kCFNumberFormatterDecimalStyle: CFNumberFormatterStyle = 1; |
| 31 |
pub const kCFNumberFormatterCurrencyStyle: CFNumberFormatterStyle = 2; |
| 32 |
pub const kCFNumberFormatterPercentStyle: CFNumberFormatterStyle = 3; |
| 33 |
pub const kCFNumberFormatterScientificStyle: CFNumberFormatterStyle = 4; |
| 34 |
pub const kCFNumberFormatterSpellOutStyle: CFNumberFormatterStyle = 5; |
| 35 |
//pub const kCFNumberFormatterOrdinalStyle: CFNumberFormatterStyle = 6; // macos(10.11)+ |
| 36 |
//pub const kCFNumberFormatterCurrencyISOCodeStyle: CFNumberFormatterStyle = 8; // macos(10.11)+ |
| 37 |
//pub const kCFNumberFormatterCurrencyPluralStyle: CFNumberFormatterStyle = 9; // macos(10.11)+ |
| 38 |
//pub const kCFNumberFormatterCurrencyAccountingStyle: CFNumberFormatterStyle = 10; // macos(10.11)+ |
| 39 |
|
| 40 |
/* Number Format Options */ |
| 41 |
pub const kCFNumberFormatterParseIntegersOnly: CFNumberFormatterOptionFlags = 1; |
| 42 |
|
| 43 |
/* CFNumberFormatterRoundingMode */ |
| 44 |
pub const kCFNumberFormatterRoundCeiling: CFNumberFormatterRoundingMode = 0; |
| 45 |
pub const kCFNumberFormatterRoundFloor: CFNumberFormatterRoundingMode = 1; |
| 46 |
pub const kCFNumberFormatterRoundDown: CFNumberFormatterRoundingMode = 2; |
| 47 |
pub const kCFNumberFormatterRoundUp: CFNumberFormatterRoundingMode = 3; |
| 48 |
pub const kCFNumberFormatterRoundHalfEven: CFNumberFormatterRoundingMode = 4; |
| 49 |
pub const kCFNumberFormatterRoundHalfDown: CFNumberFormatterRoundingMode = 5; |
| 50 |
pub const kCFNumberFormatterRoundHalfUp: CFNumberFormatterRoundingMode = 6; |
| 51 |
|
| 52 |
/* Padding Positions */ |
| 53 |
pub const kCFNumberFormatterPadBeforePrefix: CFNumberFormatterPadPosition = 0; |
| 54 |
pub const kCFNumberFormatterPadAfterPrefix: CFNumberFormatterPadPosition = 1; |
| 55 |
pub const kCFNumberFormatterPadBeforeSuffix: CFNumberFormatterPadPosition = 2; |
| 56 |
pub const kCFNumberFormatterPadAfterSuffix: CFNumberFormatterPadPosition = 3; |
| 57 |
|
| 58 |
extern "C" { |
| 59 |
/* |
| 60 |
* CFNumberFormatter.h |
| 61 |
*/ |
| 62 |
|
| 63 |
/* Number Formatter Property Keys */ |
| 64 |
// The values for these keys are all CFType objects. |
| 65 |
// The specific types for each key are specified above. |
| 66 |
pub static kCFNumberFormatterCurrencyCode: CFNumberFormatterKey; // CFString |
| 67 |
pub static kCFNumberFormatterDecimalSeparator: CFNumberFormatterKey; // CFString |
| 68 |
pub static kCFNumberFormatterCurrencyDecimalSeparator: CFNumberFormatterKey; // CFString |
| 69 |
pub static kCFNumberFormatterAlwaysShowDecimalSeparator: CFNumberFormatterKey; // CFBoolean |
| 70 |
pub static kCFNumberFormatterGroupingSeparator: CFNumberFormatterKey; // CFString |
| 71 |
pub static kCFNumberFormatterUseGroupingSeparator: CFNumberFormatterKey; // CFBoolean |
| 72 |
pub static kCFNumberFormatterPercentSymbol: CFNumberFormatterKey; // CFString |
| 73 |
pub static kCFNumberFormatterZeroSymbol: CFNumberFormatterKey; // CFString |
| 74 |
pub static kCFNumberFormatterNaNSymbol: CFNumberFormatterKey; // CFString |
| 75 |
pub static kCFNumberFormatterInfinitySymbol: CFNumberFormatterKey; // CFString |
| 76 |
pub static kCFNumberFormatterMinusSign: CFNumberFormatterKey; // CFString |
| 77 |
pub static kCFNumberFormatterPlusSign: CFNumberFormatterKey; // CFString |
| 78 |
pub static kCFNumberFormatterCurrencySymbol: CFNumberFormatterKey; // CFString |
| 79 |
pub static kCFNumberFormatterExponentSymbol: CFNumberFormatterKey; // CFString |
| 80 |
pub static kCFNumberFormatterMinIntegerDigits: CFNumberFormatterKey; // CFNumber |
| 81 |
pub static kCFNumberFormatterMaxIntegerDigits: CFNumberFormatterKey; // CFNumber |
| 82 |
pub static kCFNumberFormatterMinFractionDigits: CFNumberFormatterKey; // CFNumber |
| 83 |
pub static kCFNumberFormatterMaxFractionDigits: CFNumberFormatterKey; // CFNumber |
| 84 |
pub static kCFNumberFormatterGroupingSize: CFNumberFormatterKey; // CFNumber |
| 85 |
pub static kCFNumberFormatterSecondaryGroupingSize: CFNumberFormatterKey; // CFNumber |
| 86 |
pub static kCFNumberFormatterRoundingMode: CFNumberFormatterKey; // CFNumber |
| 87 |
pub static kCFNumberFormatterRoundingIncrement: CFNumberFormatterKey; // CFNumber |
| 88 |
pub static kCFNumberFormatterFormatWidth: CFNumberFormatterKey; // CFNumber |
| 89 |
pub static kCFNumberFormatterPaddingPosition: CFNumberFormatterKey; // CFNumber |
| 90 |
pub static kCFNumberFormatterPaddingCharacter: CFNumberFormatterKey; // CFString |
| 91 |
pub static kCFNumberFormatterDefaultFormat: CFNumberFormatterKey; // CFString |
| 92 |
pub static kCFNumberFormatterMultiplier: CFNumberFormatterKey; // CFNumber |
| 93 |
pub static kCFNumberFormatterPositivePrefix: CFNumberFormatterKey; // CFString |
| 94 |
pub static kCFNumberFormatterPositiveSuffix: CFNumberFormatterKey; // CFString |
| 95 |
pub static kCFNumberFormatterNegativePrefix: CFNumberFormatterKey; // CFString |
| 96 |
pub static kCFNumberFormatterNegativeSuffix: CFNumberFormatterKey; // CFString |
| 97 |
pub static kCFNumberFormatterPerMillSymbol: CFNumberFormatterKey; // CFString |
| 98 |
pub static kCFNumberFormatterInternationalCurrencySymbol: CFNumberFormatterKey; // CFString |
| 99 |
pub static kCFNumberFormatterCurrencyGroupingSeparator: CFNumberFormatterKey; // CFString |
| 100 |
pub static kCFNumberFormatterIsLenient: CFNumberFormatterKey; // CFBoolean |
| 101 |
pub static kCFNumberFormatterUseSignificantDigits: CFNumberFormatterKey; // CFBoolean |
| 102 |
pub static kCFNumberFormatterMinSignificantDigits: CFNumberFormatterKey; // CFNumber |
| 103 |
pub static kCFNumberFormatterMaxSignificantDigits: CFNumberFormatterKey; // CFNumber |
| 104 |
|
| 105 |
/* Creating a Number Formatter */ |
| 106 |
pub fn CFNumberFormatterCreate( |
| 107 |
allocator: CFAllocatorRef, |
| 108 |
locale: CFLocaleRef, |
| 109 |
style: CFNumberFormatterStyle, |
| 110 |
) -> CFNumberFormatterRef; |
| 111 |
|
| 112 |
/* Configuring a Number Formatter */ |
| 113 |
pub fn CFNumberFormatterSetFormat(formatter: CFNumberFormatterRef, formatString: CFStringRef); |
| 114 |
pub fn CFNumberFormatterSetProperty( |
| 115 |
formatter: CFNumberFormatterRef, |
| 116 |
key: CFNumberFormatterKey, |
| 117 |
value: CFTypeRef, |
| 118 |
); |
| 119 |
|
| 120 |
/* Formatting Values */ |
| 121 |
pub fn CFNumberFormatterCreateNumberFromString( |
| 122 |
allocator: CFAllocatorRef, |
| 123 |
formatter: CFNumberFormatterRef, |
| 124 |
string: CFStringRef, |
| 125 |
rangep: *mut CFRange, |
| 126 |
options: CFOptionFlags, |
| 127 |
) -> CFNumberRef; |
| 128 |
pub fn CFNumberFormatterCreateStringWithNumber( |
| 129 |
allocator: CFAllocatorRef, |
| 130 |
formatter: CFNumberFormatterRef, |
| 131 |
number: CFNumberRef, |
| 132 |
) -> CFStringRef; |
| 133 |
pub fn CFNumberFormatterCreateStringWithValue( |
| 134 |
allocator: CFAllocatorRef, |
| 135 |
formatter: CFNumberFormatterRef, |
| 136 |
numberType: CFNumberType, |
| 137 |
valuePtr: *const c_void, |
| 138 |
) -> CFStringRef; |
| 139 |
pub fn CFNumberFormatterGetDecimalInfoForCurrencyCode( |
| 140 |
currencyCode: CFStringRef, |
| 141 |
defaultFractionDigits: *mut i32, |
| 142 |
roundingIncrement: *mut c_double, |
| 143 |
) -> Boolean; |
| 144 |
pub fn CFNumberFormatterGetValueFromString( |
| 145 |
formatter: CFNumberFormatterRef, |
| 146 |
string: CFStringRef, |
| 147 |
rangep: *mut CFRange, |
| 148 |
numberType: CFNumberType, |
| 149 |
valuePtr: *mut c_void, |
| 150 |
) -> Boolean; |
| 151 |
|
| 152 |
/* Examining a Number Formatter */ |
| 153 |
pub fn CFNumberFormatterCopyProperty( |
| 154 |
formatter: CFNumberFormatterRef, |
| 155 |
key: CFNumberFormatterKey, |
| 156 |
) -> CFTypeRef; |
| 157 |
pub fn CFNumberFormatterGetFormat(formatter: CFNumberFormatterRef) -> CFStringRef; |
| 158 |
pub fn CFNumberFormatterGetLocale(formatter: CFNumberFormatterRef) -> CFLocaleRef; |
| 159 |
pub fn CFNumberFormatterGetStyle(formatter: CFNumberFormatterRef) -> CFNumberFormatterStyle; |
| 160 |
|
| 161 |
/* Getting the CFNumberFormatter Type ID */ |
| 162 |
pub fn CFNumberFormatterGetTypeID() -> CFTypeID; |
| 163 |
} |