Loading...
Searching...
No Matches
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:666
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:63
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
icu::ScientificNumberFormatter::createSuperscriptInstance
static ScientificNumberFormatter * createSuperscriptInstance(DecimalFormat *fmtToAdopt, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses superscript characters for exponents.
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::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(const Locale &locale, UErrorCode &status)
Creates a ScientificNumberFormatter instance that uses superscript characters for exponents for this ...
icu::ScientificNumberFormatter::~ScientificNumberFormatter
virtual ~ScientificNumberFormatter()
Destructor.
icu::ScientificNumberFormatter::format
UnicodeString & format(const Formattable &number, UnicodeString &appendTo, UErrorCode &status) const
Formats a number into user friendly scientific notation.
icu::ScientificNumberFormatter::clone
ScientificNumberFormatter * clone() const
Returns a copy of this object.
Definition scientificnumberformatter.h:121
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
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:509
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:316