IntlNumberFormat.h [plain text]
#pragma once
#if ENABLE(INTL)
#include "JSDestructibleObject.h"
#include <unicode/unum.h>
#include <unicode/uvernum.h>
#define HAVE_ICU_FORMAT_DOUBLE_FOR_FIELDS (U_ICU_VERSION_MAJOR_NUM >= 59)
namespace JSC {
class IntlNumberFormatConstructor;
class JSBoundFunction;
class IntlNumberFormat final : public JSDestructibleObject {
public:
typedef JSDestructibleObject Base;
static IntlNumberFormat* create(VM&, Structure*);
static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
DECLARE_INFO;
void initializeNumberFormat(ExecState&, JSValue locales, JSValue optionsValue);
JSValue formatNumber(ExecState&, double number);
#if HAVE(ICU_FORMAT_DOUBLE_FOR_FIELDS)
JSValue formatToParts(ExecState&, double value);
#endif
JSObject* resolvedOptions(ExecState&);
JSBoundFunction* boundFormat() const { return m_boundFormat.get(); }
void setBoundFormat(VM&, JSBoundFunction*);
protected:
IntlNumberFormat(VM&, Structure*);
void finishCreation(VM&);
static void destroy(JSCell*);
static void visitChildren(JSCell*, SlotVisitor&);
private:
enum class Style { Decimal, Percent, Currency };
enum class CurrencyDisplay { Code, Symbol, Name };
struct UNumberFormatDeleter {
void operator()(UNumberFormat*) const;
};
static ASCIILiteral styleString(Style);
static ASCIILiteral currencyDisplayString(CurrencyDisplay);
String m_locale;
String m_numberingSystem;
Style m_style { Style::Decimal };
String m_currency;
CurrencyDisplay m_currencyDisplay;
unsigned m_minimumIntegerDigits { 1 };
unsigned m_minimumFractionDigits { 0 };
unsigned m_maximumFractionDigits { 3 };
unsigned m_minimumSignificantDigits { 0 };
unsigned m_maximumSignificantDigits { 0 };
std::unique_ptr<UNumberFormat, UNumberFormatDeleter> m_numberFormat;
WriteBarrier<JSBoundFunction> m_boundFormat;
bool m_useGrouping { true };
bool m_initializedNumberFormat { false };
#if HAVE(ICU_FORMAT_DOUBLE_FOR_FIELDS)
struct UFieldPositionIteratorDeleter {
void operator()(UFieldPositionIterator*) const;
};
struct IntlNumberFormatField {
UNumberFormatFields type;
int32_t beginIndex { 0 };
int32_t endIndex { 0 };
int32_t size() const
{
return endIndex - beginIndex;
};
};
static ASCIILiteral partTypeString(UNumberFormatFields, double);
#endif
};
}
#endif // ENABLE(INTL)