Merge pull request #850 from github/cpp_heuristic

A C++ shibboleth?
This commit is contained in:
Ted Nyman
2013-12-23 10:20:36 -08:00
4 changed files with 26 additions and 11 deletions

View File

@@ -20,12 +20,14 @@ module Linguist
end
# .h extensions are ambigious between C, C++, and Objective-C.
# We want to shortcut look for Objective-C.
# We want to shortcut look for Objective-C _and_ now C++ too!
#
# Returns an array of Languages or []
# TODO rename this method as we're not strictly disambiguating between .h files here.
def self.disambiguate_h(data, languages)
matches = []
matches << Language["Objective-C"] if data.include?("@interface")
matches << Language["C++"] if data.include?("#include <cstdint>")
matches
end

View File

@@ -511,8 +511,8 @@
".gemrc"
]
},
"tokens_total": 436395,
"languages_total": 507,
"tokens_total": 436401,
"languages_total": 508,
"tokens": {
"ABAP": {
"*/**": 1,
@@ -8562,7 +8562,7 @@
"C++": {
"class": 40,
"Bar": 2,
"{": 580,
"{": 581,
"protected": 4,
"char": 127,
"*name": 6,
@@ -8572,7 +8572,7 @@
"hello": 2,
"(": 2729,
")": 2731,
"}": 580,
"}": 581,
"//": 278,
"///": 843,
"mainpage": 1,
@@ -9245,7 +9245,7 @@
"#ifndef": 27,
"BCM2835_H": 3,
"#define": 341,
"#include": 120,
"#include": 121,
"<stdint.h>": 2,
"defgroup": 7,
"constants": 1,
@@ -10120,7 +10120,7 @@
"<string>": 4,
"<vector>": 4,
"<fstream>": 2,
"namespace": 30,
"namespace": 31,
"std": 52,
"DEFAULT_DELIMITER": 1,
"CsvStreamer": 5,
@@ -11276,6 +11276,8 @@
"wrapMode": 2,
"wmode.": 1,
"wmode": 1,
"<cstdint>": 2,
"Gui": 1,
"rpc_init": 1,
"rpc_server_loop": 1,
"v8": 9,
@@ -11573,7 +11575,6 @@
"desc": 2,
"look": 1,
"ahead": 1,
"<cstdint>": 1,
"smallPrime_t": 1,
"UTILS_H": 3,
"<QtGlobal>": 1,
@@ -46342,7 +46343,7 @@
"Bluespec": 1298,
"Brightscript": 579,
"C": 58858,
"C++": 31175,
"C++": 31181,
"Ceylon": 50,
"Clojure": 510,
"COBOL": 90,
@@ -46478,7 +46479,7 @@
"Bluespec": 2,
"Brightscript": 1,
"C": 26,
"C++": 26,
"C++": 27,
"Ceylon": 1,
"Clojure": 7,
"COBOL": 4,
@@ -46600,5 +46601,5 @@
"Xtend": 2,
"YAML": 1
},
"md5": "7ab5683c610f7e81d6ea5fb470111bbe"
"md5": "4bd97c3aa060155c82b903fea0fecc57"
}

View File

@@ -0,0 +1,6 @@
#include <cstdint>
namespace Gui
{
}

View File

@@ -28,6 +28,12 @@ class TestHeuristcs < Test::Unit::TestCase
end
end
def test_cpp_by_heuristics
languages = ["C++", "Objective-C"]
results = Heuristics.disambiguate_h(fixture("C++/render_adapter.cpp"), languages)
assert_equal Language["C++"], results.first
end
def test_detect_still_works_if_nothing_matches
match = Language.detect("Hello.m", fixture("Objective-C/hello.m"))
assert_equal Language["Objective-C"], match