[Libreoffice-commits] core.git: Branch 'libreoffice-4-3' - editeng/source

Niklas Johansson sleeping.pillow at gmail.com
Mon Mar 23 09:11:55 PDT 2015


 editeng/source/misc/svxacorr.cxx |  108 +++++++++++++++++++++------------------
 1 file changed, 59 insertions(+), 49 deletions(-)

New commits:
commit c3979944ced7075e9851a69a93fa41d6680bff80
Author: Niklas Johansson <sleeping.pillow at gmail.com>
Date:   Thu Mar 19 20:30:41 2015 +0100

    tdf#89437  Ordinal suffix should never be superscript in some languages
    
    Printing ordinal suffixes as superscript is just not done in Swedish and
    likely a few other languages but this change only cares for Swedish at
    the moment.
    
    Change-Id: Ib7600ceb0534793d900f13b2740e63c1f7f34ba9
    Reviewed-on: https://gerrit.libreoffice.org/14913
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 307c25fe460857c52f0b9c2078e83f6d12f8bdc9)
    Reviewed-on: https://gerrit.libreoffice.org/14967

diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index 4745c0b..608ae61 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -436,69 +436,79 @@ bool SvxAutoCorrect::FnCptlSttWrd( SvxAutoCorrDoc& rDoc, const OUString& rTxt,
 
 
 bool SvxAutoCorrect::FnChgOrdinalNumber(
-                                SvxAutoCorrDoc& rDoc, const OUString& rTxt,
-                                sal_Int32 nSttPos, sal_Int32 nEndPos,
-                                LanguageType eLang )
+    SvxAutoCorrDoc& rDoc, const OUString& rTxt,
+    sal_Int32 nSttPos, sal_Int32 nEndPos,
+    LanguageType eLang)
 {
-// 1st, 2nd, 3rd, 4 - 0th
-// 201th or 201st
-// 12th or 12nd
-    CharClass& rCC = GetCharClass( eLang );
+    // 1st, 2nd, 3rd, 4 - 0th
+    // 201th or 201st
+    // 12th or 12nd
     bool bChg = false;
 
-    for( ; nSttPos < nEndPos; ++nSttPos )
-        if( !lcl_IsInAsciiArr( sImplSttSkipChars, rTxt[ nSttPos ] ))
-            break;
-    for( ; nSttPos < nEndPos; --nEndPos )
-        if( !lcl_IsInAsciiArr( sImplEndSkipChars, rTxt[ nEndPos - 1 ] ))
-            break;
+    // In some languages ordinal suffixes should never be
+    // changed to superscript. Let's break for those languages.
+    switch (eLang)
+    {
+    case LANGUAGE_SWEDISH:
+    case LANGUAGE_SWEDISH_FINLAND:
+        break;
+    default:
+        CharClass& rCC = GetCharClass(eLang);
 
+        for (; nSttPos < nEndPos; ++nSttPos)
+            if (!lcl_IsInAsciiArr(sImplSttSkipChars, rTxt[nSttPos]))
+                break;
+        for (; nSttPos < nEndPos; --nEndPos)
+            if (!lcl_IsInAsciiArr(sImplEndSkipChars, rTxt[nEndPos - 1]))
+                break;
 
-    // Get the last number in the string to check
-    sal_Int32 nNumEnd = nEndPos;
-    bool foundEnd = false;
-    bool validNumber = true;
-    sal_Int32 i = nEndPos;
 
-    while ( i > nSttPos )
-    {
-        i--;
-        bool isDigit = rCC.isDigit( rTxt, i );
-        if ( foundEnd )
-            validNumber |= isDigit;
+        // Get the last number in the string to check
+        sal_Int32 nNumEnd = nEndPos;
+        bool foundEnd = false;
+        bool validNumber = true;
+        sal_Int32 i = nEndPos;
 
-        if ( isDigit && !foundEnd )
+        while (i > nSttPos)
         {
-            foundEnd = true;
-            nNumEnd = i;
-        }
-    }
+            i--;
+            bool isDigit = rCC.isDigit(rTxt, i);
+            if (foundEnd)
+                validNumber |= isDigit;
 
-    if ( foundEnd && validNumber ) {
-        sal_Int32 nNum = rTxt.copy( nSttPos, nNumEnd - nSttPos + 1 ).toInt32( );
+            if (isDigit && !foundEnd)
+            {
+                foundEnd = true;
+                nNumEnd = i;
+            }
+        }
 
-        // Check if the characters after that number correspond to the ordinal suffix
-        uno::Reference< i18n::XOrdinalSuffix > xOrdSuffix
-                = i18n::OrdinalSuffix::create( comphelper::getProcessComponentContext() );
+        if (foundEnd && validNumber) {
+            sal_Int32 nNum = rTxt.copy(nSttPos, nNumEnd - nSttPos + 1).toInt32();
 
-        uno::Sequence< OUString > aSuffixes = xOrdSuffix->getOrdinalSuffix( nNum, rCC.getLanguageTag().getLocale( ) );
-        for ( sal_Int32 nSuff = 0; nSuff < aSuffixes.getLength(); nSuff++ )
-        {
-            OUString sSuffix( aSuffixes[ nSuff ] );
-            OUString sEnd = rTxt.copy( nNumEnd + 1, nEndPos - nNumEnd - 1 );
+            // Check if the characters after that number correspond to the ordinal suffix
+            uno::Reference< i18n::XOrdinalSuffix > xOrdSuffix
+                = i18n::OrdinalSuffix::create(comphelper::getProcessComponentContext());
 
-            if ( sSuffix == sEnd )
+            uno::Sequence< OUString > aSuffixes = xOrdSuffix->getOrdinalSuffix(nNum, rCC.getLanguageTag().getLocale());
+            for (sal_Int32 nSuff = 0; nSuff < aSuffixes.getLength(); nSuff++)
             {
-                // Check if the ordinal suffix has to be set as super script
-                if ( rCC.isLetter( sSuffix ) )
+                OUString sSuffix(aSuffixes[nSuff]);
+                OUString sEnd = rTxt.copy(nNumEnd + 1, nEndPos - nNumEnd - 1);
+
+                if (sSuffix == sEnd)
                 {
-                    // 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);
-                    bChg = true;
+                    // 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);
+                        bChg = true;
+                    }
                 }
             }
         }


More information about the Libreoffice-commits mailing list