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 } }
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); }
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); }
/// <summary> /// Single result /// </summary> /// <param name="detectionDetail"></param> public DetectionResult(DetectionDetail detectionDetail) { Details = new List <DetectionDetail> { detectionDetail }; }