1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253(* From https://github.com/simonjbeaumont/ocaml-glob *)letsplitcs=letlen=String.lengthsinletrecloopacclast_pospos=ifpos=-1thenString.subs0last_pos::accelseifs.[pos]=cthenletpos1=pos+1inletsub_str=String.subspos1(last_pos-pos1)inloop(sub_str::acc)pos(pos-1)elseloopacclast_pos(pos-1)inloop[]len(len-1)(** Returns list of indices of occurances of substr in x *)letfind_substrings?(start_point=0)substrx=letlen_s=String.lengthsubstrandlen_x=String.lengthxinletrecauxacci=iflen_x-i<len_sthenaccelseifString.subxilen_s=substrthenaux(i::acc)(i+1)elseauxacc(i+1)inaux[]start_pointletmatches_glob~globx=letreccontains_all_sections=function|_,[]|_,[""]->true|i,[g]->(* need to find a match that matches to end of string *)find_substrings~start_point:igx|>List.exists(funj->j+String.lengthg=String.lengthx)|0,""::g::gs->find_substringsgx|>List.exists(funj->contains_all_sections(j+String.lengthg,gs))|i,g::gs->find_substrings~start_point:igx|>List.exists(funj->(ifi=0thenj=0elsetrue)&&contains_all_sections(j+String.lengthg,gs))incontains_all_sections(0,split'*'glob)letmatches_globs~globsx=List.exists(funglob->matches_glob~globx)globsletfilter_files~globsfiles=List.filter(matches_globs~globs)files