summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--binaryurp/source/incomingrequest.cxx7
-rw-r--r--binaryurp/source/proxy.cxx6
-rw-r--r--bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx19
-rw-r--r--bridges/source/cpp_uno/gcc3_macosx_x86-64/uno2cpp.cxx18
-rw-r--r--desktop/source/app/app.cxx3
-rw-r--r--helpcompiler/source/HelpIndexer.cxx3
-rw-r--r--include/o3tl/runtimetooustring.hxx48
-rw-r--r--ucb/source/ucp/cmis/cmis_content.cxx15
-rw-r--r--vcl/unx/gtk3/gtk3gtkframe.cxx3
9 files changed, 74 insertions, 48 deletions
diff --git a/binaryurp/source/incomingrequest.cxx b/binaryurp/source/incomingrequest.cxx
index cf66f9c7286d..a1c4ef39090f 100644
--- a/binaryurp/source/incomingrequest.cxx
+++ b/binaryurp/source/incomingrequest.cxx
@@ -25,6 +25,7 @@
#include "com/sun/star/bridge/XInstanceProvider.hpp"
#include "cppuhelper/exc_hlp.hxx"
+#include "o3tl/runtimetooustring.hxx"
#include "rtl/byteseq.hxx"
#include "rtl/ref.hxx"
#include "rtl/ustring.hxx"
@@ -77,10 +78,8 @@ void IncomingRequest::execute() const {
isExc = !execute_throw(&ret, &outArgs);
} catch (const std::exception & e) {
throw css::uno::RuntimeException(
- "caught C++ exception: " +
- OStringToOUString(
- OString(e.what()), RTL_TEXTENCODING_ASCII_US));
- // best-effort string conversion
+ "caught C++ exception: "
+ + o3tl::runtimeToOUString(e.what()));
}
} catch (const css::uno::RuntimeException &) {
css::uno::Any exc(cppu::getCaughtException());
diff --git a/binaryurp/source/proxy.cxx b/binaryurp/source/proxy.cxx
index 5f23b4647208..1834968fa50b 100644
--- a/binaryurp/source/proxy.cxx
+++ b/binaryurp/source/proxy.cxx
@@ -24,6 +24,7 @@
#include <vector>
#include "cppuhelper/exc_hlp.hxx"
+#include "o3tl/runtimetooustring.hxx"
#include "rtl/ref.hxx"
#include "rtl/ustring.hxx"
#include "sal/types.h"
@@ -100,10 +101,7 @@ void Proxy::do_dispatch(
do_dispatch_throw(member, returnValue, arguments, exception);
} catch (const std::exception & e) {
throw css::uno::RuntimeException(
- "caught C++ exception: " +
- OStringToOUString(
- OString(e.what()), RTL_TEXTENCODING_ASCII_US));
- // best-effort string conversion
+ "caught C++ exception: " + o3tl::runtimeToOUString(e.what()));
}
} catch (const css::uno::RuntimeException &) {
css::uno::Any exc(cppu::getCaughtException());
diff --git a/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx b/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx
index 71e76a9f3b09..fb7bf08a81b3 100644
--- a/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx
+++ b/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx
@@ -23,10 +23,10 @@
#include <typeinfo>
#include "rtl/alloc.h"
-#include "rtl/ustrbuf.hxx"
#include <com/sun/star/uno/genfunc.hxx>
#include "com/sun/star/uno/RuntimeException.hpp"
+#include <o3tl/runtimetooustring.hxx>
#include <uno/data.h>
#include <bridge.hxx>
@@ -95,14 +95,6 @@ void INSERT_INT8(
*pDS++ = *static_cast<sal_uInt8 const *>( pSV );
}
-void appendCString(OUStringBuffer & buffer, char const * text) {
- if (text != nullptr) {
- buffer.append(
- OStringToOUString(OString(text), RTL_TEXTENCODING_ISO_8859_1));
- // use 8859-1 to avoid conversion failure
- }
-}
-
}
static void cpp_call(
@@ -246,12 +238,9 @@ static void cpp_call(
} catch (const Exception &) {
throw;
} catch (const std::exception & e) {
- OUStringBuffer buf;
- buf.append("C++ code threw ");
- appendCString(buf, typeid(e).name());
- buf.append(": ");
- appendCString(buf, e.what());
- throw RuntimeException(buf.makeStringAndClear());
+ throw RuntimeException(
+ "C++ code threw " + o3tl::runtimeToOUString(typeid(e).name())
+ + ": " + o3tl::runtimeToOUString(e.what()));
} catch (...) {
throw RuntimeException("C++ code threw unknown exception");
}
diff --git a/bridges/source/cpp_uno/gcc3_macosx_x86-64/uno2cpp.cxx b/bridges/source/cpp_uno/gcc3_macosx_x86-64/uno2cpp.cxx
index f606f7275990..9770dba7d4ba 100644
--- a/bridges/source/cpp_uno/gcc3_macosx_x86-64/uno2cpp.cxx
+++ b/bridges/source/cpp_uno/gcc3_macosx_x86-64/uno2cpp.cxx
@@ -23,10 +23,10 @@
#include <typeinfo>
#include "rtl/alloc.h"
-#include "rtl/ustrbuf.hxx"
#include <com/sun/star/uno/genfunc.hxx>
#include "com/sun/star/uno/RuntimeException.hpp"
+#include <o3tl/runtimetooustring.hxx>
#include <uno/data.h>
#include <bridge.hxx>
@@ -95,14 +95,6 @@ void INSERT_INT8(
*pDS++ = *static_cast<sal_uInt8 const *>( pSV );
}
-void appendCString(OUStringBuffer & buffer, char const * text) {
- if (text != nullptr) {
- buffer.append(
- OStringToOUString(OString(text), RTL_TEXTENCODING_ISO_8859_1));
- // use 8859-1 to avoid conversion failure
- }
-}
-
}
static void cpp_call(
@@ -246,13 +238,9 @@ static void cpp_call(
} catch (const Exception &) {
throw;
} catch (const std::exception & e) {
- OUStringBuffer buf;
- buf.append("C++ code threw ");
- appendCString(buf, typeid(e).name());
- buf.append(": ");
- appendCString(buf, e.what());
throw RuntimeException(
- buf.makeStringAndClear());
+ "C++ code threw " + o3tl::runtimeToOUString(typeid(e).name())
+ + ": " + o3tl::runtimeToOUString(e.what()));
} catch (...) {
throw RuntimeException("C++ code threw unknown exception");
}
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 7abfdda84c89..501ebe1497ce 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -37,6 +37,7 @@
#include "desktopcontext.hxx"
#include "migration.hxx"
+#include <o3tl/runtimetooustring.hxx>
#include <svl/languageoptions.hxx>
#include <svtools/javacontext.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
@@ -1696,7 +1697,7 @@ int Desktop::Main()
catch( const std::exception& exSTD)
{
RequestHandler::SetDowning();
- FatalError( OUString::createFromAscii( exSTD.what()));
+ FatalError(o3tl::runtimeToOUString(exSTD.what()));
}
catch( ...)
{
diff --git a/helpcompiler/source/HelpIndexer.cxx b/helpcompiler/source/HelpIndexer.cxx
index e6a26fce3d28..0c10da99d0c5 100644
--- a/helpcompiler/source/HelpIndexer.cxx
+++ b/helpcompiler/source/HelpIndexer.cxx
@@ -12,6 +12,7 @@
#include <rtl/string.hxx>
#include <rtl/uri.hxx>
#include <rtl/ustrbuf.hxx>
+#include <o3tl/runtimetooustring.hxx>
#include <osl/file.hxx>
#include <osl/thread.h>
#include <algorithm>
@@ -72,7 +73,7 @@ bool HelpIndexer::indexDocuments()
}
catch (CLuceneError &e)
{
- d_error = OUString::createFromAscii(e.what());
+ d_error = o3tl::runtimeToOUString(e.what());
return false;
}
diff --git a/include/o3tl/runtimetooustring.hxx b/include/o3tl/runtimetooustring.hxx
new file mode 100644
index 000000000000..7f2015805722
--- /dev/null
+++ b/include/o3tl/runtimetooustring.hxx
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_O3TL_RUNTIMETOOUSTRING_HXX
+#define INCLUDED_O3TL_RUNTIMETOOUSTRING_HXX
+
+#include <sal/config.h>
+
+#include <cassert>
+#include <cstring>
+
+#include <rtl/textcvt.h>
+#include <rtl/textenc.h>
+#include <rtl/ustring.h>
+#include <rtl/ustring.hxx>
+
+namespace o3tl {
+
+/** Convert an NTBS from the C++ runtime to an OUString.
+
+ This is used to convert an NTBS as provided by std::exception::what or
+ std::type_info::name into an OUString in a "lossless" way. The conversion
+ is done using RTL_TEXTENCODING_ISO_8859_1, so each char in the input maps
+ to one Unicode character in the output.
+*/
+inline OUString runtimeToOUString(char const * runtimeString) {
+ OUString s;
+ bool ok = rtl_convertStringToUString(
+ &s.pData, runtimeString, std::strlen(runtimeString),
+ RTL_TEXTENCODING_ISO_8859_1,
+ (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
+ | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
+ | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR));
+ assert(ok); (void) ok;
+ return s;
+}
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx
index c3fca0792a7d..c5fa4a555c82 100644
--- a/ucb/source/ucp/cmis/cmis_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_content.cxx
@@ -43,6 +43,7 @@
#include <comphelper/processfactory.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <config_oauth2.h>
+#include <o3tl/runtimetooustring.hxx>
#include <ucbhelper/cancelcommandexecution.hxx>
#include <ucbhelper/content.hxx>
#include <ucbhelper/contentidentifier.hxx>
@@ -1133,7 +1134,7 @@ namespace cmis
ucb::IOErrorCode_GENERAL,
uno::Sequence< uno::Any >( 0 ),
xEnv,
- OUString::createFromAscii( e.what() ) );
+ o3tl::runtimeToOUString(e.what()));
}
return aRet;
}
@@ -1199,7 +1200,7 @@ namespace cmis
ucb::IOErrorCode_GENERAL,
uno::Sequence< uno::Any >( 0 ),
xEnv,
- OUString::createFromAscii( e.what() ) );
+ o3tl::runtimeToOUString(e.what()));
}
return aRet;
}
@@ -1240,7 +1241,7 @@ namespace cmis
ucb::IOErrorCode_GENERAL,
uno::Sequence< uno::Any >( 0 ),
xEnv,
- OUString::createFromAscii( e.what() ) );
+ o3tl::runtimeToOUString(e.what()));
}
return uno::Sequence< document::CmisVersion > ( );
}
@@ -1449,7 +1450,7 @@ namespace cmis
ucb::IOErrorCode_GENERAL,
uno::Sequence< uno::Any >( 0 ),
xEnv,
- OUString::createFromAscii( e.what() ) );
+ o3tl::runtimeToOUString(e.what()));
}
sal_Int32 nCount = rValues.getLength();
@@ -1517,7 +1518,7 @@ namespace cmis
ucb::IOErrorCode_GENERAL,
uno::Sequence< uno::Any >( 0 ),
xEnv,
- OUString::createFromAscii( e.what() ) );
+ o3tl::runtimeToOUString(e.what()));
}
return aRet;
@@ -1564,7 +1565,7 @@ namespace cmis
ucb::IOErrorCode_GENERAL,
uno::Sequence< uno::Any >( 0 ),
xEnv,
- OUString::createFromAscii( e.what() ) );
+ o3tl::runtimeToOUString(e.what()));
}
return true;
@@ -1843,7 +1844,7 @@ namespace cmis
ucb::IOErrorCode_GENERAL,
uno::Sequence< uno::Any >( 0 ),
xEnv,
- OUString::createFromAscii( e.what() ) );
+ o3tl::runtimeToOUString(e.what()));
}
}
else if ( aCommand.Name == "checkout" )
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
index c1f70ad3dcc2..e3a628642a58 100644
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
@@ -30,6 +30,7 @@
#include <unx/genprn.h>
#include <unx/geninst.h>
#include <headless/svpgdi.hxx>
+#include <o3tl/runtimetooustring.hxx>
#include <osl/file.hxx>
#include <rtl/bootstrap.hxx>
#include <rtl/process.h>
@@ -4274,7 +4275,7 @@ long GtkSalFrame::CallCallbackExc(SalEvent nEvent, const void* pEvent) const
css::uno::Any(
css::uno::RuntimeException(
"wrapped std::exception "
- + OUString::createFromAscii(e.what()))));
+ + o3tl::runtimeToOUString(e.what()))));
}
catch (...)
{