include/sfx2/objsh.hxx | 6 ++-- sfx2/source/doc/objstor.cxx | 63 +++++++++++++++++--------------------------- 2 files changed, 28 insertions(+), 41 deletions(-)
New commits: commit f5b511b8470299caa99bf34ffac0fe272dfe9ec9 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sat Apr 20 15:06:39 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Apr 22 13:26:28 2024 +0200 loplugin:constantparam Change-Id: I0e91da1e48326495f841b53f999a0d31ecd1a36e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166419 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 38a9aa1424cf..e0b0d3f411a3 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -446,7 +446,7 @@ public: bool SetModifyPasswordInfo( const css::uno::Sequence< css::beans::PropertyValue >& aInfo ); static void DetectCharSet(SvStream& stream, rtl_TextEncoding& eCharSet, SvStreamEndian& endian); - static void DetectCsvSeparators(SvStream& stream, rtl_TextEncoding& eCharSet, OUString& separators, sal_Unicode cStringDelimiter, bool bForceCommonSeps = true, bool bAllowMultipleSeps = false); + static void DetectCsvSeparators(SvStream& stream, rtl_TextEncoding& eCharSet, OUString& separators, sal_Unicode cStringDelimiter); static void DetectCsvFilterOptions(SvStream& stream, OUString& aFilterOptions); static void DetectFilterOptions(SfxMedium* pMedium); static ErrCode HandleFilter( SfxMedium* pMedium, SfxObjectShell const * pDoc ); diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index b73802ca32b7..720e939e3885 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -948,7 +948,7 @@ void SfxObjectShell::DetectCharSet(SvStream& stream, rtl_TextEncoding& eCharSet, ucsdet_close(ucd); } -void SfxObjectShell::DetectCsvSeparators(SvStream& stream, rtl_TextEncoding& eCharSet, OUString& separators, sal_Unicode cStringDelimiter, bool bForceCommonSeps, bool bAllowMultipleSeps) +void SfxObjectShell::DetectCsvSeparators(SvStream& stream, rtl_TextEncoding& eCharSet, OUString& separators, sal_Unicode cStringDelimiter) { OUString sLine; std::vector<std::unordered_map<sal_Unicode, sal_uInt32>> aLinesCharsCount; @@ -968,9 +968,8 @@ void SfxObjectShell::DetectCsvSeparators(SvStream& stream, rtl_TextEncoding& eCh if (!cStringDelimiter) cStringDelimiter = '\"'; - if (bForceCommonSeps) - for (sal_Int32 nComSepIdx = sCommonSeps.getLength() - 1; nComSepIdx >= 0; nComSepIdx --) - usetCommonSeps.insert(sCommonSeps[nComSepIdx]); + for (sal_Int32 nComSepIdx = sCommonSeps.getLength() - 1; nComSepIdx >= 0; nComSepIdx --) + usetCommonSeps.insert(sCommonSeps[nComSepIdx]); aLinesCharsCount.reserve(nMaxLinesToProcess); separators = ""; @@ -1008,7 +1007,7 @@ void SfxObjectShell::DetectCsvSeparators(SvStream& stream, rtl_TextEncoding& eCh continue; // If restricted only to common separators then skip the rest - if (bForceCommonSeps && usetCommonSeps.find(*p) == usetCommonSeps.end()) + if (usetCommonSeps.find(*p) == usetCommonSeps.end()) continue; auto it_elem = aCharsCount.find(*p); @@ -1067,34 +1066,22 @@ void SfxObjectShell::DetectCsvSeparators(SvStream& stream, rtl_TextEncoding& eCh sInitSeps += OUStringChar(it->first); // If forced to most common or there are multiple separators then pick up only the most common by importance. - if (bForceCommonSeps || sInitSeps.getLength() > 1) + sal_Int32 nInitSepIdx; + sal_Int32 nComSepIdx; + for (nComSepIdx = 0; nComSepIdx < sCommonSeps.getLength(); nComSepIdx++) { - sal_Int32 nInitSepIdx; - sal_Int32 nComSepIdx; - for (nComSepIdx = 0; nComSepIdx < sCommonSeps.getLength(); nComSepIdx++) + sal_Unicode c = sCommonSeps[nComSepIdx]; + for (nInitSepIdx = sInitSeps.getLength() - 1; nInitSepIdx >= 0; nInitSepIdx --) { - sal_Unicode c = sCommonSeps[nComSepIdx]; - for (nInitSepIdx = sInitSeps.getLength() - 1; nInitSepIdx >= 0; nInitSepIdx --) + if (c == sInitSeps[nInitSepIdx]) { - if (c == sInitSeps[nInitSepIdx]) - { - separators += OUStringChar(c); - break; - } - } - - if (!bAllowMultipleSeps && nInitSepIdx >= 0) + separators += OUStringChar(c); break; + } } - } - // If there are no most common separators then keep the initial list. - if (!bForceCommonSeps && !separators.getLength()) - { - if (bAllowMultipleSeps) - separators = sInitSeps; - else - separators = OUStringChar(sInitSeps[0]); + if (nInitSepIdx >= 0) + break; } stream.Seek(nInitPos); commit 257954b740e7eecfc74a8d9833f131747b7ee974 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sat Apr 20 15:01:16 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Apr 22 13:26:21 2024 +0200 loplugin:constantparam Change-Id: I8ae27f060e46548aa364db8c6b82d77e6c8f3d3f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166418 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index e26c242aaaad..38a9aa1424cf 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -447,8 +447,8 @@ public: static void DetectCharSet(SvStream& stream, rtl_TextEncoding& eCharSet, SvStreamEndian& endian); static void DetectCsvSeparators(SvStream& stream, rtl_TextEncoding& eCharSet, OUString& separators, sal_Unicode cStringDelimiter, bool bForceCommonSeps = true, bool bAllowMultipleSeps = false); - static void DetectCsvFilterOptions(SvStream& stream, OUString& aFilterOptions, bool bForceDetect = false); - static void DetectFilterOptions(SfxMedium* pMedium, bool bForceDetect = false); + static void DetectCsvFilterOptions(SvStream& stream, OUString& aFilterOptions); + static void DetectFilterOptions(SfxMedium* pMedium); static ErrCode HandleFilter( SfxMedium* pMedium, SfxObjectShell const * pDoc ); virtual bool PrepareClose(bool bUI = true); diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index ccfc41f8cd93..b73802ca32b7 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -1100,7 +1100,7 @@ void SfxObjectShell::DetectCsvSeparators(SvStream& stream, rtl_TextEncoding& eCh stream.Seek(nInitPos); } -void SfxObjectShell::DetectCsvFilterOptions(SvStream& stream, OUString& aFilterOptions, bool bForceDetect) +void SfxObjectShell::DetectCsvFilterOptions(SvStream& stream, OUString& aFilterOptions) { rtl_TextEncoding eCharSet = RTL_TEXTENCODING_DONTKNOW; std::u16string_view aSeps; @@ -1110,7 +1110,7 @@ void SfxObjectShell::DetectCsvFilterOptions(SvStream& stream, OUString& aFilterO OUString aOrigFilterOpts = aFilterOptions; bool bDelimiter = false, bCharSet = false, bRest = false; // This indicates the presence of the token even if empty ;) - if (aFilterOptions.isEmpty() && !bForceDetect) + if (aFilterOptions.isEmpty()) return; const std::u16string_view aDetect = u"DETECT"; sal_Int32 nPos = 0; @@ -1128,7 +1128,7 @@ void SfxObjectShell::DetectCsvFilterOptions(SvStream& stream, OUString& aFilterO aRest = std::basic_string_view<sal_Unicode>(aOrigFilterOpts.getStr() + nPos, aOrigFilterOpts.getLength() - nPos); // Detect charset - if (bForceDetect || aCharSet == aDetect) + if (aCharSet == aDetect) { SvStreamEndian endian; DetectCharSet(stream, eCharSet, endian); @@ -1141,7 +1141,7 @@ void SfxObjectShell::DetectCsvFilterOptions(SvStream& stream, OUString& aFilterO //Detect separators aFilterOptions = ""; - if (bForceDetect || aSeps == aDetect) + if (aSeps == aDetect) { OUString separators; DetectCsvSeparators(stream, eCharSet, separators, static_cast<sal_Unicode>(o3tl::toInt32(aDelimiter))); @@ -1159,22 +1159,22 @@ void SfxObjectShell::DetectCsvFilterOptions(SvStream& stream, OUString& aFilterO aFilterOptions = aSeps; OUStringChar cComma = u','; - if (bDelimiter || bForceDetect) + if (bDelimiter) aFilterOptions += cComma + aDelimiter; - if (bCharSet || bForceDetect) - aFilterOptions += cComma + (aCharSet == aDetect || bForceDetect ? OUString::number(eCharSet) : aCharSet); + if (bCharSet) + aFilterOptions += cComma + (aCharSet == aDetect ? OUString::number(eCharSet) : aCharSet); if (bRest) aFilterOptions += cComma + aRest; } -void SfxObjectShell::DetectFilterOptions(SfxMedium* pMedium, bool bForceDetect) +void SfxObjectShell::DetectFilterOptions(SfxMedium* pMedium) { std::shared_ptr<const SfxFilter> pFilter = pMedium->GetFilter(); SfxItemSet& rSet = pMedium->GetItemSet(); const SfxStringItem* pOptions = rSet.GetItem(SID_FILE_FILTEROPTIONS, false); - // Skip if filter options are missing and the detection is not enforced - if (!bForceDetect && (!pFilter || !pOptions)) + // Skip if filter options are missing + if (!pFilter || !pOptions) return; if (pFilter->GetName() == "Text - txt - csv (StarCalc)") @@ -1187,7 +1187,7 @@ void SfxObjectShell::DetectFilterOptions(SfxMedium* pMedium, bool bForceDetect) return; OUString aFilterOptions = pOptions->GetValue(); - DetectCsvFilterOptions(*pInStream, aFilterOptions, bForceDetect); + DetectCsvFilterOptions(*pInStream, aFilterOptions); rSet.Put(SfxStringItem(SID_FILE_FILTEROPTIONS, aFilterOptions)); } }