From 2cb29a3cdff844baab3f2725f4c4ed07173ddefe Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 26 May 2018 15:59:02 +0200 Subject: Don't print empty location, zero line/column --- bpkg/diagnostics.cxx | 15 ++++++++++++++- bpkg/diagnostics.hxx | 9 ++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/bpkg/diagnostics.cxx b/bpkg/diagnostics.cxx index 9174c9f..400b352 100644 --- a/bpkg/diagnostics.cxx +++ b/bpkg/diagnostics.cxx @@ -54,7 +54,20 @@ namespace bpkg void location_prologue_base:: operator() (const diag_record& r) const { - r << loc_.file << ':' << loc_.line << ':' << loc_.column << ": "; + if (!loc_.empty ()) + { + r << loc_.file << ':'; + + if (loc_.line != 0) + { + r << loc_.line << ':'; + + if (loc_.column != 0) + r << loc_.column << ':'; + } + + r << ' '; + } if (type_ != nullptr) r << type_ << ": "; diff --git a/bpkg/diagnostics.hxx b/bpkg/diagnostics.hxx index 2816f3c..21bc157 100644 --- a/bpkg/diagnostics.hxx +++ b/bpkg/diagnostics.hxx @@ -95,10 +95,17 @@ namespace bpkg class location { public: - location () {} + // Zero lines or columns are not printed. + // + explicit location (string f, uint64_t l, uint64_t c) : file (move (f)), line (l), column (c) {} + location () = default; + + bool + empty () const {return file.empty ();} + string file; uint64_t line; uint64_t column; -- cgit v1.1