Skip to content

Commit

Permalink
Merge pull request #10060 from AbelPau/MiraMonVector-fix-a-case-sensi…
Browse files Browse the repository at this point in the history
…tive-comparison

MiraMonVector: fix a case sensitive comparison
  • Loading branch information
rouault committed May 29, 2024
2 parents c2b6e73 + 57b50d4 commit 6314e98
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
28 changes: 25 additions & 3 deletions ogr/ogrsf_frmts/miramon/mm_gdal_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,13 +1262,13 @@ int MM_ReadExtendedDBFHeaderFromFile(const char *szFileName,
if (11 > (read_bytes = fread_function(charset_cpg, 1, 10, f_cpg)))
{
charset_cpg[read_bytes] = '\0';
p = strstr(charset_cpg, "UTF-8");
p = MM_stristr(charset_cpg, "UTF-8");
if (p)
pMMBDXP->CharSet = MM_JOC_CARAC_UTF8_DBF;
p = strstr(charset_cpg, "UTF8");
p = MM_stristr(charset_cpg, "UTF8");
if (p)
pMMBDXP->CharSet = MM_JOC_CARAC_UTF8_DBF;
p = strstr(charset_cpg, "ISO-8859-1");
p = MM_stristr(charset_cpg, "ISO-8859-1");
if (p)
pMMBDXP->CharSet = MM_JOC_CARAC_ANSI_DBASE;
}
Expand Down Expand Up @@ -1947,6 +1947,28 @@ char *MM_oemansi_n(char *szszChain, size_t n_bytes)
return szszChain;
}

// An implementation of non-sensitive strstr()
char *MM_stristr(const char *haystack, const char *needle)
{
if (!haystack)
return nullptr;

if (!needle)
return nullptr;

if (!*needle)
return (char *)haystack;

char *p1 = (char *)haystack;
while (*p1 != '\0' && !EQUALN(p1, needle, strlen(needle)))
p1++;

if (*p1 == '\0')
return nullptr;

return p1;
}

char *MM_oemansi(char *szszChain)
{
return MM_oemansi_n(szszChain, SIZE_MAX);
Expand Down
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/miramon/mm_gdal_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ extern char szNumberOfElementaryPolygonsSpa[];

char *MM_oemansi(char *szcadena);
char *MM_oemansi_n(char *szcadena, size_t n_bytes);
char *MM_stristr(const char *haystack, const char *needle);
void MM_InitializeField(struct MM_FIELD *camp);
struct MM_FIELD *MM_CreateAllFields(MM_EXT_DBF_N_FIELDS ncamps);
MM_FIRST_RECORD_OFFSET_TYPE
Expand Down
6 changes: 3 additions & 3 deletions ogr/ogrsf_frmts/miramon/mm_wrlayr.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ static int MMChangeFinalPartOfTheName(char *pszName, size_t nMaxSizeOfName,
// It's the implementation on windows of the linux strrstr()
// pszLastFound = strrstr(pszWhereToFind, pszFinalPart);
pszWhereToFind = pszName;
while (nullptr != (pAux = strstr(pszWhereToFind, pszFinalPart)))
while (nullptr != (pAux = MM_stristr(pszWhereToFind, pszFinalPart)))
{
pszLastFound = pAux;
pszWhereToFind = pAux + strlen(pAux);
Expand Down Expand Up @@ -5387,7 +5387,7 @@ int MMReturnCodeFromMM_m_idofic(char *pMMSRS_or_pSRS, char *szResult,
"Wrong format in data\\MM_m_idofic.csv.\n");
return 1;
}
id_geodes = strstr(pszLine, "ID_GEODES");
id_geodes = MM_stristr(pszLine, "ID_GEODES");
if (!id_geodes)
{
fclose_function(pfMMSRS);
Expand All @@ -5396,7 +5396,7 @@ int MMReturnCodeFromMM_m_idofic(char *pMMSRS_or_pSRS, char *szResult,
return 1;
}
id_geodes[strlen("ID_GEODES")] = '\0';
psidgeodes = strstr(pszLine, "PSIDGEODES");
psidgeodes = MM_stristr(pszLine, "PSIDGEODES");
if (!psidgeodes)
{
fclose_function(pfMMSRS);
Expand Down

0 comments on commit 6314e98

Please sign in to comment.