예제 #1
0
        protected virtual void Feed(byte[] buf, int offset, int len)
        {
            if (_done)
            {
                return;
            }

            if (len > 0)
            {
                _gotData = true;
            }

            // If the data starts with BOM, we know it is UTF
            if (_start)
            {
                var bomSet = FindCharSetByBom(buf, len);
                _start = false;
                if (bomSet != null)
                {
                    _detectionDetail = new DetectionDetail(bomSet, 1);
                    _done            = true;
                    return;
                }
            }

            FindInputState(buf, len);

            switch (InputState)
            {
            case InputState.EscASCII:

                _escCharsetProber = _escCharsetProber ?? new EscCharsetProber();

                RunProber(buf, offset, len, _escCharsetProber);

                break;

            case InputState.Highbyte:
                for (int i = 0; i < ProbersNum; i++)
                {
                    var charsetProber = _charsetProbers[i];

                    if (charsetProber != null)
                    {
                        var found = RunProber(buf, offset, len, charsetProber);
                        if (found)
                        {
                            return;
                        }
                    }
                }
                break;
                // else pure ascii
            }
        }
예제 #2
0
        private bool IsStartsWithBom(byte[] buf, int len)
        {
            var bomSet = FindCharSetByBom(buf, len);

            if (bomSet != null)
            {
                _detectionDetail = new DetectionDetail(bomSet, 1.0f);
                return(true);
            }
            return(false);
        }
예제 #3
0
        private bool RunProber(byte[] buf, int offset, int len, CharsetProber charsetProber)
        {
            var probingState = charsetProber.HandleData(buf, offset, len);

            if (probingState == ProbingState.FoundIt)
            {
                _detectionDetail = new DetectionDetail(charsetProber);
                return(true);
            }
            return(false);
        }
예제 #4
0
 /// <summary>
 /// Single result
 /// </summary>
 /// <param name="detectionDetail"></param>
 public DetectionResult(DetectionDetail detectionDetail)
 {
     Details = new List <DetectionDetail> {
         detectionDetail
     };
 }