4 var common = require('./common');
7 function Mark(name, buffer, position, line, column) {
10 this.position = position;
16 Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
17 var head, start, tail, end, snippet;
24 maxLength = maxLength || 75;
27 start = this.position;
29 while (start > 0 && -1 === '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1))) {
31 if (this.position - start > (maxLength / 2 - 1)) {
41 while (end < this.buffer.length && -1 === '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end))) {
43 if (end - this.position > (maxLength / 2 - 1)) {
50 snippet = this.buffer.slice(start, end);
52 return common.repeat(' ', indent) + head + snippet + tail + '\n' +
53 common.repeat(' ', indent + this.position - start + head.length) + '^';
57 Mark.prototype.toString = function toString(compact) {
58 var snippet, where = '';
61 where += 'in "' + this.name + '" ';
64 where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
67 snippet = this.getSnippet();
70 where += ':\n' + snippet;
78 module.exports = Mark;