File tree Expand file tree Collapse file tree 6 files changed +32
-4
lines changed
common/src/codingstandards/cpp Expand file tree Collapse file tree 6 files changed +32
-4
lines changed Original file line number Diff line number Diff line change
1
+ ` A2-3-1 ` : ` cpp/autosar/invalid-character-in-string-literal `
2
+ - Fixes #311 . Exclude wide string literals and utf8 string literal.
Original file line number Diff line number Diff line change 17
17
18
18
import cpp
19
19
import codingstandards.cpp.autosar
20
+ import codingstandards.cpp.Literals
20
21
21
22
bindingset [ s]
22
23
string getCharOutsideBasicSourceCharSet ( string s ) {
@@ -27,6 +28,9 @@ string getCharOutsideBasicSourceCharSet(string s) {
27
28
from StringLiteral s , string ch
28
29
where
29
30
not isExcluded ( s , NamingPackage:: invalidCharacterInStringLiteralQuery ( ) ) and
30
- ch = getCharOutsideBasicSourceCharSet ( s .getValueText ( ) )
31
+ ch = getCharOutsideBasicSourceCharSet ( s .getValueText ( ) ) and
32
+ // wide string and utf8 string literals are exempted.
33
+ not s instanceof WideStringLiteral and
34
+ not s instanceof Utf8StringLiteral
31
35
select s ,
32
36
"String literal uses the character '" + ch + "' that is outside the language basic character set."
Original file line number Diff line number Diff line change 1
1
| test.cpp:3:1:3:37 | // Invalid character \u00ce\u00b1 NON_COMPLIANT | Comment uses the character '\u00ce\u00b1' that is outside the language basic character set. |
2
- | test.cpp:10 :1:12 :2 | /*\nInvalid character \u00e2\u0086\u00a6 NON_COMPLIANT\n*/ | Comment uses the character '\u00e2\u0086\u00a6' that is outside the language basic character set. |
2
+ | test.cpp:12 :1:14 :2 | /*\nInvalid character \u00e2\u0086\u00a6 NON_COMPLIANT\n*/ | Comment uses the character '\u00e2\u0086\u00a6' that is outside the language basic character set. |
Original file line number Diff line number Diff line change 1
- | test.cpp:7:20 :7:22 | \u00ce\u00b1 | String literal uses the character '\u03b1' that is outside the language basic character set. |
1
+ | test.cpp:7:21 :7:23 | \u00ce\u00b1 | String literal uses the character '\u03b1' that is outside the language basic character set. |
Original file line number Diff line number Diff line change 4
4
double α = 2 .; // NON_COMPLIANT; U+03b1
5
5
void *to_𐆅_and_beyond = nullptr ; // NON_COMPLIANT; U+10185
6
6
int l1_\u00A8; // COMPLIANT[FALSE_POSITIVE]
7
- const char *euro = " α" ; // NON_COMPLIANT
7
+ const char *euro1 = " α" ; // NON_COMPLIANT
8
+ const wchar_t *euro2 = L" α" ; // COMPLIANT
9
+ const char *euro3 = u8" α" ; // COMPLIANT
8
10
9
11
int valid;
10
12
/*
11
13
Invalid character ↦ NON_COMPLIANT
14
+ */
15
+
16
+ /*
17
+ Valid character @ in comments COMPLIANT
12
18
*/
Original file line number Diff line number Diff line change @@ -12,3 +12,19 @@ string getTruncatedLiteralText(Literal l) {
12
12
else result = text
13
13
)
14
14
}
15
+
16
+ class WideStringLiteral extends StringLiteral {
17
+ WideStringLiteral ( ) { this .getValueText ( ) .regexpMatch ( "(?s)\\s*L\".*" ) }
18
+ }
19
+
20
+ class Utf8StringLiteral extends StringLiteral {
21
+ Utf8StringLiteral ( ) { this .getValueText ( ) .regexpMatch ( "(?s)\\s*u8\".*" ) }
22
+ }
23
+
24
+ class Utf16StringLiteral extends StringLiteral {
25
+ Utf16StringLiteral ( ) { this .getValueText ( ) .regexpMatch ( "(?s)\\s*u\".*" ) }
26
+ }
27
+
28
+ class Utf32StringLiteral extends StringLiteral {
29
+ Utf32StringLiteral ( ) { this .getValueText ( ) .regexpMatch ( "(?s)\\s*U\".*" ) }
30
+ }
You can’t perform that action at this time.
0 commit comments