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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)