getLineCol method

String getLineCol([
  1. int pos = -1
])

Get pos (defaults to this.position) as a line:column string.

Implementation

String getLineCol([int pos = -1]) {
	if (pos < 0) pos = position;
	var subscan = Scanner(document), line = 1, col = 1;

	// create scanner and find newlines
	while (subscan.inBounds && subscan.position < pos) {
		subscan.seek();
		if (subscan.matches("\r\n")) {
			// skip again
			subscan.seek();
			// increment line, reset column
			line += 1;
			col = 1;
		} else if (subscan.matches("\r") || subscan.matches("\n")) {
			// increment line, reset column
			line += 1;
			col = 1;
		} else {
			// increment column
			col += 1;
		}
	}

	return "line $line:$col";
}