From 08489c211a902398c5f49c4f4676184b1657694c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 23 Jun 2022 14:45:26 +0200 Subject: almost nobody is using the oox::AttributeList::get methods properly Most of the call sites just ignore the fact that we are returning an optional value here. Which means that when an attribute is missing, they get an empty string or zero. And we seem to be fine with that. So make a plugin that warns about calling value() on a temporay OptValue. And add a utility method so we don't have to pay the cost of passing a default value to getString() The need for this is driven by wanting to change to std::optional, which will throw an exception if code attempts to read an empty std::optional Change-Id: Idb0a5ad1eac66b5caa93d6195928bad9e0b2ad70 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136283 Tested-by: Jenkins Reviewed-by: Noel Grandin --- oox/source/drawingml/transform2dcontext.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'oox/source/drawingml/transform2dcontext.cxx') diff --git a/oox/source/drawingml/transform2dcontext.cxx b/oox/source/drawingml/transform2dcontext.cxx index 20c90731ed8d..f16dc06489f0 100644 --- a/oox/source/drawingml/transform2dcontext.cxx +++ b/oox/source/drawingml/transform2dcontext.cxx @@ -43,7 +43,7 @@ Transform2DContext::Transform2DContext( ContextHandler2Helper const & rParent, c else { if( rAttribs.hasAttribute( XML_rot ) ) - mrShape.getTextBody()->getTextProperties().moRotation = rAttribs.getInteger( XML_rot ).value(); + mrShape.getTextBody()->getTextProperties().moRotation = rAttribs.getInteger( XML_rot, 0 ); } } @@ -59,8 +59,8 @@ ContextHandlerRef Transform2DContext::onCreateContext( sal_Int32 aElementToken, { case A_TOKEN( off ): { - const OUString sXValue = rAttribs.getString( XML_x ).value(); - const OUString sYValue = rAttribs.getString( XML_y ).value(); + const OUString sXValue = rAttribs.getStringDefaulted( XML_x ); + const OUString sYValue = rAttribs.getStringDefaulted( XML_y ); if( !sXValue.isEmpty() && nType != XML_ellipse ) mrShape.getTextBody()->getTextProperties().moTextOffLeft = GetCoordinate( sXValue.toInt32() - mrShape.getPosition().X ); @@ -70,8 +70,8 @@ ContextHandlerRef Transform2DContext::onCreateContext( sal_Int32 aElementToken, break; case A_TOKEN( ext ): { - const OUString sXValue = rAttribs.getString( XML_cx ).value(); - const OUString sYValue = rAttribs.getString( XML_cy ).value(); + const OUString sXValue = rAttribs.getStringDefaulted( XML_cx ); + const OUString sYValue = rAttribs.getStringDefaulted( XML_cy ); if( !sXValue.isEmpty() && nType == XML_rect ) { @@ -96,22 +96,22 @@ ContextHandlerRef Transform2DContext::onCreateContext( sal_Int32 aElementToken, switch( aElementToken ) { case A_TOKEN( off ): // horz/vert translation - mrShape.setPosition( awt::Point( rAttribs.getString( XML_x ).value().toInt32(), rAttribs.getString( XML_y ).value().toInt32() ) ); + mrShape.setPosition( awt::Point( rAttribs.getStringDefaulted( XML_x ).toInt32(), rAttribs.getStringDefaulted( XML_y ).toInt32() ) ); break; case A_TOKEN( ext ): // horz/vert size - mrShape.setSize( awt::Size( rAttribs.getString( XML_cx ).value().toInt32(), rAttribs.getString( XML_cy ).value().toInt32() ) ); + mrShape.setSize( awt::Size( rAttribs.getStringDefaulted( XML_cx ).toInt32(), rAttribs.getStringDefaulted( XML_cy ).toInt32() ) ); break; case A_TOKEN( chOff ): // horz/vert translation of children - mrShape.setChildPosition( awt::Point( rAttribs.getString( XML_x ).value().toInt32(), rAttribs.getString( XML_y ).value().toInt32() ) ); + mrShape.setChildPosition( awt::Point( rAttribs.getStringDefaulted( XML_x ).toInt32(), rAttribs.getStringDefaulted( XML_y ).toInt32() ) ); break; case A_TOKEN( chExt ): // horz/vert size of children { - sal_Int32 nChExtCx = rAttribs.getString(XML_cx).value().toInt32(); + sal_Int32 nChExtCx = rAttribs.getStringDefaulted(XML_cx).toInt32(); if(nChExtCx == 0) nChExtCx = mrShape.getSize().Width; - sal_Int32 nChExtCy = rAttribs.getString(XML_cy).value().toInt32(); + sal_Int32 nChExtCy = rAttribs.getStringDefaulted(XML_cy).toInt32(); if(nChExtCy == 0) nChExtCy = mrShape.getSize().Height; -- cgit