Cpp.StringLiteral Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the string_literal nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.StringLiteral represents the node string_literal in the syntax tree of your code.
#include <iostream>
int main() {
const char* s1 = "Hello";
const char* s2 = "Line\\nBreak";
const char* s3 = "A \"quoted\" string";
(void)s1; (void)s2; (void)s3;
return 0;
}The C++ code shows several string_literal occurrences. Each quoted token like "Hello" corresponds to a Cpp.StringLiteral node.
Predicates
| Type | Raisable | Printable |
|---|---|---|
StringLiteral
| Yes | No |
This class defines these predicates that act on the objects of this class. In addition, objects of this class can access the predicates defined by the base class AstNodeProperties. An object of this class is an object of AstNodeProperties class.
| Predicates | Description | Example |
|---|---|---|
is(required StringLiteral &lit)
| Matches a string_literal node and binds it to
lit for further inspection. Use this to directly obtain string
literals. | This PQL defect checks for any string literal in the code. defect FindStringLiterals =
when
Cpp.StringLiteral.is(&lit)
and lit.nodeText(&txt)
raise "Found string literal: {txt}"
on litIn this C++ code the defect finds every quoted string
token such as
#include <iostream>
int main() {
const char* s = "Hello";
(void)s;
return 0;
} |
cast(Cpp.Node.Node node, required StringLiteral &cast)
| Checks whether an arbitrary Node is a
string_literal and if so returns it as cast.
Use this when you have a node of unknown specific type. | This PQL defect checks for nodes that are string literals after casting from a generic node. defect CastNodeToStringLiteral =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.StringLiteral.cast(node, &lit)
and lit.nodeText(&txt)
raise "Casted node to string literal: {txt}"
on litIn this C++ code the defect finds string literal by casting from generic syntax nodes.
#include <iostream>
int main() {
const char* s = "World";
(void)s;
return 0;
} |
isa(Cpp.Node.Node node)
| Returns true if the given Node is a
string_literal. Use this for boolean checks or
negation. | This PQL defect checks whether a node is not a string literal using
defect NodeIsNotStringLiteral =
when
Cpp.Node.is(&node, &,&,&)
and not Cpp.StringLiteral.isa(node)
raise "Node is not a string literal"
on nodeIn this C++ code the defect finds all syntax nodes that are not string literals.
int main() {
int x = 42;
(void)x;
return 0;
} |
stringContent(StringLiteral self, Cpp.StringContent.StringContent
&content)
| Returns the inner text of the string literal excluding surrounding quotes and
escapes as content. Use this to examine the actual text
characters. | This PQL defect checks for string literals that contain a specific content fragment. defect ContainsHelloContent =
when
Cpp.StringLiteral.is(&lit)
and lit.stringContent(&content)
and content.nodeText(&txt)
and txt == "Hello"
raise "String literal contains Hello"
on litIn this C++ code the defect looks into the literal
#include <iostream>
int main() {
const char* s = "Hello";
(void)s;
return 0;
} |
escapeSequence(StringLiteral self, Cpp.EscapeSequence.EscapeSequence
&escape)
| Returns each escape sequence found inside the string literal
asescape to. Use this to detect escapes like
\n or \t. | This PQL defect checks for string literals that contain escape sequences. defect HasEscapeSequence =
when
Cpp.StringLiteral.is(&lit)
and lit.escapeSequence(&esc)
and esc.nodeText(&txt)
raise "String literal has escape sequence: {txt}"
on litIn this C++ code the defect finds the
#include <iostream>
int main() {
const char* s = "Line\nBreak";
std::cout << s << std::endl;
return 0;
} |
getEnclosingStringLiteral(Cpp.Node.Node child, required StringLiteral
&parent)
| Given a child node, finds the closest enclosing
string_literal and returns it as parent. Use
this to map inner parts back to their literal. | This PQL defect checks for a string content node and then finds its enclosing string literal. defect EnclosingStringLiteralFromContent =
when
Cpp.StringContent.is(&sc)
and sc.toNode(&child)
and Cpp.StringLiteral.getEnclosingStringLiteral(child, &parent)
and parent.nodeText(&txt)
raise "Enclosing string literal: {txt}"
on parentIn this C++ code the defect starts from the inner
content node
#include <iostream>
int main() {
const char* s = "Hello";
(void)s;
return 0;
} |
isEnclosedInStringLiteral(Cpp.Node.Node child)
| Returns true if the given node has a string_literal
ancestor. Use this to test whether a node appears inside a string literal. | This PQL defect checks whether a node is located inside any string literal. defect ChildIsInsideStringLiteral =
when
Cpp.StringContent.is(&sc)
and sc.toNode(&child)
and Cpp.StringLiteral.isEnclosedInStringLiteral(child)
raise "Node is enclosed in a string literal"
on childIn this C++ code the defect checks that a
#include <iostream>
int main() {
const char* s = "Hello";
(void)s;
return 0;
} |
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)