AAPT2: Better debugging output

Test: make aapt2_tests
Change-Id: I7778b773201381538dc1f2e376abee4eb33e44c0
diff --git a/tools/aapt2/Resource.h b/tools/aapt2/Resource.h
index 87b9867..96a0203 100644
--- a/tools/aapt2/Resource.h
+++ b/tools/aapt2/Resource.h
@@ -69,11 +69,10 @@
   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 @@
   int compare(const ResourceName& other) const;
 
   bool is_valid() const;
-  std::string ToString() const;
+  std::string to_string() const;
 };
 
 /**
@@ -115,8 +114,10 @@
   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 @@
   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 @@
   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 @@
   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 @@
          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 @@
          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 @@
   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;
 }