diff options
Diffstat (limited to 'tools/aapt2/ResourceUtils.cpp')
-rw-r--r-- | tools/aapt2/ResourceUtils.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp index e0e80ac02dea..ead06bf989d5 100644 --- a/tools/aapt2/ResourceUtils.cpp +++ b/tools/aapt2/ResourceUtils.cpp @@ -40,8 +40,7 @@ using ::android::base::StringPrintf; 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 @@ Maybe<ResourceName> ToResourceName( 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 @@ bool IsAttributeReference(const StringPiece& str) { * <[*]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 @@ Maybe<Reference> ParseStyleParentReference(const StringPiece& str, 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 @@ Maybe<Reference> ParseXmlAttributeName(const StringPiece& str) { } 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 @@ std::unique_ptr<BinaryPrimitive> TryParseColor(const StringPiece& str) { : 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 @@ Maybe<uint32_t> ParseInt(const StringPiece& str) { 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 @@ Maybe<ResourceId> ParseResourceId(const StringPiece& str) { 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 @@ Maybe<int> ParseSdkVersion(const StringPiece& str) { } // 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 @@ Maybe<int> ParseSdkVersion(const StringPiece& str) { } 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); } |