summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2021-05-26 12:21:04 +0200
committerAndreas Heinisch <andreas.heinisch@yahoo.de>2021-05-27 09:36:07 +0200
commit46e924ac80a4abd7f48bd2df34ea4c38738fd745 (patch)
treea2c3917e5b99551e373e9dcfc2b09521e0855728
parentosl::Module::loadRelative against symbol from executable is unreliable (diff)
downloadcore-46e924ac80a4abd7f48bd2df34ea4c38738fd745.tar.gz
core-46e924ac80a4abd7f48bd2df34ea4c38738fd745.zip
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@redhat.com> Tested-by: Jenkins
-rw-r--r--basctl/Library_basctl.mk7
-rw-r--r--basctl/source/basicide/baside2.cxx30
2 files changed, 13 insertions, 24 deletions
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();