@@ -222,20 +222,27 @@ module Make<InputSig Input> {
222
222
/** Provides logic related to `Folder`s. */
223
223
module Folder {
224
224
/** Holds if `relativePath` needs to be appended to `f`. */
225
- signature predicate appendSig ( Folder f , string relativePath ) ;
225
+ signature predicate shouldAppendSig ( Folder f , string relativePath ) ;
226
226
227
227
/** Provides the `append` predicate for appending a relative path onto a folder. */
228
- module Append< appendSig / 2 app > {
228
+ module Append< shouldAppendSig / 2 shouldAppend > {
229
229
pragma [ nomagic]
230
230
private string getComponent ( string relativePath , int i ) {
231
- app ( _, relativePath ) and
231
+ shouldAppend ( _, relativePath ) and
232
232
result = relativePath .replaceAll ( "\\" , "/" ) .regexpFind ( "[^/]+" , i , _)
233
233
}
234
234
235
+ private int getNumberOfComponents ( string relativePath ) {
236
+ result = strictcount ( int i | exists ( getComponent ( relativePath , i ) ) | i )
237
+ or
238
+ relativePath = "" and
239
+ result = 0
240
+ }
241
+
235
242
pragma [ nomagic]
236
243
private Container appendStep ( Folder f , string relativePath , int i ) {
237
244
i = - 1 and
238
- app ( f , relativePath ) and
245
+ shouldAppend ( f , relativePath ) and
239
246
result = f
240
247
or
241
248
exists ( Container mid , string comp |
@@ -258,9 +265,9 @@ module Make<InputSig Input> {
258
265
*/
259
266
pragma [ nomagic]
260
267
Container append ( Folder f , string relativePath ) {
261
- exists ( int components |
262
- components = ( - 1 ) . maximum ( max ( int comp | exists ( getComponent ( relativePath , comp ) ) | comp ) ) and
263
- result = appendStep ( f , relativePath , components )
268
+ exists ( int last |
269
+ last = getNumberOfComponents ( relativePath ) - 1 and
270
+ result = appendStep ( f , relativePath , last )
264
271
)
265
272
}
266
273
}
0 commit comments