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/Source.h | |
parent | b54be8de65b09c85992b30dbb1d52032f0498b6d (diff) |
AAPT2: Better debugging output
Test: make aapt2_tests
Change-Id: I7778b773201381538dc1f2e376abee4eb33e44c0
Diffstat (limited to 'tools/aapt2/Source.h')
-rw-r--r-- | tools/aapt2/Source.h | 23 |
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) { |