File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
common/src/codingstandards/cpp Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import cpp
1818import codingstandards.cpp.autosar
1919import codingstandards.cpp.LoggingOperation
2020import codingstandards.cpp.Literals
21+ import codingstandards.cpp.Cpp14Literal
2122
2223from Literal l
2324where
3536 // Exclude literal 0
3637 not l .getValue ( ) = "0" and
3738 // Exclude character literals
38- not l instanceof CharLiteral and
39+ not l instanceof Cpp14Literal :: CharLiteral and
3940 // Exclude `nullptr`
4041 not l .getType ( ) instanceof NullPointerType and
4142 // Exclude boolean `true` and `false`
Original file line number Diff line number Diff line change @@ -82,4 +82,24 @@ module Cpp14Literal {
8282
8383 override string getAPrimaryQlClass ( ) { result = "FloatingLiteral" }
8484 }
85+
86+ /**
87+ * A character literal. For example:
88+ * ```
89+ * char c1 = 'a';
90+ * char16_t c2 = u'a';
91+ * char32_t c3 = U'a';
92+ * wchar_t c4 = L'b';
93+ * ```
94+ */
95+ class CharLiteral extends StandardLibrary:: TextLiteral {
96+ CharLiteral ( ) { this .getValueText ( ) .regexpMatch ( "(?s)\\s*(L|u|U)?'.*" ) }
97+
98+ override string getAPrimaryQlClass ( ) { result = "CharLiteral" }
99+
100+ /**
101+ * Gets the character of this literal. For example `L'a'` has character `"a"`.
102+ */
103+ string getCharacter ( ) { result = this .getValueText ( ) .regexpCapture ( "(?s)\\s*(L|u|U)?'(.*)'" , 1 ) }
104+ }
85105}
You can’t perform that action at this time.
0 commit comments