diff options
author | Yusuke Sato <yusukes@google.com> | 2015-06-29 20:22:38 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-06-29 20:22:38 +0000 |
commit | 7522b3d58f9b9f397b8f25c7078273f2c0859693 (patch) | |
tree | 7d3506520c5cc11a314381da875ccfa3a8464b15 /include | |
parent | 40e8b27a58d7fd3834d4f5d530ca93a428a9d17d (diff) | |
parent | 95a37e756e42507d35c8d16f952cd696f7d6109d (diff) | |
download | core-7522b3d58f9b9f397b8f25c7078273f2c0859693.tar.gz core-7522b3d58f9b9f397b8f25c7078273f2c0859693.tar.bz2 core-7522b3d58f9b9f397b8f25c7078273f2c0859693.zip |
am 95a37e75: am 692dc75d: Merge "Rename ZipEntryName to ZipString"
* commit '95a37e756e42507d35c8d16f952cd696f7d6109d':
Rename ZipEntryName to ZipString
Diffstat (limited to 'include')
-rw-r--r-- | include/ziparchive/zip_archive.h | 35 |
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 |