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/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index e0e80ac..ead06bf 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -40,8 +40,7 @@
namespace aapt {
namespace ResourceUtils {
-Maybe<ResourceName> ToResourceName(
- const android::ResTable::resource_name& name_in) {
+std::optional<ResourceName> ToResourceName(const android::ResTable::resource_name& name_in) {
// TODO: Remove this when ResTable and AssetManager(1) are removed from AAPT2
ResourceName name_out;
if (!name_in.package) {
@@ -78,7 +77,7 @@
return name_out;
}
-Maybe<ResourceName> ToResourceName(const android::AssetManager2::ResourceName& name_in) {
+std::optional<ResourceName> ToResourceName(const android::AssetManager2::ResourceName& name_in) {
ResourceName name_out;
if (!name_in.package) {
return {};
@@ -251,8 +250,7 @@
* <[*]package>:[style/]<entry>
* [[*]package:style/]<entry>
*/
-Maybe<Reference> ParseStyleParentReference(const StringPiece& str,
- std::string* out_error) {
+std::optional<Reference> ParseStyleParentReference(const StringPiece& str, std::string* out_error) {
if (str.empty()) {
return {};
}
@@ -301,7 +299,7 @@
return result;
}
-Maybe<Reference> ParseXmlAttributeName(const StringPiece& str) {
+std::optional<Reference> ParseXmlAttributeName(const StringPiece& str) {
StringPiece trimmed_str = util::TrimWhitespace(str);
const char* start = trimmed_str.data();
const char* const end = start + trimmed_str.size();
@@ -326,7 +324,7 @@
}
ref.name = ResourceName(package, ResourceType::kAttr, name.empty() ? trimmed_str : name);
- return Maybe<Reference>(std::move(ref));
+ return std::optional<Reference>(std::move(ref));
}
std::unique_ptr<Reference> TryParseReference(const StringPiece& str,
@@ -488,18 +486,18 @@
: util::make_unique<BinaryPrimitive>(value);
}
-Maybe<bool> ParseBool(const StringPiece& str) {
+std::optional<bool> ParseBool(const StringPiece& str) {
StringPiece trimmed_str(util::TrimWhitespace(str));
if (trimmed_str == "true" || trimmed_str == "TRUE" || trimmed_str == "True") {
- return Maybe<bool>(true);
+ return std::optional<bool>(true);
} else if (trimmed_str == "false" || trimmed_str == "FALSE" ||
trimmed_str == "False") {
- return Maybe<bool>(false);
+ return std::optional<bool>(false);
}
return {};
}
-Maybe<uint32_t> ParseInt(const StringPiece& str) {
+std::optional<uint32_t> ParseInt(const StringPiece& str) {
std::u16string str16 = util::Utf8ToUtf16(str);
android::Res_value value;
if (android::ResTable::stringToInt(str16.data(), str16.size(), &value)) {
@@ -508,7 +506,7 @@
return {};
}
-Maybe<ResourceId> ParseResourceId(const StringPiece& str) {
+std::optional<ResourceId> ParseResourceId(const StringPiece& str) {
StringPiece trimmed_str(util::TrimWhitespace(str));
std::u16string str16 = util::Utf8ToUtf16(trimmed_str);
@@ -524,7 +522,7 @@
return {};
}
-Maybe<int> ParseSdkVersion(const StringPiece& str) {
+std::optional<int> ParseSdkVersion(const StringPiece& str) {
StringPiece trimmed_str(util::TrimWhitespace(str));
std::u16string str16 = util::Utf8ToUtf16(trimmed_str);
@@ -534,7 +532,7 @@
}
// Try parsing the code name.
- Maybe<int> entry = GetDevelopmentSdkCodeNameVersion(trimmed_str);
+ std::optional<int> entry = GetDevelopmentSdkCodeNameVersion(trimmed_str);
if (entry) {
return entry.value();
}
@@ -551,7 +549,7 @@
}
std::unique_ptr<BinaryPrimitive> TryParseBool(const StringPiece& str) {
- if (Maybe<bool> maybe_result = ParseBool(str)) {
+ if (std::optional<bool> maybe_result = ParseBool(str)) {
const uint32_t data = maybe_result.value() ? 0xffffffffu : 0u;
return util::make_unique<BinaryPrimitive>(android::Res_value::TYPE_INT_BOOLEAN, data);
}