mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Guess .h language
This commit is contained in:
@@ -269,8 +269,12 @@ module Linguist
|
||||
# Returns a Language object
|
||||
def language
|
||||
if text?
|
||||
# First see if there is a Language for the extension
|
||||
if Language.find_by_extension(extname)
|
||||
# If its a header file (.h) try to guess the language
|
||||
if language = header_language
|
||||
language
|
||||
|
||||
# See if there is a Language for the extension
|
||||
elsif Language.find_by_extension(extname)
|
||||
pathname.language
|
||||
|
||||
# Try to detect Language from shebang line
|
||||
@@ -293,6 +297,21 @@ module Linguist
|
||||
language.lexer
|
||||
end
|
||||
|
||||
# Internal: Guess language of header files (.h).
|
||||
#
|
||||
# Returns a Language.
|
||||
def header_language
|
||||
return unless extname == '.h'
|
||||
|
||||
if lines.grep(/^@(interface|property|private|public|end)/).any?
|
||||
Language['Objective-C']
|
||||
elsif lines.grep(/^class |^\s+(public|protected|private):/).any?
|
||||
Language['C++']
|
||||
else
|
||||
Language['C']
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Extract the script name from the shebang line
|
||||
#
|
||||
# Requires Blob#data
|
||||
|
||||
Reference in New Issue
Block a user