@@ -222,20 +222,27 @@ module Make<InputSig Input> {
222222 /** Provides logic related to `Folder`s. */
223223 module Folder {
224224 /** 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 ) ;
226226
227227 /** Provides the `append` predicate for appending a relative path onto a folder. */
228- module Append< appendSig / 2 app > {
228+ module Append< shouldAppendSig / 2 shouldAppend > {
229229 pragma [ nomagic]
230230 private string getComponent ( string relativePath , int i ) {
231- app ( _, relativePath ) and
231+ shouldAppend ( _, relativePath ) and
232232 result = relativePath .replaceAll ( "\\" , "/" ) .regexpFind ( "[^/]+" , i , _)
233233 }
234234
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+
235242 pragma [ nomagic]
236243 private Container appendStep ( Folder f , string relativePath , int i ) {
237244 i = - 1 and
238- app ( f , relativePath ) and
245+ shouldAppend ( f , relativePath ) and
239246 result = f
240247 or
241248 exists ( Container mid , string comp |
@@ -258,9 +265,9 @@ module Make<InputSig Input> {
258265 */
259266 pragma [ nomagic]
260267 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 )
264271 )
265272 }
266273 }
0 commit comments