Commit 240deb88 authored by Matija Obreza's avatar Matija Obreza

CSV: detection of separator (tab or comma) and quote char (" or ')

parent 2e8afd41
......@@ -72,7 +72,7 @@ class CSV {
// }
public static detectSeparator(lines: string[]): string {
const symbols = CSV.getAllNonLetterAndDigitSymbols(lines);
const symbols = CSV.getAllNonLetterAndDigitSymbols(lines, /[\t,]/g); // tabs or commas?
const separators: Char[] = [];
symbols.forEach((symbol) => separators.push(new Char(symbol)));
......@@ -101,7 +101,7 @@ class CSV {
public static detectQuoteChar(lines: string[], separator: string): string {
const columnValues: string[] = CSV.getColumnValues(lines, separator);
const symbols = CSV.getAllNonLetterAndDigitSymbols(lines);
const symbols = CSV.getAllNonLetterAndDigitSymbols(lines, /["']/g);
const quoteChars: Char[] = [];
columnValues.forEach((value) => {
......@@ -208,9 +208,8 @@ class CSV {
}
// scans
private static getAllNonLetterAndDigitSymbols(lines: string[]): string[] {
private static getAllNonLetterAndDigitSymbols(lines: string[], regexp = /[^A-Za-z0-9]/g): string[] {
const symbols: string[] = [];
const regexp = /[^A-Za-z0-9]/g;
lines.forEach((row) => {
if (row !== '') {
let result = regexp.exec(row);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment