summaryrefslogtreecommitdiff
path: root/src/error.h
diff options
context:
space:
mode:
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();
}