Replace Maybe with std::optional
With c++17, std::optional provides the functionality that Maybe
provided.
Bug: 183215655
Test: aapt2_tests
Change-Id: I62bb9c2fa4985dc5217a6ed153df92b85ad9a034
diff --git a/tools/aapt2/util/Files.cpp b/tools/aapt2/util/Files.cpp
index 5d57de6..5d2eda3 100644
--- a/tools/aapt2/util/Files.cpp
+++ b/tools/aapt2/util/Files.cpp
@@ -50,12 +50,12 @@
FileType GetFileType(const std::string& path) {
std::wstring path_utf16;
if (!::android::base::UTF8PathToWindowsLongPath(path.c_str(), &path_utf16)) {
- return FileType::kNonexistant;
+ return FileType::kNonExistant;
}
DWORD result = GetFileAttributesW(path_utf16.c_str());
if (result == INVALID_FILE_ATTRIBUTES) {
- return FileType::kNonexistant;
+ return FileType::kNonExistant;
}
if (result & FILE_ATTRIBUTE_DIRECTORY) {
@@ -72,7 +72,7 @@
if (result == -1) {
if (errno == ENOENT || errno == ENOTDIR) {
- return FileType::kNonexistant;
+ return FileType::kNonExistant;
}
return FileType::kUnknown;
}
@@ -208,7 +208,7 @@
return out_path;
}
-Maybe<FileMap> MmapPath(const std::string& path, std::string* out_error) {
+std::optional<FileMap> MmapPath(const std::string& path, std::string* out_error) {
int flags = O_RDONLY | O_CLOEXEC | O_BINARY;
unique_fd fd(TEMP_FAILURE_RETRY(::android::base::utf8::open(path.c_str(), flags)));
if (fd == -1) {
@@ -344,8 +344,8 @@
return true;
}
-Maybe<std::vector<std::string>> FindFiles(const android::StringPiece& path, IDiagnostics* diag,
- const FileFilter* filter) {
+std::optional<std::vector<std::string>> FindFiles(const android::StringPiece& path,
+ IDiagnostics* diag, const FileFilter* filter) {
const std::string root_dir = path.to_string();
std::unique_ptr<DIR, decltype(closedir)*> d(opendir(root_dir.data()), closedir);
if (!d) {
@@ -382,7 +382,7 @@
for (const std::string& subdir : subdirs) {
std::string full_subdir = root_dir;
AppendPath(&full_subdir, subdir);
- Maybe<std::vector<std::string>> subfiles = FindFiles(full_subdir, diag, filter);
+ std::optional<std::vector<std::string>> subfiles = FindFiles(full_subdir, diag, filter);
if (!subfiles) {
return {};
}