public Csv(Buf data) { byte[] src = data.ByteData; int bomSize; Encoding enc = Str.CheckBOM(src, out bomSize); if (bomSize >= 1) { src = Util.RemoveStartByteArray(src, bomSize); } init(new Buf(src), enc); }
void init(Buf data, Encoding encoding) { if (encoding == null) { encoding = defaultEncoding; } int bomSize = 0; Encoding enc2 = null; if (data != null) { enc2 = Str.CheckBOM(data.ByteData, out bomSize); } if (bomSize >= 1) { data = new Buf(Util.RemoveStartByteArray(data.ByteData, bomSize)); } if (enc2 != null) { encoding = enc2; } this.encoding = encoding; entryList = new List <CsvEntry>(); if (data != null) { MemoryStream ms = new MemoryStream(data.ByteData); StreamReader sr = new StreamReader(ms, this.encoding); while (true) { string s = sr.ReadLine(); if (s == null) { break; } char[] sep = { ',' }; string[] strings = s.Trim().Split(sep, StringSplitOptions.None); CsvEntry e = new CsvEntry(strings); Add(e); } } }