sc/source/ui/docshell/impex.cxx | 22 ++++++++++++++++------ sw/source/core/fields/ddefld.cxx | 10 +++++++--- 2 files changed, 23 insertions(+), 9 deletions(-)
New commits: commit 94df17f58fe6269452b7252b712a89978c444bec Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Oct 8 22:10:44 2022 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Oct 9 00:16:51 2022 +0200 tdf#151429: don't convert OUStrings to system encoding ... just to convert back to OUString in the end. Change-Id: I727d5e4c03d1a49f64bd5ca3d64157a9149cd9ef Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141125 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 2a7ed9da5d06..5ef0cca91c28 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -288,14 +288,24 @@ bool ScImportExport::ExportData( const OUString& rMimeType, css::uno::Any & rValue ) { SvMemoryStream aStrm; + SotClipboardFormatId fmtId = SotExchange::GetFormatIdFromMimeType(rMimeType); + if (fmtId == SotClipboardFormatId::STRING) + aStrm.SetStreamCharSet(RTL_TEXTENCODING_UNICODE); // mba: no BaseURL for data exchange - if( ExportStream( aStrm, OUString(), - SotExchange::GetFormatIdFromMimeType( rMimeType ) )) + if (ExportStream(aStrm, OUString(), fmtId)) { - aStrm.WriteUChar( 0 ); - rValue <<= css::uno::Sequence< sal_Int8 >( - static_cast<sal_Int8 const *>(aStrm.GetData()), - aStrm.TellEnd() ); + if (fmtId == SotClipboardFormatId::STRING) + { + assert(aStrm.TellEnd() % sizeof(sal_Unicode) == 0); + rValue <<= OUString(static_cast<const sal_Unicode*>(aStrm.GetData()), + aStrm.TellEnd() / sizeof(sal_Unicode)); + } + else + { + aStrm.WriteUChar(0); + rValue <<= css::uno::Sequence<sal_Int8>(static_cast<sal_Int8 const*>(aStrm.GetData()), + aStrm.TellEnd()); + } return true; } return false; diff --git a/sw/source/core/fields/ddefld.cxx b/sw/source/core/fields/ddefld.cxx index 19efa6a207ea..55b7d4566609 100644 --- a/sw/source/core/fields/ddefld.cxx +++ b/sw/source/core/fields/ddefld.cxx @@ -70,9 +70,13 @@ public: case SotClipboardFormatId::STRING: if( !IsNoDataFlag() ) { - uno::Sequence< sal_Int8 > aSeq; - rValue >>= aSeq; - OUString sStr( reinterpret_cast<char const *>(aSeq.getConstArray()), aSeq.getLength(), osl_getThreadTextEncoding() ); + OUString sStr; + if (!(rValue >>= sStr)) + { + uno::Sequence< sal_Int8 > aSeq; + rValue >>= aSeq; + sStr = OUString(reinterpret_cast<char const*>(aSeq.getConstArray()), aSeq.getLength(), osl_getThreadTextEncoding()); + } // remove not needed CR-LF at the end sal_Int32 n = sStr.getLength();