Skip to content

Commit bb96e90

Browse files
Copilotjketema
authored andcommitted
C++: Remove named backreferences
1 parent 985a2ba commit bb96e90

2 files changed

Lines changed: 2 additions & 25 deletions

File tree

‎cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,14 +1106,13 @@ private module Impl implements RegexTreeViewSig {
11061106
}
11071107

11081108
/**
1109-
* A back reference, that is, a term of the form `\i` or `\k<name>`
1110-
* in a regular expression.
1109+
* A back reference, that is, a term of the form `\i` in a regular
1110+
* expression.
11111111
*
11121112
* Examples:
11131113
*
11141114
* ```
11151115
* \1
1116-
* (?P=quote)
11171116
* ```
11181117
*/
11191118
class RegExpBackRef extends RegExpTerm, TRegExpBackRef {
@@ -1124,11 +1123,6 @@ private module Impl implements RegexTreeViewSig {
11241123
*/
11251124
int getNumber() { result = re.getBackRefNumber(start, end) }
11261125

1127-
/**
1128-
* Gets the name of the capture group this back reference refers to, if any.
1129-
*/
1130-
string getName() { result = re.getBackRefName(start, end) }
1131-
11321126
/** Gets the capture group this back reference refers to. */
11331127
RegExpGroup getGroup() {
11341128
result.getLiteral() = this.getLiteral() and

‎cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ abstract class RegExp extends StringLiteral {
331331
predicate escapedCharacter(int start, int end) {
332332
this.escapingChar(start) and
333333
not this.numberedBackreference(start, _, _) and
334-
not this.namedBackreference(start, _, _) and
335334
(
336335
// hex char \xhh
337336
this.getChar(start + 1) = "x" and end = start + 4
@@ -639,17 +638,6 @@ abstract class RegExp extends StringLiteral {
639638
this.isGroupEnd(inEnd)
640639
}
641640

642-
/** Matches a named backreference, e.g. `\k<foo>`. */
643-
predicate namedBackreference(int start, int end, string name) {
644-
this.escapingChar(start) and
645-
this.getChar(start + 1) = "k" and
646-
this.getChar(start + 2) = "<" and
647-
exists(int nameEnd | nameEnd = min(int i | i > start + 3 and this.getChar(i) = ">") |
648-
end = nameEnd + 1 and
649-
name = this.getText().substring(start + 3, nameEnd)
650-
)
651-
}
652-
653641
/** Matches a numbered backreference, e.g. `\1`. */
654642
predicate numberedBackreference(int start, int end, int value) {
655643
this.escapingChar(start) and
@@ -669,16 +657,11 @@ abstract class RegExp extends StringLiteral {
669657
/** Whether the text in the range `start,end` is a back reference */
670658
predicate backreference(int start, int end) {
671659
this.numberedBackreference(start, end, _)
672-
or
673-
this.namedBackreference(start, end, _)
674660
}
675661

676662
/** Gets the number of the back reference in start,end */
677663
int getBackRefNumber(int start, int end) { this.numberedBackreference(start, end, result) }
678664

679-
/** Gets the name, if it has one, of the back reference in start,end */
680-
string getBackRefName(int start, int end) { this.namedBackreference(start, end, result) }
681-
682665
private predicate baseItem(int start, int end) {
683666
this.characterItem(start, end) and
684667
not exists(int x, int y | this.charSet(x, y) and x <= start and y >= end)

0 commit comments

Comments
 (0)