Better encoding handling. Updated grit
This commit is contained in:
parent
3706a9744d
commit
80ddd2c09d
3 changed files with 29 additions and 6 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue