зеркало из 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() }
|
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
|
* 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.
|
* 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>
|
* <tr><td>"//FileServer/"</td><td>""</td></tr>
|
||||||
* </table>
|
* </table>
|
||||||
*/
|
*/
|
||||||
string getBaseName() {
|
string getBaseName() { this.splitAbsolutePath(result, 1) }
|
||||||
result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the extension of this container, that is, the suffix of its base name
|
* 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>
|
* <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr>
|
||||||
* </table>
|
* </table>
|
||||||
*/
|
*/
|
||||||
string getExtension() {
|
string getExtension() { this.splitAbsolutePath(result, 3) }
|
||||||
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Gets the file in this container that has the given `baseName`, if any. */
|
/** Gets the file in this container that has the given `baseName`, if any. */
|
||||||
File getFile(string baseName) {
|
File getFile(string baseName) {
|
||||||
|
@ -183,9 +190,7 @@ module Make<InputSig Input> {
|
||||||
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
|
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
|
||||||
* </table>
|
* </table>
|
||||||
*/
|
*/
|
||||||
string getStem() {
|
string getStem() { this.splitAbsolutePath(result, 2) }
|
||||||
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a URL representing the location of this container.
|
* Gets a URL representing the location of this container.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче