Skip to content

Commit

Permalink
Use CPLTolower() and CPLToupper()
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Apr 14, 2024
1 parent 19b0302 commit 8039763
Show file tree
Hide file tree
Showing 29 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion apps/gdaltindex_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static bool PatternMatch(const char *input, const char *pattern)
}
else
{
if (tolower(*pattern) != tolower(*input))
if (CPLTolower(*pattern) != CPLTolower(*input))
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions frmts/netcdf/netcdfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,14 +3425,14 @@ void netCDFDataset::SetProjectionFromVar(
for (unsigned int i = 0;
i < strlen(poDS->papszDimName[poDS->nXDimID]) && i < 3; i++)
{
szDimNameX[i] = (char)tolower(static_cast<unsigned char>(
szDimNameX[i] = (char)CPLTolower(static_cast<unsigned char>(
(poDS->papszDimName[poDS->nXDimID])[i]));
}
szDimNameX[3] = '\0';
// for( unsigned int i = 0;
// (i < strlen(poDS->papszDimName[poDS->nYDimID])
// && i < 3 ); i++ ) {
// szDimNameY[i]=(char)tolower(static_cast<unsigned char>((poDS->papszDimName[poDS->nYDimID])[i]));
// szDimNameY[i]=(char)CPLTolower(static_cast<unsigned char>((poDS->papszDimName[poDS->nYDimID])[i]));
// }
// szDimNameY[3] = '\0';
}
Expand Down
21 changes: 11 additions & 10 deletions frmts/pcidsk/sdk/core/pcidsk_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
#include <cstdarg>
#include <iostream>

extern "C"
{
int CPL_DLL CPLToupper(int c);
int CPL_DLL CPLTolower(int c);
}

#if !defined(va_copy) && defined(__va_copy)
#define va_copy __va_copy
#endif
Expand Down Expand Up @@ -104,8 +110,7 @@ std::string &PCIDSK::UCaseStr( std::string &target )
{
for( unsigned int i = 0; i < target.size(); i++ )
{
if( islower(static_cast<unsigned char>(target[i])) )
target[i] = (char) toupper(static_cast<unsigned char>(target[i]));
target[i] = (char) CPLToupper(static_cast<unsigned char>(target[i]));
}

return target;
Expand Down Expand Up @@ -409,10 +414,8 @@ int PCIDSK::pci_strcasecmp( const char *string1, const char *string2 )
char c1 = string1[i];
char c2 = string2[i];

if( islower(static_cast<unsigned char>(c1)) )
c1 = (char) toupper(static_cast<unsigned char>(c1));
if( islower(static_cast<unsigned char>(c2)) )
c2 = (char) toupper(static_cast<unsigned char>(c2));
c1 = (char) CPLToupper(static_cast<unsigned char>(c1));
c2 = (char) CPLToupper(static_cast<unsigned char>(c2));

if( c1 < c2 )
return -1;
Expand Down Expand Up @@ -447,10 +450,8 @@ int PCIDSK::pci_strncasecmp( const char *string1, const char *string2, size_t le
char c1 = string1[i];
char c2 = string2[i];

if( islower(static_cast<unsigned char>(c1)) )
c1 = (char) toupper(static_cast<unsigned char>(c1));
if( islower(static_cast<unsigned char>(c2)) )
c2 = (char) toupper(static_cast<unsigned char>(c2));
c1 = (char) CPLToupper(static_cast<unsigned char>(c1));
c2 = (char) CPLToupper(static_cast<unsigned char>(c2));

if( c1 < c2 )
return -1;
Expand Down
2 changes: 1 addition & 1 deletion frmts/pds/pds4dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ static CPLString FixupTableFilename(const CPLString &osFilename)
if (!osExt.empty())
{
CPLString osTry(osFilename);
if (islower(static_cast<unsigned char>(osExt[0])))
if (osExt[0] >= 'a' && osExt[0] <= 'z')
{
osTry = CPLResetExtension(osFilename, osExt.toupper());
}
Expand Down
2 changes: 1 addition & 1 deletion gcore/gdal_mdreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ static bool GDAL_IMD_AA2R(char ***ppapszIMD)
CPLString osLine;
osTarget.Printf(
"IMAGE_1.%c%s",
tolower(static_cast<unsigned char>(keylist[iKey][0])),
CPLTolower(static_cast<unsigned char>(keylist[iKey][0])),
keylist[iKey] + 1);

osLine = osTarget + "=" + osValue;
Expand Down
4 changes: 2 additions & 2 deletions gcore/gdal_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2316,9 +2316,9 @@ int GDALReadWorldFile2(const char *pszBaseFilename, const char *pszExtension,
for (int i = 0; szExtUpper[i] != '\0'; i++)
{
szExtUpper[i] = static_cast<char>(
toupper(static_cast<unsigned char>(szExtUpper[i])));
CPLToupper(static_cast<unsigned char>(szExtUpper[i])));
szExtLower[i] = static_cast<char>(
tolower(static_cast<unsigned char>(szExtLower[i])));
CPLTolower(static_cast<unsigned char>(szExtLower[i])));
}

const char *pszTFW = CPLResetExtension(pszBaseFilename, szExtLower);
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogr_srs_pci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ OGRErr OGRSpatialReference::importFromPCI(const char *pszProj,

if (nCode >= -99 && nCode <= 999)
snprintf(szEarthModel, sizeof(szEarthModel), "%c%03d",
toupper(static_cast<unsigned char>(*pszEM)), nCode);
CPLToupper(static_cast<unsigned char>(*pszEM)), nCode);

break;
}
Expand Down
10 changes: 6 additions & 4 deletions ogr/ogrsf_frmts/avc/avc_binwr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,8 @@ AVCBinFile *AVCBinWriteCreateTable(const char *pszInfoPath,
for (i = 0; *pszPtr != '\0' && *pszPtr != '.' && *pszPtr != ' ';
i++, pszPtr++)
{
szCoverName[i] = (char)tolower(static_cast<unsigned char>(*pszPtr));
szCoverName[i] =
(char)CPLTolower(static_cast<unsigned char>(*pszPtr));
}
szCoverName[i] = '\0';

Expand All @@ -1802,13 +1803,14 @@ AVCBinFile *AVCBinWriteCreateTable(const char *pszInfoPath,

for (i = 0; i < 3 && *pszPtr != '\0' && *pszPtr != ' '; i++, pszPtr++)
{
szExt[i] = (char)tolower(static_cast<unsigned char>(*pszPtr));
szExt[i] = (char)CPLTolower(static_cast<unsigned char>(*pszPtr));
}
szExt[i] = '\0';

for (i = 0; *pszPtr != '\0' && *pszPtr != ' '; i++, pszPtr++)
{
szSubclass[i] = (char)tolower(static_cast<unsigned char>(*pszPtr));
szSubclass[i] =
(char)CPLTolower(static_cast<unsigned char>(*pszPtr));
}
szSubclass[i] = '\0';

Expand Down Expand Up @@ -1980,7 +1982,7 @@ AVCBinFile *_AVCBinWriteCreateDBFTable(const char *pszPath,
i++, pszDBFBasename++)
{
psFile->pszFilename[i] =
(char)tolower(static_cast<unsigned char>(*pszDBFBasename));
(char)CPLTolower(static_cast<unsigned char>(*pszDBFBasename));
}

strcat(psFile->pszFilename, ".dbf");
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/avc/avc_e00gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const char *AVCE00GenStartSection(AVCE00GenInfo *psInfo, AVCFileType eType,
for (i = 0; pszClassName[i] != '\0'; i++)
{
psInfo->pszBuf[i] =
(char)toupper(static_cast<unsigned char>(pszClassName[i]));
(char)CPLToupper(static_cast<unsigned char>(pszClassName[i]));
}
psInfo->pszBuf[i] = '\0';
}
Expand Down
5 changes: 3 additions & 2 deletions ogr/ogrsf_frmts/avc/avc_e00read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ static int _AVCE00ReadBuildSqueleton(AVCE00ReadPtr psInfo, char **papszCoverDir)
CPLSPrintf("EXP 0 %s%s.E00", szCWD, osCoverPathTruncated.c_str()));
pcTmp = pszEXPPath;
for (; *pcTmp != '\0'; pcTmp++)
*pcTmp = (char)toupper(static_cast<unsigned char>(*pcTmp));
*pcTmp = (char)CPLToupper(static_cast<unsigned char>(*pcTmp));

/*-----------------------------------------------------------------
* EXP Header
Expand Down Expand Up @@ -1309,7 +1309,8 @@ static int _AVCE00ReadBuildSqueleton(AVCE00ReadPtr psInfo, char **papszCoverDir)
papszCoverDir[iFile]);
pcTmp = (char *)szFname;
for (; *pcTmp != '\0'; pcTmp++)
*pcTmp = (char)toupper(static_cast<unsigned char>(*pcTmp));
*pcTmp =
(char)CPLToupper(static_cast<unsigned char>(*pcTmp));
papszCoverDir[iFile][nLen - 4] = '.';

papszTables = CSLAddString(papszTables, szFname);
Expand Down
9 changes: 5 additions & 4 deletions ogr/ogrsf_frmts/avc/avc_e00write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ static void _AVCE00WriteRenameTable(AVCTableDef *psTableDef,

snprintf(szNewName, sizeof(szNewName), "%s", pszNewCoverName);
for (i = 0; szNewName[i] != '\0'; i++)
szNewName[i] = (char)toupper(static_cast<unsigned char>(szNewName[i]));
szNewName[i] =
(char)CPLToupper(static_cast<unsigned char>(szNewName[i]));

/*-----------------------------------------------------------------
* Extract components from the current table name.
Expand Down Expand Up @@ -662,7 +663,7 @@ static int _AVCE00WriteCreateCoverFile(AVCE00WritePtr psInfo, AVCFileType eType,
* Make sure filename is all lowercase and attempt to create the file
*----------------------------------------------------------------*/
for (i = 0; szFname[i] != '\0'; i++)
szFname[i] = (char)tolower(static_cast<unsigned char>(szFname[i]));
szFname[i] = (char)CPLTolower(static_cast<unsigned char>(szFname[i]));

if (nStatus == 0)
{
Expand Down Expand Up @@ -961,8 +962,8 @@ int AVCE00DeleteCoverage(const char *pszCoverToDelete)
{
/* Convert table filename to lowercases */
for (j = 0; papszFiles[i] && papszFiles[i][j] != '\0'; j++)
papszFiles[i][j] =
(char)tolower(static_cast<unsigned char>(papszFiles[i][j]));
papszFiles[i][j] = (char)CPLTolower(
static_cast<unsigned char>(papszFiles[i][j]));

/* Delete the .DAT file */
pszFname = CPLSPrintf("%s%s.dat", pszInfoPath, papszFiles[i]);
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/dxf/ogr_autocad_services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CPLString ACTextUnescape(const char *pszRawInput, const char *pszEncoding,
if (pszInput[1] == ' ')
osResult += '^';
else
osResult += static_cast<char>(toupper(
osResult += static_cast<char>(CPLToupper(
static_cast<unsigned char>(pszInput[1]))) ^
0x40;
pszInput++;
Expand Down
6 changes: 2 additions & 4 deletions ogr/ogrsf_frmts/edigeo/ogredigeodatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ VSILFILE *OGREDIGEODataSource::OpenFile(const char *pszType,
VSILFILE *fp = VSIFOpenL(osFilename, "rb");
if (fp == nullptr)
{
CPLString osExtLower = osExt;
for (int i = 0; i < (int)osExt.size(); i++)
osExtLower[i] = (char)tolower(static_cast<unsigned char>(osExt[i]));
CPLString osFilename2 = CPLFormCIFilename(
const CPLString osExtLower = CPLString(osExt).tolower();
const CPLString osFilename2 = CPLFormCIFilename(
CPLGetPath(pszName), osTmp.c_str(), osExtLower.c_str());
fp = VSIFOpenL(osFilename2, "rb");
if (fp == nullptr)
Expand Down
3 changes: 2 additions & 1 deletion ogr/ogrsf_frmts/elastic/ogrelasticlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,8 @@ static void decode_geohash_bbox(const char *geohash, double lat[2],
hashlen = static_cast<int>(strlen(geohash));
for (i = 0; i < hashlen; i++)
{
c = static_cast<char>(tolower(static_cast<unsigned char>(geohash[i])));
c = static_cast<char>(
CPLTolower(static_cast<unsigned char>(geohash[i])));
cd = static_cast<char>(strchr(BASE32, c) - BASE32);
for (j = 0; j < 5; j++)
{
Expand Down
5 changes: 2 additions & 3 deletions ogr/ogrsf_frmts/gmlas/ogrgmlasutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ CPLString OGRGMLASTruncateIdentifier(const CPLString &osName,
const char *pszToken = papszTokens[j];
bool bIsCamelCase = false;
// Split parts like camelCase or CamelCase into several tokens
if (pszToken[0] != '\0' &&
islower(static_cast<unsigned char>(pszToken[1])))
if (pszToken[0] != '\0' && pszToken[1] >= 'a' && pszToken[1] <= 'z')
{
bIsCamelCase = true;
bool bLastIsLower = true;
Expand All @@ -63,7 +62,7 @@ CPLString OGRGMLASTruncateIdentifier(const CPLString &osName,
osCurrentPart += pszToken[1];
for (int k = 2; pszToken[k]; ++k)
{
if (isupper(static_cast<unsigned char>(pszToken[k])))
if (pszToken[k] >= 'A' && pszToken[k] <= 'Z')
{
if (!bLastIsLower)
{
Expand Down
8 changes: 4 additions & 4 deletions ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ GetGeometryColumnDescription(odbc::Connection &conn, const CPLString &query,
columnName.end(),
[](char ch1, char ch2)
{
return std::toupper(static_cast<unsigned char>(ch1)) ==
std::toupper(static_cast<unsigned char>(ch2));
return CPLToupper(static_cast<unsigned char>(ch1)) ==
CPLToupper(static_cast<unsigned char>(ch2));
});

if (it != preparedQuery.end())
Expand Down Expand Up @@ -1285,8 +1285,8 @@ std::pair<OGRErr, CPLString> OGRHanaDataSource::LaunderName(const char *name)
if (c == '-' || c == '#')
newName[i] = '_';
else
newName[i] =
static_cast<char>(toupper(static_cast<unsigned char>(c)));
newName[i] = static_cast<char>(
CPLToupper(static_cast<unsigned char>(c)));
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions ogr/ogrsf_frmts/ili/ili2reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ int cmpStr(const string &s1, const string &s2)

while (p1 != s1.end() && p2 != s2.end())
{
if (toupper(static_cast<unsigned char>(*p1)) !=
toupper(static_cast<unsigned char>(*p2)))
return (toupper(static_cast<unsigned char>(*p1)) <
toupper(static_cast<unsigned char>(*p2)))
if (CPLToupper(static_cast<unsigned char>(*p1)) !=
CPLToupper(static_cast<unsigned char>(*p2)))
return (CPLToupper(static_cast<unsigned char>(*p1)) <
CPLToupper(static_cast<unsigned char>(*p2)))
? -1
: 1;
++p1;
Expand Down
4 changes: 2 additions & 2 deletions ogr/ogrsf_frmts/mitab/mitab_feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ const char *TABCustomPoint::GetSymbolStyleString(double dfAngle) const
for (i = 0; i < 7 && *pszPtr != '\0' && *pszPtr != ' '; i++, pszPtr++)
{
szLowerExt[i] =
static_cast<char>(tolower(static_cast<unsigned char>(*pszPtr)));
static_cast<char>(CPLTolower(static_cast<unsigned char>(*pszPtr)));
}
szLowerExt[i] = '\0';

Expand Down Expand Up @@ -6314,7 +6314,7 @@ const char *TABText::GetLabelStyleString() const
for (int i = 0; pszTextString[i]; ++i)
if (isalpha(static_cast<unsigned char>(pszTextString[i])))
pszTextString[i] = static_cast<char>(
toupper(static_cast<unsigned char>(pszTextString[i])));
CPLToupper(static_cast<unsigned char>(pszTextString[i])));

/* Escape the double quote chars and expand the text */
char *pszTmpTextString = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions ogr/ogrsf_frmts/mitab/mitab_indfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ GByte *TABINDFile::BuildKey(int nIndexNumber, const char *pszStr)
int i = 0;
for (i = 0; i < nKeyLength && pszStr[i] != '\0'; i++)
{
m_papbyKeyBuffers[nIndexNumber - 1][i] =
static_cast<GByte>(toupper(static_cast<unsigned char>(pszStr[i])));
m_papbyKeyBuffers[nIndexNumber - 1][i] = static_cast<GByte>(
CPLToupper(static_cast<unsigned char>(pszStr[i])));
}

/* Pad the end of the buffer with '\0' */
Expand Down
8 changes: 4 additions & 4 deletions ogr/ogrsf_frmts/mitab/mitab_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ GBool TABAdjustFilenameExtension(char *pszFname)
for (int i = static_cast<int>(strlen(pszFname)) - 1;
i >= 0 && pszFname[i] != '.'; i--)
{
pszFname[i] =
static_cast<char>(toupper(static_cast<unsigned char>(pszFname[i])));
pszFname[i] = static_cast<char>(
CPLToupper(static_cast<unsigned char>(pszFname[i])));
}

if (VSIStatL(pszFname, &sStatBuf) == 0)
Expand All @@ -253,8 +253,8 @@ GBool TABAdjustFilenameExtension(char *pszFname)
for (int i = static_cast<int>(strlen(pszFname)) - 1;
i >= 0 && pszFname[i] != '.'; i--)
{
pszFname[i] =
static_cast<char>(tolower(static_cast<unsigned char>(pszFname[i])));
pszFname[i] = static_cast<char>(
CPLTolower(static_cast<unsigned char>(pszFname[i])));
}

if (VSIStatL(pszFname, &sStatBuf) == 0)
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/mssqlspatial/ogrmssqlspatialdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ char *OGRMSSQLSpatialDataSource::LaunderName(const char *pszSrcName)
for (i = 0; pszSafeName[i] != '\0'; i++)
{
pszSafeName[i] =
(char)tolower(static_cast<unsigned char>(pszSafeName[i]));
(char)CPLTolower(static_cast<unsigned char>(pszSafeName[i]));
if (pszSafeName[i] == '-' || pszSafeName[i] == '#')
pszSafeName[i] = '_';
}
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/mysql/ogrmysqldatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ char *OGRMySQLDataSource::LaunderName(const char *pszSrcName)
for (int i = 0; pszSafeName[i] != '\0'; i++)
{
pszSafeName[i] =
(char)tolower(static_cast<unsigned char>(pszSafeName[i]));
(char)CPLTolower(static_cast<unsigned char>(pszSafeName[i]));
if (pszSafeName[i] == '-' || pszSafeName[i] == '#')
pszSafeName[i] = '_';
}
Expand Down
4 changes: 2 additions & 2 deletions ogr/ogrsf_frmts/oci/ogrocisession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ void OGROCISession::CleanName(char *pszName)

for (i = 0; pszName[i] != '\0'; i++)
{
pszName[i] =
static_cast<char>(toupper(static_cast<unsigned char>(pszName[i])));
pszName[i] = static_cast<char>(
CPLToupper(static_cast<unsigned char>(pszName[i])));

if ((pszName[i] < '0' || pszName[i] > '9') &&
(pszName[i] < 'A' || pszName[i] > 'Z') && pszName[i] != '_')
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/pgdump/ogrpgdumpdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ char *OGRPGCommonLaunderName(const char *pszSrcName, const char *pszDebugPrefix,
if (static_cast<unsigned char>(pszSafeName[i]) <= 127)
{
pszSafeName[i] =
(char)tolower(static_cast<unsigned char>(pszSafeName[i]));
(char)CPLTolower(static_cast<unsigned char>(pszSafeName[i]));
if (pszSafeName[i] == '\'' || pszSafeName[i] == '-' ||
pszSafeName[i] == '#')
{
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3746,7 +3746,7 @@ char *OGRSQLiteDataSource::LaunderName(const char *pszSrcName)
for (int i = 0; pszSafeName[i] != '\0'; i++)
{
pszSafeName[i] =
(char)tolower(static_cast<unsigned char>(pszSafeName[i]));
(char)CPLTolower(static_cast<unsigned char>(pszSafeName[i]));
if (pszSafeName[i] == '\'' || pszSafeName[i] == '-' ||
pszSafeName[i] == '#')
pszSafeName[i] = '_';
Expand Down
Loading

0 comments on commit 8039763

Please sign in to comment.