2014-04-09 23:00:45 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Copyright (c) 2014, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
#ifndef SCIFORMATHELPER_H
|
|
|
|
#define SCIFORMATHELPER_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#ifndef U_HIDE_DRAFT_API
|
|
|
|
|
|
|
|
#include "unicode/unistr.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief C++ API: Formatter for measure objects.
|
|
|
|
*/
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class DecimalFormatSymbols;
|
|
|
|
class FieldPositionIterator;
|
2014-04-10 18:13:29 +00:00
|
|
|
class DecimalFormatStaticSets;
|
2014-04-09 23:00:45 +00:00
|
|
|
|
|
|
|
/**
|
2014-06-13 16:40:17 +00:00
|
|
|
* A helper class for formatting numbers in standard scientific notation
|
|
|
|
* instead of E notation.
|
2014-04-09 23:00:45 +00:00
|
|
|
*
|
|
|
|
* Sample code:
|
|
|
|
* <pre>
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
|
|
|
* DecimalFormat *decfmt = (DecimalFormat *)
|
|
|
|
* NumberFormat::createScientificInstance("en", status);
|
|
|
|
* UnicodeString appendTo;
|
|
|
|
* FieldPositionIterator fpositer;
|
|
|
|
* decfmt->format(1.23456e-78, appendTo, &fpositer, status);
|
|
|
|
* ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status);
|
|
|
|
* UnicodeString result;
|
|
|
|
*
|
2014-06-13 16:40:17 +00:00
|
|
|
* // result = "1.23456x10<sup>-78</sup>"
|
2014-04-30 20:15:10 +00:00
|
|
|
* helper.insertMarkup(appendTo, fpositer, "<sup>", "</sup>", result, status));
|
2014-04-09 23:00:45 +00:00
|
|
|
* </pre>
|
|
|
|
*
|
|
|
|
* @see NumberFormat
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
class U_I18N_API ScientificFormatHelper : public UObject {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor.
|
2014-06-13 16:40:17 +00:00
|
|
|
* @param symbols comes from DecimalFormat instance used for default
|
|
|
|
* scientific notation.
|
|
|
|
* @param status any error reported here.
|
2014-04-09 23:00:45 +00:00
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
ScientificFormatHelper(const DecimalFormatSymbols &symbols, UErrorCode& status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor.
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
ScientificFormatHelper(const ScientificFormatHelper &other);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator.
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
ScientificFormatHelper &operator=(const ScientificFormatHelper &other);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
virtual ~ScientificFormatHelper();
|
|
|
|
|
|
|
|
/**
|
2014-06-13 16:45:12 +00:00
|
|
|
* Formats standard scientific notation by surrounding exponent with
|
2014-04-09 23:00:45 +00:00
|
|
|
* html to make it superscript.
|
2014-06-13 16:40:17 +00:00
|
|
|
* @param s the original formatted scientific notation
|
|
|
|
* e.g "6.02e23". s is output from
|
|
|
|
* NumberFormat::createScientificInstance()->format().
|
|
|
|
* @param fpi the FieldPositionIterator from the format call.
|
|
|
|
* fpi is output from
|
|
|
|
* NumberFormat::createScientificInstance()->format().
|
2014-04-09 23:00:45 +00:00
|
|
|
* @param beginMarkup the start html for the exponent e.g "<sup>"
|
2014-06-13 16:40:17 +00:00
|
|
|
* @param endMarkup the end html for the exponent e.g "</sup>"
|
2014-06-13 16:45:12 +00:00
|
|
|
* @param result standard scientific notation appended here.
|
2014-06-13 16:40:17 +00:00
|
|
|
* @param status any error returned here. When status is set to a
|
|
|
|
* non-zero error, the value of result is unspecified,
|
|
|
|
* and client should fallback to using s for scientific
|
|
|
|
* notation.
|
2014-04-09 23:00:45 +00:00
|
|
|
* @return the value stored in result.
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
2014-04-30 20:15:10 +00:00
|
|
|
UnicodeString &insertMarkup(
|
2014-04-09 23:00:45 +00:00
|
|
|
const UnicodeString &s,
|
|
|
|
FieldPositionIterator &fpi,
|
|
|
|
const UnicodeString &beginMarkup,
|
|
|
|
const UnicodeString &endMarkup,
|
|
|
|
UnicodeString &result,
|
|
|
|
UErrorCode &status) const;
|
|
|
|
|
|
|
|
/**
|
2014-06-13 16:45:12 +00:00
|
|
|
* Formats standard scientific notation by using superscript unicode
|
|
|
|
* points 0..9.
|
2014-06-13 16:40:17 +00:00
|
|
|
* @param s the original formatted scientific notation
|
|
|
|
* e.g "6.02e23". s is output from
|
|
|
|
* NumberFormat::createScientificInstance()->format().
|
|
|
|
* @param fpi the FieldPositionIterator from the format call.
|
|
|
|
* fpi is output from
|
|
|
|
* NumberFormat::createScientificInstance()->format().
|
2014-06-13 16:45:12 +00:00
|
|
|
* @param result standard scientific notation appended here.
|
2014-06-13 16:40:17 +00:00
|
|
|
* @param status any error returned here. When status is set to a
|
|
|
|
* non-zero error, the value of result is unspecified,
|
|
|
|
* and client should fallback to using s for scientific
|
|
|
|
* notation.
|
2014-04-09 23:00:45 +00:00
|
|
|
* @return the value stored in result.
|
|
|
|
* @draft ICU 54
|
|
|
|
*/
|
|
|
|
UnicodeString &toSuperscriptExponentDigits(
|
|
|
|
const UnicodeString &s,
|
|
|
|
FieldPositionIterator &fpi,
|
|
|
|
UnicodeString &result,
|
|
|
|
UErrorCode &status) const;
|
|
|
|
private:
|
|
|
|
UnicodeString fPreExponent;
|
2014-04-10 18:13:29 +00:00
|
|
|
const DecimalFormatStaticSets *fStaticSets;
|
2014-04-09 23:00:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* U_HIDE_DRAFT_API */
|
|
|
|
|
|
|
|
#endif /* !UCONFIG_NO_FORMATTING */
|
|
|
|
#endif
|