ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

scientificnumberformatter.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 * Copyright (c) 2014-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 */
9 #ifndef SCINUMBERFORMATTER_H
10 #define SCINUMBERFORMATTER_H
11
12 #include "unicode/utypes.h"
13
14 #if !UCONFIG_NO_FORMATTING
15
16
17 #include "unicode/unistr.h"
18
24 U_NAMESPACE_BEGIN
25
26 class FieldPositionIterator;
27 class DecimalFormatStaticSets;
28 class DecimalFormatSymbols;
29 class DecimalFormat;
30 class Formattable;
31
51 class U_I18N_API ScientificNumberFormatter : public UObject {
52 public:
53
64 static ScientificNumberFormatter *createSuperscriptInstance(
65 DecimalFormat *fmtToAdopt, UErrorCode &status);
66
76 static ScientificNumberFormatter *createSuperscriptInstance(
77 const Locale &locale, UErrorCode &status);
78
79
92 static ScientificNumberFormatter *createMarkupInstance(
93 DecimalFormat *fmtToAdopt,
94 const UnicodeString &beginMarkup,
95 const UnicodeString &endMarkup,
96 UErrorCode &status);
97
109 static ScientificNumberFormatter *createMarkupInstance(
110 const Locale &locale,
111 const UnicodeString &beginMarkup,
112 const UnicodeString &endMarkup,
113 UErrorCode &status);
114
115
120 ScientificNumberFormatter *clone() const {
121 return new ScientificNumberFormatter(*this);
122 }
123
128 virtual ~ScientificNumberFormatter();
129
140 UnicodeString &format(
141 const Formattable &number,
142 UnicodeString &appendTo,
143 UErrorCode &status) const;
144 private:
145 class U_I18N_API Style : public UObject {
146 public:
147 virtual Style *clone() const = 0;
148 protected:
149 virtual UnicodeString &format(
150 const UnicodeString &original,
151 FieldPositionIterator &fpi,
152 const UnicodeString &preExponent,
153 const DecimalFormatStaticSets &decimalFormatSets,
154 UnicodeString &appendTo,
155 UErrorCode &status) const = 0;
156 private:
157 friend class ScientificNumberFormatter;
158 };
159
160 class U_I18N_API SuperscriptStyle : public Style {
161 public:
162 virtual Style *clone() const;
163 protected:
164 virtual UnicodeString &format(
165 const UnicodeString &original,
166 FieldPositionIterator &fpi,
167 const UnicodeString &preExponent,
168 const DecimalFormatStaticSets &decimalFormatSets,
169 UnicodeString &appendTo,
170 UErrorCode &status) const;
171 };
172
173 class U_I18N_API MarkupStyle : public Style {
174 public:
175 MarkupStyle(
176 const UnicodeString &beginMarkup,
177 const UnicodeString &endMarkup)
178 : Style(),
179 fBeginMarkup(beginMarkup),
180 fEndMarkup(endMarkup) { }
181 virtual Style *clone() const;
182 protected:
183 virtual UnicodeString &format(
184 const UnicodeString &original,
185 FieldPositionIterator &fpi,
186 const UnicodeString &preExponent,
187 const DecimalFormatStaticSets &decimalFormatSets,
188 UnicodeString &appendTo,
189 UErrorCode &status) const;
190 private:
191 UnicodeString fBeginMarkup;
192 UnicodeString fEndMarkup;
193 };
194
195 ScientificNumberFormatter(
196 DecimalFormat *fmtToAdopt,
197 Style *styleToAdopt,
198 UErrorCode &status);
199
200 ScientificNumberFormatter(const ScientificNumberFormatter &other);
201 ScientificNumberFormatter &operator=(const ScientificNumberFormatter &);
202
203 static void getPreExponent(
204 const DecimalFormatSymbols &dfs, UnicodeString &preExponent);
205
206 static ScientificNumberFormatter *createInstance(
207 DecimalFormat *fmtToAdopt,
208 Style *styleToAdopt,
209 UErrorCode &status);
210
211 UnicodeString fPreExponent;
212 DecimalFormat *fDecimalFormat;
213 Style *fStyle;
214 const DecimalFormatStaticSets *fStaticSets;
215
216 };
217
218 U_NAMESPACE_END
219
220
221 #endif /* !UCONFIG_NO_FORMATTING */
222 #endif
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:88
icu::DecimalFormat
DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers.
Definition: decimfmt.h:669
unistr.h
C++ API: Unicode String.
icu::ScientificNumberFormatter::clone
ScientificNumberFormatter * clone() const
Returns a copy of this object.
Definition: scientificnumberformatter.h:120
icu::ScientificNumberFormatter
A formatter that formats numbers in user-friendly scientific notation.
Definition: scientificnumberformatter.h:51
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:360
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:62
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188