Skip to content

Commit

Permalink
Use std::string::pop_back() instead of resize(size() - 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Sep 7, 2024
1 parent 7a7cb80 commit 81f5ed9
Show file tree
Hide file tree
Showing 53 changed files with 93 additions and 93 deletions.
4 changes: 2 additions & 2 deletions apps/ogr2ogr_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ static int GetFieldType(const char *pszArg, int *pnSubFieldType)
*pnSubFieldType = -1;
CPLString osArgSubType = pszOpenParenthesis + 1;
if (!osArgSubType.empty() && osArgSubType.back() == ')')
osArgSubType.resize(osArgSubType.size() - 1);
osArgSubType.pop_back();
for (int iSubType = 0;
iSubType <= static_cast<int>(OFSTMaxSubType); iSubType++)
{
Expand Down Expand Up @@ -6880,7 +6880,7 @@ static std::unique_ptr<GDALArgumentParser> GDALVectorTranslateOptionsGetParser(
osGeomName.c_str() + osGeomName.size() - 1, "Z"))
{
bIs3D = true;
osGeomName.resize(osGeomName.size() - 1);
osGeomName.pop_back();
}
if (EQUAL(osGeomName.c_str(), "NONE"))
{
Expand Down
2 changes: 1 addition & 1 deletion apps/ogrdissolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ MAIN_START(nArgc, papszArgv)
"Z"))
{
bIs3D = TRUE;
osGeomName.resize(osGeomName.size() - 1);
osGeomName.pop_back();
}
if (EQUAL(osGeomName, "NONE"))
eGType = wkbNone;
Expand Down
2 changes: 1 addition & 1 deletion frmts/georaster/georaster_rasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ GDALRasterAttributeTable *GeoRasterRasterBand::GetDefaultRAT()
}

if (!osColumnList.empty())
osColumnList.resize(osColumnList.size() - 1); // remove the last comma
osColumnList.pop_back(); // remove the last comma

// ----------------------------------------------------------
// Read VAT and load RAT
Expand Down
2 changes: 1 addition & 1 deletion frmts/l1b/l1bdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3310,7 +3310,7 @@ GDALDataset *L1BDataset::Open(GDALOpenInfo *poOpenInfo)
pszFilename++;
osFilename = pszFilename;
if (!osFilename.empty() && osFilename.back() == '"')
osFilename.resize(osFilename.size() - 1);
osFilename.pop_back();
fp = VSIFOpenL(osFilename, "rb");
if (!fp)
{
Expand Down
2 changes: 1 addition & 1 deletion frmts/mrf/marfa_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ CPLXMLNode *MRFDataset::BuildConfig()
options += optlist[i];
options += ' ';
}
options.resize(options.size() - 1);
options.pop_back();
CPLCreateXMLElementAndValue(config, "Options", options);
}

