Example #1
0
        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());
        }
Example #2
0
 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);
     }
 }
Example #3
0
        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));
        }
Example #4
0
 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);
 }
Example #5
0
        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);
                }
            }
        }
Example #6
0
        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);
                }
            }
        }
Example #7
0
        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));
        }
Example #8
0
 internal void Write(Stream output)
 {
     Utf8Csv.WriteRawRow(output, this.encodedFields);
 }
Example #9
0
 internal static byte[] Escape(byte[] data)
 {
     return(Utf8Csv.Escape(data, false));
 }
Example #10
0
 public static void WriteBom(Stream output)
 {
     Utf8Csv.WriteBytes(output, Utf8Csv.Bom);
 }
Example #11
0
 public static void EncodeEscapeAndWriteLine(Stream output, string s)
 {
     Utf8Csv.WriteBytes(output, Utf8Csv.EncodeAndEscape(s));
     Utf8Csv.WriteBytes(output, Utf8Csv.NewLine);
 }
Example #12
0
 public static void EncodeAndWrite(Stream output, string s)
 {
     Utf8Csv.WriteBytes(output, Utf8Csv.Encode(s));
 }
Example #13
0
 internal static byte[] EncodeAndEscape(string s, bool escapeLineBreaks)
 {
     return(Utf8Csv.Escape(Encoding.UTF8.GetBytes(s), escapeLineBreaks));
 }
Example #14
0
 internal static byte[] EncodeAndEscape(string s)
 {
     return(Utf8Csv.EncodeAndEscape(s, false));
 }