ICU 78.2: i18n/unicode/scientificnumberformatter.h Source File

ICU 78.2 78.2

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 U_SHOW_CPLUSPLUS_API
15
16 #if !UCONFIG_NO_FORMATTING
17
18
19 #include "unicode/unistr.h"
20
26 U_NAMESPACE_BEGIN
27
28 class FieldPositionIterator;
29 class DecimalFormatSymbols;
30 class DecimalFormat;
31 class Formattable;
32
52 class U_I18N_API ScientificNumberFormatter : public UObject {
53 public:
54
65 static ScientificNumberFormatter *createSuperscriptInstance(
66 DecimalFormat *fmtToAdopt, UErrorCode &status);
67
77 static ScientificNumberFormatter *createSuperscriptInstance(
78 const Locale &locale, UErrorCode &status);
79
80
93 static ScientificNumberFormatter *createMarkupInstance(
94 DecimalFormat *fmtToAdopt,
95 const UnicodeString &beginMarkup,
96 const UnicodeString &endMarkup,
97 UErrorCode &status);
98
110 static ScientificNumberFormatter *createMarkupInstance(
111 const Locale &locale,
112 const UnicodeString &beginMarkup,
113 const UnicodeString &endMarkup,
114 UErrorCode &status);
115
116
121 ScientificNumberFormatter *clone() const {
122 return new ScientificNumberFormatter(*this);
123 }
124
129 virtual ~ScientificNumberFormatter();
130
141 UnicodeString &format(
142 const Formattable &number,
143 UnicodeString &appendTo,
144 UErrorCode &status) const;
145 private:
146 class U_I18N_API Style : public UObject {
147 public:
148 virtual Style *clone() const = 0;
149 protected:
150 virtual UnicodeString &format(
151 const UnicodeString &original,
152 FieldPositionIterator &fpi,
153 const UnicodeString &preExponent,
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 SuperscriptStyle *clone() const override;
163 protected:
164 virtual UnicodeString &format(
165 const UnicodeString &original,
166 FieldPositionIterator &fpi,
167 const UnicodeString &preExponent,
168 UnicodeString &appendTo,
169 UErrorCode &status) const override;
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 MarkupStyle *clone() const override;
181 protected:
182 virtual UnicodeString &format(
183 const UnicodeString &original,
184 FieldPositionIterator &fpi,
185 const UnicodeString &preExponent,
186 UnicodeString &appendTo,
187 UErrorCode &status) const override;
188 private:
189 UnicodeString fBeginMarkup;
190 UnicodeString fEndMarkup;
191 };
192
193 ScientificNumberFormatter(
194 DecimalFormat *fmtToAdopt,
195 Style *styleToAdopt,
196 UErrorCode &status);
197
198 ScientificNumberFormatter(const ScientificNumberFormatter &other);
199 ScientificNumberFormatter &operator=(const ScientificNumberFormatter &) = delete;
200
201 static void getPreExponent(
202 const DecimalFormatSymbols &dfs, UnicodeString &preExponent);
203
204 static ScientificNumberFormatter *createInstance(
205 DecimalFormat *fmtToAdopt,
206 Style *styleToAdopt,
207 UErrorCode &status);
208
209 UnicodeString fPreExponent;
210 DecimalFormat *fDecimalFormat;
211 Style *fStyle;
212
213 };
214
215 U_NAMESPACE_END
216
217
218 #endif /* !UCONFIG_NO_FORMATTING */
219
220 #endif /* U_SHOW_CPLUSPLUS_API */
221
222 #endif
icu::DecimalFormat
IMPORTANT: New users are strongly encouraged to see if numberformatter.h fits their use case.
Definition: decimfmt.h:666
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:58
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:63
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:198
icu::ScientificNumberFormatter
A formatter that formats numbers in user-friendly scientific notation.
Definition: scientificnumberformatter.h:52
icu::ScientificNumberFormatter::createMarkupInstance
static ScientificNumberFormatter * createMarkupInstance(DecimalFormat *fmtToAdopt, const UnicodeString &beginMarkup, const UnicodeString &endMarkup, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses markup for exponents.
icu::ScientificNumberFormatter::clone
ScientificNumberFormatter * clone() const
Returns a copy of this object.
Definition: scientificnumberformatter.h:121
icu::ScientificNumberFormatter::~ScientificNumberFormatter
virtual ~ScientificNumberFormatter()
Destructor.
icu::ScientificNumberFormatter::createSuperscriptInstance
static ScientificNumberFormatter * createSuperscriptInstance(const Locale &locale, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses superscript characters for exponents for this ...
icu::ScientificNumberFormatter::format
UnicodeString & format(const Formattable &number, UnicodeString &appendTo, UErrorCode &status) const
Formats a number into user friendly scientific notation.
icu::ScientificNumberFormatter::createMarkupInstance
static ScientificNumberFormatter * createMarkupInstance(const Locale &locale, const UnicodeString &beginMarkup, const UnicodeString &endMarkup, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses markup for exponents for this locale.
icu::ScientificNumberFormatter::createSuperscriptInstance
static ScientificNumberFormatter * createSuperscriptInstance(DecimalFormat *fmtToAdopt, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses superscript characters for exponents.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:222
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:303
unistr.h
C++ API: Unicode String.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:509
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:316