示例#1
0
        public void Load(string file)
        {
            using (FileStream fs = File.OpenRead(file))
            {
                byte[] buf = new byte[1024];
                int    nread;
                if ((nread = fs.Read(buf, 0, buf.Length)) <= 0)
                {
                    return;
                }
                int i;
                if (ByteOrderMark.TryParse(buf, nread, out this.bom))
                {
                    i = this.bom.Length;
                }
                else
                {
                    i = 0;
                }
                while (true)
                {
                    if (i < nread)
                    {
                        if (buf[i] == 13)
                        {
                            this.newLine = "\r\n";
                        }
                        else
                        {
                            if (buf[i] != 10)
                            {
                                i++;
                                continue;
                            }
                            this.newLine = "\n";
                        }
                    }
                    if (this.newLine == null)
                    {
                        if ((nread = fs.Read(buf, 0, buf.Length)) <= 0)
                        {
                            break;
                        }
                        i = 0;
                    }
                    if (this.newLine != null)
                    {
                        goto IL_A7;
                    }
                }
                this.newLine = "\n";
IL_A7:
                this.endsWithEmptyLine = (fs.Seek(-1L, SeekOrigin.End) > 0L && fs.ReadByte() == 10);
            }
            this.doc = new XmlDocument();
            this.doc.PreserveWhitespace = false;
            string xml = File.ReadAllText(file);

            this.doc.LoadXml(xml);
        }
示例#2
0
 public static bool TryParse(byte[] buffer, int available, out ByteOrderMark bom)
 {
     if (buffer.Length >= 2)
     {
         for (int i = 0; i < ByteOrderMark.table.Length; i++)
         {
             bool matched = true;
             if (available >= ByteOrderMark.table[i].Bytes.Length)
             {
                 for (int j = 0; j < ByteOrderMark.table[i].Bytes.Length; j++)
                 {
                     if (buffer[j] != ByteOrderMark.table[i].Bytes[j])
                     {
                         matched = false;
                         break;
                     }
                 }
                 if (matched)
                 {
                     bom = ByteOrderMark.table[i];
                     return(true);
                 }
             }
         }
     }
     bom = null;
     return(false);
 }
示例#3
0
        public static bool TryParse(Stream stream, out ByteOrderMark bom)
        {
            byte[] buffer = new byte[4];
            int    nread;

            if ((nread = stream.Read(buffer, 0, buffer.Length)) < 2)
            {
                bom = null;
                return(false);
            }
            return(ByteOrderMark.TryParse(buffer, nread, out bom));
        }
示例#4
0
 public ProjectWriter(ByteOrderMark bom)
 {
     this.encoding      = ((bom != null) ? Encoding.GetEncoding(bom.Name) : null);
     this.ByteOrderMark = bom;
 }
示例#5
0
        static ByteOrderMark()
        {
            // Note: this type is marked as 'beforefieldinit'.
            ByteOrderMark[] array = new ByteOrderMark[14];
            array[0] = new ByteOrderMark("UTF-8", new byte[]
            {
                239,
                187,
                191
            });
            array[1] = new ByteOrderMark("UTF-32BE", new byte[]
            {
                0,
                0,
                254,
                255
            });
            ByteOrderMark[] arg_6F_0 = array;
            int             arg_6F_1 = 2;
            string          arg_6A_0 = "UTF-32LE";

            byte[] array2 = new byte[4];
            array2[0]          = 255;
            array2[1]          = 254;
            arg_6F_0[arg_6F_1] = new ByteOrderMark(arg_6A_0, array2);
            array[3]           = new ByteOrderMark("UTF-16BE", new byte[]
            {
                254,
                255
            });
            array[4] = new ByteOrderMark("UTF-16LE", new byte[]
            {
                255,
                254
            });
            array[5] = new ByteOrderMark("UTF-7", new byte[]
            {
                43,
                47,
                118,
                56
            });
            array[6] = new ByteOrderMark("UTF-7", new byte[]
            {
                43,
                47,
                118,
                57
            });
            array[7] = new ByteOrderMark("UTF-7", new byte[]
            {
                43,
                47,
                118,
                43
            });
            array[8] = new ByteOrderMark("UTF-7", new byte[]
            {
                43,
                47,
                118,
                47
            });
            array[9] = new ByteOrderMark("UTF-1", new byte[]
            {
                247,
                100,
                76
            });
            array[10] = new ByteOrderMark("UTF-EBCDIC", new byte[]
            {
                221,
                115,
                102,
                115
            });
            array[11] = new ByteOrderMark("SCSU", new byte[]
            {
                14,
                254,
                255
            });
            array[12] = new ByteOrderMark("BOCU-1", new byte[]
            {
                251,
                238,
                40
            });
            array[13] = new ByteOrderMark("GB18030", new byte[]
            {
                132,
                49,
                149,
                51
            });
            ByteOrderMark.table = array;
        }