2 * Copyright 2003, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de.
4 * Copyright 2012, John Scipione, jscipione@gmail.com
5 * All rights reserved. Distributed under the terms of the MIT License.
9 #include <unicode/uversion.h>
10 #include <NumberFormat.h>
12 #include <AutoDeleter.h>
14 #include <FormattingConventionsPrivate.h>
16 #include <ICUWrapper.h>
18 #include <unicode/numfmt.h>
21 BNumberFormat::BNumberFormat()
27 BNumberFormat::BNumberFormat(const BNumberFormat
&other
)
33 BNumberFormat::~BNumberFormat()
38 // #pragma mark - Formatting
42 BNumberFormat::Format(char* string
, size_t maxSize
, const double value
) const
45 status_t status
= Format(fullString
, value
);
49 return strlcpy(string
, fullString
.String(), maxSize
);
54 BNumberFormat::Format(BString
& string
, const double value
) const
56 UErrorCode err
= U_ZERO_ERROR
;
57 ObjectDeleter
<NumberFormat
> numberFormatter(NumberFormat::createInstance(
58 *BFormattingConventions::Private(&fConventions
).ICULocale(),
61 if (numberFormatter
.Get() == NULL
)
66 UnicodeString icuString
;
67 numberFormatter
->format(value
, icuString
);
70 BStringByteSink
stringConverter(&string
);
71 icuString
.toUTF8(stringConverter
);
78 BNumberFormat::Format(char* string
, size_t maxSize
, const int32 value
) const
81 status_t status
= Format(fullString
, value
);
85 return strlcpy(string
, fullString
.String(), maxSize
);
90 BNumberFormat::Format(BString
& string
, const int32 value
) const
92 UErrorCode err
= U_ZERO_ERROR
;
93 ObjectDeleter
<NumberFormat
> numberFormatter(NumberFormat::createInstance(
94 *BFormattingConventions::Private(&fConventions
).ICULocale(),
97 if (numberFormatter
.Get() == NULL
)
102 UnicodeString icuString
;
103 numberFormatter
->format((int32_t)value
, icuString
);
106 BStringByteSink
stringConverter(&string
);
107 icuString
.toUTF8(stringConverter
);
114 BNumberFormat::FormatMonetary(char* string
, size_t maxSize
, const double value
)
118 status_t status
= FormatMonetary(fullString
, value
);
122 return strlcpy(string
, fullString
.String(), maxSize
);
127 BNumberFormat::FormatMonetary(BString
& string
, const double value
) const
132 UErrorCode err
= U_ZERO_ERROR
;
133 ObjectDeleter
<NumberFormat
> numberFormatter(
134 NumberFormat::createCurrencyInstance(
135 *BFormattingConventions::Private(&fConventions
).ICULocale(),
138 if (numberFormatter
.Get() == NULL
)
143 UnicodeString icuString
;
144 numberFormatter
->format(value
, icuString
);
147 BStringByteSink
stringConverter(&string
);
148 icuString
.toUTF8(stringConverter
);