summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-04-10 20:17:54 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-04-11 14:45:38 +0200
commit85c2ed8dc790689ce69ff0a08ff5a4de98df54b7 (patch)
treef7d7f6fce51d1a4443608971da7d9c42b1201fa3 /oox
parent117688bd3f51a7a50b2620aa7dcc0c065f29d402 (diff)
loplugin:stringview add check for getToken().toInt32
where we can convert that to o3tl::toInt32(o3tl::getToken( and avoid the heap allocation of a temporary string Change-Id: Ib11c19c6e6cdc0de3e551affd3578d181e292de4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132810 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/drawingml/customshapepresetdata.cxx78
-rw-r--r--oox/source/ppt/comments.cxx3
-rw-r--r--oox/source/ppt/pptfilterhelpers.cxx13
-rw-r--r--oox/source/vml/vmlformatting.cxx2
-rw-r--r--oox/source/vml/vmlshape.cxx10
5 files changed, 57 insertions, 49 deletions
diff --git a/oox/source/drawingml/customshapepresetdata.cxx b/oox/source/drawingml/customshapepresetdata.cxx
index 45f6b21a903d..c7e68a88165a 100644
--- a/oox/source/drawingml/customshapepresetdata.cxx
+++ b/oox/source/drawingml/customshapepresetdata.cxx
@@ -85,91 +85,96 @@ void lcl_parseAdjustmentValues(
}
drawing::EnhancedCustomShapeParameterPair
-lcl_parseEnhancedCustomShapeParameterPair(const OString& rValue)
+lcl_parseEnhancedCustomShapeParameterPair(std::string_view rValue)
{
drawing::EnhancedCustomShapeParameterPair aPair;
// We expect the following here: First.Value, First.Type, Second.Value, Second.Type
static const char aExpectedFVPrefix[]
= "First = (com.sun.star.drawing.EnhancedCustomShapeParameter) { Value = (any) { (long) ";
- assert(rValue.startsWith(aExpectedFVPrefix));
+ assert(o3tl::starts_with(rValue, aExpectedFVPrefix));
sal_Int32 nIndex = strlen(aExpectedFVPrefix);
- aPair.First.Value <<= static_cast<sal_uInt32>(rValue.getToken(0, '}', nIndex).toInt32());
+ aPair.First.Value
+ <<= static_cast<sal_uInt32>(o3tl::toInt32(o3tl::getToken(rValue, 0, '}', nIndex)));
static const char aExpectedFTPrefix[] = ", Type = (short) ";
- assert(nIndex >= 0 && rValue.match(aExpectedFTPrefix, nIndex));
+ assert(nIndex >= 0 && o3tl::starts_with(rValue.substr(nIndex), aExpectedFTPrefix));
nIndex += strlen(aExpectedFTPrefix);
- aPair.First.Type = static_cast<sal_uInt16>(rValue.getToken(0, '}', nIndex).toInt32());
+ aPair.First.Type
+ = static_cast<sal_uInt16>(o3tl::toInt32(o3tl::getToken(rValue, 0, '}', nIndex)));
static const char aExpectedSVPrefix[] = ", Second = "
"(com.sun.star.drawing.EnhancedCustomShapeParameter) { "
"Value = (any) { (long) ";
- assert(nIndex >= 0 && rValue.match(aExpectedSVPrefix, nIndex));
+ assert(nIndex >= 0 && o3tl::starts_with(rValue.substr(nIndex), aExpectedSVPrefix));
nIndex += strlen(aExpectedSVPrefix);
- aPair.Second.Value <<= static_cast<sal_uInt32>(rValue.getToken(0, '}', nIndex).toInt32());
+ aPair.Second.Value
+ <<= static_cast<sal_uInt32>(o3tl::toInt32(o3tl::getToken(rValue, 0, '}', nIndex)));
static const char aExpectedSTPrefix[] = ", Type = (short) ";
- assert(nIndex >= 0 && rValue.match(aExpectedSTPrefix, nIndex));
+ assert(nIndex >= 0 && o3tl::starts_with(rValue.substr(nIndex), aExpectedSTPrefix));
nIndex += strlen(aExpectedSTPrefix);
- aPair.Second.Type = static_cast<sal_uInt16>(rValue.getToken(0, '}', nIndex).toInt32());
+ aPair.Second.Type
+ = static_cast<sal_uInt16>(o3tl::toInt32(o3tl::getToken(rValue, 0, '}', nIndex)));
return aPair;
}
-drawing::EnhancedCustomShapeSegment lcl_parseEnhancedCustomShapeSegment(const OString& rValue)
+drawing::EnhancedCustomShapeSegment lcl_parseEnhancedCustomShapeSegment(std::string_view rValue)
{
drawing::EnhancedCustomShapeSegment aSegment;
// We expect the following here: Command, Count
static const char aExpectedCommandPrefix[] = "Command = (short) ";
- assert(rValue.startsWith(aExpectedCommandPrefix));
+ assert(o3tl::starts_with(rValue, aExpectedCommandPrefix));
sal_Int32 nIndex = strlen(aExpectedCommandPrefix);
- aSegment.Command = static_cast<sal_Int16>(rValue.getToken(0, ',', nIndex).toInt32());
+ aSegment.Command
+ = static_cast<sal_Int16>(o3tl::toInt32(o3tl::getToken(rValue, 0, ',', nIndex)));
static const char aExpectedCountPrefix[] = " Count = (short) ";
- assert(nIndex >= 0 && rValue.match(aExpectedCountPrefix, nIndex));
+ assert(nIndex >= 0 && o3tl::starts_with(rValue.substr(nIndex), aExpectedCountPrefix));
nIndex += strlen(aExpectedCountPrefix);
- aSegment.Count = static_cast<sal_Int16>(rValue.getToken(0, '}', nIndex).toInt32());
+ aSegment.Count = static_cast<sal_Int16>(o3tl::toInt32(o3tl::getToken(rValue, 0, '}', nIndex)));
return aSegment;
}
-awt::Rectangle lcl_parseRectangle(const OString& rValue)
+awt::Rectangle lcl_parseRectangle(std::string_view rValue)
{
awt::Rectangle aRectangle;
// We expect the following here: X, Y, Width, Height
static const char aExpectedXPrefix[] = "X = (long) ";
- assert(rValue.startsWith(aExpectedXPrefix));
+ assert(o3tl::starts_with(rValue, aExpectedXPrefix));
sal_Int32 nIndex = strlen(aExpectedXPrefix);
- aRectangle.X = rValue.getToken(0, ',', nIndex).toInt32();
+ aRectangle.X = o3tl::toInt32(o3tl::getToken(rValue, 0, ',', nIndex));
static const char aExpectedYPrefix[] = " Y = (long) ";
- assert(nIndex >= 0 && rValue.match(aExpectedYPrefix, nIndex));
+ assert(nIndex >= 0 && o3tl::starts_with(rValue.substr(nIndex), aExpectedYPrefix));
nIndex += strlen(aExpectedYPrefix);
- aRectangle.Y = rValue.getToken(0, ',', nIndex).toInt32();
+ aRectangle.Y = o3tl::toInt32(o3tl::getToken(rValue, 0, ',', nIndex));
static const char aExpectedWidthPrefix[] = " Width = (long) ";
- assert(nIndex >= 0 && rValue.match(aExpectedWidthPrefix, nIndex));
+ assert(nIndex >= 0 && o3tl::starts_with(rValue.substr(nIndex), aExpectedWidthPrefix));
nIndex += strlen(aExpectedWidthPrefix);
- aRectangle.Width = rValue.getToken(0, ',', nIndex).toInt32();
+ aRectangle.Width = o3tl::toInt32(o3tl::getToken(rValue, 0, ',', nIndex));
static const char aExpectedHeightPrefix[] = " Height = (long) ";
- assert(nIndex >= 0 && rValue.match(aExpectedHeightPrefix, nIndex));
+ assert(nIndex >= 0 && o3tl::starts_with(rValue.substr(nIndex), aExpectedHeightPrefix));
nIndex += strlen(aExpectedHeightPrefix);
- aRectangle.Height = o3tl::toInt32(rValue.subView(nIndex));
+ aRectangle.Height = o3tl::toInt32(rValue.substr(nIndex));
return aRectangle;
}
-awt::Size lcl_parseSize(const OString& rValue)
+awt::Size lcl_parseSize(std::string_view rValue)
{
awt::Size aSize;
// We expect the following here: Width, Height
static const char aExpectedWidthPrefix[] = "Width = (long) ";
- assert(rValue.startsWith(aExpectedWidthPrefix));
+ assert(o3tl::starts_with(rValue, aExpectedWidthPrefix));
sal_Int32 nIndex = strlen(aExpectedWidthPrefix);
- aSize.Width = rValue.getToken(0, ',', nIndex).toInt32();
+ aSize.Width = o3tl::toInt32(o3tl::getToken(rValue, 0, ',', nIndex));
static const char aExpectedHeightPrefix[] = " Height = (long) ";
- assert(nIndex >= 0 && rValue.match(aExpectedHeightPrefix, nIndex));
+ assert(nIndex >= 0 && o3tl::starts_with(rValue.substr(nIndex), aExpectedHeightPrefix));
nIndex += strlen(aExpectedHeightPrefix);
- aSize.Height = o3tl::toInt32(rValue.subView(nIndex));
+ aSize.Height = o3tl::toInt32(rValue.substr(nIndex));
return aSize;
}
@@ -305,12 +310,13 @@ void lcl_parseHandleRange(std::vector<beans::PropertyValue>& rHandle, const OStr
static const char aExpectedVPrefix[] = "Value = (any) { (long) ";
assert(rValue.match(aExpectedVPrefix, nIndex));
nIndex += strlen(aExpectedVPrefix);
- aParameter.Value <<= rValue.getToken(0, '}', nIndex).toInt32();
+ aParameter.Value <<= o3tl::toInt32(o3tl::getToken(rValue, 0, '}', nIndex));
static const char aExpectedTPrefix[] = ", Type = (short) ";
assert(nIndex >= 0 && rValue.match(aExpectedTPrefix, nIndex));
nIndex += strlen(aExpectedTPrefix);
- aParameter.Type = static_cast<sal_Int16>(rValue.getToken(0, '}', nIndex).toInt32());
+ aParameter.Type
+ = static_cast<sal_Int16>(o3tl::toInt32(o3tl::getToken(rValue, 0, '}', nIndex)));
beans::PropertyValue aPropertyValue;
aPropertyValue.Name = rName;
@@ -339,7 +345,7 @@ void lcl_parseHandleRef(std::vector<beans::PropertyValue>& rHandle, const OStrin
beans::PropertyValue aPropertyValue;
aPropertyValue.Name = rName;
// We only expect a Value here
- aPropertyValue.Value <<= rValue.getToken(0, '}', nIndex).toInt32();
+ aPropertyValue.Value <<= o3tl::toInt32(o3tl::getToken(rValue, 0, '}', nIndex));
rHandle.push_back(aPropertyValue);
}
else
@@ -459,7 +465,7 @@ void lcl_parsePathCoordinateValues(std::vector<beans::PropertyValue>& rPath, con
nLevel--;
if (!nLevel)
aPairs.push_back(lcl_parseEnhancedCustomShapeParameterPair(
- rValue.copy(nStart + strlen("{ "), i - nStart - strlen(" },"))));
+ rValue.subView(nStart + strlen("{ "), i - nStart - strlen(" },"))));
}
}
@@ -526,7 +532,7 @@ void lcl_parsePathGluePointsValues(std::vector<beans::PropertyValue>& rPath, con
nLevel--;
if (!nLevel)
aPairs.push_back(lcl_parseEnhancedCustomShapeParameterPair(
- rValue.copy(nStart + strlen("{ "), i - nStart - strlen(" },"))));
+ rValue.subView(nStart + strlen("{ "), i - nStart - strlen(" },"))));
}
}
@@ -591,7 +597,7 @@ void lcl_parsePathSegmentValues(std::vector<beans::PropertyValue>& rPath, const
nLevel--;
if (!nLevel)
aSegments.push_back(lcl_parseEnhancedCustomShapeSegment(
- rValue.copy(nStart + strlen("{ "), i - nStart - strlen(" },"))));
+ rValue.subView(nStart + strlen("{ "), i - nStart - strlen(" },"))));
}
}
@@ -724,8 +730,8 @@ void lcl_parsePathSubViewSizeValues(std::vector<beans::PropertyValue>& rPath, co
{
nLevel--;
if (!nLevel)
- aSizes.push_back(
- lcl_parseSize(rValue.copy(nStart + strlen("{ "), i - nStart - strlen(" },"))));
+ aSizes.push_back(lcl_parseSize(
+ rValue.subView(nStart + strlen("{ "), i - nStart - strlen(" },"))));
}
}
diff --git a/oox/source/ppt/comments.cxx b/oox/source/ppt/comments.cxx
index 8034a3978b45..a255dd010950 100644
--- a/oox/source/ppt/comments.cxx
+++ b/oox/source/ppt/comments.cxx
@@ -11,6 +11,7 @@
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <rtl/math.h>
#include <rtl/math.hxx>
+#include <o3tl/string_view.hxx>
namespace oox::ppt
{
@@ -33,7 +34,7 @@ void CommentAuthorList::setValues(const CommentAuthorList& list)
void Comment::setDateTime(const OUString& sDateTime)
{
sal_Int32 nIdx{ 0 };
- aDateTime.Year = sDateTime.getToken(0, '-', nIdx).toInt32();
+ aDateTime.Year = o3tl::toInt32(o3tl::getToken(sDateTime, 0, '-', nIdx));
aDateTime.Month = sDateTime.getToken(0, '-', nIdx).toUInt32();
aDateTime.Day = sDateTime.getToken(0, 'T', nIdx).toUInt32();
aDateTime.Hours = sDateTime.getToken(0, ':', nIdx).toUInt32();
diff --git a/oox/source/ppt/pptfilterhelpers.cxx b/oox/source/ppt/pptfilterhelpers.cxx
index 23aae31c2212..fff1d3ddd3b5 100644
--- a/oox/source/ppt/pptfilterhelpers.cxx
+++ b/oox/source/ppt/pptfilterhelpers.cxx
@@ -28,6 +28,7 @@
#include <com/sun/star/uno/Sequence.hxx>
#include <oox/ppt/pptfilterhelpers.hxx>
#include <tools/color.hxx>
+#include <o3tl/string_view.hxx>
namespace {
int lcl_gethex(int nChar)
@@ -288,20 +289,20 @@ namespace oox::ppt {
Color aColor;
sal_Int32 index = 0;
aColor.SetRed(
- static_cast<sal_uInt8>(aString.getToken(0, ',', index).toInt32()));
+ static_cast<sal_uInt8>(o3tl::toInt32(o3tl::getToken(aString, 0, ',', index))));
aColor.SetGreen(
- static_cast<sal_uInt8>(aString.getToken(0, ',', index).toInt32()));
+ static_cast<sal_uInt8>(o3tl::toInt32(o3tl::getToken(aString, 0, ',', index))));
aColor.SetRed(
- static_cast<sal_uInt8>(aString.getToken(0, ',', index).toInt32()));
+ static_cast<sal_uInt8>(o3tl::toInt32(o3tl::getToken(aString, 0, ',', index))));
rValue <<= aColor;
bRet = true;
}
else if (aString.startsWith("hsl("))
{
sal_Int32 index = 0;
- sal_Int32 nA = aString.getToken(0, ',', index).toInt32();
- sal_Int32 nB = aString.getToken(0, ',', index).toInt32();
- sal_Int32 nC = aString.getToken(0, ',', index).toInt32();
+ sal_Int32 nA = o3tl::toInt32(o3tl::getToken(aString, 0, ',', index));
+ sal_Int32 nB = o3tl::toInt32(o3tl::getToken(aString, 0, ',', index));
+ sal_Int32 nC = o3tl::toInt32(o3tl::getToken(aString, 0, ',', index));
css::uno::Sequence<double> aHSL
{
nA * 360.0 / 255.0,
diff --git a/oox/source/vml/vmlformatting.cxx b/oox/source/vml/vmlformatting.cxx
index 5967e7be0f34..2143647edec1 100644
--- a/oox/source/vml/vmlformatting.cxx
+++ b/oox/source/vml/vmlformatting.cxx
@@ -581,7 +581,7 @@ void lclGetDmlLineDash( OptValue< sal_Int32 >& oroPresetDash, LineProperties::Da
::std::vector< sal_Int32 > aValues;
sal_Int32 nIndex = 0;
while( nIndex >= 0 )
- aValues.push_back( rDashStyle.getToken( 0, ' ', nIndex ).toInt32() );
+ aValues.push_back( o3tl::toInt32(o3tl::getToken(rDashStyle, 0, ' ', nIndex )) );
size_t nPairs = aValues.size() / 2; // ignore last value if size is odd
for( size_t nPairIdx = 0; nPairIdx < nPairs; ++nPairIdx )
orCustomDash.emplace_back( aValues[ 2 * nPairIdx ], aValues[ 2 * nPairIdx + 1 ] );
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx
index c5ccb9346289..188e3303449c 100644
--- a/oox/source/vml/vmlshape.cxx
+++ b/oox/source/vml/vmlshape.cxx
@@ -1020,7 +1020,7 @@ Reference<XShape> RectangleShape::implConvertAndInsert(const Reference<XShapes>&
if ( !sArcsize.isEmpty( ) )
{
sal_Unicode cLastChar = sArcsize[sArcsize.getLength() - 1];
- sal_Int32 nValue = sArcsize.copy( 0, sArcsize.getLength() - 1 ).toInt32( );
+ sal_Int32 nValue = o3tl::toInt32(sArcsize.subView( 0, sArcsize.getLength() - 1 ));
// Get the smallest half-side
double size = std::min( rShapeRect.Height, rShapeRect.Width ) / 2.0;
sal_Int32 nRadius = 0;
@@ -1156,11 +1156,11 @@ awt::Rectangle LineShape::getRelRectangle() const
awt::Rectangle aShapeRect;
sal_Int32 nIndex = 0;
- aShapeRect.X = maShapeModel.maFrom.getToken(0, ',', nIndex).toInt32();
- aShapeRect.Y = maShapeModel.maFrom.getToken(0, ',', nIndex).toInt32();
+ aShapeRect.X = o3tl::toInt32(o3tl::getToken(maShapeModel.maFrom, 0, ',', nIndex));
+ aShapeRect.Y = o3tl::toInt32(o3tl::getToken(maShapeModel.maFrom, 0, ',', nIndex));
nIndex = 0;
- aShapeRect.Width = maShapeModel.maTo.getToken(0, ',', nIndex).toInt32() - aShapeRect.X;
- aShapeRect.Height = maShapeModel.maTo.getToken(0, ',', nIndex).toInt32() - aShapeRect.Y;
+ aShapeRect.Width = o3tl::toInt32(o3tl::getToken(maShapeModel.maTo, 0, ',', nIndex)) - aShapeRect.X;
+ aShapeRect.Height = o3tl::toInt32(o3tl::getToken(maShapeModel.maTo, 0, ',', nIndex)) - aShapeRect.Y;
return aShapeRect;
}