From fc32608f193d446dce4027353ed9c55cd46f5e6c Mon Sep 17 00:00:00 2001 From: Cédric Bosdonnat Date: Thu, 7 Apr 2011 13:33:48 +0200 Subject: i#20348: made the ordinal suffixe autocorrection internationalized --- editeng/source/misc/svxacorr.cxx | 79 +++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 34 deletions(-) (limited to 'editeng/source/misc/svxacorr.cxx') diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index ff7a98dedd..b5973a3bb1 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -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); } } -- cgit v1.2.3