sw/inc/iodetect.hxx           |    2 +-
 sw/source/ui/index/cnttab.cxx |   16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

New commits:
commit 7e6e0fd63eac57de0f76ab1efdb1283c22ad6e6c
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Fri Jan 21 21:01:41 2022 +0100
Commit:     Andreas Heinisch <andreas.heini...@yahoo.de>
CommitDate: Sun Jan 30 21:35:02 2022 +0100

    tdf#108910, tdf#125496 - read/write index entries using utf8
    
    Always write an index concordance file using the utf8 encoding and read
    the index entries using the appropriate character set which is either
    utf8 or the os thread encoding.
    
    Change-Id: I5b30f4749f635bd51d8f0933ce5029d5303aef3f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128745
    Tested-by: Jenkins
    Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de>

diff --git a/sw/inc/iodetect.hxx b/sw/inc/iodetect.hxx
index 1733bde20701..7deb65fcdd91 100644
--- a/sw/inc/iodetect.hxx
+++ b/sw/inc/iodetect.hxx
@@ -108,7 +108,7 @@ public:
     static bool IsValidStgFilter( const css::uno::Reference < 
css::embed::XStorage >& rStg, const SfxFilter& rFilter);
 
     // tdf#106899 - wrapper around IsDetectableText to retrieve the text 
encoding for a given stream
-    static rtl_TextEncoding GetTextEncoding(SvStream&);
+    SW_DLLPUBLIC static rtl_TextEncoding GetTextEncoding(SvStream&);
     static bool IsDetectableText( const char* pBuf, sal_uLong &rLen,
             rtl_TextEncoding *pCharSet, bool *pSwap, LineEnd *pLineEnd, bool 
*pBom);
 
diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx
index e2a334ebda26..1f7393fe3fa8 100644
--- a/sw/source/ui/index/cnttab.cxx
+++ b/sw/source/ui/index/cnttab.cxx
@@ -54,6 +54,7 @@
 #include <docsh.hxx>
 #include <swmodule.hxx>
 #include <modcfg.hxx>
+#include <iodetect.hxx>
 
 #include <cmdid.h>
 #include <cnttab.hrc>
@@ -3773,7 +3774,10 @@ void SwEntryBrowseBox::InitController(
 void SwEntryBrowseBox::ReadEntries(SvStream& rInStr)
 {
     AutoMarkEntry* pToInsert = nullptr;
-    rtl_TextEncoding  eTEnc = osl_getThreadTextEncoding();
+    // tdf#108910, tdf#125496 - read index entries using the appropriate 
character set
+    rtl_TextEncoding eTEnc = SwIoSystem::GetTextEncoding(rInStr);
+    if (eTEnc == RTL_TEXTENCODING_DONTKNOW)
+        eTEnc = osl_getThreadTextEncoding();
     while (rInStr.good())
     {
         OUString sLine;
@@ -3833,13 +3837,13 @@ void SwEntryBrowseBox::WriteEntries(SvStream& rOutStr)
     if (pController->IsValueChangedFromSaved())
         GoToColumnId(nCol + (nCol < ITEM_CASE ? 1 : -1 ));
 
-    rtl_TextEncoding  eTEnc = osl_getThreadTextEncoding();
     for(const std::unique_ptr<AutoMarkEntry> & rpEntry : m_Entries)
     {
         AutoMarkEntry* pEntry = rpEntry.get();
         if(!pEntry->sComment.isEmpty())
         {
-            rOutStr.WriteByteStringLine( OUStringConcatenation("#" + 
pEntry->sComment), eTEnc );
+            // tdf#108910, tdf#125496 - write index entries using the utf8 
text encoding
+            rOutStr.WriteByteStringLine( OUStringConcatenation("#" + 
pEntry->sComment), RTL_TEXTENCODING_UTF8 );
         }
 
         OUString sWrite( pEntry->sSearch + ";" +
@@ -3851,7 +3855,8 @@ void SwEntryBrowseBox::WriteEntries(SvStream& rOutStr)
                          (pEntry->bWord ? std::u16string_view(u"1") : 
std::u16string_view(u"0")) );
 
         if( sWrite.getLength() > 5 )
-            rOutStr.WriteByteStringLine( sWrite, eTEnc );
+            // tdf#108910, tdf#125496 - write index entries using the utf8 
text encoding
+            rOutStr.WriteByteStringLine( sWrite, RTL_TEXTENCODING_UTF8 );
     }
 }
 
@@ -3919,7 +3924,8 @@ IMPL_LINK_NOARG(SwAutoMarkDlg_Impl, OkHdl, weld::Button&, 
void)
                         bCreateMode ? StreamMode::WRITE
                                     : StreamMode::WRITE| StreamMode::TRUNC );
         SvStream* pStrm = aMed.GetOutStream();
-        pStrm->SetStreamCharSet( RTL_TEXTENCODING_MS_1253 );
+        // tdf#108910, tdf#125496 - write index entries using the utf8 text 
encoding
+        pStrm->SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
         if( !pStrm->GetError() )
         {
             m_xEntriesBB->WriteEntries( *pStrm );

Reply via email to