aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Tomayko <rtomayko@gmail.com>2012-09-10 01:05:48 -0700
committerRyan Tomayko <rtomayko@gmail.com>2012-09-10 01:05:48 -0700
commit2e49c06f47d63ac3de03de59ecd98466c83497a7 (patch)
tree32441077843097554d738c868b7aa633626cd909
parentae137847b42c21e15b5459ee85a28b0710e8af54 (diff)
Handle :sparkles:Mac Format:sparkles: when splitting lines
-rw-r--r--lib/linguist/blob_helper.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb
index 04c3f0a..de75dbc 100644
--- a/lib/linguist/blob_helper.rb
+++ b/lib/linguist/blob_helper.rb
@@ -204,7 +204,31 @@ module Linguist
#
# Returns an Array of lines
def lines
- @lines ||= (viewable? && data) ? data.split("\n", -1) : []
+ @lines ||=
+ if viewable? && data
+ data.split(line_split_character, -1)
+ else
+ []
+ end
+ end
+
+ # Character used to split lines. This is almost always "\n" except when Mac
+ # Format is detected in which case it's "\r".
+ #
+ # Returns a split pattern string.
+ def line_split_character
+ @line_split_character ||= (mac_format?? "\r" : "\n")
+ end
+
+ # Public: Is the data in ** Mac Format **. This format uses \r (0x0d) characters
+ # for line ends and does not include a \n (0x0a).
+ #
+ # Returns true when mac format is detected.
+ def mac_format?
+ return if !viewable?
+ if pos = data.index("\r")
+ data[pos + 1] != ?\n
+ end
end
# Public: Get number of lines of code