scientificnumberformatter.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (c) 2014-2016, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
#ifndef SCINUMBERFORMATTER_H
#define SCINUMBERFORMATTER_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/unistr.h"
U_NAMESPACE_BEGIN
class FieldPositionIterator;
class DecimalFormatSymbols;
class DecimalFormat;
class Formattable;
class U_I18N_API ScientificNumberFormatter : public UObject {
public:
static ScientificNumberFormatter *createSuperscriptInstance(
DecimalFormat *fmtToAdopt, UErrorCode &status);
static ScientificNumberFormatter *createSuperscriptInstance(
const Locale &locale, UErrorCode &status);
static ScientificNumberFormatter *createMarkupInstance(
DecimalFormat *fmtToAdopt,
const UnicodeString &beginMarkup,
const UnicodeString &endMarkup,
UErrorCode &status);
static ScientificNumberFormatter *createMarkupInstance(
const Locale &locale,
const UnicodeString &beginMarkup,
const UnicodeString &endMarkup,
UErrorCode &status);
ScientificNumberFormatter *clone() const {
return new ScientificNumberFormatter(*this);
}
virtual ~ScientificNumberFormatter();
UnicodeString &format(
const Formattable &number,
UnicodeString &appendTo,
UErrorCode &status) const;
private:
class U_I18N_API Style : public UObject {
public:
virtual Style *clone() const = 0;
protected:
virtual UnicodeString &format(
const UnicodeString &original,
FieldPositionIterator &fpi,
const UnicodeString &preExponent,
UnicodeString &appendTo,
UErrorCode &status) const = 0;
private:
friend class ScientificNumberFormatter;
};
class U_I18N_API SuperscriptStyle : public Style {
public:
virtual SuperscriptStyle *clone() const override;
protected:
virtual UnicodeString &format(
const UnicodeString &original,
FieldPositionIterator &fpi,
const UnicodeString &preExponent,
UnicodeString &appendTo,
UErrorCode &status) const override;
};
class U_I18N_API MarkupStyle : public Style {
public:
MarkupStyle(
const UnicodeString &beginMarkup,
const UnicodeString &endMarkup)
: Style(),
fBeginMarkup(beginMarkup),
fEndMarkup(endMarkup) { }
virtual MarkupStyle *clone() const override;
protected:
virtual UnicodeString &format(
const UnicodeString &original,
FieldPositionIterator &fpi,
const UnicodeString &preExponent,
UnicodeString &appendTo,
UErrorCode &status) const override;
private:
UnicodeString fBeginMarkup;
UnicodeString fEndMarkup;
};
ScientificNumberFormatter(
DecimalFormat *fmtToAdopt,
Style *styleToAdopt,
UErrorCode &status);
ScientificNumberFormatter(const ScientificNumberFormatter &other);
ScientificNumberFormatter &operator=(const ScientificNumberFormatter &) = delete;
static void getPreExponent(
const DecimalFormatSymbols &dfs, UnicodeString &preExponent);
static ScientificNumberFormatter *createInstance(
DecimalFormat *fmtToAdopt,
Style *styleToAdopt,
UErrorCode &status);
UnicodeString fPreExponent;
DecimalFormat *fDecimalFormat;
Style *fStyle;
};
U_NAMESPACE_END
#endif /* !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif
icu::DecimalFormat
IMPORTANT: New users are strongly encouraged to see if numberformatter.h fits their use case.
Definition: decimfmt.h:668
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:58
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::ScientificNumberFormatter
A formatter that formats numbers in user-friendly scientific notation.
Definition: scientificnumberformatter.h:52
icu::ScientificNumberFormatter::createMarkupInstance
static ScientificNumberFormatter * createMarkupInstance(DecimalFormat *fmtToAdopt, const UnicodeString &beginMarkup, const UnicodeString &endMarkup, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses markup for exponents.
icu::ScientificNumberFormatter::clone
ScientificNumberFormatter * clone() const
Returns a copy of this object.
Definition: scientificnumberformatter.h:121
icu::ScientificNumberFormatter::~ScientificNumberFormatter
virtual ~ScientificNumberFormatter()
Destructor.
icu::ScientificNumberFormatter::createSuperscriptInstance
static ScientificNumberFormatter * createSuperscriptInstance(const Locale &locale, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses superscript characters for exponents for this ...
icu::ScientificNumberFormatter::format
UnicodeString & format(const Formattable &number, UnicodeString &appendTo, UErrorCode &status) const
Formats a number into user friendly scientific notation.
icu::ScientificNumberFormatter::createMarkupInstance
static ScientificNumberFormatter * createMarkupInstance(const Locale &locale, const UnicodeString &beginMarkup, const UnicodeString &endMarkup, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses markup for exponents for this locale.
icu::ScientificNumberFormatter::createSuperscriptInstance
static ScientificNumberFormatter * createSuperscriptInstance(DecimalFormat *fmtToAdopt, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses superscript characters for exponents.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
unistr.h
C++ API: Unicode String.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301