27#include <unicode/rbnf.h>
28#include <unicode/normlzr.h>
50 OUString mungeUnicodeStringToOUString(
const icu::UnicodeString &rIn, UErrorCode &rCode)
53 icu::UnicodeString normalized;
54 icu::Normalizer::normalize(rIn, UNORM_NFKC, 0, normalized, rCode);
56 OUString sRet = (U_SUCCESS(rCode))
57 ? OUString(
reinterpret_cast<const sal_Unicode *
>(normalized.getBuffer()), normalized.length())
62 return sRet.replace(0x2212,
'-');
71 const lang::Locale &rLocale )
73 uno::Sequence< OUString > retValue;
76 UErrorCode nCode = U_ZERO_ERROR;
79 icu::RuleBasedNumberFormat formatter(icu::URBNF_ORDINAL, aIcuLocale, nCode);
80 if (!U_SUCCESS(nCode))
83 std::unique_ptr<icu::NumberFormat> xNumberFormat(icu::NumberFormat::createInstance(aIcuLocale, nCode));
84 if (!U_SUCCESS(nCode))
87 icu::UnicodeString sFormatWithNoOrdinal;
88 icu::Formattable ftmNumber(
static_cast<int32_t
>(nNumber));
89 icu::FieldPosition icuPosA;
90 xNumberFormat->format(ftmNumber, sFormatWithNoOrdinal, icuPosA, nCode);
91 if (!U_SUCCESS(nCode))
94 OUString sValueWithNoOrdinal = mungeUnicodeStringToOUString(sFormatWithNoOrdinal, nCode);
95 if (!U_SUCCESS(nCode))
98 int32_t nRuleSets = formatter.getNumberOfRuleSetNames( );
99 std::vector<OUString> retVec;
100 retVec.reserve(nRuleSets);
101 for (int32_t
i = 0;
i < nRuleSets; ++
i)
103 icu::UnicodeString ruleSet = formatter.getRuleSetName(
i);
106 icu::UnicodeString sFormatWithOrdinal;
107 icu::FieldPosition icuPosB;
108 formatter.format(
static_cast<int32_t
>(nNumber), ruleSet, sFormatWithOrdinal, icuPosB, nCode);
110 if (!U_SUCCESS(nCode))
113 OUString sValueWithOrdinal = mungeUnicodeStringToOUString(sFormatWithOrdinal, nCode);
114 if (!U_SUCCESS(nCode))
120 bool bSimpleOrdinalSuffix = sValueWithOrdinal.startsWith(sValueWithNoOrdinal);
122 SAL_WARN_IF(!bSimpleOrdinalSuffix,
"i18npool",
"ordinal " <<
123 sValueWithOrdinal <<
" didn't start with expected " <<
124 sValueWithNoOrdinal <<
" prefix");
126 if (!bSimpleOrdinalSuffix)
130 sal_Int32 len = sValueWithNoOrdinal.getLength();
131 retVec.push_back(sValueWithOrdinal.copy(len));
156extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
158 css::uno::XComponentContext *,
159 css::uno::Sequence<css::uno::Any>
const &)
static icu::Locale getIcuLocale(const LanguageTag &rLanguageTag)
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual ~OrdinalSuffixService() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Sequence< OUString > SAL_CALL getOrdinalSuffix(sal_Int32 nNumber, const css::lang::Locale &rLocale) override
#define SAL_WARN_IF(condition, area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Constant values shared between i18npool and, for example, the number formatter.
constexpr OUStringLiteral cOrdinalSuffix
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_i18n_OrdinalSuffix_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)