summaryrefslogtreecommitdiff
path: root/src/error.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-01-22 21:16:43 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-01-22 21:16:43 -0400
commit812d38c176b76b0fda5228338f5c5d70b3c6edf1 (patch)
tree75b50d517d948fe6808dcc1fc3b9e6594fb573fb /src/error.h
parentd9e97cfede4afcda55eaa8defaaa63c0c18065b1 (diff)
downloadfork-ledger-812d38c176b76b0fda5228338f5c5d70b3c6edf1.tar.gz
fork-ledger-812d38c176b76b0fda5228338f5c5d70b3c6edf1.tar.bz2
fork-ledger-812d38c176b76b0fda5228338f5c5d70b3c6edf1.zip
Correctly report the line context when there is a valexpr parsing error.
Diffstat (limited to 'src/error.h')
-rw-r--r--src/error.h30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/error.h b/src/error.h
index 1ef6ff3c..6730ce17 100644
--- a/src/error.h
+++ b/src/error.h
@@ -63,15 +63,29 @@ inline string file_context(const path& file, std::size_t line) {
return buf.str();
}
-inline string line_context(const string& line, istream_pos_type pos) {
+inline string line_context(const string& line,
+ istream_pos_type pos = istream_pos_type(0),
+ istream_pos_type end_pos = istream_pos_type(0))
+{
std::ostringstream buf;
- buf << " " << line << " ";
- istream_pos_type idx = (pos == istream_pos_type(0) ?
- istream_pos_type(line.length()) : pos);
- idx -= 1;
- for (istream_pos_type i = 0; i < idx; i += 1)
- buf << " ";
- buf << "^" << std::endl;
+ buf << " " << line << "\n";
+
+ if (pos != istream_pos_type(0)) {
+ buf << " ";
+ if (end_pos == istream_pos_type(0)) {
+ for (istream_pos_type i = 0; i < pos; i += 1)
+ buf << " ";
+ buf << "^\n";
+ } else {
+ for (istream_pos_type i = 0; i < end_pos; i += 1) {
+ if (i >= pos)
+ buf << "^";
+ else
+ buf << " ";
+ }
+ buf << '\n';
+ }
+ }
return buf.str();
}