mirror of
https://github.com/github/codeql.git
synced 2026-07-31 07:22:56 +02:00
C++: Remove lookbehind assertions
This commit is contained in:
committed by
GitHub
parent
0323da39c9
commit
8e6b168730
@@ -991,15 +991,13 @@ private module Impl implements RegexTreeViewSig {
|
||||
}
|
||||
|
||||
/**
|
||||
* A zero-width lookahead or lookbehind assertion.
|
||||
* A zero-width lookahead assertion.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* ```
|
||||
* (?=\w)
|
||||
* (?!\n)
|
||||
* (?<=\.)
|
||||
* (?<!\\)
|
||||
* ```
|
||||
*/
|
||||
class RegExpSubPattern extends RegExpZeroWidthMatch {
|
||||
@@ -1061,44 +1059,16 @@ private module Impl implements RegexTreeViewSig {
|
||||
override string getAPrimaryQlClass() { result = "RegExpNegativeLookahead" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A zero-width lookbehind assertion.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* ```
|
||||
* (?<=\.)
|
||||
* (?<!\\)
|
||||
* ```
|
||||
*/
|
||||
abstract class RegExpLookbehind extends RegExpSubPattern { }
|
||||
|
||||
/**
|
||||
* A positive-lookbehind assertion.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* ```
|
||||
* (?<=\.)
|
||||
* ```
|
||||
*/
|
||||
class RegExpPositiveLookbehind extends RegExpLookbehind {
|
||||
RegExpPositiveLookbehind() { re.positiveLookbehindAssertionGroup(start, end) }
|
||||
RegExpPositiveLookbehind() { none() }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "RegExpPositiveLookbehind" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A negative-lookbehind assertion.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* ```
|
||||
* (?<!\\)
|
||||
* ```
|
||||
*/
|
||||
additional class RegExpNegativeLookbehind extends RegExpLookbehind {
|
||||
RegExpNegativeLookbehind() { re.negativeLookbehindAssertionGroup(start, end) }
|
||||
RegExpNegativeLookbehind() { none() }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "RegExpNegativeLookbehind" }
|
||||
}
|
||||
|
||||
@@ -510,8 +510,6 @@ abstract class RegExp extends StringLiteral {
|
||||
this.negativeAssertionGroup(start, end)
|
||||
or
|
||||
this.positiveLookaheadAssertionGroup(start, end)
|
||||
or
|
||||
this.positiveLookbehindAssertionGroup(start, end)
|
||||
}
|
||||
|
||||
/** Holds if an empty group is found between `start` and `end`. */
|
||||
@@ -534,16 +532,10 @@ abstract class RegExp extends StringLiteral {
|
||||
this.emptyGroup(start, end)
|
||||
or
|
||||
this.negativeAssertionGroup(start, end)
|
||||
or
|
||||
this.positiveLookbehindAssertionGroup(start, end)
|
||||
}
|
||||
|
||||
private predicate negativeAssertionGroup(int start, int end) {
|
||||
exists(int inStart |
|
||||
this.negativeLookaheadAssertionStart(start, inStart)
|
||||
or
|
||||
this.negativeLookbehindAssertionStart(start, inStart)
|
||||
|
|
||||
exists(int inStart | this.negativeLookaheadAssertionStart(start, inStart) |
|
||||
this.groupContents(start, end, inStart, _)
|
||||
)
|
||||
}
|
||||
@@ -555,13 +547,6 @@ abstract class RegExp extends StringLiteral {
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if a negative lookbehind is found between `start` and `end` */
|
||||
predicate negativeLookbehindAssertionGroup(int start, int end) {
|
||||
exists(int inStart | this.negativeLookbehindAssertionStart(start, inStart) |
|
||||
this.groupContents(start, end, inStart, _)
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if a positive lookahead is found between `start` and `end` */
|
||||
predicate positiveLookaheadAssertionGroup(int start, int end) {
|
||||
exists(int inStart | this.lookaheadAssertionStart(start, inStart) |
|
||||
@@ -569,13 +554,6 @@ abstract class RegExp extends StringLiteral {
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if a positive lookbehind is found between `start` and `end` */
|
||||
predicate positiveLookbehindAssertionGroup(int start, int end) {
|
||||
exists(int inStart | this.lookbehindAssertionStart(start, inStart) |
|
||||
this.groupContents(start, end, inStart, _)
|
||||
)
|
||||
}
|
||||
|
||||
private predicate groupStart(int start, int end) {
|
||||
this.nonCapturingGroupStart(start, end)
|
||||
or
|
||||
@@ -583,10 +561,6 @@ abstract class RegExp extends StringLiteral {
|
||||
or
|
||||
this.negativeLookaheadAssertionStart(start, end)
|
||||
or
|
||||
this.lookbehindAssertionStart(start, end)
|
||||
or
|
||||
this.negativeLookbehindAssertionStart(start, end)
|
||||
or
|
||||
this.simpleGroupStart(start, end)
|
||||
}
|
||||
|
||||
@@ -621,24 +595,6 @@ abstract class RegExp extends StringLiteral {
|
||||
end = start + 3
|
||||
}
|
||||
|
||||
/** Matches the start of a positive lookbehind assertion, i.e. `(?<=`. */
|
||||
private predicate lookbehindAssertionStart(int start, int end) {
|
||||
this.isGroupStart(start) and
|
||||
this.getChar(start + 1) = "?" and
|
||||
this.getChar(start + 2) = "<" and
|
||||
this.getChar(start + 3) = "=" and
|
||||
end = start + 4
|
||||
}
|
||||
|
||||
/** Matches the start of a negative lookbehind assertion, i.e. `(?<!`. */
|
||||
private predicate negativeLookbehindAssertionStart(int start, int end) {
|
||||
this.isGroupStart(start) and
|
||||
this.getChar(start + 1) = "?" and
|
||||
this.getChar(start + 2) = "<" and
|
||||
this.getChar(start + 3) = "!" and
|
||||
end = start + 4
|
||||
}
|
||||
|
||||
/** Matches the contents of a group. */
|
||||
predicate groupContents(int start, int end, int inStart, int inEnd) {
|
||||
this.groupStart(start, inStart) and
|
||||
|
||||
Reference in New Issue
Block a user