ICU 66.0.1  66.0.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 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 
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 
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,
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;
163  protected:
164  virtual UnicodeString &format(
165  const UnicodeString &original,
167  const UnicodeString &preExponent,
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 MarkupStyle *clone() const;
181  protected:
182  virtual UnicodeString &format(
183  const UnicodeString &original,
185  const UnicodeString &preExponent,
186  UnicodeString &appendTo,
187  UErrorCode &status) const;
188  private:
189  UnicodeString fBeginMarkup;
190  UnicodeString fEndMarkup;
191  };
192 
194  DecimalFormat *fmtToAdopt,
195  Style *styleToAdopt,
196  UErrorCode &status);
197 
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
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:86
IMPORTANT: New users are strongly encouraged to see if numberformatter.h fits their use case...
Definition: decimfmt.h:668
C++ API: Unicode String.
A formatter that formats numbers in user-friendly scientific notation.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:58
ScientificNumberFormatter * clone() const
Returns a copy of this object.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195