Detect C++ language from all C++ file extensions

This commit is contained in:
Alan Hamlett 2019-03-11 11:20:23 +09:00
parent 9b2eabe568
commit 540557e998
15 changed files with 21 additions and 2 deletions

View file

View file

@ -0,0 +1,8 @@
#include <stdio.h>
#include <openssl/rand.h>
main()
{
printf("Hello World\n");
return 0;
}

View file

View file

View file

@ -69,6 +69,12 @@ class LanguagesTestCase(utils.TestCase):
entity='c_and_cpp/cpp.h', entity='c_and_cpp/cpp.h',
) )
def test_cpp_language_detected_for_header_with_c_and_cxx_files_in_folder(self):
self.shared(
expected_language='C++',
entity='c_and_cxx/cpp.h',
)
def test_c_not_detected_for_non_header_with_c_files_in_folder(self): def test_c_not_detected_for_non_header_with_c_files_in_folder(self):
self.shared( self.shared(
expected_language='Python', expected_language='Python',

View file

@ -25,6 +25,7 @@ from .packages.pygments.lexers import (
_fn_matches, _fn_matches,
basename, basename,
ClassNotFound, ClassNotFound,
CppLexer,
find_lexer_class, find_lexer_class,
get_lexer_by_name, get_lexer_by_name,
) )
@ -181,8 +182,12 @@ def get_language_from_extension(file_name):
return 'Objective-C++' return 'Objective-C++'
available_extensions = extensions_in_same_folder(file_name) available_extensions = extensions_in_same_folder(file_name)
if '.cpp' in available_extensions:
return 'C++' for ext in CppLexer.filenames:
ext = ext.lstrip('*')
if ext in available_extensions:
return 'C++'
if '.c' in available_extensions: if '.c' in available_extensions:
return 'C' return 'C'