ICU 63.1 63.1

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 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 UnicodeString &appendTo,
153 UErrorCode &status) const = 0;
154 private:
155 friend class ScientificNumberFormatter;
156 };
157
158 class U_I18N_API SuperscriptStyle : public Style {
159 public:
160 virtual Style *clone() const;
161 protected:
162 virtual UnicodeString &format(
163 const UnicodeString &original,
164 FieldPositionIterator &fpi,
165 const UnicodeString &preExponent,
166 UnicodeString &appendTo,
167 UErrorCode &status) const;
168 };
169
170 class U_I18N_API MarkupStyle : public Style {
171 public:
172 MarkupStyle(
173 const UnicodeString &beginMarkup,
174 const UnicodeString &endMarkup)
175 : Style(),
176 fBeginMarkup(beginMarkup),
177 fEndMarkup(endMarkup) { }
178 virtual Style *clone() const;
179 protected:
180 virtual UnicodeString &format(
181 const UnicodeString &original,
182 FieldPositionIterator &fpi,
183 const UnicodeString &preExponent,
184 UnicodeString &appendTo,
185 UErrorCode &status) const;
186 private:
187 UnicodeString fBeginMarkup;
188 UnicodeString fEndMarkup;
189 };
190
191 ScientificNumberFormatter(
192 DecimalFormat *fmtToAdopt,
193 Style *styleToAdopt,
194 UErrorCode &status);
195
196 ScientificNumberFormatter(const ScientificNumberFormatter &other);
197 ScientificNumberFormatter &operator=(const ScientificNumberFormatter &);
198
199 static void getPreExponent(
200 const DecimalFormatSymbols &dfs, UnicodeString &preExponent);
201
202 static ScientificNumberFormatter *createInstance(
203 DecimalFormat *fmtToAdopt,
204 Style *styleToAdopt,
205 UErrorCode &status);
206
207 UnicodeString fPreExponent;
208 DecimalFormat *fDecimalFormat;
209 Style *fStyle;
210
211 };
212
213 U_NAMESPACE_END
214
215
216 #endif /* !UCONFIG_NO_FORMATTING */
217 #endif
icu::DecimalFormat
IMPORTANT: New users are strongly encouraged to see if numberformatter.h fits their use case...
Definition: decimfmt.h:677
unistr.h
C++ API: Unicode String.
icu::ScientificNumberFormatter
A formatter that formats numbers in user-friendly scientific notation.
Definition: scientificnumberformatter.h:50
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:301
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:55
icu::ScientificNumberFormatter::clone
ScientificNumberFormatter * clone() const
Returns a copy of this object.
Definition: scientificnumberformatter.h:119
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
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:289
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192