diff options
author | Cédric Bosdonnat <cedricbosdo@openoffice.org> | 2011-04-07 13:33:48 +0200 |
---|---|---|
committer | Cédric Bosdonnat <cedricbosdo@openoffice.org> | 2011-04-07 18:27:48 +0200 |
commit | 908989d52e79efadb43072b34a43da5b4ee2f4c4 (patch) | |
tree | 4444b804c9c35dacfde9ff92e2d0845c31bcd038 | |
parent | fix cast to implementation objects failure from some vba objects (diff) | |
download | core-908989d52e79efadb43072b34a43da5b4ee2f4c4.tar.gz core-908989d52e79efadb43072b34a43da5b4ee2f4c4.zip |
i#20348: made the ordinal suffixe autocorrection internationalized
-rw-r--r-- | desktop/source/app/dispatchwatcher.cxx | 2 | ||||
-rw-r--r-- | editeng/source/misc/svxacorr.cxx | 79 |
2 files changed, 46 insertions, 35 deletions
diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx index 10a9b3b9f0e7..e575ea8f3727 100644 --- a/desktop/source/app/dispatchwatcher.cxx +++ b/desktop/source/app/dispatchwatcher.cxx @@ -479,7 +479,7 @@ sal_Bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatch { xStorable->storeToURL( aOutFile, conversionProperties ); } - catch ( Exception& ) + catch ( Exception& e ) { fprintf( stderr, "Error: Please reverify input parameters...\n" ); } diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 44f328508b95..b0a489b6279a 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -49,6 +49,7 @@ #include <unotools/collatorwrapper.hxx> #include <com/sun/star/i18n/CollatorOptions.hpp> #include <com/sun/star/i18n/UnicodeScript.hpp> +#include <com/sun/star/i18n/XOrdinalSuffix.hpp> #include <unotools/localedatawrapper.hxx> #include <unotools/transliterationwrapper.hxx> #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -510,48 +511,58 @@ sal_Bool SvxAutoCorrect::FnChgOrdinalNumber( 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 const - sAll[] = "th", /* rest */ - sFirst[] = "st", /* 1 */ - sSecond[] = "nd", /* 2 */ - sThird[] = "rd"; /* 3 */ - static const sal_Char* const aNumberTab[ 4 ] = + i--; + bool isDigit = rCC.isDigit( rTxt, i ); + if ( foundEnd ) + validNumber |= isDigit; + + if ( isDigit && !foundEnd ) { - sAll, sFirst, sSecond, sThird - }; + foundEnd = true; + nNumEnd = i; + } + } + while ( i > nSttPos ); - sal_Unicode c = rTxt.GetChar( nEndPos - 3 ); - if( ( c -= '0' ) > 3 ) - c = 0; + if ( foundEnd && validNumber ) { + sal_Int32 nNum = rTxt.Copy( nSttPos, nNumEnd - nSttPos + 1 ).ToInt32( ); - 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 ))); + // 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( bChg ) + if ( xOrdSuffix.is( ) ) { - // then check to the start, if all are numbers - for( xub_StrLen n = nEndPos - 3; nSttPos < n; ) - if( !rCC.isDigit( rTxt, --n ) ) + uno::Sequence< rtl::OUString > aSuffixes = xOrdSuffix->getOrdinalSuffix( nNum, rCC.getLocale( ) ); + for ( sal_Int32 nSuff = 0; nSuff < aSuffixes.getLength(); nSuff++ ) + { + String sSuffix( aSuffixes[ nSuff ] ); + String sEnd = rTxt.Copy( nNumEnd + 1, nEndPos - nNumEnd - 1 ); + + if ( sSuffix == sEnd ) { - bChg = !rCC.isLetter( rTxt, n ); - break; + // 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); + } } - - if( bChg ) // then set the escapement attribute - { - SvxEscapementItem aSvxEscapementItem( DFLT_ESC_AUTO_SUPER, - DFLT_ESC_PROP, SID_ATTR_CHAR_ESCAPEMENT ); - rDoc.SetAttr( nEndPos - 2, nEndPos, - SID_ATTR_CHAR_ESCAPEMENT, - aSvxEscapementItem); } } |