[ooo-build-commit] 2 commits - patches/dev300
Cédric Bosdonnat
cbosdo at kemper.freedesktop.org
Mon Aug 10 02:23:37 PDT 2009
patches/dev300/apply | 2
patches/dev300/svx-i18n-ordinal-autocorr.diff | 186 ++++++++++++++++++++++++++
2 files changed, 188 insertions(+)
New commits:
commit 15046866f2f828cd35d09530b3ad0250df229ef2
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date: Mon Aug 10 11:22:58 2009 +0200
Added missing include
* patches/dev300/svx-i18n-ordinal-autocorr.diff:
diff --git a/patches/dev300/svx-i18n-ordinal-autocorr.diff b/patches/dev300/svx-i18n-ordinal-autocorr.diff
index fc86f7d..2bc918f 100644
--- a/patches/dev300/svx-i18n-ordinal-autocorr.diff
+++ b/patches/dev300/svx-i18n-ordinal-autocorr.diff
@@ -73,6 +73,14 @@ diff -u -r -N -x unxlngi6.pro i18npool/source/ordinalsuffix/ordinalsuffix.cxx i1
diff -u -r -N -x unxlngi6.pro svx/source/editeng/svxacorr.cxx svx/source/editeng/svxacorr.cxx
--- svx/source/editeng/svxacorr.cxx 2009-08-07 17:06:55.000000000 +0200
+++ svx/source/editeng/svxacorr.cxx 2009-08-07 16:48:59.000000000 +0200
+@@ -63,6 +63,7 @@
+ #endif
+ #include <unotools/collatorwrapper.hxx>
+ #include <com/sun/star/i18n/CollatorOptions.hpp>
++#include <com/sun/star/i18n/XOrdinalSuffix.hpp>
+ #include <unotools/localedatawrapper.hxx>
+ #include <unotools/transliterationwrapper.hxx>
+ #include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -522,7 +522,6 @@
return 0 != cChar;
}
@@ -175,5 +183,4 @@ diff -u -r -N -x unxlngi6.pro svx/source/editeng/svxacorr.cxx svx/source/editeng
}
+
return bChg;
- }
-
+ }
commit 953f8fb26f5fa101cda550bf4ba3db5aa577d1f1
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date: Fri Aug 7 17:30:05 2009 +0200
Internationalized 1st auto correction.
This patch has been added in the Experimental section, because it needs
ICU 4.2. ICU 4.0 should work as well, but getting the suffix for a given
number doesn't work for most of the languages (at least english).
* patches/dev300/apply:
* patches/dev300/svx-i18n-ordinal-autocorr.diff:
diff --git a/patches/dev300/apply b/patches/dev300/apply
index 53c3c6f..06a0c63 100644
--- a/patches/dev300/apply
+++ b/patches/dev300/apply
@@ -2165,6 +2165,8 @@ transogl-buildfix-mesa-7.0.3.diff, pmladek
[ Experimental ]
# sal_uInt32 -> sal_uIntPtr for events on some places
events-intptr.diff, i#59411, jholesov
+# internationalized ordinal suffix autocorrection. Needs ICU 4.2
+svx-i18n-ordinal-autocorr.diff, i#20348, cbosdo
[ DebianEtchOnly ]
static-libs-use-_pic.diff, rengelha
diff --git a/patches/dev300/svx-i18n-ordinal-autocorr.diff b/patches/dev300/svx-i18n-ordinal-autocorr.diff
new file mode 100644
index 0000000..fc86f7d
--- /dev/null
+++ b/patches/dev300/svx-i18n-ordinal-autocorr.diff
@@ -0,0 +1,179 @@
+diff -u -r -N -x unxlngi6.pro i18npool/source/ordinalsuffix/ordinalsuffix.cxx i18npool/source/ordinalsuffix/ordinalsuffix.cxx
+--- i18npool/source/ordinalsuffix/ordinalsuffix.cxx 2009-08-04 15:49:26.000000000 +0200
++++ i18npool/source/ordinalsuffix/ordinalsuffix.cxx 2009-08-06 15:51:57.000000000 +0200
+@@ -34,10 +34,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 {
+@@ -86,13 +90,49 @@
+ }
+
+
++/*
++ * For this method to properly return the ordinal suffix for other locales
++ * than english ones, ICU 4.2+ has to be used.
++ */
+ OUString SAL_CALL OrdinalSuffix::getOrdinalSuffix( sal_Int32 nNumber,
+- const Locale &aLocale ) throw( RuntimeException )
++ const lang::Locale &aLocale ) throw( RuntimeException )
+ {
+ 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 (aLocale.Language.equalsAsciiL("en",2))
+- retValue = getOrdinalSuffixEn( nNumber );
++ if ( U_SUCCESS( nCode ) )
++ {
++ // format the string
++ icu::UnicodeString icuRet;
++ formatter.format( (int32_t)nNumber, icuRet );
++
++ // 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 ) )
++ {
++ // 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( );
++ retValue = sValue.copy( len );
++ }
++ }
++ else
++ {
++ if (aLocale.Language.equalsAsciiL("en",2))
++ retValue = getOrdinalSuffixEn( nNumber );
++ }
+
+ return retValue;
+ }
+diff -u -r -N -x unxlngi6.pro svx/source/editeng/svxacorr.cxx svx/source/editeng/svxacorr.cxx
+--- svx/source/editeng/svxacorr.cxx 2009-08-07 17:06:55.000000000 +0200
++++ svx/source/editeng/svxacorr.cxx 2009-08-07 16:48:59.000000000 +0200
+@@ -522,7 +522,6 @@
+ return 0 != cChar;
+ }
+
+-
+ BOOL SvxAutoCorrect::FnChgOrdinalNumber(
+ SvxAutoCorrDoc& rDoc, const String& rTxt,
+ xub_StrLen nSttPos, xub_StrLen nEndPos,
+@@ -541,52 +540,58 @@
+ if( !lcl_IsInAsciiArr( sImplEndSkipChars, rTxt.GetChar( nEndPos - 1 ) ))
+ break;
+
+- if( 2 < nEndPos - nSttPos &&
+- rCC.isDigit( rTxt, nEndPos - 3 ) )
++
++ // Get the last number in the string to check
++ xub_StrLen nNumEnd = nEndPos;
++ bool foundEnd = false;
++ bool validNumber = true;
++ xub_StrLen i = nEndPos;
++
++ do
+ {
+- static sal_Char __READONLY_DATA
+- sAll[] = "th", /* rest */
+- sFirst[] = "st", /* 1 */
+- sSecond[] = "nd", /* 2 */
+- sThird[] = "rd"; /* 3 */
+- static const sal_Char* __READONLY_DATA aNumberTab[ 4 ] =
+- {
+- sAll, sFirst, sSecond, sThird
+- };
++ i--;
++ bool isDigit = rCC.isDigit( rTxt, i );
++ if ( foundEnd )
++ validNumber |= isDigit;
+
+- sal_Unicode c = rTxt.GetChar( nEndPos - 3 );
+- if( ( c -= '0' ) > 3 )
+- c = 0;
+-
+- bChg = ( ((sal_Unicode)*((aNumberTab[ c ])+0)) ==
+- rTxt.GetChar( nEndPos - 2 ) &&
+- ((sal_Unicode)*((aNumberTab[ c ])+1)) ==
+- rTxt.GetChar( nEndPos - 1 )) ||
+- ( 3 < nEndPos - nSttPos &&
+- ( ((sal_Unicode)*(sAll+0)) == rTxt.GetChar( nEndPos - 2 ) &&
+- ((sal_Unicode)*(sAll+1)) == rTxt.GetChar( nEndPos - 1 )));
++ if ( isDigit && !foundEnd )
++ {
++ foundEnd = true;
++ nNumEnd = i;
++ }
++ }
++ while ( i > nSttPos );
+
+- if( bChg )
++ if ( foundEnd && validNumber ) {
++ sal_Int32 nNum = rTxt.Copy( nSttPos, nNumEnd - nSttPos + 1 ).ToInt32( );
++
++ // Check if the characters after that number correspond to the ordinal suffix
++ rtl::OUString sServiceName = rtl::OUString::createFromAscii( "com.sun.star.i18n.OrdinalSuffix" );
++ uno::Reference< i18n::XOrdinalSuffix > xOrdSuffix(
++ comphelper::createProcessComponent( sServiceName ),
++ uno::UNO_QUERY );
++
++ if ( xOrdSuffix.is( ) )
+ {
+- // dann pruefe mal, ob alle bis zum Start alle Zahlen sind
+- for( xub_StrLen n = nEndPos - 3; nSttPos < n; )
+- if( !rCC.isDigit( rTxt, --n ) )
+- {
+- bChg = !rCC.isLetter( rTxt, n );
+- break;
+- }
++ String sSuffix( xOrdSuffix->getOrdinalSuffix( nNum, rCC.getLocale( ) ) );
++ String sEnd = rTxt.Copy( nNumEnd + 1, nEndPos - nNumEnd - 1 );
+
+- if( bChg ) // dann setze mal das Escapement Attribut
++ if ( sSuffix == sEnd )
+ {
+- SvxEscapementItem aSvxEscapementItem( DFLT_ESC_AUTO_SUPER,
+- DFLT_ESC_PROP, SID_ATTR_CHAR_ESCAPEMENT );
+- rDoc.SetAttr( nEndPos - 2, nEndPos,
+- SID_ATTR_CHAR_ESCAPEMENT,
+- aSvxEscapementItem);
++ // Check if the ordinal suffix has to be set as super script
++ if ( rCC.isLetter( sSuffix ) )
++ {
++ // Do the change
++ SvxEscapementItem aSvxEscapementItem( DFLT_ESC_AUTO_SUPER,
++ DFLT_ESC_PROP, SID_ATTR_CHAR_ESCAPEMENT );
++ rDoc.SetAttr( nNumEnd + 1 , nEndPos,
++ SID_ATTR_CHAR_ESCAPEMENT,
++ aSvxEscapementItem);
++ }
+ }
+ }
+-
+ }
++
+ return bChg;
+ }
+
More information about the ooo-build-commit
mailing list