The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #14276 from hhugo/cleanup

Small cleanup in filename.ml

authored by

Gabriel Scherer and committed by
GitHub
b5cfb447 11c9a6bb

+14 -31
+14 -31
stdlib/filename.ml
··· 78 78 val is_relative : string -> bool 79 79 val is_implicit : string -> bool 80 80 val check_suffix : string -> string -> bool 81 - val chop_suffix_opt : suffix:string -> string -> string option 82 81 val temp_dir_name : string 83 82 val quote : string -> string 84 83 val quote_command : ··· 97 96 let is_relative n = String.length n < 1 || n.[0] <> '/' 98 97 let is_implicit n = 99 98 is_relative n 100 - && (String.length n < 2 || String.sub n 0 2 <> "./") 101 - && (String.length n < 3 || String.sub n 0 3 <> "../") 99 + && not (String.starts_with n ~prefix:"./") 100 + && not (String.starts_with n ~prefix:"../") 102 101 let check_suffix name suff = 103 102 String.ends_with ~suffix:suff name 104 103 105 - let chop_suffix_opt ~suffix filename = 106 - let len_s = String.length suffix and len_f = String.length filename in 107 - if len_f >= len_s then 108 - let r = String.sub filename (len_f - len_s) len_s in 109 - if r = suffix then 110 - Some (String.sub filename 0 (len_f - len_s)) 111 - else 112 - None 113 - else 114 - None 115 - 116 104 let temp_dir_name = 117 105 try Sys.getenv "TMPDIR" with Not_found -> "/tmp" 118 106 let quote = generic_quote "'\\''" ··· 139 127 && (String.length n < 2 || n.[1] <> ':') 140 128 let is_implicit n = 141 129 is_relative n 142 - && (String.length n < 2 || String.sub n 0 2 <> "./") 143 - && (String.length n < 2 || String.sub n 0 2 <> ".\\") 144 - && (String.length n < 3 || String.sub n 0 3 <> "../") 145 - && (String.length n < 3 || String.sub n 0 3 <> "..\\") 146 - let check_suffix name suff = 147 - String.length name >= String.length suff && 148 - (let s = String.sub name (String.length name - String.length suff) 149 - (String.length suff) in 150 - String.lowercase_ascii s = String.lowercase_ascii suff) 151 - 152 - let chop_suffix_opt ~suffix filename = 130 + && not (String.starts_with n ~prefix:"./") 131 + && not (String.starts_with n ~prefix:".\\") 132 + && not (String.starts_with n ~prefix:"../") 133 + && not (String.starts_with n ~prefix:"..\\") 134 + let check_suffix filename suffix = 153 135 let len_s = String.length suffix and len_f = String.length filename in 154 136 if len_f >= len_s then 155 137 let r = String.sub filename (len_f - len_s) len_s in 156 - if String.lowercase_ascii r = String.lowercase_ascii suffix then 157 - Some (String.sub filename 0 (len_f - len_s)) 158 - else 159 - None 138 + String.lowercase_ascii r = String.lowercase_ascii suffix 160 139 else 161 - None 140 + false 162 141 163 142 external temp_dir_name: unit -> string = "caml_sys_temp_dir_name" 164 143 let temp_dir_name = temp_dir_name () ··· 277 256 let is_relative = Win32.is_relative 278 257 let is_implicit = Win32.is_implicit 279 258 let check_suffix = Win32.check_suffix 280 - let chop_suffix_opt = Win32.chop_suffix_opt 281 259 let temp_dir_name = Unix.temp_dir_name 282 260 let quote = Unix.quote 283 261 let quote_command = Unix.quote_command ··· 303 281 if check_suffix name suff 304 282 then String.sub name 0 (String.length name - String.length suff) 305 283 else invalid_arg "Filename.chop_suffix" 284 + 285 + let chop_suffix_opt ~suffix name = 286 + if check_suffix name suffix 287 + then Some (String.sub name 0 (String.length name - String.length suffix)) 288 + else None 306 289 307 290 let extension_len name = 308 291 let rec check i0 i =