diff options
Diffstat (limited to 'tools/aapt2/ResourceUtils.h')
-rw-r--r-- | tools/aapt2/ResourceUtils.h | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/tools/aapt2/ResourceUtils.h b/tools/aapt2/ResourceUtils.h index a0fbcc6e700b..871ed7ca1e3b 100644 --- a/tools/aapt2/ResourceUtils.h +++ b/tools/aapt2/ResourceUtils.h @@ -28,6 +28,11 @@ namespace aapt { namespace ResourceUtils { +/** + * Convert an android::ResTable::resource_name to an aapt::ResourceName struct. + */ +Maybe<ResourceName> toResourceName(const android::ResTable::resource_name& name); + /* * Extracts the package, type, and name from a string of the format: * @@ -37,15 +42,15 @@ namespace ResourceUtils { * individual extracted piece to verify that the pieces are valid. * Returns false if there was no package but a ':' was present. */ -bool extractResourceName(const StringPiece16& str, StringPiece16* outPackage, - StringPiece16* outType, StringPiece16* outEntry); +bool extractResourceName(const StringPiece& str, StringPiece* outPackage, + StringPiece* outType, StringPiece* outEntry); /** * Returns true if the string was parsed as a resource name ([*][package:]type/name), with * `outResource` set to the parsed resource name and `outPrivate` set to true if a '*' prefix * was present. */ -bool parseResourceName(const StringPiece16& str, ResourceNameRef* outResource, +bool parseResourceName(const StringPiece& str, ResourceNameRef* outResource, bool* outPrivate = nullptr); /* @@ -55,29 +60,34 @@ bool parseResourceName(const StringPiece16& str, ResourceNameRef* outResource, * If '+' was present in the reference, `outCreate` is set to true. * If '*' was present in the reference, `outPrivate` is set to true. */ -bool tryParseReference(const StringPiece16& str, ResourceNameRef* outReference, +bool tryParseReference(const StringPiece& str, ResourceNameRef* outReference, bool* outCreate = nullptr, bool* outPrivate = nullptr); /* * Returns true if the string is in the form of a resource reference (@[+][package:]type/name). */ -bool isReference(const StringPiece16& str); +bool isReference(const StringPiece& str); /* * Returns true if the string was parsed as an attribute reference (?[package:][type/]name), * with `outReference` set to the parsed reference. */ -bool tryParseAttributeReference(const StringPiece16& str, ResourceNameRef* outReference); +bool tryParseAttributeReference(const StringPiece& str, ResourceNameRef* outReference); /** * Returns true if the string is in the form of an attribute reference(?[package:][type/]name). */ -bool isAttributeReference(const StringPiece16& str); +bool isAttributeReference(const StringPiece& str); /** * Returns true if the value is a boolean, putting the result in `outValue`. */ -bool tryParseBool(const StringPiece16& str, bool* outValue); +bool tryParseBool(const StringPiece& str, bool* outValue); + +/** + * Parses an SDK version, which can be an integer, or a letter from A-Z. + */ +Maybe<int> tryParseSdkVersion(const StringPiece& str); /* * Returns a Reference, or None Maybe instance if the string `str` was parsed as a @@ -88,58 +98,58 @@ bool tryParseBool(const StringPiece16& str, bool* outValue); * ?[package:]style/<entry> or * <package>:[style/]<entry> */ -Maybe<Reference> parseStyleParentReference(const StringPiece16& str, std::string* outError); +Maybe<Reference> parseStyleParentReference(const StringPiece& str, std::string* outError); /* * Returns a Reference object if the string was parsed as a resource or attribute reference, * ( @[+][package:]type/name | ?[package:]type/name ) setting outCreate to true if * the '+' was present in the string. */ -std::unique_ptr<Reference> tryParseReference(const StringPiece16& str, bool* outCreate = nullptr); +std::unique_ptr<Reference> tryParseReference(const StringPiece& str, bool* outCreate = nullptr); /* * Returns a BinaryPrimitve object representing @null or @empty if the string was parsed * as one. */ -std::unique_ptr<BinaryPrimitive> tryParseNullOrEmpty(const StringPiece16& str); +std::unique_ptr<BinaryPrimitive> tryParseNullOrEmpty(const StringPiece& str); /* * Returns a BinaryPrimitve object representing a color if the string was parsed * as one. */ -std::unique_ptr<BinaryPrimitive> tryParseColor(const StringPiece16& str); +std::unique_ptr<BinaryPrimitive> tryParseColor(const StringPiece& str); /* * Returns a BinaryPrimitve object representing a boolean if the string was parsed * as one. */ -std::unique_ptr<BinaryPrimitive> tryParseBool(const StringPiece16& str); +std::unique_ptr<BinaryPrimitive> tryParseBool(const StringPiece& str); /* * Returns a BinaryPrimitve object representing an integer if the string was parsed * as one. */ -std::unique_ptr<BinaryPrimitive> tryParseInt(const StringPiece16& str); +std::unique_ptr<BinaryPrimitive> tryParseInt(const StringPiece& str); /* * Returns a BinaryPrimitve object representing a floating point number * (float, dimension, etc) if the string was parsed as one. */ -std::unique_ptr<BinaryPrimitive> tryParseFloat(const StringPiece16& str); +std::unique_ptr<BinaryPrimitive> tryParseFloat(const StringPiece& str); /* * Returns a BinaryPrimitve object representing an enum symbol if the string was parsed * as one. */ std::unique_ptr<BinaryPrimitive> tryParseEnumSymbol(const Attribute* enumAttr, - const StringPiece16& str); + const StringPiece& str); /* * Returns a BinaryPrimitve object representing a flag symbol if the string was parsed * as one. */ std::unique_ptr<BinaryPrimitive> tryParseFlagSymbol(const Attribute* enumAttr, - const StringPiece16& str); + const StringPiece& str); /* * Try to convert a string to an Item for the given attribute. The attribute will * restrict what values the string can be converted to. @@ -147,11 +157,11 @@ std::unique_ptr<BinaryPrimitive> tryParseFlagSymbol(const Attribute* enumAttr, * reference to an ID that must be created (@+id/foo). */ std::unique_ptr<Item> parseItemForAttribute( - const StringPiece16& value, const Attribute* attr, + const StringPiece& value, const Attribute* attr, std::function<void(const ResourceName&)> onCreateReference = {}); std::unique_ptr<Item> parseItemForAttribute( - const StringPiece16& value, uint32_t typeMask, + const StringPiece& value, uint32_t typeMask, std::function<void(const ResourceName&)> onCreateReference = {}); uint32_t androidTypeToAttributeTypeMask(uint16_t type); |