@@ -84,6 +84,17 @@ module Make<InputSig Input> {
84
84
*/
85
85
string getAbsolutePath ( ) { result = super .getAbsolutePath ( ) }
86
86
87
+ /**
88
+ * Holds if either,
89
+ * - `part` is the base name of this container and `i = 1`, or
90
+ * - `part` is the stem of this container and `i = 2`, or
91
+ * - `part` is the extension of this container and `i = 3`.
92
+ */
93
+ cached
94
+ private predicate splitAbsolutePath ( string part , int i ) {
95
+ part = this .getAbsolutePath ( ) .regexpCapture ( ".*/(([^/]*?)(?:\\.([^.]*))?)" , i )
96
+ }
97
+
87
98
/**
88
99
* Gets the base name of this container including extension, that is, the last
89
100
* segment of its absolute path, or the empty string if it has no segments.
@@ -101,9 +112,7 @@ module Make<InputSig Input> {
101
112
* <tr><td>"//FileServer/"</td><td>""</td></tr>
102
113
* </table>
103
114
*/
104
- string getBaseName ( ) {
105
- result = this .getAbsolutePath ( ) .regexpCapture ( ".*/(([^/]*?)(?:\\.([^.]*))?)" , 1 )
106
- }
115
+ string getBaseName ( ) { this .splitAbsolutePath ( result , 1 ) }
107
116
108
117
/**
109
118
* Gets the extension of this container, that is, the suffix of its base name
@@ -128,9 +137,7 @@ module Make<InputSig Input> {
128
137
* <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr>
129
138
* </table>
130
139
*/
131
- string getExtension ( ) {
132
- result = this .getAbsolutePath ( ) .regexpCapture ( ".*/([^/]*?)(\\.([^.]*))?" , 3 )
133
- }
140
+ string getExtension ( ) { this .splitAbsolutePath ( result , 3 ) }
134
141
135
142
/** Gets the file in this container that has the given `baseName`, if any. */
136
143
File getFile ( string baseName ) {
@@ -183,9 +190,7 @@ module Make<InputSig Input> {
183
190
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
184
191
* </table>
185
192
*/
186
- string getStem ( ) {
187
- result = this .getAbsolutePath ( ) .regexpCapture ( ".*/([^/]*?)(?:\\.([^.]*))?" , 1 )
188
- }
193
+ string getStem ( ) { this .splitAbsolutePath ( result , 2 ) }
189
194
190
195
/**
191
196
* Gets a URL representing the location of this container.
0 commit comments