Expand Down
2 changes: 1 addition & 1 deletion frmts/mrf/mrf_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ void XMLSetAttributeVal(CPLXMLNode *parent, const char *pszName,
single_val = false;
value.append(PrintDouble(values[i]) + " ");
}
value.resize(value.size() - 1); // Cut the last space
value.pop_back(); // Cut the last space
if (single_val)
value = PrintDouble(values[0]);
CPLCreateXMLNode(parent, CXT_Attribute, pszName);
Expand Down
14 changes: 7 additions & 7 deletions frmts/netcdf/netcdfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6451,7 +6451,7 @@ void netCDFDataset::CreateSubDatasetList(int nGroupId)
nc_type nVarType;
nc_inq_vartype(nGroupId, nVar, &nVarType);
// Get rid of the last "x" character.
osDim.resize(osDim.size() - 1);
osDim.pop_back();
const char *pszType = "";
switch (nVarType)
{
Expand Down Expand Up @@ -7649,11 +7649,11 @@ bool netCDFDatasetCreateTempFile(NetCDFFormatEnum eFormat,
{
if (osVal.back() == ';' || osVal.back() == ' ')
{
osVal.resize(osVal.size() - 1);
osVal.pop_back();
}
else if (osVal.back() == '"')
{
osVal.resize(osVal.size() - 1);
osVal.pop_back();
break;
}
else
Expand All @@ -7672,7 +7672,7 @@ bool netCDFDatasetCreateTempFile(NetCDFFormatEnum eFormat,
{
if (osVal.back() == ';' || osVal.back() == ' ')
{
osVal.resize(osVal.size() - 1);
osVal.pop_back();
}
else
{
Expand All @@ -7683,12 +7683,12 @@ bool netCDFDatasetCreateTempFile(NetCDFFormatEnum eFormat,
if (!osVal.empty() && osVal.back() == 'b')
{
nc_datatype = NC_BYTE;
osVal.resize(osVal.size() - 1);
osVal.pop_back();
}
else if (!osVal.empty() && osVal.back() == 's')
{
nc_datatype = NC_SHORT;
osVal.resize(osVal.size() - 1);
osVal.pop_back();
}
if (CPLGetValueType(osVal) == CPL_VALUE_INTEGER)
{
Expand Down Expand Up @@ -7782,7 +7782,7 @@ bool netCDFDatasetCreateTempFile(NetCDFFormatEnum eFormat,
}
if (pszLine == nullptr)
break;
osAccVal.resize(osAccVal.size() - 1);
osAccVal.pop_back();

const std::vector<int> aoDimIds =
oMapVarIdToVectorOfDimId[nVarId];
Expand Down
2 changes: 1 addition & 1 deletion frmts/plmosaic/plmosaicdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ CPLHTTPResult *PLMosaicDataset::Download(const char *pszURL, int bQuiet404Error)
vsi_l_offset nDataLength = 0;
CPLString osURL(pszURL);
if (osURL.back() == '/')
osURL.resize(osURL.size() - 1);
osURL.pop_back();
GByte *pabyBuf = VSIGetMemFileBuffer(osURL, &nDataLength, FALSE);
if (pabyBuf)
{
Expand Down
2 changes: 1 addition & 1 deletion frmts/stacit/stacitdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static std::string SanitizeCRSValue(const std::string &v)
}
}
if (!ret.empty() && ret.back() == '_')
ret.resize(ret.size() - 1);
ret.pop_back();
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions frmts/tga/tgadataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ GDALDataset *GDALTGADataset::Open(GDALOpenInfo *poOpenInfo)
while (!osAuthorName.empty() &&
osAuthorName.back() == ' ')
{
osAuthorName.resize(osAuthorName.size() - 1);
osAuthorName.pop_back();
}
poDS->GDALDataset::SetMetadataItem(
"AUTHOR_NAME", osAuthorName.c_str());
Expand All @@ -645,7 +645,7 @@ GDALDataset *GDALTGADataset::Open(GDALOpenInfo *poOpenInfo)
osLine.resize(strlen(osLine.c_str()));
while (!osLine.empty() && osLine.back() == ' ')
{
osLine.resize(osLine.size() - 1);
osLine.pop_back();
}
if (i > 0)
osComments += '\n';
Expand Down
4 changes: 2 additions & 2 deletions frmts/vrt/vrtdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ CPLXMLNode *VRTDataset::SerializeToXML(const char *pszVRTPathIn)
if (osCoordinateEpoch.find('.') != std::string::npos)
{
while (osCoordinateEpoch.back() == '0')
osCoordinateEpoch.resize(osCoordinateEpoch.size() - 1);
osCoordinateEpoch.pop_back();
}
CPLAddXMLAttributeAndValue(psSRSNode, "coordinateEpoch",
osCoordinateEpoch.c_str());
Expand Down Expand Up @@ -2795,7 +2795,7 @@ bool VRTDataset::AddVirtualOverview(int nOvFactor, const char *pszResampling)
GDALDatasetH hOverviewDS =
GDALTranslate("", GDALDataset::ToHandle(this), psOptions, nullptr);
m_bCanTakeRef = true;
m_apoOverviews.resize(m_apoOverviews.size() - 1);
m_apoOverviews.pop_back();

GDALTranslateOptionsFree(psOptions);
if (hOverviewDS == nullptr)
Expand Down
2 changes: 1 addition & 1 deletion frmts/vrt/vrtderivedrasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ bool VRTDerivedRasterBand::InitializePython()
CPLString osException = GetPyExceptionString();
if (!osException.empty() && osException.back() == '\n')
{
osException.resize(osException.size() - 1);
osException.pop_back();
}
if (osException.find("ModuleNotFoundError") == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion frmts/wms/minidriver_mrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void *SectorCache::data(size_t address)
// If this is the last sector, it could be a new sector with invalid data,
// so we remove it Otherwise, the previous content is still good
if (target == &store.back())
store.resize(store.size() - 1);
store.pop_back();
// Signal invalid request
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion frmts/wms/wmsdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static CPLXMLNode *GDALWMSDatasetGetConfigFromURL(GDALOpenInfo *poOpenInfo)
osBaseURL = CPLURLAddKVP(osBaseURL, "BBOXORDER", nullptr);

if (!osBaseURL.empty() && osBaseURL.back() == '&')
osBaseURL.resize(osBaseURL.size() - 1);
osBaseURL.pop_back();

if (osVersion.empty())
osVersion = "1.1.1";
Expand Down
2 changes: 1 addition & 1 deletion frmts/wmts/wmtsdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ CPLString WMTSDataset::FixCRSName(const char *pszCRS)
while (osRet.size() && (osRet.back() == ' ' || osRet.back() == '\r' ||
osRet.back() == '\n'))
{
osRet.resize(osRet.size() - 1);
osRet.pop_back();
}
return osRet;
}
Expand Down
2 changes: 1 addition & 1 deletion frmts/zarr/zarr_sharedresource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ZarrSharedResource::ZarrSharedResource(const std::string &osRootDirectoryName,
m_osRootDirectoryName = osRootDirectoryName;
if (!m_osRootDirectoryName.empty() && m_osRootDirectoryName.back() == '/')
{
m_osRootDirectoryName.resize(m_osRootDirectoryName.size() - 1);
m_osRootDirectoryName.pop_back();
}
m_poPAM = std::make_shared<GDALPamMultiDim>(
CPLFormFilename(m_osRootDirectoryName.c_str(), "pam", nullptr));
Expand Down
2 changes: 1 addition & 1 deletion frmts/zarr/zarrdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ GDALDataset *ZarrDataset::OpenMultidim(const char *pszFilename,
{
CPLString osFilename(pszFilename);
if (osFilename.back() == '/')
osFilename.resize(osFilename.size() - 1);
osFilename.pop_back();

auto poSharedResource = ZarrSharedResource::Create(osFilename, bUpdateMode);
poSharedResource->SetOpenOptions(papszOpenOptionsIn);
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogr_srs_erm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ OGRErr OGRSpatialReference::importFromERM(const char *pszProj,
}

// Remove trailing ]
osProjWKT.resize(osProjWKT.size() - 1);
osProjWKT.pop_back();

// Remove any UNIT
auto nPos = osProjWKT.find(",UNIT");
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7002,7 +7002,7 @@ void OGRFeature::FillUnsetWithDefault(int bNotNullableOnly,
pszDefault[strlen(pszDefault) - 1] == '\'')
{
CPLString osDefault(pszDefault + 1);
osDefault.resize(osDefault.size() - 1);
osDefault.pop_back();
char *pszTmp = CPLUnescapeString(osDefault, nullptr, CPLES_SQL);
SetField(i, pszTmp);
CPLFree(pszTmp);
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/avc/avc_e00read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ static int _AVCE00ReadBuildSqueleton(AVCE00ReadPtr psInfo, char **papszCoverDir)
}

CPLString osCoverPathTruncated(psInfo->pszCoverPath);
osCoverPathTruncated.resize(osCoverPathTruncated.size() - 1);
osCoverPathTruncated.pop_back();
pszEXPPath = CPLStrdup(
CPLSPrintf("EXP 0 %s%s.E00", szCWD, osCoverPathTruncated.c_str()));
pcTmp = pszEXPPath;
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/csv/ogrcsvlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool OGRCSVLayer::Matches(const char *pszFieldName, char **papszPossibleNames)
{
// *pattern*
CPLString oPattern(pszPattern + 1);
oPattern.resize(oPattern.size() - 1);
oPattern.pop_back();
if (CPLString(pszFieldName).ifind(oPattern) !=
std::string::npos)
return true;
Expand Down
4 changes: 2 additions & 2 deletions ogr/ogrsf_frmts/dwg/ogrdwglayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ OGRFeature *OGRDWGLayer::TranslateMTEXT(OdDbEntityPtr poEntity)
CPLString osText = TextUnescape(poMTE->contents(), true);

if (!osText.empty() && osText.back() == '\n')
osText.resize(osText.size() - 1);
osText.pop_back();

poFeature->SetField("Text", osText);

Expand Down Expand Up @@ -543,7 +543,7 @@ OGRFeature *OGRDWGLayer::TranslateTEXT(OdDbEntityPtr poEntity)
CPLString osText = TextUnescape(poText->textString(), false);

if (!osText.empty() && osText.back() == '\n')
osText.resize(osText.size() - 1);
osText.pop_back();

poFeature->SetField("Text", osText);

Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ OGRDXFFeature *OGRDXFLayer::TranslateMTEXT()
/* Apply text after stripping off any extra terminating newline. */
/* -------------------------------------------------------------------- */
if (!osText.empty() && osText.back() == '\n')
osText.resize(osText.size() - 1);
osText.pop_back();

poFeature->SetField("Text", osText);

Expand Down
6 changes: 3 additions & 3 deletions ogr/ogrsf_frmts/filegdb/FGdbDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ OGRErr FGdbTransactionManager::StartTransaction(OGRDataSource *&poDSInOut,
CPLString osName(poMutexedDS->GetName());
CPLString osNameOri(osName);
if (osName.back() == '/' || osName.back() == '\\')
osName.resize(osName.size() - 1);
osName.pop_back();

#ifndef _WIN32
int bPerLayerCopyingForTransaction =
Expand Down Expand Up @@ -452,7 +452,7 @@ OGRErr FGdbTransactionManager::CommitTransaction(OGRDataSource *&poDSInOut,
CPLString osName(poMutexedDS->GetName());
CPLString osNameOri(osName);
if (osName.back() == '/' || osName.back() == '\\')
osName.resize(osName.size() - 1);
osName.pop_back();

#ifndef _WIN32
int bPerLayerCopyingForTransaction =
Expand Down Expand Up @@ -696,7 +696,7 @@ OGRErr FGdbTransactionManager::RollbackTransaction(OGRDataSource *&poDSInOut,
CPLString osName(poMutexedDS->GetName());
CPLString osNameOri(osName);
if (osName.back() == '/' || osName.back() == '\\')
osName.resize(osName.size() - 1);
osName.pop_back();

// int bPerLayerCopyingForTransaction =
// poDS->HasPerLayerCopyingForTransaction();
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ char *FGdbLayer::CreateFieldDefn(OGRFieldDefn &oField, int bApproxOK,
if (osVal[0] == '\'' && osVal.back() == '\'')
{
osVal = osVal.substr(1);
osVal.resize(osVal.size() - 1);
osVal.pop_back();
char *pszTmp = CPLUnescapeString(osVal, nullptr, CPLES_SQL);
osVal = pszTmp;
CPLFree(pszTmp);
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/flatgeobuf/ogrflatgeobuflayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ void OGRFlatGeobufLayer::writeHeader(VSILFILE *poFp, uint64_t featuresCount,
if (osCoordinateEpoch.find('.') != std::string::npos)
{
while (osCoordinateEpoch.back() == '0')
osCoordinateEpoch.resize(osCoordinateEpoch.size() - 1);
osCoordinateEpoch.pop_back();
}

std::string osWKT("COORDINATEMETADATA[");
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/geojson/ogrgeojsonseqdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ json_object *OGRGeoJSONSeqLayer::GetNextObject(bool bLooseIdentification)
(m_osFeatureBuffer.back() == '\r' ||
m_osFeatureBuffer.back() == '\n'))
{
m_osFeatureBuffer.resize(m_osFeatureBuffer.size() - 1);
m_osFeatureBuffer.pop_back();
}
if (!m_osFeatureBuffer.empty())
{
Expand Down
10 changes: 5 additions & 5 deletions ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ bool GMLASWriter::WriteFieldRegular(
// For extension/* case
if (!aoFieldComponents.empty() && aoFieldComponents.back().second == "*")
{
aoFieldComponents.resize(aoFieldComponents.size() - 1);
aoFieldComponents.pop_back();
}

const size_t nCommonLength =
Expand Down Expand Up @@ -2405,7 +2405,7 @@ bool GMLASWriter::WriteFieldNoLink(
</xs:element>
*/
aoNewInitialContext = std::move(aoFieldComponents);
aoNewInitialContext.resize(aoNewInitialContext.size() - 1);
aoNewInitialContext.pop_back();
}
else
{
Expand Down Expand Up @@ -2585,7 +2585,7 @@ bool GMLASWriter::WriteFieldWithLink(
oSetLayersInIterationSub.insert(oChildLayerDesc.osName);

XPathComponents aoPrefixComponentsNew(aoFieldComponents);
aoPrefixComponentsNew.resize(aoPrefixComponentsNew.size() - 1);
aoPrefixComponentsNew.pop_back();

if (aoLayerComponents.empty())
{
Expand All @@ -2603,7 +2603,7 @@ bool GMLASWriter::WriteFieldWithLink(
{
aoInitialComponents = std::move(aoFieldComponents);
if (!aoInitialComponents.empty())
aoInitialComponents.resize(aoInitialComponents.size() - 1);
aoInitialComponents.pop_back();
WriteClosingAndStartingTags(aoCurComponents, aoInitialComponents,
bCurIsRegularField);
}
Expand Down Expand Up @@ -2754,7 +2754,7 @@ bool GMLASWriter::WriteFieldJunctionTable(
aoPrefixComponents.end());

if (!aoInitialComponents.empty())
aoInitialComponents.resize(aoInitialComponents.size() - 1);
aoInitialComponents.pop_back();
WriteClosingAndStartingTags(
aoCurComponents, aoInitialComponents, bCurIsRegularField);
}
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7521,7 +7521,7 @@ OGRLayer *GDALGeoPackageDataset::ExecuteSQL(const char *pszSQLCommand,

CPLString osSQLCommand(pszSQLCommand);
if (!osSQLCommand.empty() && osSQLCommand.back() == ';')
osSQLCommand.resize(osSQLCommand.size() - 1);
osSQLCommand.pop_back();

if (pszDialect == nullptr || !EQUAL(pszDialect, "DEBUG"))
{
Expand Down
Loading

0 comments on commit 81f5ed9

Please sign in to comment.