[Libreoffice-commits] core.git: basctl/Library_basctl.mk basctl/source

Andreas Heinisch (via logerrit) logerrit at kemper.freedesktop.org
Tue May 25 20:20:53 UTC 2021


 basctl/Library_basctl.mk           |    7 ++++++-
 basctl/source/basicide/baside2.cxx |   22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

New commits:
commit 178adcd8459af63ddb48927207baa5b4efbfda12
Author:     Andreas Heinisch <andreas.heinisch at yahoo.de>
AuthorDate: Sat May 22 21:10:49 2021 +0200
Commit:     Andreas Heinisch <andreas.heinisch at yahoo.de>
CommitDate: Tue May 25 22:20:10 2021 +0200

    tdf#139196 - Import/export macros using utf-8 including BOM
    
    In addition, try to detect the charset during the import of a *.bas
    file.
    
    Change-Id: I0dfe7f1b5349db409d90ed92b2e19c9946ae50cc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116004
    Tested-by: Jenkins
    Reviewed-by: Andreas Heinisch <andreas.heinisch at yahoo.de>

diff --git a/basctl/Library_basctl.mk b/basctl/Library_basctl.mk
index f874dfe9cc54..d38a776312e9 100644
--- a/basctl/Library_basctl.mk
+++ b/basctl/Library_basctl.mk
@@ -29,7 +29,12 @@ $(eval $(call gb_Library_set_include,basctl,\
 	-I$(WORKDIR)/SdiTarget/basctl/sdi \
 ))
 
-$(eval $(call gb_Library_use_external,basctl,boost_headers))
+$(eval $(call gb_Library_use_externals,basctl,\
+	boost_headers \
+	icui18n \
+	icuuc \
+	icu_headers \
+))
 
 $(eval $(call gb_Library_use_custom_headers,basctl,\
 	officecfg/registry \
diff --git a/basctl/source/basicide/baside2.cxx b/basctl/source/basicide/baside2.cxx
index bebbe643874c..1b5cfce918bf 100644
--- a/basctl/source/basicide/baside2.cxx
+++ b/basctl/source/basicide/baside2.cxx
@@ -42,6 +42,7 @@
 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
 #include <comphelper/SetFlagContextHelper.hxx>
 #include <comphelper/string.hxx>
+#include <unicode/ucsdet.h>
 #include <svl/srchdefs.hxx>
 #include <sfx2/bindings.hxx>
 #include <sfx2/docfile.hxx>
@@ -436,6 +437,24 @@ void ModulWindow::LoadBasic()
         // nLines*4: ReadText/Formatting/Highlighting/Formatting
         GetEditorWindow().CreateProgress( IDEResId(RID_STR_GENERATESOURCE), nLines*4 );
         GetEditEngine()->SetUpdateMode( false );
+        // tdf#139196 - import macros using either default or utf-8 text encoding
+        constexpr size_t buffsize = 1024 * 1024;
+        sal_Int8 bytes[buffsize] = { 0 };
+        sal_Int32 nRead = pStream->ReadBytes(bytes, buffsize);
+        UErrorCode uerr = U_ZERO_ERROR;
+        UCharsetDetector* ucd = ucsdet_open(&uerr);
+        ucsdet_setText(ucd, reinterpret_cast<const char*>(bytes), nRead, &uerr);
+        if (const UCharsetMatch* match = ucsdet_detect(ucd, &uerr))
+        {
+            const char* pEncodingName = ucsdet_getName(match, &uerr);
+
+            if (U_SUCCESS(uerr) && !strcmp("UTF-8", pEncodingName))
+            {
+                pStream->SetStreamCharSet(RTL_TEXTENCODING_UTF8);
+            }
+        }
+        ucsdet_close(ucd);
+        pStream->Seek(0);
         GetEditView()->Read( *pStream );
         GetEditEngine()->SetUpdateMode( true );
         GetEditorWindow().PaintImmediately();
@@ -483,6 +502,9 @@ void ModulWindow::SaveBasicSource()
     {
         EnterWait();
         AssertValidEditEngine();
+        // tdf#139196 - export macros using utf-8 including BOM
+        pStream->SetStreamCharSet(RTL_TEXTENCODING_UTF8);
+        pStream->WriteUChar(0xEF).WriteUChar(0xBB).WriteUChar(0xBF);
         GetEditEngine()->Write( *pStream );
         aMedium.Commit();
         LeaveWait();


More information about the Libreoffice-commits mailing list