import std.array; import std.range; enum testDocLines = [ "line 1", "line 2", "line 3", "line 4", ]; auto testDoc = testDocLines.join('\n') ~ '\n'; auto tracker = trackLineLocation(refRange(&testDoc)); // default tracker starts at line 1 column 1 assert(tracker.line == 1); assert(tracker.column == 1); // read to end of first line tracker.popFrontExactly(testDocLines[0].length); // still on first line but column changed to last column in the line // which is the newline itself assert(tracker.line == 1); assert(tracker.column == testDocLines[0].length + 1); // pop the newline tracker.popFront(); // now we are on line 2 column 1 assert(tracker.line == 2); assert(tracker.column == 1); // read until the end tracker.popFrontN(testDoc.length); assert(tracker.line == 5); assert(tracker.column == 1);
Wraps given input range and keeps track of the line number and column.