public void Tsv_Escape_Quote_Process() { string line = "aaa\t\"\"\"hi\"\"\tJack\""; var expectedTokens = new List <string> { "aaa", "\"hi\"\tJack" }; List <string> result = null; result = tsvParser.CsvSplit(line); Assert.True(result.SequenceEqual(expectedTokens)); }
public void Csv_NotTrim_Process() { string line = " 123 , aaa , 1.233 "; var expectedTokens = new List <string> { " 123 ", " aaa ", " 1.233 " }; List <string> result = null; result = csvParserNotTrim.CsvSplit(line); Assert.True(result.SequenceEqual(expectedTokens)); }
public ICell ImportEntity(string type, string content, long?parent_id = null) { var fields = parser.CsvSplit(content); if (fields.Count != m_fieldNames.Count) { throw new ImporterException("Invalid record. The number of a field ({0}) must equal to {1}: {2}", fields.Count, m_fieldNames.Count, content); } var jsonObj = new JObject(); var fieldDescDict = GetFieldDescriptors(type); IFieldDescriptor fieldDesc = null; for (int colIndex = 0; colIndex < m_fieldNames.Count; colIndex++) { var fieldName = m_fieldNames[colIndex]; string fieldValue = fields[colIndex]; if (fieldValue == null || !fieldDescDict.TryGetValue(fieldName, out fieldDesc)) { // Ignore this field if it's value is null or could not find the descriptor. continue; } string csvArraySplitBy = fieldDesc.GetAttributeValue(Consts.c_KW_CsvArray); if (fieldValue == null || csvArraySplitBy == null) { jsonObj[fieldName] = fieldValue; } else { var elements = fieldValue.Split(csvArraySplitBy.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var jsonArray = new JArray(); foreach (var elem in elements) { jsonArray.Add(elem); } jsonObj[fieldName] = jsonArray; } } return(m_jsonImporter.ImportEntity(type, jsonObj.ToString(), parent_id)); }