offsetLineColumn

Convert byte offset offset at source to line and column.

TODO: extend to support UTF-8 in column offset. TODO: Move to Phobos std.string?

@safe pure nothrow @nogc
offsetLineColumn
(
scope const char[] source
,
in size_t offset
)

Examples

auto x = "\nx\n y";
assert(x.length == 5);
assert(x.offsetLineColumn(0) == LineColumn(0, 0));
assert(x.offsetLineColumn(1) == LineColumn(1, 0));
assert(x.offsetLineColumn(2) == LineColumn(1, 1));
assert(x.offsetLineColumn(3) == LineColumn(2, 0));
assert(x.offsetLineColumn(4) == LineColumn(2, 1));

Meta