summaryrefslogtreecommitdiff
path: root/linguistic/source
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2024-06-14 11:26:22 +0200
committerLászló Németh <nemeth@numbertext.org>2024-06-14 18:44:11 +0200
commit8de1941fe61b461be617e1e88bb362bbd8315654 (patch)
treeddb002f15817c1fc5090ceb04e29362558d460b5 /linguistic/source
parente78bb77c3c5930b20113bff3de2dd02065cead85 (diff)
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 <nemeth@numbertext.org>
Diffstat (limited to 'linguistic/source')
-rw-r--r--linguistic/source/spelldsp.cxx32
-rw-r--r--linguistic/source/spelldsp.hxx2
2 files changed, 27 insertions, 7 deletions
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