ICU 55.1 55.1

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

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
scientificnumberformatter.h
Go to the documentation of this file.
1 /*
2 **********************************************************************
3 * Copyright (c) 2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 */
7 #ifndef SCINUMBERFORMATTER_H
8 #define SCINUMBERFORMATTER_H
9
10 #include "unicode/utypes.h"
11
12 #if !UCONFIG_NO_FORMATTING
13
14 #ifndef U_HIDE_DRAFT_API
15
16 #include "unicode/unistr.h"
17
23 U_NAMESPACE_BEGIN
24
25 class FieldPositionIterator;
26 class DecimalFormatStaticSets;
27 class DecimalFormatSymbols;
28 class DecimalFormat;
29 class Formattable;
30
50 class U_I18N_API ScientificNumberFormatter : public UObject {
51 public:
52
63 static ScientificNumberFormatter *createSuperscriptInstance(
64 DecimalFormat *fmtToAdopt, UErrorCode &status);
65
75 static ScientificNumberFormatter *createSuperscriptInstance(
76 const Locale &locale, UErrorCode &status);
77
78
91 static ScientificNumberFormatter *createMarkupInstance(
92 DecimalFormat *fmtToAdopt,
93 const UnicodeString &beginMarkup,
94 const UnicodeString &endMarkup,
95 UErrorCode &status);
96
108 static ScientificNumberFormatter *createMarkupInstance(
109 const Locale &locale,
110 const UnicodeString &beginMarkup,
111 const UnicodeString &endMarkup,
112 UErrorCode &status);
113
114
119 ScientificNumberFormatter *clone() const {
120 return new ScientificNumberFormatter(*this);
121 }
122
127 virtual ~ScientificNumberFormatter();
128
139 UnicodeString &format(
140 const Formattable &number,
141 UnicodeString &appendTo,
142 UErrorCode &status) const;
143 private:
144 class U_I18N_API Style : public UObject {
145 public:
146 virtual Style *clone() const = 0;
147 protected:
148 virtual UnicodeString &format(
149 const UnicodeString &original,
150 FieldPositionIterator &fpi,
151 const UnicodeString &preExponent,
152 const DecimalFormatStaticSets &decimalFormatSets,
153 UnicodeString &appendTo,
154 UErrorCode &status) const = 0;
155 private:
156 friend class ScientificNumberFormatter;
157 };
158
159 class U_I18N_API SuperscriptStyle : public Style {
160 public:
161 virtual Style *clone() const;
162 protected:
163 virtual UnicodeString &format(
164 const UnicodeString &original,
165 FieldPositionIterator &fpi,
166 const UnicodeString &preExponent,
167 const DecimalFormatStaticSets &decimalFormatSets,
168 UnicodeString &appendTo,
169 UErrorCode &status) const;
170 };
171
172 class U_I18N_API MarkupStyle : public Style {
173 public:
174 MarkupStyle(
175 const UnicodeString &beginMarkup,
176 const UnicodeString &endMarkup)
177 : Style(),
178 fBeginMarkup(beginMarkup),
179 fEndMarkup(endMarkup) { }
180 virtual Style *clone() const;
181 protected:
182 virtual UnicodeString &format(
183 const UnicodeString &original,
184 FieldPositionIterator &fpi,
185 const UnicodeString &preExponent,
186 const DecimalFormatStaticSets &decimalFormatSets,
187 UnicodeString &appendTo,
188 UErrorCode &status) const;
189 private:
190 UnicodeString fBeginMarkup;
191 UnicodeString fEndMarkup;
192 };
193
194 ScientificNumberFormatter(
195 DecimalFormat *fmtToAdopt,
196 Style *styleToAdopt,
197 UErrorCode &status);
198
199 ScientificNumberFormatter(const ScientificNumberFormatter &other);
200 ScientificNumberFormatter &operator=(const ScientificNumberFormatter &);
201
202 static void getPreExponent(
203 const DecimalFormatSymbols &dfs, UnicodeString &preExponent);
204
205 static ScientificNumberFormatter *createInstance(
206 DecimalFormat *fmtToAdopt,
207 Style *styleToAdopt,
208 UErrorCode &status);
209
210 UnicodeString fPreExponent;
211 DecimalFormat *fDecimalFormat;
212 Style *fStyle;
213 const DecimalFormatStaticSets *fStaticSets;
214
215 };
216
217 U_NAMESPACE_END
218
219 #endif /* U_HIDE_DRAFT_API */
220
221 #endif /* !UCONFIG_NO_FORMATTING */
222 #endif