From 842634cd809e0c9e19b84cfbd57ade916c2fb4e6 Mon Sep 17 00:00:00 2001 From: hogliux Date: Thu, 24 Aug 2017 11:30:11 +0100 Subject: [PATCH] Added an option to ignore the case when getting an entry inside a zip file with ZipFile::getEntry --- modules/juce_core/zip/juce_ZipFile.cpp | 13 +++++++++---- modules/juce_core/zip/juce_ZipFile.h | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/juce_core/zip/juce_ZipFile.cpp b/modules/juce_core/zip/juce_ZipFile.cpp index 77b2e83001..87e461f14f 100644 --- a/modules/juce_core/zip/juce_ZipFile.cpp +++ b/modules/juce_core/zip/juce_ZipFile.cpp @@ -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) diff --git a/modules/juce_core/zip/juce_ZipFile.h b/modules/juce_core/zip/juce_ZipFile.h index d8d95da567..ca83230577 100644 --- a/modules/juce_core/zip/juce_ZipFile.h +++ b/modules/juce_core/zip/juce_ZipFile.h @@ -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();