Counts the number of lines correctly for files with certain multibyte encodings

This commit is contained in:
Andy Lindeman
2014-05-21 11:44:18 -04:00
parent 93d7aa3d07
commit 85efbde3f7
4 changed files with 6 additions and 2 deletions

View File

@@ -241,7 +241,8 @@ module Linguist
def lines
@lines ||=
if viewable? && data
data.split(/\r\n|\r|\n/, -1)
newlines = Regexp.new("\r\n|\r|\n".encode(encoding))
data.force_encoding(encoding).split(newlines, -1)
else
[]
end
@@ -262,7 +263,7 @@ module Linguist
#
# Returns Integer
def sloc
lines.grep(/\S/).size
lines.grep(Regexp.new('\S'.encode(encoding))).size
end
# Public: Is the blob a generated file?