summaryrefslogtreecommitdiff
path: root/tools/aapt2/Source.h
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2017-11-08 00:20:40 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-11-08 00:20:40 +0000
commit2dd3953ae00068a71da9f0a0d4e2fb9d8517424c (patch)
tree4b345841dfdcf6e51b6636292efb3f7aa4c3123a /tools/aapt2/Source.h
parentf450f6dfe43daf1c06c54f32feb5aae7b453710c (diff)
parent93190b79d11d874199cfe7258526a48cfc8399fc (diff)
Merge "AAPT2: Better debugging output"
Diffstat (limited to 'tools/aapt2/Source.h')
-rw-r--r--tools/aapt2/Source.h23
1 files changed, 13 insertions, 10 deletions
diff --git a/tools/aapt2/Source.h b/tools/aapt2/Source.h
index d7f2a668477c..0f312d6998f1 100644
--- a/tools/aapt2/Source.h
+++ b/tools/aapt2/Source.h
@@ -20,16 +20,14 @@
#include <ostream>
#include <string>
+#include "android-base/stringprintf.h"
#include "androidfw/StringPiece.h"
#include "util/Maybe.h"
namespace aapt {
-/**
- * Represents a file on disk. Used for logging and
- * showing errors.
- */
+// Represents a file on disk. Used for logging and showing errors.
struct Source {
std::string path;
Maybe<size_t> line;
@@ -42,7 +40,16 @@ struct Source {
inline Source(const android::StringPiece& path, size_t line)
: path(path.to_string()), line(line) {}
- inline Source WithLine(size_t line) const { return Source(path, line); }
+ inline Source WithLine(size_t line) const {
+ return Source(path, line);
+ }
+
+ std::string to_string() const {
+ if (line) {
+ return ::android::base::StringPrintf("%s:%zd", path.c_str(), line.value());
+ }
+ return path;
+ }
};
//
@@ -50,11 +57,7 @@ struct Source {
//
inline ::std::ostream& operator<<(::std::ostream& out, const Source& source) {
- out << source.path;
- if (source.line) {
- out << ":" << source.line.value();
- }
- return out;
+ return out << source.to_string();
}
inline bool operator==(const Source& lhs, const Source& rhs) {