Exemplo n.º 1
0
        internal void ValidateCharset(bool charsetWasDefaulted, Stream contentStream)
        {
            bool strongDefault = !charsetWasDefaulted && this.charset.CodePage != 20127;
            FeInboundCharsetDetector feInboundCharsetDetector = new FeInboundCharsetDetector(this.charset.CodePage, strongDefault, true, true, true);

            byte[] byteBuffer = ScratchPad.GetByteBuffer(1024);
            int    num        = 0;
            int    num2       = 0;

            while (num2 < 4096 && (num = contentStream.Read(byteBuffer, 0, byteBuffer.Length)) != 0)
            {
                feInboundCharsetDetector.AddBytes(byteBuffer, 0, num, false);
                num2 += num;
            }
            if (num == 0)
            {
                feInboundCharsetDetector.AddBytes(byteBuffer, 0, 0, true);
            }
            int codePageChoice = feInboundCharsetDetector.GetCodePageChoice();

            if (codePageChoice != this.charset.CodePage)
            {
                this.charset = Charset.GetCharset(codePageChoice);
            }
        }
Exemplo n.º 2
0
        private Charset DetectValueCharset(Charset defaultCharset, bool enableJisDetection, bool enableUtf8Detection, bool enableDbcsDetection, out EncodingScheme encodingScheme)
        {
            ValueIterator            valueIterator            = new ValueIterator(this.iterator.Lines, this.iterator.LinesMask);
            FeInboundCharsetDetector feInboundCharsetDetector = new FeInboundCharsetDetector(defaultCharset.CodePage, false, enableJisDetection, enableUtf8Detection, enableDbcsDetection);

            while (!valueIterator.Eof)
            {
                feInboundCharsetDetector.AddBytes(valueIterator.Bytes, valueIterator.Offset, valueIterator.Length, false);
                valueIterator.Get(valueIterator.Length);
            }
            feInboundCharsetDetector.AddBytes(null, 0, 0, true);
            int codePageChoice = feInboundCharsetDetector.GetCodePageChoice();

            if (codePageChoice != defaultCharset.CodePage)
            {
                defaultCharset = Charset.GetCharset(codePageChoice);
            }
            if (!feInboundCharsetDetector.PureAscii)
            {
                if (feInboundCharsetDetector.Iso2022JpLikely || feInboundCharsetDetector.Iso2022KrLikely)
                {
                    encodingScheme = EncodingScheme.Jis;
                }
                else
                {
                    encodingScheme = EncodingScheme.EightBit;
                }
            }
            else if (defaultCharset.Name == "iso-2022-jp" && !feInboundCharsetDetector.Iso2022KrLikely)
            {
                encodingScheme = EncodingScheme.Jis;
            }
            else
            {
                encodingScheme = EncodingScheme.None;
            }
            return(defaultCharset);
        }