GIT
remote: https://github.com/gitlabhq/grit.git
- revision: ff015074ef35bd94cba943f9c0f98e161ab5851c
+ revision: 3fc864f3c637e06e2fa7a81f6b48a5df58a9bc5b
specs:
grit (2.4.1)
diff-lcs (~> 1.1)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.7.0)
- mime-types (1.17.2)
+ mime-types (1.18)
modularity (0.6.1)
multi_json (1.0.4)
multi_xml (0.4.1)
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
+ end
+
+ def z_binary?(string)
+ string.each_byte do |x|
+ x.nonzero? or return true
end
- content
+ false
end
end