2 * Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de.
3 * Distributed under the terms of the MIT License.
7 #include "ICUNumericData.h"
19 ICUNumericData::ICUNumericData(pthread_key_t tlsKey
, struct lconv
& localeConv
)
22 fLocaleConv(localeConv
),
25 fLocaleConv
.decimal_point
= fDecimalPoint
;
26 fLocaleConv
.thousands_sep
= fThousandsSep
;
27 fLocaleConv
.grouping
= fGrouping
;
32 ICUNumericData::Initialize(LocaleNumericDataBridge
* dataBridge
)
34 dataBridge
->glibcNumericLocale
.values
[0].string
= fDecimalPoint
;
35 dataBridge
->glibcNumericLocale
.values
[1].string
= fThousandsSep
;
36 dataBridge
->glibcNumericLocale
.values
[2].string
= fGrouping
;
37 fDataBridge
= dataBridge
;
42 ICUNumericData::SetTo(const Locale
& locale
, const char* posixLocaleName
)
44 status_t result
= inherited::SetTo(locale
, posixLocaleName
);
47 UErrorCode icuStatus
= U_ZERO_ERROR
;
48 DecimalFormat
* numberFormat
= dynamic_cast<DecimalFormat
*>(
49 NumberFormat::createInstance(locale
, UNUM_DECIMAL
, icuStatus
));
50 if (!U_SUCCESS(icuStatus
))
54 const DecimalFormatSymbols
* formatSymbols
55 = numberFormat
->getDecimalFormatSymbols();
60 result
= _SetLocaleconvEntry(formatSymbols
, fDecimalPoint
,
61 DecimalFormatSymbols::kDecimalSeparatorSymbol
);
62 fDataBridge
->glibcNumericLocale
.values
[3].word
63 = (unsigned int)fDecimalPoint
[0];
66 result
= _SetLocaleconvEntry(formatSymbols
, fThousandsSep
,
67 DecimalFormatSymbols::kGroupingSeparatorSymbol
);
68 fDataBridge
->glibcNumericLocale
.values
[4].word
69 = (unsigned int)fThousandsSep
[0];
72 int32 groupingSize
= numberFormat
->getGroupingSize();
76 fGrouping
[0] = groupingSize
;
77 int32 secondaryGroupingSize
78 = numberFormat
->getSecondaryGroupingSize();
79 if (secondaryGroupingSize
< 1)
82 fGrouping
[1] = secondaryGroupingSize
;
96 ICUNumericData::SetToPosix()
98 status_t result
= inherited::SetToPosix();
100 if (result
== B_OK
) {
101 strcpy(fDecimalPoint
, fDataBridge
->posixLocaleConv
->decimal_point
);
102 strcpy(fThousandsSep
, fDataBridge
->posixLocaleConv
->thousands_sep
);
103 strcpy(fGrouping
, fDataBridge
->posixLocaleConv
->grouping
);
104 fDataBridge
->glibcNumericLocale
.values
[3].word
105 = (unsigned int)fDecimalPoint
[0];
106 fDataBridge
->glibcNumericLocale
.values
[4].word
107 = (unsigned int)fThousandsSep
[0];
115 ICUNumericData::GetLanginfo(int index
)
119 return fDecimalPoint
;
121 return fThousandsSep
;
128 } // namespace Libroot
129 } // namespace BPrivate