diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2021-05-22 21:10:49 +0200 |
---|---|---|
committer | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2021-05-25 22:20:10 +0200 |
commit | 178adcd8459af63ddb48927207baa5b4efbfda12 (patch) | |
tree | 938cb7a6e2a3f694cb36ebf9fe692c995511871a /basctl | |
parent | 60d216ed1a5ad74a93edfb288206ce9ae20380a4 (diff) |
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@yahoo.de>
Diffstat (limited to 'basctl')
-rw-r--r-- | basctl/Library_basctl.mk | 7 | ||||
-rw-r--r-- | basctl/source/basicide/baside2.cxx | 22 |
2 files changed, 28 insertions, 1 deletions
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(); |