-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathInvalidCharacterInComment.ql
40 lines (37 loc) · 1.43 KB
/
InvalidCharacterInComment.ql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @id cpp/autosar/invalid-character-in-comment
* @name A2-3-1: Use of characters outside the C++ Language Standard basic source character set
* @description Only those characters specified in the C++ Language Standard basic source character
* set shall be used in a comment.
* @kind problem
* @precision very-high
* @problem.severity recommendation
* @tags external/autosar/id/a2-3-1
* maintainability
* external/autosar/allocated-target/architecture
* external/autosar/allocated-target/design
* external/autosar/allocated-target/implementation
* external/autosar/enforcement/automated
* external/autosar/obligation/required
*/
import cpp
import codingstandards.cpp.autosar
string getCharOutsideBasicSourceCharSet(Comment c) {
exists(string s | s = c.getContents() |
result =
s.regexpFind("(?![\\p{Alnum}\\p{Space}_{}\\[\\]#()<>%:;.?*+-/^&|~!=,\\\\\"'@])[\\u0000-\\u007f]",
_, _)
or
result = s.regexpFind("[\\u00c0-\\u00df][\\u0080-\\u00bf]", _, _)
or
result = s.regexpFind("[\\u00e0-\\u00ef][\\u0080-\\u00bf]{2}", _, _)
or
result = s.regexpFind("[\\u00f0-\\u00f7][\\u0080-\\u00bf]{3}", _, _)
)
}
from Comment c, string ch
where
not isExcluded(c, NamingPackage::invalidCharacterInCommentQuery()) and
ch = getCharOutsideBasicSourceCharSet(c)
select c,
"Comment uses the character '" + ch + "' that is outside the language basic character set."