Move GDALRemoveSQLComments() to CPLRemoveSQLComments()
This commit is contained in:
parent
65a47f45ea
commit
7ab4e4fa46
|
@ -154,53 +154,6 @@ void GDALRemoveBOM(GByte *pabyData)
|
|||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* GDALRemoveSQLComments() */
|
||||
/************************************************************************/
|
||||
|
||||
std::string GDALRemoveSQLComments(const std::string &osInput)
|
||||
{
|
||||
const CPLStringList aosLines(
|
||||
CSLTokenizeStringComplex(osInput.c_str(), "\r\n", FALSE, FALSE));
|
||||
std::string osSQL;
|
||||
for (const char *pszLine : aosLines)
|
||||
{
|
||||
char chQuote = 0;
|
||||
int i = 0;
|
||||
for (; pszLine[i] != '\0'; ++i)
|
||||
{
|
||||
if (chQuote)
|
||||
{
|
||||
if (pszLine[i] == chQuote)
|
||||
{
|
||||
if (pszLine[i + 1] == chQuote)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
chQuote = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (pszLine[i] == '\'' || pszLine[i] == '"')
|
||||
{
|
||||
chQuote = pszLine[i];
|
||||
}
|
||||
else if (pszLine[i] == '-' && pszLine[i + 1] == '-')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
osSQL.append(pszLine, i);
|
||||
}
|
||||
osSQL += ' ';
|
||||
}
|
||||
return osSQL;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* ArgIsNumeric() */
|
||||
/************************************************************************/
|
||||
|
|
|
@ -94,7 +94,6 @@ std::vector<std::string> CPL_DLL
|
|||
GetOutputDriversFor(const char *pszDestFilename, int nFlagRasterVector);
|
||||
CPLString CPL_DLL GetOutputDriverForRaster(const char *pszDestFilename);
|
||||
void GDALRemoveBOM(GByte *pabyData);
|
||||
std::string GDALRemoveSQLComments(const std::string &osInput);
|
||||
|
||||
int ArgIsNumeric(const char *pszArg);
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ GDALRasterizeOptionsGetParser(GDALRasterizeOptions *psOptions,
|
|||
char *pszSQLStatement =
|
||||
reinterpret_cast<char *>(pabyRet);
|
||||
psOptions->osSQL = CPLStrdup(
|
||||
GDALRemoveSQLComments(pszSQLStatement).c_str());
|
||||
CPLRemoveSQLComments(pszSQLStatement).c_str());
|
||||
VSIFree(pszSQLStatement);
|
||||
}
|
||||
})
|
||||
|
|
|
@ -7176,7 +7176,7 @@ static std::unique_ptr<GDALArgumentParser> GDALVectorTranslateOptionsGetParser(
|
|||
GDALRemoveBOM(pabyRet);
|
||||
char *pszSQLStatement = reinterpret_cast<char *>(pabyRet);
|
||||
psOptions->osSQLStatement =
|
||||
GDALRemoveSQLComments(pszSQLStatement);
|
||||
CPLRemoveSQLComments(pszSQLStatement);
|
||||
VSIFree(pszSQLStatement);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -2589,7 +2589,7 @@ GDALVectorInfoOptionsNew(char **papszArgv,
|
|||
GDALRemoveBOM(pabyRet);
|
||||
char *pszSQLStatement = reinterpret_cast<char *>(pabyRet);
|
||||
psOptions->osSQLStatement =
|
||||
GDALRemoveSQLComments(pszSQLStatement);
|
||||
CPLRemoveSQLComments(pszSQLStatement);
|
||||
VSIFree(pabyRet);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -3161,3 +3161,56 @@ int CPLTolower(int c)
|
|||
{
|
||||
return (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* CPLRemoveSQLComments() */
|
||||
/************************************************************************/
|
||||
|
||||
/** Remove SQL comments from a string
|
||||
*
|
||||
* @param osInput Input string.
|
||||
* @since GDAL 3.11
|
||||
*/
|
||||
std::string CPLRemoveSQLComments(const std::string &osInput)
|
||||
{
|
||||
const CPLStringList aosLines(
|
||||
CSLTokenizeStringComplex(osInput.c_str(), "\r\n", FALSE, FALSE));
|
||||
std::string osSQL;
|
||||
for (const char *pszLine : aosLines)
|
||||
{
|
||||
char chQuote = 0;
|
||||
int i = 0;
|
||||
for (; pszLine[i] != '\0'; ++i)
|
||||
{
|
||||
if (chQuote)
|
||||
{
|
||||
if (pszLine[i] == chQuote)
|
||||
{
|
||||
if (pszLine[i + 1] == chQuote)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
chQuote = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (pszLine[i] == '\'' || pszLine[i] == '"')
|
||||
{
|
||||
chQuote = pszLine[i];
|
||||
}
|
||||
else if (pszLine[i] == '-' && pszLine[i + 1] == '-')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
if (!osSQL.empty())
|
||||
osSQL += ' ';
|
||||
osSQL.append(pszLine, i);
|
||||
}
|
||||
}
|
||||
return osSQL;
|
||||
}
|
||||
|
|
|
@ -270,6 +270,15 @@ int CPL_DLL CPLCanRecode(const char *pszTestStr, const char *pszSrcEncoding,
|
|||
const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT;
|
||||
CPL_C_END
|
||||
|
||||
#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
|
||||
|
||||
extern "C++"
|
||||
{
|
||||
std::string CPL_DLL CPLRemoveSQLComments(const std::string &osInput);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/************************************************************************/
|
||||
/* CPLString */
|
||||
/************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue