git.dumitru.net fructose / master src / Document.ts
master

Tree @master (Download .tar.gz)

Document.ts @masterraw · history · blame

import DocumentLocation from "./DocumentLocation";

export default class Document {
  public readonly lines: string[];

  constructor(lines: string[]) {
    this.lines = lines;
  }

  public getLine(index: number): string | null {
    if ((index < 0) || (index >= this.lines.length)) {
      return null;
    }

    return this.lines[index];
  }

  public getLineFromLocation(loc: DocumentLocation): string | null {
    const line = this.getLine(loc.line);

    if (line === null) {
      return null;
    }

    return line.substring(loc.char);
  }
}