summaryrefslogtreecommitdiff
path: root/include/ziparchive/zip_archive.h
diff options
context:
space:
mode:
authorYusuke Sato <yusukes@google.com>2015-06-25 14:39:19 -0700
committerYusuke Sato <yusukes@google.com>2015-06-26 10:34:01 -0700
commit07447544adbde8f688806b43f47c182eaeda4bb3 (patch)
treee96c7b8d3353d0e506824044c8216c09cd77300d /include/ziparchive/zip_archive.h
parentf1d3d3b2477a813805b71099c60e07d36dbb225a (diff)
Rename ZipEntryName to ZipString
since the struct is now used for other purposes. Also add some comparator functions to the struct to simplify zip_archive.cc. This is a follow-up CL for f1d3d3b2477a813805b71099c60e07d36dbb225a. Bug: 21957428 Change-Id: I60d4171eeacc561d59226d946e9eb5f9c96d80cf
Diffstat (limited to 'include/ziparchive/zip_archive.h')
-rw-r--r--include/ziparchive/zip_archive.h35
1 files changed, 25 insertions, 10 deletions
diff --git a/include/ziparchive/zip_archive.h b/include/ziparchive/zip_archive.h
index 3b0068370..5ef2ab0d7 100644
--- a/include/ziparchive/zip_archive.h
+++ b/include/ziparchive/zip_archive.h
@@ -33,17 +33,33 @@ enum {
kCompressDeflated = 8, // standard deflate
};
-struct ZipEntryName {
+struct ZipString {
const uint8_t* name;
uint16_t name_length;
- ZipEntryName() {}
+ ZipString() {}
/*
* entry_name has to be an c-style string with only ASCII characters.
*/
- explicit ZipEntryName(const char* entry_name)
+ explicit ZipString(const char* entry_name)
: name(reinterpret_cast<const uint8_t*>(entry_name)), name_length(strlen(entry_name)) {}
+
+ bool operator==(const ZipString& rhs) const {
+ return name && (name_length == rhs.name_length) &&
+ (memcmp(name, rhs.name, name_length) == 0);
+ }
+
+ bool StartsWith(const ZipString& prefix) const {
+ return name && (name_length >= prefix.name_length) &&
+ (memcmp(name, prefix.name, prefix.name_length) == 0);
+ }
+
+ bool EndsWith(const ZipString& suffix) const {
+ return name && (name_length >= suffix.name_length) &&
+ (memcmp(name + name_length - suffix.name_length, suffix.name,
+ suffix.name_length) == 0);
+ }
};
/*
@@ -136,7 +152,7 @@ void CloseArchive(ZipArchiveHandle handle);
* and length, a call to VerifyCrcAndLengths must be made after entry data
* has been processed.
*/
-int32_t FindEntry(const ZipArchiveHandle handle, const ZipEntryName& entryName,
+int32_t FindEntry(const ZipArchiveHandle handle, const ZipString& entryName,
ZipEntry* data);
/*
@@ -147,15 +163,14 @@ int32_t FindEntry(const ZipArchiveHandle handle, const ZipEntryName& entryName,
* calls to Next. All calls to StartIteration must be matched by a call to
* EndIteration to free any allocated memory.
*
- * This method also accepts an optional prefix to restrict iteration to
- * entry names that start with |optional_prefix|.
+ * This method also accepts optional prefix and suffix to restrict iteration to
+ * entry names that start with |optional_prefix| or end with |optional_suffix|.
*
* Returns 0 on success and negative values on failure.
*/
int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr,
- const ZipEntryName* optional_prefix,
- // TODO: Remove the default parameter.
- const ZipEntryName* optional_suffix = NULL);
+ const ZipString* optional_prefix,
+ const ZipString* optional_suffix);
/*
* Advance to the next element in the zipfile in iteration order.
@@ -163,7 +178,7 @@ int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr,
* Returns 0 on success, -1 if there are no more elements in this
* archive and lower negative values on failure.
*/
-int32_t Next(void* cookie, ZipEntry* data, ZipEntryName *name);
+int32_t Next(void* cookie, ZipEntry* data, ZipString* name);
/*
* End iteration over all entries of a zip file and frees the memory allocated