summaryrefslogtreecommitdiffstats
path: root/basctl
diff options
context:
space:
mode:
Diffstat (limited to 'basctl')
-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();