зеркало из https://github.com/github/codeql.git
FileSystem: Improve regex by only matching once instead of 3x.
This commit is contained in:
Родитель
cfd08f23a5
Коммит
80f00bcb0b
|
@ -84,6 +84,17 @@ module Make<InputSig Input> {
|
|||
*/
|
||||
string getAbsolutePath() { result = super.getAbsolutePath() }
|
||||
|
||||
/**
|
||||
* Holds if either,
|
||||
* - `part` is the base name of this container and `i = 1`, or
|
||||
* - `part` is the stem of this container and `i = 2`, or
|
||||
* - `part` is the extension of this container and `i = 3`.
|
||||
*/
|
||||
cached
|
||||
private predicate splitAbsolutePath(string part, int i) {
|
||||
part = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", i)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the base name of this container including extension, that is, the last
|
||||
* segment of its absolute path, or the empty string if it has no segments.
|
||||
|
@ -101,9 +112,7 @@ module Make<InputSig Input> {
|
|||
* <tr><td>"//FileServer/"</td><td>""</td></tr>
|
||||
* </table>
|
||||
*/
|
||||
string getBaseName() {
|
||||
result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
|
||||
}
|
||||
string getBaseName() { this.splitAbsolutePath(result, 1) }
|
||||
|
||||
/**
|
||||
* Gets the extension of this container, that is, the suffix of its base name
|
||||
|
@ -128,9 +137,7 @@ module Make<InputSig Input> {
|
|||
* <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr>
|
||||
* </table>
|
||||
*/
|
||||
string getExtension() {
|
||||
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3)
|
||||
}
|
||||
string getExtension() { this.splitAbsolutePath(result, 3) }
|
||||
|
||||
/** Gets the file in this container that has the given `baseName`, if any. */
|
||||
File getFile(string baseName) {
|
||||
|
@ -183,9 +190,7 @@ module Make<InputSig Input> {
|
|||
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
|
||||
* </table>
|
||||
*/
|
||||
string getStem() {
|
||||
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1)
|
||||
}
|
||||
string getStem() { this.splitAbsolutePath(result, 2) }
|
||||
|
||||
/**
|
||||
* Gets a URL representing the location of this container.
|
||||
|
|
Загрузка…
Ссылка в новой задаче