editeng/source/misc/svxacorr.cxx |   55 +++++++++++++++++----------------------
 include/editeng/svxacorr.hxx     |   10 ++++++-
 2 files changed, 33 insertions(+), 32 deletions(-)

New commits:
commit aad0972496411d8ef3834f699b4b1211c2998ab5
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed May 27 18:15:26 2020 +0200
Commit:     Gabor Kelemen <kelemen.gab...@nisz.hu>
CommitDate: Tue Jul 21 11:51:04 2020 +0200

    AutoCorrect: clean-up InsertQuote
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95211
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit c87c7ddca46ae093a703ca673a204e4593402c38)
    
    Change-Id: I577115805e5bcc29f6eb4d853aaa523495f30126
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99052
    Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu>

diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index 10f91239625a..ad85d8f89550 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -1190,9 +1190,8 @@ sal_Unicode SvxAutoCorrect::GetQuote( sal_Unicode 
cInsChar, bool bSttQuote,
 
 void SvxAutoCorrect::InsertQuote( SvxAutoCorrDoc& rDoc, sal_Int32 nInsPos,
                                     sal_Unicode cInsChar, bool bSttQuote,
-                                    bool bIns, bool b_iApostrophe ) const
+                                    bool bIns, LanguageType eLang, ACQuotes 
eType ) const
 {
-    const LanguageType eLang = GetDocLanguage( rDoc, nInsPos );
     sal_Unicode cRet = GetQuote( cInsChar, bSttQuote, eLang );
 
     OUString sChg( cInsChar );
@@ -1203,36 +1202,21 @@ void SvxAutoCorrect::InsertQuote( SvxAutoCorrDoc& rDoc, 
sal_Int32 nInsPos,
 
     sChg = OUString(cRet);
 
-    if( '\"' == cInsChar )
+    if( eType == ACQuotes::NonBreakingSpace )
     {
-        if (primary(eLang) == primary(LANGUAGE_FRENCH) && eLang != 
LANGUAGE_FRENCH_SWISS)
+        OUString s( cNonBreakingSpace ); // UNICODE code for no break space
+        if( rDoc.Insert( bSttQuote ? nInsPos+1 : nInsPos, s ))
         {
-            OUString s( cNonBreakingSpace ); // UNICODE code for no break space
-            if( rDoc.Insert( bSttQuote ? nInsPos+1 : nInsPos, s ))
-            {
-                if( !bSttQuote )
-                    ++nInsPos;
-            }
+            if( !bSttQuote )
+                ++nInsPos;
         }
     }
 
     rDoc.Replace( nInsPos, sChg );
 
-    // i' -> I' in English (last step for the undo)
-    if( b_iApostrophe && eLang.anyOf(
-        LANGUAGE_ENGLISH,
-        LANGUAGE_ENGLISH_US,
-        LANGUAGE_ENGLISH_UK,
-        LANGUAGE_ENGLISH_AUS,
-        LANGUAGE_ENGLISH_CAN,
-        LANGUAGE_ENGLISH_NZ,
-        LANGUAGE_ENGLISH_EIRE,
-        LANGUAGE_ENGLISH_SAFRICA,
-        LANGUAGE_ENGLISH_JAMAICA,
-        LANGUAGE_ENGLISH_CARRIBEAN))
-    {
+    // i' -> I' in English (last step for the Undo)
+    if( eType == ACQuotes::CapitalizeIAm )
         rDoc.Replace( nInsPos-1, "I" );
-    }
 }
 
 OUString SvxAutoCorrect::GetQuote( SvxAutoCorrDoc const & rDoc, sal_Int32 
nInsPos,
@@ -1283,7 +1267,8 @@ void SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, 
const OUString& rTxt,
             {
                 sal_Unicode cPrev;
                 bool bSttQuote = !nInsPos;
-                bool b_iApostrophe = false;
+                ACQuotes eType = ACQuotes::NONE;
+                const LanguageType eLang = GetDocLanguage( rDoc, nInsPos );
                 if (!bSttQuote)
                 {
                     cPrev = rTxt[ nInsPos-1 ];
@@ -1293,17 +1278,25 @@ void SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& 
rDoc, const OUString& rTxt,
                         ( cEnDash == cPrev );
                     // tdf#38394 use opening quotation mark << in French 
l'<<word>>
                     if ( !bSingle && !bSttQuote && cPrev == cApostrophe &&
+                        primary(eLang) == primary(LANGUAGE_FRENCH) &&
                         (nInsPos == 2 || (nInsPos > 2 && IsWordDelim( rTxt[ 
nInsPos-3 ] ))) )
                     {
-                        const LanguageType eLang = GetDocLanguage( rDoc, 
nInsPos );
-                        if ( primary(eLang) == primary(LANGUAGE_FRENCH) )
-                            bSttQuote = true;
+                        bSttQuote = true;
                     }
                     // tdf#108423 for capitalization of English i'm
-                    b_iApostrophe = bSingle && ( cPrev == 'i' ) &&
-                        (( nInsPos == 1 ) || IsWordDelim( rTxt[ nInsPos-2 ] ));
+                    else if ( bSingle && ( cPrev == 'i' ) &&
+                        primary(eLang) == primary(LANGUAGE_ENGLISH) &&
+                        ( nInsPos == 1 || IsWordDelim( rTxt[ nInsPos-2 ] ) ) )
+                    {
+                        eType = ACQuotes::CapitalizeIAm;
+                    }
                 }
-                InsertQuote( rDoc, nInsPos, cChar, bSttQuote, bInsert, 
b_iApostrophe );
+
+                if ( eType == ACQuotes::NONE && !bSingle &&
+                    ( primary(eLang) == primary(LANGUAGE_FRENCH) && eLang != 
LANGUAGE_FRENCH_SWISS ) )
+                    eType = ACQuotes::NonBreakingSpace;
+
+                InsertQuote( rDoc, nInsPos, cChar, bSttQuote, bInsert, eLang, 
eType );
                 break;
             }
 
diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx
index 46c3df27f18f..7b0e3e0cb7ef 100644
--- a/include/editeng/svxacorr.hxx
+++ b/include/editeng/svxacorr.hxx
@@ -80,6 +80,13 @@ namespace o3tl {
     template<> struct typed_flags<ACFlags> : is_typed_flags<ACFlags, 
0xe0003fff> {};
 }
 
+enum class ACQuotes
+{
+    NONE,
+    NonBreakingSpace,
+    CapitalizeIAm,
+};
+
 // TODO: handle code points > U+FFFF and check users of this class
 
 // only a mapping class
@@ -324,7 +331,8 @@ public:
     OUString GetQuote( SvxAutoCorrDoc const & rDoc, sal_Int32 nInsPos,
                     sal_Unicode cInsChar, bool bSttQuote );
     void InsertQuote( SvxAutoCorrDoc& rDoc, sal_Int32 nInsPos,
-                    sal_Unicode cInsChar, bool bSttQuote, bool bIns, bool 
b_iApostrophe ) const;
+                    sal_Unicode cInsChar, bool bSttQuote, bool bIns,
+                    LanguageType eLang, ACQuotes eType ) const;
 
     // Query/Set the name of the AutoCorrect file
     // the default is "autocorr.dat"
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to