summaryrefslogtreecommitdiff
path: root/i18npool/source
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2024-06-26 17:53:21 +0200
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2024-07-08 16:24:04 +0200
commit80ad887134d0a253aaf60f66fcd980e2b3c92743 (patch)
tree0d85b0379b6bb2da6abb6b927a15d16f94649be2 /i18npool/source
parent281749bd9684dd979cb57064ad3fc9dd4d464bce (diff)
tdf#138258 i18npool: allow ASCII double quote to match typographic quote
Similar to the straight (typewriter or ASCII) apostrophe, straight double quotation mark (") matches its typographic variants now, like other word processors do. Note: regex search doesn't use this matching, similar to the apostrophe search. Follow-up to commit d40f2d02df26e216f367b5da3f9546b73f250469 "tdf#117643 Writer: fix apostrophe search regression". Change-Id: If6a3ee00750828583cd0cfc4aa7f7b656ea9bd1e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169605 Reviewed-by: László Németh <nemeth@numbertext.org> Tested-by: Jenkins (cherry picked from commit 3a02490e1a04c32e18ce5bad5f3c3cb70501a7a4) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169590 Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'i18npool/source')
-rw-r--r--i18npool/source/search/textsearch.cxx40
1 files changed, 32 insertions, 8 deletions
diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index 816e162c1e6e..dbb49f494781 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -93,6 +93,30 @@ bool isSimpleRegexTrans( TransliterationFlags n )
{
return bool(maskSimpleRegexTrans(n));
}
+
+bool isReplacePunctuation( OUString &rStr )
+{
+ return rStr.indexOf(u'\u2018') > -1 ||
+ rStr.indexOf(u'\u2019') > -1 ||
+ rStr.indexOf(u'\u201A') > -1 ||
+ rStr.indexOf(u'\u201B') > -1 ||
+ rStr.indexOf(u'\u201C') > -1 ||
+ rStr.indexOf(u'\u201D') > -1 ||
+ rStr.indexOf(u'\u201E') > -1 ||
+ rStr.indexOf(u'\u201F') > -1;
+}
+
+OUString replacePunctuation( OUString &rStr )
+{
+ return rStr.replace(u'\u2018', '\'')
+ .replace(u'\u2019', '\'')
+ .replace(u'\u201A', '\'')
+ .replace(u'\u201B', '\'')
+ .replace(u'\u201C', '"')
+ .replace(u'\u201D', '"')
+ .replace(u'\u201E', '"')
+ .replace(u'\u201F', '"');
+}
};
TextSearch::TextSearch(const Reference < XComponentContext > & rxContext)
@@ -139,10 +163,10 @@ void TextSearch::setOptions2( const SearchOptions2& rOptions )
// match is not case-altered, leave case-(in)sensitive to regex engine.
transliterateFlags &= ~TransliterationFlags::IGNORE_CASE;
}
- else if ( aSrchPara.searchString.indexOf('\'') > - 1 )
+ else if ( aSrchPara.searchString.indexOf('\'') > - 1 || aSrchPara.searchString.indexOf('"') > - 1 )
{
bSearchApostrophe = true;
- bReplaceApostrophe = aSrchPara.searchString.indexOf(u'\u2019') > -1;
+ bReplaceApostrophe = isReplacePunctuation(aSrchPara.searchString);
}
// Create Transliteration class
@@ -215,7 +239,7 @@ void TextSearch::setOptions2( const SearchOptions2& rOptions )
}
if ( bReplaceApostrophe )
- sSrchStr = sSrchStr.replace(u'\u2019', '\'');
+ sSrchStr = replacePunctuation(sSrchStr);
// Take the new SearchOptions2::AlgorithmType2 field and ignore
// SearchOptions::algorithmType
@@ -308,7 +332,7 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta
// in non-regex mode, allow searching typographical apostrophe with the ASCII one
// to avoid regression after using automatic conversion to U+2019 during typing in Writer
- bool bReplaceApostrophe = bSearchApostrophe && in_str.indexOf(u'\u2019') > -1;
+ bool bReplaceApostrophe = bSearchApostrophe && isReplacePunctuation(in_str);
bUsePrimarySrchStr = true;
@@ -340,7 +364,7 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta
in_str = xTranslit->transliterate(searchStr, nInStartPos, nInEndPos - nInStartPos, offset);
if ( bReplaceApostrophe )
- in_str = in_str.replace(u'\u2019', '\'');
+ in_str = replacePunctuation(in_str);
// JP 20.6.2001: also the start and end positions must be corrected!
sal_Int32 newStartPos =
@@ -447,7 +471,7 @@ SearchResult TextSearch::searchBackward( const OUString& searchStr, sal_Int32 st
// in non-regex mode, allow searching typographical apostrophe with the ASCII one
// to avoid regression after using automatic conversion to U+2019 during typing in Writer
- bool bReplaceApostrophe = bSearchApostrophe && in_str.indexOf(u'\u2019') > -1;
+ bool bReplaceApostrophe = bSearchApostrophe && isReplacePunctuation(in_str);
bUsePrimarySrchStr = true;
@@ -458,7 +482,7 @@ SearchResult TextSearch::searchBackward( const OUString& searchStr, sal_Int32 st
in_str = xTranslit->transliterate( searchStr, endPos, startPos - endPos, offset );
if ( bReplaceApostrophe )
- in_str = in_str.replace(u'\u2019', '\'');
+ in_str = replacePunctuation(in_str);
// JP 20.6.2001: also the start and end positions must be corrected!
sal_Int32 const newStartPos = (startPos < searchStr.getLength())
@@ -508,7 +532,7 @@ SearchResult TextSearch::searchBackward( const OUString& searchStr, sal_Int32 st
else
{
if ( bReplaceApostrophe )
- in_str = in_str.replace(u'\u2019', '\'');
+ in_str = replacePunctuation(in_str);
sres = (this->*fnBackward)( in_str, startPos, endPos );
}