diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-11-03 15:20:17 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-11-07 11:21:10 -0800 |
commit | 93190b79d11d874199cfe7258526a48cfc8399fc (patch) | |
tree | 3a7ae2b44c7f9693d54cdb0849e21338398de3d3 /tools/aapt2/Resource.h | |
parent | b54be8de65b09c85992b30dbb1d52032f0498b6d (diff) |
AAPT2: Better debugging output
Test: make aapt2_tests
Change-Id: I7778b773201381538dc1f2e376abee4eb33e44c0
Diffstat (limited to 'tools/aapt2/Resource.h')
-rw-r--r-- | tools/aapt2/Resource.h | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/tools/aapt2/Resource.h b/tools/aapt2/Resource.h index 87b986784961..96a02033fc1d 100644 --- a/tools/aapt2/Resource.h +++ b/tools/aapt2/Resource.h @@ -69,11 +69,10 @@ enum class ResourceType { kXml, }; -android::StringPiece ToString(ResourceType type); +android::StringPiece to_string(ResourceType type); /** - * Returns a pointer to a valid ResourceType, or nullptr if - * the string was invalid. + * Returns a pointer to a valid ResourceType, or nullptr if the string was invalid. */ const ResourceType* ParseResourceType(const android::StringPiece& str); @@ -92,7 +91,7 @@ struct ResourceName { int compare(const ResourceName& other) const; bool is_valid() const; - std::string ToString() const; + std::string to_string() const; }; /** @@ -115,8 +114,10 @@ struct ResourceNameRef { ResourceNameRef& operator=(ResourceNameRef&& rhs) = default; ResourceNameRef& operator=(const ResourceName& rhs); - ResourceName ToResourceName() const; bool is_valid() const; + + ResourceName ToResourceName() const; + std::string to_string() const; }; constexpr const uint8_t kAppPackageId = 0x7fu; @@ -149,6 +150,8 @@ struct ResourceId { uint8_t package_id() const; uint8_t type_id() const; uint16_t entry_id() const; + + std::string to_string() const; }; struct SourcedResourceName { @@ -229,7 +232,9 @@ inline bool ResourceId::is_valid() const { return (id & 0xff000000u) != 0 && (id & 0x00ff0000u) != 0; } -inline bool ResourceId::is_valid_dynamic() const { return (id & 0x00ff0000u) != 0; } +inline bool ResourceId::is_valid_dynamic() const { + return (id & 0x00ff0000u) != 0; +} inline uint8_t ResourceId::package_id() const { return static_cast<uint8_t>(id >> 24); @@ -259,24 +264,16 @@ inline bool operator!=(const ResourceId& lhs, const ResourceId& rhs) { return lhs.id != rhs.id; } -inline ::std::ostream& operator<<(::std::ostream& out, - const ResourceId& res_id) { - std::ios_base::fmtflags old_flags = out.flags(); - char old_fill = out.fill(); - out << "0x" << std::internal << std::setfill('0') << std::setw(8) << std::hex - << res_id.id; - out.flags(old_flags); - out.fill(old_fill); - return out; +inline ::std::ostream& operator<<(::std::ostream& out, const ResourceId& res_id) { + return out << res_id.to_string(); } // // ResourceType implementation. // -inline ::std::ostream& operator<<(::std::ostream& out, - const ResourceType& val) { - return out << ToString(val); +inline ::std::ostream& operator<<(::std::ostream& out, const ResourceType& val) { + return out << to_string(val); } // @@ -315,18 +312,8 @@ inline bool operator!=(const ResourceName& lhs, const ResourceName& rhs) { std::tie(rhs.package, rhs.type, rhs.entry); } -inline ::std::ostream& operator<<(::std::ostream& out, - const ResourceName& name) { - if (!name.package.empty()) { - out << name.package << ":"; - } - return out << name.type << "/" << name.entry; -} - -inline std::string ResourceName::ToString() const { - std::stringstream stream; - stream << *this; - return stream.str(); +inline ::std::ostream& operator<<(::std::ostream& out, const ResourceName& name) { + return out << name.to_string(); } // @@ -370,12 +357,8 @@ inline bool operator!=(const ResourceNameRef& lhs, const ResourceNameRef& rhs) { std::tie(rhs.package, rhs.type, rhs.entry); } -inline ::std::ostream& operator<<(::std::ostream& out, - const ResourceNameRef& name) { - if (!name.package.empty()) { - out << name.package << ":"; - } - return out << name.type << "/" << name.entry; +inline ::std::ostream& operator<<(::std::ostream& out, const ResourceNameRef& name) { + return out << name.to_string(); } inline bool operator<(const ResourceName& lhs, const ResourceNameRef& b) { @@ -386,8 +369,7 @@ inline bool operator!=(const ResourceName& lhs, const ResourceNameRef& rhs) { return ResourceNameRef(lhs) != rhs; } -inline bool operator==(const SourcedResourceName& lhs, - const SourcedResourceName& rhs) { +inline bool operator==(const SourcedResourceName& lhs, const SourcedResourceName& rhs) { return lhs.name == rhs.name && lhs.line == rhs.line; } |