editeng/source/misc/svxacorr.cxx   |   23 +++++++++++++++++++++--
 include/editeng/svxacorr.hxx       |    2 +-
 sw/qa/extras/uiwriter/uiwriter.cxx |   21 +++++++++++++++++++++
 3 files changed, 43 insertions(+), 3 deletions(-)

New commits:
commit 62ba1f0af72b0c86889a3aea19efd76da3cbe840
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Mon Apr 1 21:57:13 2019 +0200
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Wed Apr 3 17:53:19 2019 +0200

    tdf#108423 autocorrect English word i' -> I’
    
    Now correction of the ASCII quotation mark to the
    typographical one (’) capitalizes the preceding single
    lowercase i, too, as in MSO, if the language of the
    text is English.
    
    Change-Id: Ic7586f07aa13f441e25494ff4cc11c672ac4a67a
    Reviewed-on: https://gerrit.libreoffice.org/70088
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit 376e3a4893356d2eb7c2a5a902b533982e2663ae)
    Reviewed-on: https://gerrit.libreoffice.org/70190
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index 2d3a3069241d..e1a32bb154b5 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -1168,7 +1168,7 @@ 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 bIns, bool b_iApostrophe )
 {
     const LanguageType eLang = GetDocLanguage( rDoc, nInsPos );
     sal_Unicode cRet = GetQuote( cInsChar, bSttQuote, eLang );
@@ -1200,6 +1200,22 @@ void SvxAutoCorrect::InsertQuote( SvxAutoCorrDoc& rDoc, 
sal_Int32 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))
+    {
+        rDoc.Replace( nInsPos-1, "I" );
+    }
 }
 
 OUString SvxAutoCorrect::GetQuote( SvxAutoCorrDoc const & rDoc, sal_Int32 
nInsPos,
@@ -1255,6 +1271,7 @@ void SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, 
const OUString& rTxt,
             {
                 sal_Unicode cPrev;
                 bool bSttQuote = !nInsPos;
+                bool b_iApostrophe = false;
                 if (!bSttQuote)
                 {
                     cPrev = rTxt[ nInsPos-1 ];
@@ -1262,8 +1279,10 @@ void SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& 
rDoc, const OUString& rTxt,
                         lcl_IsInAsciiArr( "([{", cPrev ) ||
                         ( cEmDash == cPrev ) ||
                         ( cEnDash == cPrev );
+                    b_iApostrophe = bSingle && ( cPrev == 'i' ) &&
+                        (( nInsPos == 1 ) || IsWordDelim( rTxt[ nInsPos-2 ] ));
                 }
-                InsertQuote( rDoc, nInsPos, cChar, bSttQuote, bInsert );
+                InsertQuote( rDoc, nInsPos, cChar, bSttQuote, bInsert, 
b_iApostrophe );
                 break;
             }
 
diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx
index 5dc0e5fbc158..988680984e12 100644
--- a/include/editeng/svxacorr.hxx
+++ b/include/editeng/svxacorr.hxx
@@ -319,7 +319,7 @@ 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 );
+                    sal_Unicode cInsChar, bool bSttQuote, bool bIns, bool 
b_iApostrophe );
 
     // Query/Set the name of the AutoCorrect file
     // the default is "autocorr.dat"
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx 
b/sw/qa/extras/uiwriter/uiwriter.cxx
index e2844a663ded..e8ed45a9f13b 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -347,6 +347,7 @@ public:
     void testTdf117225();
     void testTdf91801();
     void testTdf51223();
+    void testTdf108423();
     void testInconsistentBookmark();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
@@ -547,6 +548,7 @@ public:
     CPPUNIT_TEST(testTdf91801);
     CPPUNIT_TEST(testTdf51223);
     CPPUNIT_TEST(testInconsistentBookmark);
+    CPPUNIT_TEST(testTdf108423);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6529,6 +6531,25 @@ void SwUiWriterTest::testInconsistentBookmark()
     }
 }
 
+void SwUiWriterTest::testTdf108423()
+{
+    SwDoc* pDoc = createDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    // testing autocorrect of i' -> I' on start of first paragraph
+    SwAutoCorrect corr(*SvxAutoCorrCfg::Get().GetAutoCorrect());
+    pWrtShell->Insert("i");
+    const sal_Unicode cChar = '\'';
+    pWrtShell->AutoCorrect(corr, cChar);
+    // The word "i" should be capitalized due to autocorrect, followed by a 
typographical apostrophe
+    sal_uLong nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
+    OUString sIApostrophe = OUString(u"I" + OUStringLiteral1(0x2019));
+    CPPUNIT_ASSERT_EQUAL(sIApostrophe, 
static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
+    pWrtShell->Insert(" i");
+    pWrtShell->AutoCorrect(corr, cChar);
+    OUString sText = OUString(sIApostrophe + u" " + sIApostrophe);
+    CPPUNIT_ASSERT_EQUAL(sText, 
static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to