Make use of string_util

This commit is contained in:
Pengfei
2021-07-16 22:10:49 +08:00
parent 27988d09e2
commit 0c04e31405
+6 -7
View File
@@ -13,6 +13,7 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/string_util.h"
#include "common/swap.h" #include "common/swap.h"
namespace Core { namespace Core {
@@ -292,10 +293,8 @@ public:
} }
const auto& entry = this->directory_entry_table[index]; const auto& entry = this->directory_entry_table[index];
std::array<char, 17> name_data = {}; // Append a null terminator const std::string name =
std::memcpy(name_data.data(), entry.name.data(), entry.name.size()); Common::StringFromFixedZeroTerminatedBuffer(entry.name.data(), entry.name.size());
const std::string name = name_data.data();
std::string new_path = name.empty() ? path : path + name + "/"; // Name is empty for root std::string new_path = name.empty() ? path : path + name + "/"; // Name is empty for root
if (!FileUtil::CreateFullPath(new_path)) { if (!FileUtil::CreateFullPath(new_path)) {
@@ -311,10 +310,10 @@ public:
return false; return false;
} }
const auto& file_entry = this->file_entry_table[cur]; const auto& file_entry = this->file_entry_table[cur];
std::memcpy(name_data.data(), file_entry.name.data(), file_entry.name.size()); const std::string file_name = Common::StringFromFixedZeroTerminatedBuffer(
file_entry.name.data(), file_entry.name.size());
if (!static_cast<const T*>(this)->ExtractFile(new_path + std::string{name_data.data()}, if (!static_cast<const T*>(this)->ExtractFile(new_path + file_name, cur)) {
cur)) {
return false; return false;
} }
cur = this->file_entry_table[cur].next_sibling_index; cur = this->file_entry_table[cur].next_sibling_index;