From 657f067b917169f41a8432c8f329877f6e50c3f6 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 20 Feb 2017 13:55:39 +0200 Subject: remove some unnecessary OUStringBuffer usage Change-Id: Iae9146a3be569107019d9c5af404b94e51e76cd5 Reviewed-on: https://gerrit.libreoffice.org/34469 Tested-by: Jenkins Reviewed-by: Noel Grandin --- pyuno/source/loader/pyuno_loader.cxx | 6 ++---- pyuno/source/module/pyuno.cxx | 6 +----- pyuno/source/module/pyuno_adapter.cxx | 10 ++-------- pyuno/source/module/pyuno_except.cxx | 14 ++++---------- pyuno/source/module/pyuno_module.cxx | 16 +++++----------- pyuno/source/module/pyuno_runtime.cxx | 18 +++++------------- pyuno/source/module/pyuno_type.cxx | 34 ++++++++++++---------------------- pyuno/source/module/pyuno_util.cxx | 5 +---- 8 files changed, 32 insertions(+), 77 deletions(-) (limited to 'pyuno') diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx index 01878630353d..adbf6c88e098 100644 --- a/pyuno/source/loader/pyuno_loader.cxx +++ b/pyuno/source/loader/pyuno_loader.cxx @@ -100,10 +100,8 @@ static PyRef getObjectFromLoaderModule( const char * func ) PyRef object( PyDict_GetItemString(getLoaderModule().get(), func ) ); if( !object.is() ) { - OUStringBuffer buf; - buf.append( "pythonloader: couldn't find core element pythonloader." ); - buf.appendAscii( func ); - throw RuntimeException(buf.makeStringAndClear()); + throw RuntimeException( "pythonloader: couldn't find core element pythonloader." + + OUString::createFromAscii( func )); } return object; } diff --git a/pyuno/source/module/pyuno.cxx b/pyuno/source/module/pyuno.cxx index 473df58e1972..0281f705a914 100644 --- a/pyuno/source/module/pyuno.cxx +++ b/pyuno/source/module/pyuno.cxx @@ -403,11 +403,7 @@ PyObject *PyUNO_invoke( PyObject *object, const char *name , PyObject *args ) OUString attrName = OUString::createFromAscii(name); if (! me->members->xInvocation->hasMethod (attrName)) { - OUStringBuffer buf; - buf.append( "Attribute " ); - buf.append( attrName ); - buf.append( " unknown" ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "Attribute " + attrName + " unknown" ); } callable = PyUNO_callable_new ( me->members->xInvocation, diff --git a/pyuno/source/module/pyuno_adapter.cxx b/pyuno/source/module/pyuno_adapter.cxx index 9d2140e33b36..3a3b5728dc17 100644 --- a/pyuno/source/module/pyuno_adapter.cxx +++ b/pyuno/source/module/pyuno_adapter.cxx @@ -355,10 +355,7 @@ void Adapter::setValue( const OUString & aPropertyName, const Any & value ) { if( !hasProperty( aPropertyName ) ) { - OUStringBuffer buf; - buf.append( "pyuno::Adapter: Property " ).append( aPropertyName ); - buf.append( " is unknown." ); - throw UnknownPropertyException( buf.makeStringAndClear() ); + throw UnknownPropertyException( "pyuno::Adapter: Property " + aPropertyName + " is unknown." ); } PyThreadAttach guard( mInterpreter ); @@ -401,10 +398,7 @@ Any Adapter::getValue( const OUString & aPropertyName ) if (!pyRef.is() || PyErr_Occurred()) { - OUStringBuffer buf; - buf.append( "pyuno::Adapter: Property " ).append( aPropertyName ); - buf.append( " is unknown." ); - throw UnknownPropertyException( buf.makeStringAndClear() ); + throw UnknownPropertyException( "pyuno::Adapter: Property " + aPropertyName + " is unknown." ); } ret = runtime.pyObject2Any( pyRef ); } diff --git a/pyuno/source/module/pyuno_except.cxx b/pyuno/source/module/pyuno_except.cxx index 643f3aaacd7c..074fd7d1cebd 100644 --- a/pyuno/source/module/pyuno_except.cxx +++ b/pyuno/source/module/pyuno_except.cxx @@ -82,10 +82,7 @@ static PyRef createClass( const OUString & name, const Runtime &runtime ) TypeDescription desc( name ); if( ! desc.is() ) { - OUStringBuffer buf; - buf.append( "pyuno.getClass: uno exception " ); - buf.append(name).append( " is unknown" ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "pyuno.getClass: uno exception " + name + " is unknown" ); } bool isStruct = desc.get()->eTypeClass == typelib_TypeClass_STRUCT; @@ -93,12 +90,9 @@ static PyRef createClass( const OUString & name, const Runtime &runtime ) bool isInterface = desc.get()->eTypeClass == typelib_TypeClass_INTERFACE; if( !isStruct && !isExc && ! isInterface ) { - OUStringBuffer buf; - buf.append( "pyuno.getClass: " ).append(name).append( "is a " ); - buf.appendAscii( - typeClassToString( (css::uno::TypeClass) desc.get()->eTypeClass)); - buf.append( ", expected EXCEPTION, STRUCT or INTERFACE" ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "pyuno.getClass: " + name + "is a " + + OUString::createFromAscii( typeClassToString( (css::uno::TypeClass) desc.get()->eTypeClass) ) + + ", expected EXCEPTION, STRUCT or INTERFACE" ); } // retrieve base class diff --git a/pyuno/source/module/pyuno_module.cxx b/pyuno/source/module/pyuno_module.cxx index 83888802d0ee..40ed69e0191b 100644 --- a/pyuno/source/module/pyuno_module.cxx +++ b/pyuno/source/module/pyuno_module.cxx @@ -416,13 +416,10 @@ static PyObject *createUnoStructHelper( fillStruct( me->members->xInvocation, pCompType, initializer, keywordArgs, state, runtime ); if( state.getCntConsumed() != PyTuple_Size(initializer) ) { - OUStringBuffer buf; - buf.append( "pyuno._createUnoStructHelper: too many "); - buf.append( "elements in the initializer list, expected " ); - buf.append( state.getCntConsumed() ); - buf.append( ", got " ); - buf.append( (sal_Int32) PyTuple_Size(initializer) ); - throw RuntimeException( buf.makeStringAndClear()); + throw RuntimeException( "pyuno._createUnoStructHelper: too many " + "elements in the initializer list, expected " + + OUString::number(state.getCntConsumed()) + ", got " + + OUString::number( PyTuple_Size(initializer) ) ); } ret = PyRef( PyTuple_Pack(2, returnCandidate.get(), state.getUsed()), SAL_NO_ACQUIRE); } @@ -518,10 +515,7 @@ static PyObject *getConstantByName( typeName) >>= td)) { - OUStringBuffer buf; - buf.append( "pyuno.getConstantByName: " ).append( typeName ); - buf.append( "is not a constant" ); - throw RuntimeException(buf.makeStringAndClear() ); + throw RuntimeException( "pyuno.getConstantByName: " + typeName + "is not a constant" ); } PyRef constant = runtime.any2PyObject( td->getConstantValue() ); ret = constant.getAcquired(); diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx index 755a6dc46a75..69e5a1732605 100644 --- a/pyuno/source/module/pyuno_runtime.cxx +++ b/pyuno/source/module/pyuno_runtime.cxx @@ -464,11 +464,8 @@ PyRef Runtime::any2PyObject (const Any &a ) const } } } - OUStringBuffer buf; - buf.append( "Any carries enum " ); - buf.append( a.getValueType().getTypeName()); - buf.append( " with invalid value " ).append( l ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "Any carries enum " + a.getValueType().getTypeName() + + " with invalid value " + OUString::number(l) ); } case typelib_TypeClass_EXCEPTION: case typelib_TypeClass_STRUCT: @@ -480,10 +477,8 @@ PyRef Runtime::any2PyObject (const Any &a ) const PyRef ret( PyObject_CallObject( excClass.get() , argsTuple.get() ), SAL_NO_ACQUIRE ); if( ! ret.is() ) { - OUStringBuffer buf; - buf.append( "Couldn't instantiate python representation of structured UNO type " ); - buf.append( a.getValueType().getTypeName() ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "Couldn't instantiate python representation of structured UNO type " + + a.getValueType().getTypeName() ); } if( auto e = o3tl::tryAccess(a) ) @@ -550,10 +545,7 @@ PyRef Runtime::any2PyObject (const Any &a ) const } default: { - OUStringBuffer buf; - buf.append( "Unknown UNO type class " ); - buf.append( (sal_Int32 ) a.getValueTypeClass() ); - throw RuntimeException(buf.makeStringAndClear( ) ); + throw RuntimeException( "Unknown UNO type class " + OUString::number(a.getValueTypeClass()) ); } } } diff --git a/pyuno/source/module/pyuno_type.cxx b/pyuno/source/module/pyuno_type.cxx index 2de1b90ef323..b09c78de1205 100644 --- a/pyuno/source/module/pyuno_type.cxx +++ b/pyuno/source/module/pyuno_type.cxx @@ -164,12 +164,9 @@ Any PyEnum2Enum( PyObject *obj ) { if(desc.get()->eTypeClass != typelib_TypeClass_ENUM ) { - OUStringBuffer buf; - buf.append( "pyuno.checkEnum: " ).append(strTypeName).append( "is a " ); - buf.appendAscii( - typeClassToString( (css::uno::TypeClass) desc.get()->eTypeClass)); - buf.append( ", expected ENUM" ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "pyuno.checkEnum: " + strTypeName + "is a " + + OUString::createFromAscii(typeClassToString( (css::uno::TypeClass) desc.get()->eTypeClass)) + + ", expected ENUM" ); } desc.makeComplete(); @@ -185,18 +182,15 @@ Any PyEnum2Enum( PyObject *obj ) } if( i == pEnumDesc->nEnumValues ) { - OUStringBuffer buf; - buf.append( "value " ).appendAscii( stringValue ).append( "is unknown in enum " ); - buf.appendAscii( PyStr_AsString( typeName.get() ) ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "value " + OUString::createFromAscii( stringValue ) + + "is unknown in enum " + + OUString::createFromAscii( PyStr_AsString( typeName.get() ) ) ); } ret = Any( &pEnumDesc->pEnumValues[i], desc.get()->pWeakRef ); } else { - OUStringBuffer buf; - buf.append( "enum " ).appendAscii( PyStr_AsString(typeName.get()) ).append( " is unknown" ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "enum " + OUString::createFromAscii( PyStr_AsString(typeName.get()) ) + " is unknown" ); } return ret; } @@ -218,19 +212,15 @@ Type PyType2Type( PyObject * o ) TypeDescription desc( name ); if( ! desc.is() ) { - OUStringBuffer buf; - buf.append( "type " ).append(name).append( " is unknown" ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "type " + name + " is unknown" ); } css::uno::TypeClass tc = *o3tl::doAccess(enumValue); if( static_cast(desc.get()->eTypeClass) != tc ) { - OUStringBuffer buf; - buf.append( "pyuno.checkType: " ).append(name).append( " is a " ); - buf.appendAscii( typeClassToString( (TypeClass) desc.get()->eTypeClass) ); - buf.append( ", but type got construct with typeclass " ); - buf.appendAscii( typeClassToString( tc ) ); - throw RuntimeException( buf.makeStringAndClear() ); + throw RuntimeException( "pyuno.checkType: " + name + " is a " + + OUString::createFromAscii( typeClassToString( (TypeClass) desc.get()->eTypeClass) ) + + ", but type got construct with typeclass " + + OUString::createFromAscii( typeClassToString( tc ) ) ); } return desc.get()->pWeakRef; } diff --git a/pyuno/source/module/pyuno_util.cxx b/pyuno/source/module/pyuno_util.cxx index 4f5901e67806..ecb383222458 100644 --- a/pyuno/source/module/pyuno_util.cxx +++ b/pyuno/source/module/pyuno_util.cxx @@ -107,10 +107,7 @@ PyRef getObjectFromUnoModule( const Runtime &runtime, const char * func ) PyRef object(PyDict_GetItemString( runtime.getImpl()->cargo->getUnoModule().get(), func ) ); if( !object.is() ) { - OUStringBuffer buf; - buf.append( "couldn't find core function " ); - buf.appendAscii( func ); - throw RuntimeException(buf.makeStringAndClear()); + throw RuntimeException("couldn't find core function " + OUString::createFromAscii(func)); } return object; } -- cgit