diff options
author | 2019-06-14 15:28:38 -0700 | |
---|---|---|
committer | 2019-06-17 16:47:58 +0000 | |
commit | 78de4f999dffd9638f5add13240d97fd7b3293ec (patch) | |
tree | e63f21950490d2639d2aa6532885ce91b95836bd | |
parent | aa4c25ed7500668cb44b9446c04b78a8e214fecb (diff) |
Move off ZipString and over to std::string/std::string_view as appropriate.
Bug: http://b/129068177
Test: treehugger
Change-Id: Ib46761d89772d3a3c655a39df573fd305c117d19
-rw-r--r-- | libs/androidfw/ApkAssets.cpp | 4 | ||||
-rw-r--r-- | libs/androidfw/ZipFileRO.cpp | 8 | ||||
-rw-r--r-- | tools/aapt2/cmd/Convert_test.cpp | 2 | ||||
-rw-r--r-- | tools/aapt2/io/ZipArchive.cpp | 8 |
4 files changed, 9 insertions, 13 deletions
diff --git a/libs/androidfw/ApkAssets.cpp b/libs/androidfw/ApkAssets.cpp index 61e32301dc85..237c1e970b17 100644 --- a/libs/androidfw/ApkAssets.cpp +++ b/libs/androidfw/ApkAssets.cpp @@ -216,7 +216,7 @@ bool ApkAssets::ForEachFile(const std::string& root_path, return false; } - ::ZipString name; + std::string name; ::ZipEntry entry; // We need to hold back directories because many paths will contain them and we want to only @@ -225,7 +225,7 @@ bool ApkAssets::ForEachFile(const std::string& root_path, int32_t result; while ((result = ::Next(cookie, &entry, &name)) == 0) { - StringPiece full_file_path(reinterpret_cast<const char*>(name.name), name.name_length); + StringPiece full_file_path(name); StringPiece leaf_file_path = full_file_path.substr(root_path_full.size()); if (!leaf_file_path.empty()) { diff --git a/libs/androidfw/ZipFileRO.cpp b/libs/androidfw/ZipFileRO.cpp index ee5f7783635d..e77ac3df474c 100644 --- a/libs/androidfw/ZipFileRO.cpp +++ b/libs/androidfw/ZipFileRO.cpp @@ -39,7 +39,7 @@ using namespace android; class _ZipEntryRO { public: ZipEntry entry; - ZipString name; + std::string_view name; void *cookie; _ZipEntryRO() : cookie(NULL) {} @@ -96,7 +96,7 @@ ZipEntryRO ZipFileRO::findEntryByName(const char* entryName) const { _ZipEntryRO* data = new _ZipEntryRO; - data->name = ZipString(entryName); + data->name = entryName; const int32_t error = FindEntry(mHandle, entryName, &(data->entry)); if (error) { @@ -194,14 +194,14 @@ int ZipFileRO::getEntryFileName(ZipEntryRO entry, char* buffer, size_t bufLen) const { const _ZipEntryRO* zipEntry = reinterpret_cast<_ZipEntryRO*>(entry); - const uint16_t requiredSize = zipEntry->name.name_length + 1; + const uint16_t requiredSize = zipEntry->name.length() + 1; if (bufLen < requiredSize) { ALOGW("Buffer too short, requires %d bytes for entry name", requiredSize); return requiredSize; } - memcpy(buffer, zipEntry->name.name, requiredSize - 1); + memcpy(buffer, zipEntry->name.data(), requiredSize - 1); buffer[requiredSize - 1] = '\0'; return 0; diff --git a/tools/aapt2/cmd/Convert_test.cpp b/tools/aapt2/cmd/Convert_test.cpp index ddc146cd27f4..f35237ec25e3 100644 --- a/tools/aapt2/cmd/Convert_test.cpp +++ b/tools/aapt2/cmd/Convert_test.cpp @@ -132,7 +132,7 @@ TEST_F(ConvertTest, DuplicateEntriesWrittenOnce) { int count = 0; // Can't pass nullptrs into Next() - ZipString zip_name; + std::string zip_name; ZipEntry zip_data; while ((result = Next(cookie, &zip_data, &zip_name)) == 0) { diff --git a/tools/aapt2/io/ZipArchive.cpp b/tools/aapt2/io/ZipArchive.cpp index a692ba5d26c0..4380586b1d3c 100644 --- a/tools/aapt2/io/ZipArchive.cpp +++ b/tools/aapt2/io/ZipArchive.cpp @@ -123,13 +123,9 @@ std::unique_ptr<ZipFileCollection> ZipFileCollection::Create( using IterationEnder = std::unique_ptr<void, decltype(EndIteration)*>; IterationEnder iteration_ender(cookie, EndIteration); - ZipString zip_entry_name; + std::string zip_entry_path; ZipEntry zip_data; - while ((result = Next(cookie, &zip_data, &zip_entry_name)) == 0) { - std::string zip_entry_path = - std::string(reinterpret_cast<const char*>(zip_entry_name.name), - zip_entry_name.name_length); - + while ((result = Next(cookie, &zip_data, &zip_entry_path)) == 0) { // Do not add folders to the file collection if (util::EndsWith(zip_entry_path, "/")) { continue; |