Better encoding handling. Updated grit

This commit is contained in:
Dmitriy Zaporozhets 2012-04-05 01:51:49 +03:00
parent 3706a9744d
commit 80ddd2c09d
3 changed files with 29 additions and 6 deletions

View file

@ -17,13 +17,35 @@ Grit::GitRuby::Internal::RawObject.class_eval do
end
private
def transcoding(content)
content ||= ""
detection = CharlockHolmes::EncodingDetector.detect(content)
if hash = detection
content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
hash = CharlockHolmes::EncodingDetector.detect(content)
if hash
return content if hash[:type] == :binary
if hash[:encoding] == "UTF-8"
content = if hash[:confidence] < 100
content
else
content.force_encoding("UTF-8")
end
return content
end
CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
else
content.force_encoding("UTF-8")
end
content
end
def z_binary?(string)
string.each_byte do |x|
x.nonzero? or return true
end
false
end
end