MCPcopy Create free account
hub / github.com/OSGeo/gdal / CSLRemoveStrings

Function CSLRemoveStrings

port/cpl_string.cpp:572–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

570 */
571
572char **CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete,
573 int nNumToRemove, char ***ppapszRetStrings)
574{
575 const int nSrcLines = CSLCount(papszStrList);
576
577 if (nNumToRemove < 1 || nSrcLines == 0)
578 return papszStrList; // Nothing to do!
579
580 // If operation will result in an empty StringList, don't waste
581 // time here.
582 const int nDstLines = nSrcLines - nNumToRemove;
583 if (nDstLines < 1)
584 {
585 CSLDestroy(papszStrList);
586 return nullptr;
587 }
588
589 // Remove lines from the source StringList.
590 // Either free() each line or store them to a new StringList depending on
591 // the caller's choice.
592 char **ppszDst = papszStrList + nFirstLineToDelete;
593
594 if (ppapszRetStrings == nullptr)
595 {
596 // free() all the strings that will be removed.
597 for (int i = 0; i < nNumToRemove; ++i)
598 {
599 CPLFree(*ppszDst);
600 *ppszDst = nullptr;
601 }
602 }
603 else
604 {
605 // Store the strings to remove in a new StringList.
606 *ppapszRetStrings =
607 static_cast<char **>(CPLCalloc(nNumToRemove + 1, sizeof(char *)));
608
609 for (int i = 0; i < nNumToRemove; ++i)
610 {
611 (*ppapszRetStrings)[i] = *ppszDst;
612 *ppszDst = nullptr;
613 ++ppszDst;
614 }
615 }
616
617 // Shift down all the lines that follow the lines to remove.
618 if (nFirstLineToDelete == -1 || nFirstLineToDelete > nSrcLines)
619 nFirstLineToDelete = nDstLines;
620
621 char **ppszSrc = papszStrList + nFirstLineToDelete + nNumToRemove;
622 ppszDst = papszStrList + nFirstLineToDelete;
623
624 for (; *ppszSrc != nullptr; ++ppszSrc, ++ppszDst)
625 {
626 *ppszDst = *ppszSrc;
627 }
628 // Move the NULL pointer at the end of the StringList.
629 *ppszDst = *ppszSrc;

Callers 15

RemoveStyleMethod · 0.85
AlterFieldDefnMethod · 0.85
GDAL_IMD_AA2RFunction · 0.85
CreateCopyMethod · 0.85
cplstringlist.cppFile · 0.85
CreateCopyMethod · 0.85
SetCategoryNamesMethod · 0.85
ParseIdentificatorMethod · 0.85
OpenMethod · 0.85
SetGeoTransformMethod · 0.85
PushMetadataToPamMethod · 0.85
SetTileOOMethod · 0.85

Calls 2

CSLCountFunction · 0.85
CPLCallocFunction · 0.85

Tested by

no test coverage detected