linguistic/source/spelldsp.cxx |   32 ++++++++++++++++++++++++++------
 linguistic/source/spelldsp.hxx |    2 +-
 2 files changed, 27 insertions(+), 7 deletions(-)

New commits:
commit f3958668003a8aae1ce0ff0473b2b3e75d285739
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Fri Jun 14 11:26:22 2024 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Jun 18 11:21:41 2024 +0200

    tdf#150582 linguistic: fix always rejected words with U+2019 apostrophe
    
    During spell checking, words added to the user dictionaries still
    weren't recognized by Calc, Impress and Draw because of the unnecessary
    conversion their typographic apostrophes to ASCII apostrophes.
    
    Note: Writer has no such problem because of its (obsolete) apostrophe
    conversion for the user dictionary.
    
    First skip the obsolete apostrophe conversion in isValid(), but keep
    it as a fallback for Writer users.
    
    Change-Id: I09870a35d7a91017281ba4b228d338336e7bd9c1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168858
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit 8de1941fe61b461be617e1e88bb362bbd8315654)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168878
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/linguistic/source/spelldsp.cxx b/linguistic/source/spelldsp.cxx
index 92b2d4c3efbd..cf83b3a2e3b7 100644
--- a/linguistic/source/spelldsp.cxx
+++ b/linguistic/source/spelldsp.cxx
@@ -199,10 +199,19 @@ sal_Bool SAL_CALL
             const css::uno::Sequence< ::css::beans::PropertyValue >& 
rProperties )
 {
     MutexGuard  aGuard( GetLinguMutex() );
-    return isValid_Impl( rWord, LinguLocaleToLanguage( rLocale ), rProperties 
);
+    // for historical reasons, the word can be only with ASCII apostrophe in 
the dictionaries,
+    // so as a fallback, convert typographical apostrophes to avoid annoying 
users, if they
+    // have old (user) dictionaries only with the obsolete ASCII apostrophe.
+    bool bConvert = false;
+    bool bRet = isValid_Impl( rWord, LinguLocaleToLanguage( rLocale ), 
rProperties, bConvert );
+    if (!bRet && bConvert)
+    {
+        // fallback: convert the apostrophes
+        bRet = isValid_Impl( rWord, LinguLocaleToLanguage( rLocale ), 
rProperties, bConvert );
+    }
+    return bRet;
 }
 
-
 Reference< XSpellAlternatives > SAL_CALL
     SpellCheckerDispatcher::spell( const OUString& rWord, const Locale& 
rLocale,
             const css::uno::Sequence< ::css::beans::PropertyValue >& 
rProperties )
@@ -249,7 +258,8 @@ static Reference< XDictionaryEntry > 
lcl_GetRulingDictionaryEntry(
 bool SpellCheckerDispatcher::isValid_Impl(
             const OUString& rWord,
             LanguageType nLanguage,
-            const PropertyValues& rProperties)
+            const PropertyValues& rProperties,
+            bool& rConvertApostrophe)
 {
     MutexGuard  aGuard( GetLinguMutex() );
 
@@ -267,11 +277,21 @@ bool SpellCheckerDispatcher::isValid_Impl(
         OUString aChkWord( rWord );
         Locale aLocale( LanguageTag::convertToLocale( nLanguage ) );
 
-        // replace typographical apostroph by ascii apostroph
+        // replace typographical apostrophe by ASCII apostrophe only as a 
fallback
+        // for old user dictionaries before the time of the default 
typographical apostrophe
+        // (Note: otherwise also no problem with non-Unicode Hunspell 
dictionaries, because
+        // the character conversion converts also the typographical apostrophe 
to the ASCII one)
         OUString aSingleQuote( GetLocaleDataWrapper( nLanguage 
).getQuotationMarkEnd() );
         DBG_ASSERT( 1 == aSingleQuote.getLength(), "unexpected length of 
quotation mark" );
-        if (!aSingleQuote.isEmpty())
-            aChkWord = aChkWord.replace( aSingleQuote[0], '\'' );
+        if (!aSingleQuote.isEmpty() && aChkWord.indexOf(aSingleQuote[0]) > -1)
+        {
+            // tdf#150582 first check with the original typographical 
apostrophe,
+            // and convert it only on the second try
+            if (rConvertApostrophe)
+                aChkWord = aChkWord.replace( aSingleQuote[0], '\'' );
+            else
+                rConvertApostrophe = true;
+        }
 
         RemoveHyphens( aChkWord );
         if (IsIgnoreControlChars( rProperties, GetPropSet() ))
diff --git a/linguistic/source/spelldsp.hxx b/linguistic/source/spelldsp.hxx
index 73fe59579ff3..c05676e1c9f0 100644
--- a/linguistic/source/spelldsp.hxx
+++ b/linguistic/source/spelldsp.hxx
@@ -69,7 +69,7 @@ class SpellCheckerDispatcher :
     /// @throws css::uno::RuntimeException
     /// @throws css::lang::IllegalArgumentException
     bool    isValid_Impl(const OUString& aWord, LanguageType nLanguage,
-                    const css::beans::PropertyValues& aProperties);
+                    const css::beans::PropertyValues& aProperties, bool& 
rConvertApostrophe);
 
     /// @throws css::uno::RuntimeException
     /// @throws css::lang::IllegalArgumentException

Reply via email to