public static string FormatCollection(IEnumerable data, bool escapeLineBreaks, out bool needsEscaping) { StringBuilder stringBuilder = new StringBuilder(256); needsEscaping = false; foreach (object data2 in data) { bool flag; string text = LogRowFormatter.Format(data2, out flag); if (flag) { needsEscaping = true; Utf8Csv.EscapeAndAppendCollectionMember(stringBuilder, text, escapeLineBreaks); } else { Utf8Csv.AppendCollectionMember(stringBuilder, text); } } if (stringBuilder.Length > 0) { stringBuilder.Remove(stringBuilder.Length - 1, 1); } return(stringBuilder.ToString()); }
internal void Write(Stream output, DateTime date) { if (output.Position == 0L) { if (this.CsvOption != LogHeaderCsvOption.NotCsvCompatible) { Utf8Csv.WriteHeaderRow(output, this.schema.Fields); } else { Utf8Csv.WriteBom(output); } } if (this.CsvOption != LogHeaderCsvOption.CsvStrict) { Utf8Csv.EncodeAndWrite(output, "#Software: "); Utf8Csv.EncodeAndWriteLine(output, this.schema.Software); Utf8Csv.EncodeAndWrite(output, "#Version: "); Utf8Csv.EncodeAndWriteLine(output, this.schema.Version); Utf8Csv.EncodeAndWrite(output, "#Log-type: "); Utf8Csv.EncodeAndWriteLine(output, this.schema.LogType); Utf8Csv.EncodeAndWrite(output, "#Date: "); Utf8Csv.EncodeAndWriteLine(output, date.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffZ", DateTimeFormatInfo.InvariantInfo)); Utf8Csv.EncodeAndWrite(output, "#Fields: "); Utf8Csv.WriteHeaderRow(output, this.schema.Fields); } }
protected virtual byte[] EncodeCollection(IEnumerable data) { bool flag; string s = LogRowFormatter.FormatCollection(data, this.escapeLineBreaks, out flag); if (!flag) { return(Utf8Csv.Encode(s)); } return(Utf8Csv.EncodeAndEscape(s, this.escapeLineBreaks)); }
protected virtual byte[] EncodeBytes(byte[] data) { if (this.escapeRawData) { byte[] data2 = data; if (this.ShouldConvertEncoding) { data2 = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, data); } return(Utf8Csv.Escape(data2, true)); } return(data); }
public static void WriteRawRow(Stream output, byte[][] fields) { int num = fields.Length - 1; for (int i = 0; i < fields.Length; i++) { if (fields[i] != null) { Utf8Csv.WriteBytes(output, fields[i]); } if (i == num) { Utf8Csv.WriteBytes(output, Utf8Csv.NewLine); } else { Utf8Csv.WriteByte(output, 44); } } }
public static void WriteHeaderRow(Stream output, string[] fields) { int num = fields.Length - 1; for (int i = 0; i < fields.Length; i++) { if (fields[i] != null) { Utf8Csv.EncodeEscapeAndWrite(output, fields[i]); } if (i == num) { Utf8Csv.WriteBytes(output, Utf8Csv.NewLine); } else { Utf8Csv.WriteByte(output, 44); } } }
protected virtual byte[] Encode(object data) { if (data == null) { return(null); } if (data is byte[]) { return(this.EncodeBytes((byte[])data)); } if (!(data is string) && data is IEnumerable) { return(this.EncodeCollection((IEnumerable)data)); } bool flag; string s = LogRowFormatter.Format(data, out flag); if (!flag) { return(Utf8Csv.Encode(s)); } return(Utf8Csv.EncodeAndEscape(s, this.escapeLineBreaks)); }
internal void Write(Stream output) { Utf8Csv.WriteRawRow(output, this.encodedFields); }
internal static byte[] Escape(byte[] data) { return(Utf8Csv.Escape(data, false)); }
public static void WriteBom(Stream output) { Utf8Csv.WriteBytes(output, Utf8Csv.Bom); }
public static void EncodeEscapeAndWriteLine(Stream output, string s) { Utf8Csv.WriteBytes(output, Utf8Csv.EncodeAndEscape(s)); Utf8Csv.WriteBytes(output, Utf8Csv.NewLine); }
public static void EncodeAndWrite(Stream output, string s) { Utf8Csv.WriteBytes(output, Utf8Csv.Encode(s)); }
internal static byte[] EncodeAndEscape(string s, bool escapeLineBreaks) { return(Utf8Csv.Escape(Encoding.UTF8.GetBytes(s), escapeLineBreaks)); }
internal static byte[] EncodeAndEscape(string s) { return(Utf8Csv.EncodeAndEscape(s, false)); }