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

Andreas Heinisch (via logerrit) logerrit at kemper.freedesktop.org
Thu May 27 07:36:42 UTC 2021


 basctl/Library_basctl.mk           |    7 +------
 basctl/source/basicide/baside2.cxx |   30 ++++++++++++------------------
 2 files changed, 13 insertions(+), 24 deletions(-)

New commits:
commit 46e924ac80a4abd7f48bd2df34ea4c38738fd745
Author:     Andreas Heinisch <andreas.heinisch at yahoo.de>
AuthorDate: Wed May 26 12:21:04 2021 +0200
Commit:     Andreas Heinisch <andreas.heinisch at yahoo.de>
CommitDate: Thu May 27 09:36:07 2021 +0200

    tdf#139196 - Import/export macros using utf-8 including BOM
    
    Moved import logic to a local function, and during the import of a *.bas
    file, check if it starts with BOM in order to detect the correct
    charset. If there is no BOM, use the default charset of the system, since
    after the change in 178adcd8459af63ddb48927207baa5b4efbfda12, all the
    newly created *.bas files have a BOM and are written using the utf-8
    charset.
    
    Change-Id: Iefdecb5762d896ce3e52fd6d212de42cf417ddac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116186
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
    Tested-by: Jenkins

diff --git a/basctl/Library_basctl.mk b/basctl/Library_basctl.mk
index d38a776312e9..f874dfe9cc54 100644
--- a/basctl/Library_basctl.mk
+++ b/basctl/Library_basctl.mk
@@ -29,12 +29,7 @@ $(eval $(call gb_Library_set_include,basctl,\
 	-I$(WORKDIR)/SdiTarget/basctl/sdi \
 ))
 
-$(eval $(call gb_Library_use_externals,basctl,\
-	boost_headers \
-	icui18n \
-	icuuc \
-	icu_headers \
-))
+$(eval $(call gb_Library_use_external,basctl,boost_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 1b5cfce918bf..ce654b998904 100644
--- a/basctl/source/basicide/baside2.cxx
+++ b/basctl/source/basicide/baside2.cxx
@@ -42,7 +42,6 @@
 #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>
@@ -190,6 +189,17 @@ void lcl_ConvertTabsToSpaces( OUString& rLine )
     rLine = aResult.makeStringAndClear();
 }
 
+void DetectUTF8BOMCharset(SvStream& pStream)
+{
+    sal_uInt8 pBuf[3];
+    sal_Int32 nRead = pStream.ReadBytes(pBuf, 3);
+    unsigned char const BOM[3] = { 0xEF, 0xBB, 0xBF };
+    if (nRead == 3 && memcmp(pBuf, BOM, 3) == 0)
+        pStream.SetStreamCharSet(RTL_TEXTENCODING_UTF8);
+    else
+        pStream.Seek(0);
+}
+
 } // namespace
 
 ModulWindow::ModulWindow (ModulWindowLayout* pParent, ScriptDocument const& rDocument,
@@ -438,23 +448,7 @@ void ModulWindow::LoadBasic()
         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);
+        DetectUTF8BOMCharset(*pStream);
         GetEditView()->Read( *pStream );
         GetEditEngine()->SetUpdateMode( true );
         GetEditorWindow().PaintImmediately();


More information about the Libreoffice-commits mailing list