summaryrefslogtreecommitdiff
path: root/lib/coderay/scanner.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2011-03-01 01:02:36 +0000
committermurphy <murphy@rubychan.de>2011-03-01 01:02:36 +0000
commit6b7871b94c83d904d158d9809ee70907e3d24d33 (patch)
tree6bcbd2f073bbf43df4f22cb8b8014f806ebd6fe7 /lib/coderay/scanner.rb
parent9adbbf5913979b3e73d6a01d83530ac88748abad (diff)
downloadcoderay-6b7871b94c83d904d158d9809ee70907e3d24d33.tar.gz
Fix handling of Windows newlines in Scanner.
Diffstat (limited to 'lib/coderay/scanner.rb')
-rw-r--r--lib/coderay/scanner.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb
index ae27b0d..3276d4b 100644
--- a/lib/coderay/scanner.rb
+++ b/lib/coderay/scanner.rb
@@ -69,8 +69,11 @@ module CodeRay
def normalize code
original = code
code = code.to_s unless code.is_a? ::String
- code = encode_with_encoding code, self.encoding if code.respond_to? :encoding
- # code = to_unix code if code.index ?\r
+ if code.respond_to? :encoding
+ code = encode_with_encoding code, self.encoding
+ else
+ code = to_unix code if code.index ?\r
+ end
# code = code.dup if code.eql? original
code
end
@@ -93,7 +96,7 @@ module CodeRay
def encode_with_encoding code, target_encoding
if code.encoding == target_encoding
if code.valid_encoding?
- return code
+ return to_unix code
else
source_encoding = guess_encoding code
end
@@ -105,13 +108,11 @@ module CodeRay
end
def to_unix code
- print 'to_unix'
code.gsub(/\r\n?/, "\n")
end
def guess_encoding s
#:nocov:
- # print 'guess_encoding'
IO.popen("file -b --mime -", "w+") do |file|
file.write s[0, 1024]
file.close_write