ICU 64.2  64.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 !UCONFIG_NO_FORMATTING
15 
16 
17 #include "unicode/unistr.h"
18 
25 
26 class FieldPositionIterator;
27 class DecimalFormatSymbols;
28 class DecimalFormat;
29 class Formattable;
30 
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 
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,
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,
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,
183  const UnicodeString &preExponent,
184  UnicodeString &appendTo,
185  UErrorCode &status) const;
186  private:
187  UnicodeString fBeginMarkup;
188  UnicodeString fEndMarkup;
189  };
190 
192  DecimalFormat *fmtToAdopt,
193  Style *styleToAdopt,
194  UErrorCode &status);
195 
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 
214 
215 
216 #endif /* !UCONFIG_NO_FORMATTING */
217 #endif
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:84
IMPORTANT: New users are strongly encouraged to see if numberformatter.h fits their use case...
Definition: decimfmt.h:665
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
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
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:138
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
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:289
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
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:192