示例#1
0
        public void TestAsciiStream()
        {
            string s =
                "The Documentation of the libraries is not complete " +
                "and your contributions would be greatly appreciated " +
                "the documentation you want to contribute to and " +
                "click on the [Edit] link to start writing";
            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(s)))
            {
                var detector = new StreamDetector();
                var expectedCharset = Charsets.Ascii;
                var expectedConfidence = 1.0f;

                detector.Read(stream);
                detector.DataEnd();
                Assert.Equal(expectedCharset, detector.Charset);
                Assert.Equal(expectedConfidence, detector.Confidence);
            }
        }
示例#2
0
        public void TestAsciiStream()
        {
            string s =
                "The Documentation of the libraries is not complete " +
                "and your contributions would be greatly appreciated " +
                "the documentation you want to contribute to and " +
                "click on the [Edit] link to start writing";

            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(s)))
            {
                var detector           = new StreamDetector();
                var expectedCharset    = Charsets.Ascii;
                var expectedConfidence = 1.0f;

                detector.Read(stream);
                detector.DataEnd();
                Assert.Equal(expectedCharset, detector.Charset);
                Assert.Equal(expectedConfidence, detector.Confidence);
            }
        }
        private void Process(string expected, string dirname)
        {
            var detector = new StreamDetector();
            var path     = Path.Combine(DataRoot, dirname);

            Assert.True(Directory.Exists(path), $"File path not found: {path}");

            string[] files = Directory.GetFiles(path);

            foreach (string file in files)
            {
                using (FileStream fs = new FileStream(file, FileMode.Open))
                {
                    Debug.WriteLine($"Analyzing {file}");
                    detector.Read(fs);
                    detector.DataEnd();
                    Debug.WriteLine($"{file} : {detector.Charset} {detector.Confidence}");
                    Assert.Equal(expected, detector.Charset);
                    detector.Reset();
                }
            }

            detector = null;
        }
        private void Process(string expected, string dirname)
        {
            var detector = new StreamDetector();
            var path = Path.Combine(DataRoot, dirname);

            Assert.True(Directory.Exists(path), $"File path not found: {path}");

            string[] files = Directory.GetFiles(path);

            foreach (string file in files)
            {
                using (FileStream fs = new FileStream(file, FileMode.Open))
                {
                    Debug.WriteLine($"Analyzing {file}");
                    detector.Read(fs);
                    detector.DataEnd();
                    Debug.WriteLine($"{file} : {detector.Charset} {detector.Confidence}");
                    Assert.Equal(expected, detector.Charset);
                    detector.Reset();
                }
            }

            detector = null;
        }