Browse Source

Added an option to ignore the case when getting an entry inside a zip file with ZipFile::getEntry

tags/2021-05-28
hogliux 8 years ago
parent
commit
842634cd80
2 changed files with 11 additions and 6 deletions
  1. +9
    -4
      modules/juce_core/zip/juce_ZipFile.cpp
  2. +2
    -2
      modules/juce_core/zip/juce_ZipFile.h

+ 9
- 4
modules/juce_core/zip/juce_ZipFile.cpp View File

@@ -263,18 +263,23 @@ const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const noexcept
return nullptr;
}
int ZipFile::getIndexOfFileName (const String& fileName) const noexcept
int ZipFile::getIndexOfFileName (const String& fileName, bool ignoreCase) const noexcept
{
for (int i = 0; i < entries.size(); ++i)
if (entries.getUnchecked (i)->entry.filename == fileName)
{
auto& entryFilename = entries.getUnchecked (i)->entry.filename;
if (ignoreCase ? entryFilename.equalsIgnoreCase (fileName)
: entryFilename == fileName)
return i;
}
return -1;
}
const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const noexcept
const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName, bool ignoreCase) const noexcept
{
return getEntry (getIndexOfFileName (fileName));
return getEntry (getIndexOfFileName (fileName, ignoreCase));
}
InputStream* ZipFile::createStreamForEntry (const int index)


+ 2
- 2
modules/juce_core/zip/juce_ZipFile.h View File

@@ -95,7 +95,7 @@ public:
@see ZipFile::ZipEntry
*/
int getIndexOfFileName (const String& fileName) const noexcept;
int getIndexOfFileName (const String& fileName, bool ignoreCase = false) const noexcept;
/** Returns a structure that describes one of the entries in the zip file.
@@ -104,7 +104,7 @@ public:
@see ZipFile::ZipEntry
*/
const ZipEntry* getEntry (const String& fileName) const noexcept;
const ZipEntry* getEntry (const String& fileName, bool ignoreCase = false) const noexcept;
/** Sorts the list of entries, based on the filename. */
void sortEntriesByFilename();


Loading…
Cancel
Save