File indexing completed on 2025-01-18 10:13:07
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef SCINUMBERFORMATTER_H
0010 #define SCINUMBERFORMATTER_H
0011
0012 #include "unicode/utypes.h"
0013
0014 #if U_SHOW_CPLUSPLUS_API
0015
0016 #if !UCONFIG_NO_FORMATTING
0017
0018
0019 #include "unicode/unistr.h"
0020
0021
0022
0023
0024
0025
0026 U_NAMESPACE_BEGIN
0027
0028 class FieldPositionIterator;
0029 class DecimalFormatSymbols;
0030 class DecimalFormat;
0031 class Formattable;
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 class U_I18N_API ScientificNumberFormatter : public UObject {
0053 public:
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 static ScientificNumberFormatter *createSuperscriptInstance(
0066 DecimalFormat *fmtToAdopt, UErrorCode &status);
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 static ScientificNumberFormatter *createSuperscriptInstance(
0078 const Locale &locale, UErrorCode &status);
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 static ScientificNumberFormatter *createMarkupInstance(
0094 DecimalFormat *fmtToAdopt,
0095 const UnicodeString &beginMarkup,
0096 const UnicodeString &endMarkup,
0097 UErrorCode &status);
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 static ScientificNumberFormatter *createMarkupInstance(
0111 const Locale &locale,
0112 const UnicodeString &beginMarkup,
0113 const UnicodeString &endMarkup,
0114 UErrorCode &status);
0115
0116
0117
0118
0119
0120
0121 ScientificNumberFormatter *clone() const {
0122 return new ScientificNumberFormatter(*this);
0123 }
0124
0125
0126
0127
0128
0129 virtual ~ScientificNumberFormatter();
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 UnicodeString &format(
0142 const Formattable &number,
0143 UnicodeString &appendTo,
0144 UErrorCode &status) const;
0145 private:
0146 class U_I18N_API Style : public UObject {
0147 public:
0148 virtual Style *clone() const = 0;
0149 protected:
0150 virtual UnicodeString &format(
0151 const UnicodeString &original,
0152 FieldPositionIterator &fpi,
0153 const UnicodeString &preExponent,
0154 UnicodeString &appendTo,
0155 UErrorCode &status) const = 0;
0156 private:
0157 friend class ScientificNumberFormatter;
0158 };
0159
0160 class U_I18N_API SuperscriptStyle : public Style {
0161 public:
0162 virtual SuperscriptStyle *clone() const override;
0163 protected:
0164 virtual UnicodeString &format(
0165 const UnicodeString &original,
0166 FieldPositionIterator &fpi,
0167 const UnicodeString &preExponent,
0168 UnicodeString &appendTo,
0169 UErrorCode &status) const override;
0170 };
0171
0172 class U_I18N_API MarkupStyle : public Style {
0173 public:
0174 MarkupStyle(
0175 const UnicodeString &beginMarkup,
0176 const UnicodeString &endMarkup)
0177 : Style(),
0178 fBeginMarkup(beginMarkup),
0179 fEndMarkup(endMarkup) { }
0180 virtual MarkupStyle *clone() const override;
0181 protected:
0182 virtual UnicodeString &format(
0183 const UnicodeString &original,
0184 FieldPositionIterator &fpi,
0185 const UnicodeString &preExponent,
0186 UnicodeString &appendTo,
0187 UErrorCode &status) const override;
0188 private:
0189 UnicodeString fBeginMarkup;
0190 UnicodeString fEndMarkup;
0191 };
0192
0193 ScientificNumberFormatter(
0194 DecimalFormat *fmtToAdopt,
0195 Style *styleToAdopt,
0196 UErrorCode &status);
0197
0198 ScientificNumberFormatter(const ScientificNumberFormatter &other);
0199 ScientificNumberFormatter &operator=(const ScientificNumberFormatter &) = delete;
0200
0201 static void getPreExponent(
0202 const DecimalFormatSymbols &dfs, UnicodeString &preExponent);
0203
0204 static ScientificNumberFormatter *createInstance(
0205 DecimalFormat *fmtToAdopt,
0206 Style *styleToAdopt,
0207 UErrorCode &status);
0208
0209 UnicodeString fPreExponent;
0210 DecimalFormat *fDecimalFormat;
0211 Style *fStyle;
0212
0213 };
0214
0215 U_NAMESPACE_END
0216
0217
0218 #endif
0219
0220 #endif
0221
0222 #endif