def feed(aBuf)
return if @done
aLen = aBuf.length
return if not aLen
if not @_mGotData
if aBuf[0...3] == "\xEF\xBB\xBF"
@result = {'encoding' => "UTF-8", 'confidence' => 1.0}
elsif aBuf[0...4] == "\xFF\xFE\x00\x00"
@result = {'encoding' => "UTF-32LE", 'confidence' => 1.0}
elsif aBuf[0...4] == "\x00\x00\xFE\xFF"
@result = {'encoding' => "UTF-32BE", 'confidence' => 1.0}
elsif aBuf[0...4] == "\xFE\xFF\x00\x00"
@result = {'encoding' => "X-ISO-10646-UCS-4-3412", 'confidence' => 1.0}
elsif aBuf[0...4] == "\x00\x00\xFF\xFE"
@result = {'encoding' => "X-ISO-10646-UCS-4-2143", 'confidence' => 1.0}
elsif aBuf[0...2] == "\xFF\xFE"
@result = {'encoding' => "UTF-16LE", 'confidence' => 1.0}
elsif aBuf[0...2] == "\xFE\xFF"
@result = {'encoding' => "UTF-16BE", 'confidence' => 1.0}
end
end
@_mGotData = true
if @result['encoding'] and (@result['confidence'] > 0.0):
@done = true
return
end
if @_mInputState == EPureAscii:
if @_highBitDetector =~ (aBuf)
@_mInputState = EHighbyte
elsif (@_mInputState == EPureAscii) and @_escDetector =~ (@_mLastChar + aBuf)
@_mInputState = EEscAscii
end
end
@_mLastChar = aBuf[-1..-1]
if @_mInputState == EEscAscii
if not @_mEscCharSetProber
@_mEscCharSetProber = EscCharSetProber.new()
end
if @_mEscCharSetProber.feed(aBuf) == EFoundIt
@result = {'encoding' => self._mEscCharSetProber.get_charset_name(),
'confidence' => @_mEscCharSetProber.get_confidence()
}
@done = true
end
elsif @_mInputState == EHighbyte
if not @_mCharSetProbers or @_mCharSetProbers.empty?
@_mCharSetProbers = [MBCSGroupProber.new(), SBCSGroupProber.new(), Latin1Prober.new()]
end
for prober in @_mCharSetProbers
if prober.feed(aBuf) == EFoundIt
@result = {'encoding' => prober.get_charset_name(),
'confidence' => prober.get_confidence()}
@done = true
break
end
end
end
end