]> git.saurik.com Git - apple/cf.git/blame - CFNumberFormatter.h
CF-1151.16.tar.gz
[apple/cf.git] / CFNumberFormatter.h
CommitLineData
bd5b749c 1/*
d8b101a4 2 * Copyright (c) 2014 Apple Inc. All rights reserved.
bd5b749c
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
d7384798 5 *
bd5b749c
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
d7384798 12 *
bd5b749c
A
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
d7384798 20 *
bd5b749c
A
21 * @APPLE_LICENSE_HEADER_END@
22 */
f64f9b69 23
bd5b749c 24/* CFNumberFormatter.h
d7384798 25 Copyright (c) 2003-2014, Apple Inc. All rights reserved.
bd5b749c
A
26*/
27
28#if !defined(__COREFOUNDATION_CFNUMBERFORMATTER__)
29#define __COREFOUNDATION_CFNUMBERFORMATTER__ 1
30
31#include <CoreFoundation/CFBase.h>
32#include <CoreFoundation/CFNumber.h>
33#include <CoreFoundation/CFLocale.h>
34
d7384798 35CF_IMPLICIT_BRIDGING_ENABLED
bd5b749c
A
36CF_EXTERN_C_BEGIN
37
38typedef struct __CFNumberFormatter *CFNumberFormatterRef;
39
40// CFNumberFormatters are not thread-safe. Do not use one from multiple threads!
41
42CF_EXPORT
8ca704e1 43CFTypeID CFNumberFormatterGetTypeID(void);
bd5b749c 44
856091c5 45typedef CF_ENUM(CFIndex, CFNumberFormatterStyle) { // number format styles
bd5b749c
A
46 kCFNumberFormatterNoStyle = 0,
47 kCFNumberFormatterDecimalStyle = 1,
48 kCFNumberFormatterCurrencyStyle = 2,
49 kCFNumberFormatterPercentStyle = 3,
50 kCFNumberFormatterScientificStyle = 4,
51 kCFNumberFormatterSpellOutStyle = 5
52};
bd5b749c
A
53
54
55CF_EXPORT
8ca704e1 56CFNumberFormatterRef CFNumberFormatterCreate(CFAllocatorRef allocator, CFLocaleRef locale, CFNumberFormatterStyle style);
bd5b749c
A
57 // Returns a CFNumberFormatter, localized to the given locale, which
58 // will format numbers to the given style.
59
60CF_EXPORT
8ca704e1 61CFLocaleRef CFNumberFormatterGetLocale(CFNumberFormatterRef formatter);
bd5b749c
A
62
63CF_EXPORT
8ca704e1 64CFNumberFormatterStyle CFNumberFormatterGetStyle(CFNumberFormatterRef formatter);
bd5b749c
A
65 // Get the properties with which the number formatter was created.
66
67CF_EXPORT
8ca704e1 68CFStringRef CFNumberFormatterGetFormat(CFNumberFormatterRef formatter);
bd5b749c
A
69
70CF_EXPORT
8ca704e1 71void CFNumberFormatterSetFormat(CFNumberFormatterRef formatter, CFStringRef formatString);
bd5b749c
A
72 // Set the format description string of the number formatter. This
73 // overrides the style settings. The format of the format string
74 // is as defined by the ICU library, and is similar to that found
856091c5 75 // in Microsoft Excel and NSNumberFormatter.
bd5b749c
A
76 // The number formatter starts with a default format string defined
77 // by the style argument with which it was created.
78
79
80CF_EXPORT
8ca704e1 81CFStringRef CFNumberFormatterCreateStringWithNumber(CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFNumberRef number);
bd5b749c
A
82
83CF_EXPORT
8ca704e1 84CFStringRef CFNumberFormatterCreateStringWithValue(CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFNumberType numberType, const void *valuePtr);
bd5b749c
A
85 // Create a string representation of the given number or value
86 // using the current state of the number formatter.
87
88
856091c5 89typedef CF_OPTIONS(CFOptionFlags, CFNumberFormatterOptionFlags) {
bd5b749c
A
90 kCFNumberFormatterParseIntegersOnly = 1 /* only parse integers */
91};
bd5b749c
A
92
93CF_EXPORT
8ca704e1 94CFNumberRef CFNumberFormatterCreateNumberFromString(CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFStringRef string, CFRange *rangep, CFOptionFlags options);
bd5b749c
A
95
96CF_EXPORT
8ca704e1 97Boolean CFNumberFormatterGetValueFromString(CFNumberFormatterRef formatter, CFStringRef string, CFRange *rangep, CFNumberType numberType, void *valuePtr);
bd5b749c
A
98 // Parse a string representation of a number using the current state
99 // of the number formatter. The range parameter specifies the range
100 // of the string in which the parsing should occur in input, and on
101 // output indicates the extent that was used; this parameter can
102 // be NULL, in which case the whole string may be used. The
103 // return value indicates whether some number was computed and
104 // (if valuePtr is not NULL) stored at the location specified by
105 // valuePtr. The numberType indicates the type of value pointed
106 // to by valuePtr.
107
108
109CF_EXPORT
8ca704e1 110void CFNumberFormatterSetProperty(CFNumberFormatterRef formatter, CFStringRef key, CFTypeRef value);
bd5b749c
A
111
112CF_EXPORT
8ca704e1 113CFTypeRef CFNumberFormatterCopyProperty(CFNumberFormatterRef formatter, CFStringRef key);
bd5b749c
A
114 // Set and get various properties of the number formatter, the set of
115 // which may be expanded in the future.
116
8ca704e1
A
117CF_EXPORT const CFStringRef kCFNumberFormatterCurrencyCode; // CFString
118CF_EXPORT const CFStringRef kCFNumberFormatterDecimalSeparator; // CFString
119CF_EXPORT const CFStringRef kCFNumberFormatterCurrencyDecimalSeparator; // CFString
120CF_EXPORT const CFStringRef kCFNumberFormatterAlwaysShowDecimalSeparator; // CFBoolean
121CF_EXPORT const CFStringRef kCFNumberFormatterGroupingSeparator; // CFString
122CF_EXPORT const CFStringRef kCFNumberFormatterUseGroupingSeparator; // CFBoolean
123CF_EXPORT const CFStringRef kCFNumberFormatterPercentSymbol; // CFString
124CF_EXPORT const CFStringRef kCFNumberFormatterZeroSymbol; // CFString
125CF_EXPORT const CFStringRef kCFNumberFormatterNaNSymbol; // CFString
126CF_EXPORT const CFStringRef kCFNumberFormatterInfinitySymbol; // CFString
127CF_EXPORT const CFStringRef kCFNumberFormatterMinusSign; // CFString
128CF_EXPORT const CFStringRef kCFNumberFormatterPlusSign; // CFString
129CF_EXPORT const CFStringRef kCFNumberFormatterCurrencySymbol; // CFString
130CF_EXPORT const CFStringRef kCFNumberFormatterExponentSymbol; // CFString
131CF_EXPORT const CFStringRef kCFNumberFormatterMinIntegerDigits; // CFNumber
132CF_EXPORT const CFStringRef kCFNumberFormatterMaxIntegerDigits; // CFNumber
133CF_EXPORT const CFStringRef kCFNumberFormatterMinFractionDigits; // CFNumber
134CF_EXPORT const CFStringRef kCFNumberFormatterMaxFractionDigits; // CFNumber
135CF_EXPORT const CFStringRef kCFNumberFormatterGroupingSize; // CFNumber
136CF_EXPORT const CFStringRef kCFNumberFormatterSecondaryGroupingSize; // CFNumber
137CF_EXPORT const CFStringRef kCFNumberFormatterRoundingMode; // CFNumber
138CF_EXPORT const CFStringRef kCFNumberFormatterRoundingIncrement; // CFNumber
139CF_EXPORT const CFStringRef kCFNumberFormatterFormatWidth; // CFNumber
140CF_EXPORT const CFStringRef kCFNumberFormatterPaddingPosition; // CFNumber
141CF_EXPORT const CFStringRef kCFNumberFormatterPaddingCharacter; // CFString
142CF_EXPORT const CFStringRef kCFNumberFormatterDefaultFormat; // CFString
143CF_EXPORT const CFStringRef kCFNumberFormatterMultiplier; // CFNumber
144CF_EXPORT const CFStringRef kCFNumberFormatterPositivePrefix; // CFString
145CF_EXPORT const CFStringRef kCFNumberFormatterPositiveSuffix; // CFString
146CF_EXPORT const CFStringRef kCFNumberFormatterNegativePrefix; // CFString
147CF_EXPORT const CFStringRef kCFNumberFormatterNegativeSuffix; // CFString
148CF_EXPORT const CFStringRef kCFNumberFormatterPerMillSymbol; // CFString
149CF_EXPORT const CFStringRef kCFNumberFormatterInternationalCurrencySymbol; // CFString
150CF_EXPORT const CFStringRef kCFNumberFormatterCurrencyGroupingSeparator CF_AVAILABLE(10_5, 2_0); // CFString
151CF_EXPORT const CFStringRef kCFNumberFormatterIsLenient CF_AVAILABLE(10_5, 2_0); // CFBoolean
152CF_EXPORT const CFStringRef kCFNumberFormatterUseSignificantDigits CF_AVAILABLE(10_5, 2_0); // CFBoolean
153CF_EXPORT const CFStringRef kCFNumberFormatterMinSignificantDigits CF_AVAILABLE(10_5, 2_0); // CFNumber
154CF_EXPORT const CFStringRef kCFNumberFormatterMaxSignificantDigits CF_AVAILABLE(10_5, 2_0); // CFNumber
bd5b749c 155
856091c5 156typedef CF_ENUM(CFIndex, CFNumberFormatterRoundingMode) {
bd5b749c
A
157 kCFNumberFormatterRoundCeiling = 0,
158 kCFNumberFormatterRoundFloor = 1,
159 kCFNumberFormatterRoundDown = 2,
160 kCFNumberFormatterRoundUp = 3,
161 kCFNumberFormatterRoundHalfEven = 4,
162 kCFNumberFormatterRoundHalfDown = 5,
163 kCFNumberFormatterRoundHalfUp = 6
164};
bd5b749c 165
856091c5 166typedef CF_ENUM(CFIndex, CFNumberFormatterPadPosition) {
bd5b749c
A
167 kCFNumberFormatterPadBeforePrefix = 0,
168 kCFNumberFormatterPadAfterPrefix = 1,
169 kCFNumberFormatterPadBeforeSuffix = 2,
170 kCFNumberFormatterPadAfterSuffix = 3
171};
bd5b749c
A
172
173
174CF_EXPORT
8ca704e1 175Boolean CFNumberFormatterGetDecimalInfoForCurrencyCode(CFStringRef currencyCode, int32_t *defaultFractionDigits, double *roundingIncrement);
bd5b749c
A
176 // Returns the number of fraction digits that should be displayed, and
177 // the rounding increment (or 0.0 if no rounding is done by the currency)
178 // for the given currency. Returns false if the currency code is unknown
179 // or the information is not available.
180 // Not localized because these are properties of the currency.
181
182CF_EXTERN_C_END
d7384798 183CF_IMPLICIT_BRIDGING_DISABLED
bd5b749c 184
bd5b749c
A
185#endif /* ! __COREFOUNDATION_CFNUMBERFORMATTER__ */
186