[Libreoffice-commits] .: Branch 'libreoffice-3-4' - i18npool/inc i18npool/source
Cédric Bosdonnat
cbosdo at kemper.freedesktop.org
Thu Apr 7 09:29:41 PDT 2011
i18npool/inc/ordinalsuffix.hxx | 2
i18npool/source/ordinalsuffix/ordinalsuffix.cxx | 85 ++++++++++++++----------
2 files changed, 51 insertions(+), 36 deletions(-)
New commits:
commit 2db919542241a53c866c96162a6fd5d2e55977fb
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date: Thu Apr 7 13:33:50 2011 +0200
i#20348: made the ordinal suffixe autocorrection internationalized
diff --git a/i18npool/inc/ordinalsuffix.hxx b/i18npool/inc/ordinalsuffix.hxx
index a9fa0b1..3aa66d6 100644
--- a/i18npool/inc/ordinalsuffix.hxx
+++ b/i18npool/inc/ordinalsuffix.hxx
@@ -45,7 +45,7 @@ class OrdinalSuffix : public cppu::WeakImplHelper2
virtual ~OrdinalSuffix();
// XOrdinalSuffix
- virtual rtl::OUString SAL_CALL getOrdinalSuffix( sal_Int32 nNumber, const com::sun::star::lang::Locale &rLocale) throw(com::sun::star::uno::RuntimeException);
+ virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getOrdinalSuffix( sal_Int32 nNumber, const com::sun::star::lang::Locale &rLocale ) throw(com::sun::star::uno::RuntimeException);
// XServiceInfo
virtual rtl::OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException);
diff --git a/i18npool/source/ordinalsuffix/ordinalsuffix.cxx b/i18npool/source/ordinalsuffix/ordinalsuffix.cxx
index 224ea8e..bd63edb 100644
--- a/i18npool/source/ordinalsuffix/ordinalsuffix.cxx
+++ b/i18npool/source/ordinalsuffix/ordinalsuffix.cxx
@@ -32,10 +32,14 @@
#include <string.h>
#include "ordinalsuffix.hxx"
+#include <unicode/rbnf.h>
+#include <unicode/normlzr.h>
+
+#define CSTR( ouStr ) rtl::OUStringToOString( ouStr, RTL_TEXTENCODING_UTF8 ).getStr( )
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star;
using namespace ::rtl;
namespace com { namespace sun { namespace star { namespace i18n {
@@ -52,50 +56,61 @@ OrdinalSuffix::~OrdinalSuffix()
}
-static OUString getOrdinalSuffixEn( sal_Int32 nNumber )
+/*
+ * For this method to properly return the ordinal suffix for other locales
+ * than english ones, ICU 4.2+ has to be used.
+ */
+uno::Sequence< OUString > SAL_CALL OrdinalSuffix::getOrdinalSuffix( sal_Int32 nNumber,
+ const lang::Locale &aLocale ) throw( RuntimeException )
{
- OUString retValue;
-
- switch( labs( nNumber ) % 100 )
+ uno::Sequence< OUString > retValue;
+
+ // Get the value from ICU
+ UErrorCode nCode = U_ZERO_ERROR;
+ const icu::Locale rIcuLocale(
+ CSTR( aLocale.Language ),
+ CSTR( aLocale.Country ),
+ CSTR( aLocale.Variant ) );
+ icu::RuleBasedNumberFormat formatter(
+ icu::URBNF_ORDINAL, rIcuLocale, nCode );
+
+ if ( U_SUCCESS( nCode ) )
{
- case 11: case 12: case 13:
- retValue = OUString(RTL_CONSTASCII_USTRINGPARAM("th"));
- break;
- default:
- switch( nNumber % 10 )
+ int32_t nRuleSets = formatter.getNumberOfRuleSetNames( );
+ for ( int32_t i = 0; i < nRuleSets; i++ )
+ {
+ icu::UnicodeString ruleSet = formatter.getRuleSetName( i );
+ // format the string
+ icu::UnicodeString icuRet;
+ icu::FieldPosition icuPos;
+ formatter.format( (int32_t)nNumber, ruleSet, icuRet, icuPos, nCode );
+
+ if ( U_SUCCESS( nCode ) )
{
- case 1:
- retValue = OUString(RTL_CONSTASCII_USTRINGPARAM("st"));
- break;
- case 2:
- retValue = OUString(RTL_CONSTASCII_USTRINGPARAM("nd"));
- break;
- case 3:
- retValue = OUString(RTL_CONSTASCII_USTRINGPARAM("rd"));
- break;
- default:
- retValue = OUString(RTL_CONSTASCII_USTRINGPARAM("th"));
- break;
+ // Apply NFKC normalization to get normal letters
+ icu::UnicodeString normalized;
+ nCode = U_ZERO_ERROR;
+ icu::Normalizer::normalize( icuRet, UNORM_NFKC, 0, normalized, nCode );
+ if ( U_SUCCESS( nCode ) && ( normalized != icuRet ) )
+ {
+ // Convert the normalized UnicodeString to OUString
+ OUString sValue( reinterpret_cast<const sal_Unicode *>( normalized.getBuffer( ) ), normalized.length() );
+
+ // Remove the number to get the prefix
+ sal_Int32 len = OUString::valueOf( nNumber ).getLength( );
+
+ sal_Int32 newLength = retValue.getLength() + 1;
+ retValue.realloc( newLength );
+ retValue[ newLength - 1 ] = sValue.copy( len );
+ }
}
- break;
+ }
}
return retValue;
}
-OUString SAL_CALL OrdinalSuffix::getOrdinalSuffix( sal_Int32 nNumber,
- const Locale &aLocale ) throw( RuntimeException )
-{
- OUString retValue;
-
- if (aLocale.Language.equalsAsciiL("en",2))
- retValue = getOrdinalSuffixEn( nNumber );
-
- return retValue;
-}
-
-
const sal_Char cOrdinalSuffix[] = "com.sun.star.i18n.OrdinalSuffix";
OUString SAL_CALL OrdinalSuffix::getImplementationName(void) throw( RuntimeException )
More information about the Libreoffice-commits
mailing list