import { IParserLine } from "../models/IParserLine"; export class Line implements IParserLine { private _segments: string[] | null = new Array(0); /** * Regular Expression used for the parsing */ get regEx(): RegExp { return /(?!\B"[^"]*),(?![^"]*"\B)/; } get elementCount(): number { if (this._segments == null) { return 0; } return this._segments.length; } get items(): string[] { return this._segments || []; } /** * * @param lineNo The line number/position in the delimited file * @param line The unparsed/raw line of the delimited file * @param delimiter The delimiter that is to be used for the parsing */ constructor(public lineNo: number, private line: string) { this._segments = this.splitArray(); } /** * Splits the string into its components * @returns {(string[] | null)} The result of the split in the form on an array * */ private splitArray(): string[] | null { if (this.line == null || this.line.length === 0) { return null; } const array = this.line.split(this.regEx); return array; } /** * Returns the delimited as an array * * @returns {(string[] | null)} * @memberof LineParser */ toArray(): string[] | null { return this._segments; } }