OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ********************************************************************** |
| 3 * Copyright (c) 2014, International Business Machines |
| 4 * Corporation and others. All Rights Reserved. |
| 5 ********************************************************************** |
| 6 */ |
| 7 #ifndef SCIFORMATHELPER_H |
| 8 #define SCIFORMATHELPER_H |
| 9 |
| 10 #include "unicode/utypes.h" |
| 11 |
| 12 #if !UCONFIG_NO_FORMATTING |
| 13 |
| 14 #ifndef U_HIDE_DRAFT_API |
| 15 |
| 16 #include "unicode/unistr.h" |
| 17 |
| 18 /** |
| 19 * \file |
| 20 * \brief C++ API: Formatter for measure objects. |
| 21 */ |
| 22 |
| 23 U_NAMESPACE_BEGIN |
| 24 |
| 25 class DecimalFormatSymbols; |
| 26 class FieldPositionIterator; |
| 27 class DecimalFormatStaticSets; |
| 28 |
| 29 /** |
| 30 * A helper class for formatting numbers in standard scientific notation |
| 31 * instead of E notation. |
| 32 * |
| 33 * Sample code: |
| 34 * <pre> |
| 35 * UErrorCode status = U_ZERO_ERROR; |
| 36 * DecimalFormat *decfmt = (DecimalFormat *) |
| 37 * NumberFormat::createScientificInstance("en", status); |
| 38 * UnicodeString appendTo; |
| 39 * FieldPositionIterator fpositer; |
| 40 * decfmt->format(1.23456e-78, appendTo, &fpositer, status); |
| 41 * ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status); |
| 42 * UnicodeString result; |
| 43 * |
| 44 * // result = "1.23456x10<sup>-78</sup>" |
| 45 * helper.insertMarkup(appendTo, fpositer, "<sup>", "</sup>", result, status)); |
| 46 * </pre> |
| 47 * |
| 48 * @see NumberFormat |
| 49 * @draft ICU 54 |
| 50 */ |
| 51 class U_I18N_API ScientificFormatHelper : public UObject { |
| 52 public: |
| 53 /** |
| 54 * Constructor. |
| 55 * @param symbols comes from DecimalFormat instance used for default |
| 56 * scientific notation. |
| 57 * @param status any error reported here. |
| 58 * @draft ICU 54 |
| 59 */ |
| 60 ScientificFormatHelper(const DecimalFormatSymbols &symbols, UErrorCode& stat
us); |
| 61 |
| 62 /** |
| 63 * Copy constructor. |
| 64 * @draft ICU 54 |
| 65 */ |
| 66 ScientificFormatHelper(const ScientificFormatHelper &other); |
| 67 |
| 68 /** |
| 69 * Assignment operator. |
| 70 * @draft ICU 54 |
| 71 */ |
| 72 ScientificFormatHelper &operator=(const ScientificFormatHelper &other); |
| 73 |
| 74 /** |
| 75 * Destructor. |
| 76 * @draft ICU 54 |
| 77 */ |
| 78 virtual ~ScientificFormatHelper(); |
| 79 |
| 80 /** |
| 81 * Formats standard scientific notation by surrounding exponent with |
| 82 * html to make it superscript. |
| 83 * @param s the original formatted scientific notation |
| 84 * e.g "6.02e23". s is output from |
| 85 * NumberFormat::createScientificInstance()->format(). |
| 86 * @param fpi the FieldPositionIterator from the format call. |
| 87 * fpi is output from |
| 88 * NumberFormat::createScientificInstance()->format(). |
| 89 * @param beginMarkup the start html for the exponent e.g "<sup>" |
| 90 * @param endMarkup the end html for the exponent e.g "</sup>" |
| 91 * @param result standard scientific notation appended here. |
| 92 * @param status any error returned here. When status is set to a |
| 93 * non-zero error, the value of result is unspecified, |
| 94 * and client should fallback to using s for scientific |
| 95 * notation. |
| 96 * @return the value stored in result. |
| 97 * @draft ICU 54 |
| 98 */ |
| 99 UnicodeString &insertMarkup( |
| 100 const UnicodeString &s, |
| 101 FieldPositionIterator &fpi, |
| 102 const UnicodeString &beginMarkup, |
| 103 const UnicodeString &endMarkup, |
| 104 UnicodeString &result, |
| 105 UErrorCode &status) const; |
| 106 |
| 107 /** |
| 108 * Formats standard scientific notation by using superscript unicode |
| 109 * points 0..9. |
| 110 * @param s the original formatted scientific notation |
| 111 * e.g "6.02e23". s is output from |
| 112 * NumberFormat::createScientificInstance()->format(). |
| 113 * @param fpi the FieldPositionIterator from the format call. |
| 114 * fpi is output from |
| 115 * NumberFormat::createScientificInstance()->format(). |
| 116 * @param result standard scientific notation appended here. |
| 117 * @param status any error returned here. When status is set to a |
| 118 * non-zero error, the value of result is unspecified, |
| 119 * and client should fallback to using s for scientific |
| 120 * notation. |
| 121 * @return the value stored in result. |
| 122 * @draft ICU 54 |
| 123 */ |
| 124 UnicodeString &toSuperscriptExponentDigits( |
| 125 const UnicodeString &s, |
| 126 FieldPositionIterator &fpi, |
| 127 UnicodeString &result, |
| 128 UErrorCode &status) const; |
| 129 private: |
| 130 UnicodeString fPreExponent; |
| 131 const DecimalFormatStaticSets *fStaticSets; |
| 132 }; |
| 133 |
| 134 U_NAMESPACE_END |
| 135 |
| 136 #endif /* U_HIDE_DRAFT_API */ |
| 137 |
| 138 #endif /* !UCONFIG_NO_FORMATTING */ |
| 139 #endif |
OLD | NEW |