21#include <com/sun/star/i18n/KNumberFormatUsage.hpp>
22#include <com/sun/star/i18n/KNumberFormatType.hpp>
23#include <com/sun/star/i18n/LocaleData2.hpp>
28 const css::uno::Reference < css::uno::XComponentContext >& rxContext )
30 m_xLocaleData.set( css::i18n::LocaleData2::create( rxContext ) );
39css::i18n::NumberFormatCode SAL_CALL
47 const css::uno::Sequence< css::i18n::FormatElement > &aFormatSeq =
getFormats( rLocale );
49 auto pFormat = std::find_if(aFormatSeq.begin(), aFormatSeq.end(),
50 [&
elementType, &elementUsage](
const css::i18n::FormatElement& rFormat) {
51 return rFormat.isDefault
52 && rFormat.formatType == elementType
53 && rFormat.formatUsage == elementUsage; });
54 if (pFormat != aFormatSeq.end())
55 return css::i18n::NumberFormatCode(formatType,
62 css::i18n::NumberFormatCode defaultNumberFormatCode;
63 return defaultNumberFormatCode;
67css::i18n::NumberFormatCode SAL_CALL
71 const css::uno::Sequence< css::i18n::FormatElement > &aFormatSeq =
getFormats( rLocale );
73 auto pFormat = std::find_if(aFormatSeq.begin(), aFormatSeq.end(),
74 [formatIndex](
const css::i18n::FormatElement& rFormat) { return rFormat.formatIndex == formatIndex; });
75 if (pFormat != aFormatSeq.end())
83 css::i18n::NumberFormatCode defaultNumberFormatCode;
84 return defaultNumberFormatCode;
88css::uno::Sequence< css::i18n::NumberFormatCode > SAL_CALL
92 const css::uno::Sequence< css::i18n::FormatElement > &aFormatSeq =
getFormats( rLocale );
94 std::vector<css::i18n::NumberFormatCode> aVec;
95 aVec.reserve(aFormatSeq.getLength());
97 for (
const auto& rFormat : aFormatSeq) {
99 if ( elementUsage == formatUsage ) {
113css::uno::Sequence< css::i18n::NumberFormatCode > SAL_CALL
117 const css::uno::Sequence< css::i18n::FormatElement > &aFormatSeq =
getFormats( rLocale );
119 std::vector<css::i18n::NumberFormatCode> aVec;
120 aVec.reserve(aFormatSeq.getLength());
122 std::transform(aFormatSeq.begin(), aFormatSeq.end(), std::back_inserter(aVec),
123 [](
const css::i18n::FormatElement& rFormat) -> css::i18n::NumberFormatCode {
124 return { mapElementTypeStringToShort(rFormat.formatType),
125 mapElementUsageStringToShort(rFormat.formatUsage),
143 if ( item.first == rLocale )
148 css::uno::Sequence< css::i18n::FormatElement > aFormatElementSequence;
150 aFormatElementSequence =
m_xLocaleData->getAllFormats( rLocale );
153 const int FORMATELEMENTCACHE_SIZE = 3;
165 switch ( formatType )
167 case css::i18n::KNumberFormatType::SHORT :
169 case css::i18n::KNumberFormatType::MEDIUM :
171 case css::i18n::KNumberFormatType::LONG :
180 if ( formatType ==
u"short" )
181 return css::i18n::KNumberFormatType::SHORT;
182 if ( formatType ==
u"medium" )
183 return css::i18n::KNumberFormatType::MEDIUM;
184 if ( formatType ==
u"long" )
185 return css::i18n::KNumberFormatType::LONG;
187 return css::i18n::KNumberFormatType::SHORT;
193 switch ( formatUsage )
195 case css::i18n::KNumberFormatUsage::DATE :
197 case css::i18n::KNumberFormatUsage::TIME :
199 case css::i18n::KNumberFormatUsage::DATE_TIME :
201 case css::i18n::KNumberFormatUsage::FIXED_NUMBER :
202 return "FIXED_NUMBER";
203 case css::i18n::KNumberFormatUsage::FRACTION_NUMBER :
204 return "FRACTION_NUMBER";
205 case css::i18n::KNumberFormatUsage::PERCENT_NUMBER :
206 return "PERCENT_NUMBER";
207 case css::i18n::KNumberFormatUsage::CURRENCY :
209 case css::i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER :
210 return "SCIENTIFIC_NUMBER";
219 if ( formatUsage ==
u"DATE" )
220 return css::i18n::KNumberFormatUsage::DATE;
221 if ( formatUsage ==
u"TIME" )
222 return css::i18n::KNumberFormatUsage::TIME;
223 if ( formatUsage ==
u"DATE_TIME" )
224 return css::i18n::KNumberFormatUsage::DATE_TIME;
225 if ( formatUsage ==
u"FIXED_NUMBER" )
226 return css::i18n::KNumberFormatUsage::FIXED_NUMBER;
227 if ( formatUsage ==
u"FRACTION_NUMBER" )
228 return css::i18n::KNumberFormatUsage::FRACTION_NUMBER;
229 if ( formatUsage ==
u"PERCENT_NUMBER" )
230 return css::i18n::KNumberFormatUsage::PERCENT_NUMBER;
231 if ( formatUsage ==
u"CURRENCY" )
232 return css::i18n::KNumberFormatUsage::CURRENCY;
233 if ( formatUsage ==
u"SCIENTIFIC_NUMBER" )
234 return css::i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER;
243 return "com.sun.star.i18n.NumberFormatCodeMapper";
251css::uno::Sequence< OUString > SAL_CALL
254 return {
"com.sun.star.i18n.NumberFormatMapper" };
257extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
259 css::uno::XComponentContext *context,
260 css::uno::Sequence<css::uno::Any>
const &)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Type elementType(Type type)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)