/// <summary> /// Create using supplied settings. /// </summary> /// <param name="contentOrFilePath"></param> /// <param name="isFilePath"></param> /// <param name="settings"></param> /// <param name="autoLoad"></param> public CsvDoc(string contentOrFilePath, bool isFilePath, CsvConfig settings, bool autoLoad) { // Store settings _isFileBased = isFilePath; if (isFilePath && !File.Exists(contentOrFilePath)) { throw new IOException("Csv file : " + contentOrFilePath + " does not exist."); } _content = isFilePath ? File.ReadAllText(contentOrFilePath) : contentOrFilePath; _filePath = isFilePath ? contentOrFilePath : ""; _settings = settings; var lexListSettings = new LexListSettings() { MultipleRecordsUsingNewLine = true, Delimeter = settings.Separator }; // If the separator is the tab character, do not consider the tab as a whitespace character. if (settings.Separator == '\t') { lexListSettings = new LexListSettings() { MultipleRecordsUsingNewLine = true, Delimeter = settings.Separator, WhiteSpaceChars = new char[] { ' ' } } } ; _parser = new LexList(lexListSettings); if (autoLoad) { ParseDict(); } }
/// <summary> /// Create using supplied settings. /// </summary> /// <param name="contentOfFilePath"></param> /// <param name="isFilePath"></param> /// <param name="settings"></param> public CsvDoc(string contentOrFilePath, bool isFilePath, CsvConfig settings, bool autoLoad) { // Store settings _isFileBased = isFilePath; if (isFilePath && !File.Exists(contentOrFilePath)) { throw new IOException("Csv file : " + contentOrFilePath + " does not exist."); } _content = isFilePath ? File.ReadAllText(contentOrFilePath) : contentOrFilePath; _filePath = isFilePath ? contentOrFilePath : ""; _settings = settings; var lexListSettings = new LexListSettings() { MultipleRecordsUsingNewLine = true, Delimeter = settings.Separator }; _parser = new LexList(lexListSettings); if (autoLoad) { ParseDict(); } }
public void CanParseSingleQuotedListWithCommaSeparator() { string line = "'batman', 'bruce wayne', 'gambit'"; IDictionary <string, string> items = LexList.Parse(line); Assert.IsTrue(items.ContainsKey("batman")); Assert.IsTrue(items.ContainsKey("bruce wayne")); Assert.IsTrue(items.ContainsKey("gambit")); }
public void CanParseQuotedListNewLine() { string line = "'batman', 'bruce wayne', 'gambit'\r\n"; IDictionary <string, string> items = LexList.Parse(line); Assert.IsTrue(items.ContainsKey("batman")); Assert.IsTrue(items.ContainsKey("bruce wayne")); Assert.IsTrue(items.ContainsKey("gambit")); }
public void CanParseDoubleQuotedListWithCommaSeparatorWithInnerComma() { string line = "\"batman\", \"bruce, wayne\", \"gambit\""; IDictionary <string, string> items = LexList.Parse(line); Assert.IsTrue(items.ContainsKey("batman")); Assert.IsTrue(items.ContainsKey("bruce, wayne")); Assert.IsTrue(items.ContainsKey("gambit")); }
public void CanParseSingleQuotedListWithCommaSeparatorWithInnerComma() { var line = "'batman', 'bruce, wayne', 'gambit'"; var items = LexList.Parse(line); Assert.IsTrue(items.ContainsKey("batman")); Assert.IsTrue(items.ContainsKey("bruce, wayne")); Assert.IsTrue(items.ContainsKey("gambit")); }
public void CanParseNonQuotedListWithCommaSeparator() { var line = "batman, bruce wayne, gambit"; var items = LexList.Parse(line); Assert.IsTrue(items.ContainsKey("batman")); Assert.IsTrue(items.ContainsKey("bruce wayne")); Assert.IsTrue(items.ContainsKey("gambit")); }
public void CanParseQuotedListNewLine() { var line = "'batman', 'bruce wayne', 'gambit'\r\n"; var items = LexList.Parse(line); Assert.IsTrue(items.ContainsKey("batman")); Assert.IsTrue(items.ContainsKey("bruce wayne")); Assert.IsTrue(items.ContainsKey("gambit")); }
public void CanParseMultiLineSingleQuotedListWithCommaSeparator() { string line = "'batman', 'lantern', 'superman' " + Environment.NewLine + "'cyclops', 'colossus', 'logon'"; List <List <string> > items = LexList.ParseTable(line); Assert.IsTrue(items[0].Contains("batman")); Assert.IsTrue(items[0].Contains("lantern")); Assert.IsTrue(items[0].Contains("superman")); Assert.IsTrue(items[1].Contains("cyclops")); Assert.IsTrue(items[1].Contains("colossus")); Assert.IsTrue(items[1].Contains("logon")); }
/// <summary> /// Create using supplied settings. /// </summary> /// <param name="contentOfFilePath"></param> /// <param name="isFilePath"></param> /// <param name="settings"></param> public CsvDocument(string contentOrFilePath, bool isFilePath, CsvSettings settings) { _content = contentOrFilePath; if (isFilePath) { _filePath = contentOrFilePath; _content = File.ReadAllText(contentOrFilePath); _isFileBased = true; } LexListSettings lexListSettings = new LexListSettings(); lexListSettings.MultipleRecordsUsingNewLine = true; _parser = new LexList(lexListSettings); }
/// <summary> /// Create using supplied settings. /// </summary> /// <param name="contentOfFilePath"></param> /// <param name="isFilePath"></param> /// <param name="settings"></param> public CsvDoc(string contentOrFilePath, bool isFilePath, CsvConfig settings, bool autoLoad) { // Store settings _isFileBased = isFilePath; _content = isFilePath ? File.ReadAllText(contentOrFilePath) : contentOrFilePath; _filePath = isFilePath ? contentOrFilePath : ""; _settings = settings; LexListSettings lexListSettings = new LexListSettings() { MultipleRecordsUsingNewLine = true }; _parser = new LexList(lexListSettings); if (autoLoad) { ParseDict(); } }