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 1717
1818import cpp
1919import codingstandards.cpp.autosar
20+ import codingstandards.cpp.Literals
2021
2122bindingset [ s]
2223string getCharOutsideBasicSourceCharSet ( string s ) {
@@ -27,6 +28,9 @@ string getCharOutsideBasicSourceCharSet(string s) {
2728from StringLiteral s , string ch
2829where
2930 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
3135select s ,
3236 "String literal uses the character '" + ch + "' that is outside the language basic character set."
Original file line number Diff line number Diff line change 11| 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 44double α = 2 .; // NON_COMPLIANT; U+03b1
55void *to_𐆅_and_beyond = nullptr ; // NON_COMPLIANT; U+10185
66int 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
810
911int valid;
1012/*
1113Invalid character ↦ NON_COMPLIANT
14+ */
15+
16+ /*
17+ Valid character @ in comments COMPLIANT
1218*/
Original file line number Diff line number Diff line change @@ -12,3 +12,19 @@ string getTruncatedLiteralText(Literal l) {
1212 else result = text
1313 )
1414}
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