ziparchive: add a std::string_view overload to Next.
Recovery wanted this, and frameworks/base/ wants it too.
Bug: http://b/129068177
Test: treehugger
Change-Id: I8ee3f7c058fc9c1cde829da613ed15be5ce7b41e
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index f4b6c74..e966295 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -748,10 +748,19 @@
}
int32_t Next(void* cookie, ZipEntry* data, std::string* name) {
+ std::string_view sv;
+ int32_t result = Next(cookie, data, &sv);
+ if (result == 0 && name) {
+ *name = std::string(sv);
+ }
+ return result;
+}
+
+int32_t Next(void* cookie, ZipEntry* data, std::string_view* name) {
ZipString zs;
int32_t result = Next(cookie, data, &zs);
- if (result == 0) {
- *name = std::string(reinterpret_cast<const char*>(zs.name), zs.name_length);
+ if (result == 0 && name) {
+ *name = std::string_view(reinterpret_cast<const char*>(zs.name), zs.name_length);
}
return result;
}