mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add detection for generated PostScript files.
This commit is contained in:
@@ -57,6 +57,7 @@ module Linguist
|
|||||||
xcode_project_file? ||
|
xcode_project_file? ||
|
||||||
generated_net_docfile? ||
|
generated_net_docfile? ||
|
||||||
generated_parser? ||
|
generated_parser? ||
|
||||||
|
generated_postscript? ||
|
||||||
generated_protocol_buffer?
|
generated_protocol_buffer?
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -160,6 +161,29 @@ module Linguist
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Internal: Is the blob of PostScript generated?
|
||||||
|
#
|
||||||
|
# PostScript files are often generated by other programs. If they tell us so,
|
||||||
|
# we can detect them.
|
||||||
|
#
|
||||||
|
# Returns true or false.
|
||||||
|
def generated_postscript?
|
||||||
|
return false unless ['.ps', '.eps'].include? extname
|
||||||
|
|
||||||
|
# We analyze the "%%Creator:" comment, which contains the author/generator
|
||||||
|
# of the file. If there is one, it should be in one of the first few lines.
|
||||||
|
creator = lines[0..9].find {|line| line =~ /^%%Creator: /}
|
||||||
|
return false if creator.nil?
|
||||||
|
|
||||||
|
# Most generators write their version number, while human authors' or companies'
|
||||||
|
# names don't contain numbers. So look if the line contains digits. Also
|
||||||
|
# look for some special cases without version numbers.
|
||||||
|
return creator =~ /[0-9]/ ||
|
||||||
|
creator.include? "mpage" ||
|
||||||
|
creator.include? "draw" ||
|
||||||
|
creator.include? "ImageMagick"
|
||||||
|
end
|
||||||
|
|
||||||
# Internal: Is the blob a C++, Java or Python source file generated by the
|
# Internal: Is the blob a C++, Java or Python source file generated by the
|
||||||
# Protocol Buffer compiler?
|
# Protocol Buffer compiler?
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -188,6 +188,9 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
# PEG.js-generated parsers
|
# PEG.js-generated parsers
|
||||||
assert blob("JavaScript/parser.js").generated?
|
assert blob("JavaScript/parser.js").generated?
|
||||||
|
|
||||||
|
# Generated PostScript
|
||||||
|
assert !blob("PostScript/sierpinski.ps").generated?
|
||||||
|
|
||||||
# These examples are too basic to tell
|
# These examples are too basic to tell
|
||||||
assert !blob("JavaScript/empty.js").generated?
|
assert !blob("JavaScript/empty.js").generated?
|
||||||
assert !blob("JavaScript/hello.js").generated?
|
assert !blob("JavaScript/hello.js").generated?
|
||||||
|
|||||||
Reference in New Issue
Block a user