ICU 59.1  59.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 
25 
26 class FieldPositionIterator;
27 class DecimalFormatStaticSets;
28 class DecimalFormatSymbols;
29 class DecimalFormat;
30 class Formattable;
31 
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 
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,
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,
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,
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 
196  DecimalFormat *fmtToAdopt,
197  Style *styleToAdopt,
198  UErrorCode &status);
199 
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 
219 
220 
221 #endif /* !UCONFIG_NO_FORMATTING */
222 #endif
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:87
DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers.
Definition: decimfmt.h:669
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:360
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:55
ScientificNumberFormatter * clone() const
Returns a copy of this object.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
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:296
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
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:188