Use the :ruby_encoding value from charlock 0.7.2

This commit is contained in:
Brian Lopez
2014-06-04 15:51:33 -05:00
parent 09c234ec26
commit 7e8be1293e
2 changed files with 8 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.files = Dir['lib/**/*']
s.executables << 'linguist'
s.add_dependency 'charlock_holmes', '~> 0.7.1'
s.add_dependency 'charlock_holmes', '~> 0.7.2'
s.add_dependency 'escape_utils', '~> 1.0.1'
s.add_dependency 'mime-types', '~> 1.19'
s.add_dependency 'pygments.rb', '~> 0.5.4'

View File

@@ -112,6 +112,12 @@ module Linguist
end
end
def ruby_encoding
if hash = detect_encoding
hash[:ruby_encoding]
end
end
# Try to guess the encoding
#
# Returns: a Hash, with :encoding, :confidence, :type
@@ -258,7 +264,7 @@ module Linguist
# large) strings.
begin
encoded_newlines = ["\r\n", "\r", "\n"].
map { |nl| nl.encode(encoding, "ASCII-8BIT").force_encoding(data.encoding) }
map { |nl| nl.encode(ruby_encoding, "ASCII-8BIT").force_encoding(data.encoding) }
data.split(Regexp.union(encoded_newlines), -1)
rescue Encoding::ConverterNotFoundError