Cpp.EscapeSequence Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the escape_sequence nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.EscapeSequence represents the node escape_sequence in the syntax tree of your code.
void test_escape_sequences() {
char c1 = '\n';
char c2 = '\x41';
char c3 = '\101';
char c4 = '\\';
char c5 = '\'';
const char* s1 = "Hello\nWorld";
const char* s2 = "Tab:\tEnd";
const char* s3 = "Quote: \"";
const char* s4 = "Backslash: \\";
}The C++ code above includes several escape_sequence occurrences such as '\n', '\x41', "\n" and "\\" that correspond to the Cpp.EscapeSequence nodes in the PQL syntax tree.
Predicates
| Type | Raisable | Printable |
|---|---|---|
EscapeSequence
| 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 Cpp.EscapeSequence &expr)
| Matches an escape_sequence node and binds it to
expr for further checks. Use this to directly select escape
sequences. | This PQL defect checks for any escape sequence node in the code. defect defectIs =
when
Cpp.EscapeSequence.is(&esc)
and esc.nodeText(&txt)
raise "EscapeSequence.is matched: \"{txt}\""
on escIn this C++ code, the defect finds literal escape sequences such as character and string escapes.
int main() {
const char* s = "Hello\nWorld";
char c = '\x41';
return 0;
} |
cast(Cpp.Node.Node node, required Cpp.EscapeSequence &cast)
| Treats a generic Node as an
escape_sequence and binds it to cast if the
node is actually an escape_sequence. Use this to continue from a
node you already have. | This PQL defect checks for an defect defectCast =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.EscapeSequence.cast(node, &esc)
and esc.nodeText(&txt)
raise "EscapeSequence.cast matched inside string: \"{txt}\""
on escIn this C++ code, the defect finds escape sequences.
int main() {
const char* s = "Line1\nLine2";
return 0;
} |
isa(Cpp.Node.Node node)
| Checks whether a provided Node is an
escape_sequence and returns true or false. Use this when you
only need a boolean test. | This PQL defect checks whether a given node is an
defect defectIsa =
when
CCpp.Node.is(&n, &,&,&)
and Cpp.EscapeSequence.isa(node)
raise "Node is an EscapeSequence inside a char literal"
on charlitIn this C++ code, the defect detects escape
sequences like
int main() {
char c = '\n';
return 0;
} |
isInStringLiteral(Cpp.EscapeSequence.Cpp.EscapeSequence self,
Cpp.StringLiteral.StringLiteral lit)
| Checks that an escape_sequence appears inside a
string_literal and binds the surrounding string literal to
lit. Use this to locate escapes within string
constants. | This PQL defect checks for escape sequences that are located inside string literals. defect defectInString =
when
Cpp.EscapeSequence.is(&esc)
and Cpp.EscapeSequence.isInStringLiteral(esc, &strlit)
and strlit.nodeText(&txt)
raise "Escape sequence found in string literal: \"{txt}\""
on escIn this C++ code, the defect finds escape
sequences inside string literals such as
int main() {
const char* s = "Tab:\tEnd";
return 0;
} |
isInCharLiteral(Cpp.EscapeSequence.Cpp.EscapeSequence self,
Cpp.CharLiteral.CharLiteral lit)
| Checks that an escape_sequence appears inside a
char_literal and binds the surrounding char literal to
lit. Use this to find escapes used in character
constants. | This PQL defect checks for escape sequences located inside character literals. defect defectInChar =
when
Cpp.EscapeSequence.is(&esc)
and Cpp.EscapeSequence.isInCharLiteral(esc, &chlit)
and chlit.nodeText(&txt)
raise "Escape sequence found in char literal: \"{txt}\""
on escIn this C++ code, the defect finds escape
sequences in char literals like
int main() {
char q = '\'';
char b = '\\';
return 0;
} |
parentLiteral(Cpp.EscapeSequence.Cpp.EscapeSequence self, required
Cpp.Node.Node &lit)
| Returns the parent literal node containing the escape sequence which may be
either a string or char literal and binds it to lit. Use this to
retrieve the enclosing literal regardless of type. | This PQL defect checks for an escape sequence and then retrieves its enclosing literal as a generic node. defect defectParentLiteral =
when
Cpp.EscapeSequence.is(&esc)
and Cpp.EscapeSequence.parentLiteral(esc, &lit)
and lit.nodeText(&txt)
raise "EscapeSequence parent literal: \"{txt}\""
on escIn this C++ code, the defect finds an escape
sequence and prints the full literal that contains it, such as
int main() {
const char* s = "Quote: \"";
char c = '\n';
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.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)