1/*
2 * Copyright (c) 2014 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24/*	CFNumberFormatter.h
25	Copyright (c) 2003-2013, Apple Inc. All rights reserved.
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
35CF_EXTERN_C_BEGIN
36
37typedef struct __CFNumberFormatter *CFNumberFormatterRef;
38
39// CFNumberFormatters are not thread-safe.  Do not use one from multiple threads!
40
41CF_EXPORT
42CFTypeID CFNumberFormatterGetTypeID(void);
43
44typedef CF_ENUM(CFIndex, CFNumberFormatterStyle) {	// number format styles
45	kCFNumberFormatterNoStyle = 0,
46	kCFNumberFormatterDecimalStyle = 1,
47	kCFNumberFormatterCurrencyStyle = 2,
48	kCFNumberFormatterPercentStyle = 3,
49	kCFNumberFormatterScientificStyle = 4,
50	kCFNumberFormatterSpellOutStyle = 5
51};
52
53
54CF_EXPORT
55CFNumberFormatterRef CFNumberFormatterCreate(CFAllocatorRef allocator, CFLocaleRef locale, CFNumberFormatterStyle style);
56	// Returns a CFNumberFormatter, localized to the given locale, which
57	// will format numbers to the given style.
58
59CF_EXPORT
60CFLocaleRef CFNumberFormatterGetLocale(CFNumberFormatterRef formatter);
61
62CF_EXPORT
63CFNumberFormatterStyle CFNumberFormatterGetStyle(CFNumberFormatterRef formatter);
64	// Get the properties with which the number formatter was created.
65
66CF_EXPORT
67CFStringRef CFNumberFormatterGetFormat(CFNumberFormatterRef formatter);
68
69CF_EXPORT
70void CFNumberFormatterSetFormat(CFNumberFormatterRef formatter, CFStringRef formatString);
71	// Set the format description string of the number formatter.  This
72	// overrides the style settings.  The format of the format string
73	// is as defined by the ICU library, and is similar to that found
74	// in Microsoft Excel and NSNumberFormatter.
75	// The number formatter starts with a default format string defined
76	// by the style argument with which it was created.
77
78
79CF_EXPORT
80CFStringRef CFNumberFormatterCreateStringWithNumber(CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFNumberRef number);
81
82CF_EXPORT
83CFStringRef CFNumberFormatterCreateStringWithValue(CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFNumberType numberType, const void *valuePtr);
84	// Create a string representation of the given number or value
85	// using the current state of the number formatter.
86
87
88typedef CF_OPTIONS(CFOptionFlags, CFNumberFormatterOptionFlags) {
89    kCFNumberFormatterParseIntegersOnly = 1	/* only parse integers */
90};
91
92CF_EXPORT
93CFNumberRef CFNumberFormatterCreateNumberFromString(CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFStringRef string, CFRange *rangep, CFOptionFlags options);
94
95CF_EXPORT
96Boolean CFNumberFormatterGetValueFromString(CFNumberFormatterRef formatter, CFStringRef string, CFRange *rangep, CFNumberType numberType, void *valuePtr);
97	// Parse a string representation of a number using the current state
98	// of the number formatter.  The range parameter specifies the range
99	// of the string in which the parsing should occur in input, and on
100	// output indicates the extent that was used; this parameter can
101	// be NULL, in which case the whole string may be used.  The
102	// return value indicates whether some number was computed and
103	// (if valuePtr is not NULL) stored at the location specified by
104	// valuePtr.  The numberType indicates the type of value pointed
105	// to by valuePtr.
106
107
108CF_EXPORT
109void CFNumberFormatterSetProperty(CFNumberFormatterRef formatter, CFStringRef key, CFTypeRef value);
110
111CF_EXPORT
112CFTypeRef CFNumberFormatterCopyProperty(CFNumberFormatterRef formatter, CFStringRef key);
113	// Set and get various properties of the number formatter, the set of
114	// which may be expanded in the future.
115
116CF_EXPORT const CFStringRef kCFNumberFormatterCurrencyCode;		// CFString
117CF_EXPORT const CFStringRef kCFNumberFormatterDecimalSeparator;	// CFString
118CF_EXPORT const CFStringRef kCFNumberFormatterCurrencyDecimalSeparator; // CFString
119CF_EXPORT const CFStringRef kCFNumberFormatterAlwaysShowDecimalSeparator; // CFBoolean
120CF_EXPORT const CFStringRef kCFNumberFormatterGroupingSeparator;	// CFString
121CF_EXPORT const CFStringRef kCFNumberFormatterUseGroupingSeparator;	// CFBoolean
122CF_EXPORT const CFStringRef kCFNumberFormatterPercentSymbol;		// CFString
123CF_EXPORT const CFStringRef kCFNumberFormatterZeroSymbol;		// CFString
124CF_EXPORT const CFStringRef kCFNumberFormatterNaNSymbol;		// CFString
125CF_EXPORT const CFStringRef kCFNumberFormatterInfinitySymbol;		// CFString
126CF_EXPORT const CFStringRef kCFNumberFormatterMinusSign;		// CFString
127CF_EXPORT const CFStringRef kCFNumberFormatterPlusSign;		// CFString
128CF_EXPORT const CFStringRef kCFNumberFormatterCurrencySymbol;		// CFString
129CF_EXPORT const CFStringRef kCFNumberFormatterExponentSymbol;		// CFString
130CF_EXPORT const CFStringRef kCFNumberFormatterMinIntegerDigits;	// CFNumber
131CF_EXPORT const CFStringRef kCFNumberFormatterMaxIntegerDigits;	// CFNumber
132CF_EXPORT const CFStringRef kCFNumberFormatterMinFractionDigits;	// CFNumber
133CF_EXPORT const CFStringRef kCFNumberFormatterMaxFractionDigits;	// CFNumber
134CF_EXPORT const CFStringRef kCFNumberFormatterGroupingSize;		// CFNumber
135CF_EXPORT const CFStringRef kCFNumberFormatterSecondaryGroupingSize;	// CFNumber
136CF_EXPORT const CFStringRef kCFNumberFormatterRoundingMode;		// CFNumber
137CF_EXPORT const CFStringRef kCFNumberFormatterRoundingIncrement;	// CFNumber
138CF_EXPORT const CFStringRef kCFNumberFormatterFormatWidth;		// CFNumber
139CF_EXPORT const CFStringRef kCFNumberFormatterPaddingPosition;	// CFNumber
140CF_EXPORT const CFStringRef kCFNumberFormatterPaddingCharacter;	// CFString
141CF_EXPORT const CFStringRef kCFNumberFormatterDefaultFormat;		// CFString
142CF_EXPORT const CFStringRef kCFNumberFormatterMultiplier;		// CFNumber
143CF_EXPORT const CFStringRef kCFNumberFormatterPositivePrefix;		// CFString
144CF_EXPORT const CFStringRef kCFNumberFormatterPositiveSuffix;		// CFString
145CF_EXPORT const CFStringRef kCFNumberFormatterNegativePrefix;		// CFString
146CF_EXPORT const CFStringRef kCFNumberFormatterNegativeSuffix;		// CFString
147CF_EXPORT const CFStringRef kCFNumberFormatterPerMillSymbol;		// CFString
148CF_EXPORT const CFStringRef kCFNumberFormatterInternationalCurrencySymbol; // CFString
149CF_EXPORT const CFStringRef kCFNumberFormatterCurrencyGroupingSeparator CF_AVAILABLE(10_5, 2_0); // CFString
150CF_EXPORT const CFStringRef kCFNumberFormatterIsLenient CF_AVAILABLE(10_5, 2_0);		// CFBoolean
151CF_EXPORT const CFStringRef kCFNumberFormatterUseSignificantDigits CF_AVAILABLE(10_5, 2_0);	// CFBoolean
152CF_EXPORT const CFStringRef kCFNumberFormatterMinSignificantDigits CF_AVAILABLE(10_5, 2_0);	// CFNumber
153CF_EXPORT const CFStringRef kCFNumberFormatterMaxSignificantDigits CF_AVAILABLE(10_5, 2_0);	// CFNumber
154
155typedef CF_ENUM(CFIndex, CFNumberFormatterRoundingMode) {
156    kCFNumberFormatterRoundCeiling = 0,
157    kCFNumberFormatterRoundFloor = 1,
158    kCFNumberFormatterRoundDown = 2,
159    kCFNumberFormatterRoundUp = 3,
160    kCFNumberFormatterRoundHalfEven = 4,
161    kCFNumberFormatterRoundHalfDown = 5,
162    kCFNumberFormatterRoundHalfUp = 6
163};
164
165typedef CF_ENUM(CFIndex, CFNumberFormatterPadPosition) {
166    kCFNumberFormatterPadBeforePrefix = 0,
167    kCFNumberFormatterPadAfterPrefix = 1,
168    kCFNumberFormatterPadBeforeSuffix = 2,
169    kCFNumberFormatterPadAfterSuffix = 3
170};
171
172
173CF_EXPORT
174Boolean CFNumberFormatterGetDecimalInfoForCurrencyCode(CFStringRef currencyCode, int32_t *defaultFractionDigits, double *roundingIncrement);
175	// Returns the number of fraction digits that should be displayed, and
176	// the rounding increment (or 0.0 if no rounding is done by the currency)
177	// for the given currency.  Returns false if the currency code is unknown
178	// or the information is not available.
179	// Not localized because these are properties of the currency.
180
181CF_EXTERN_C_END
182
183#endif /* ! __COREFOUNDATION_CFNUMBERFORMATTER__ */
184
185