Advertisement
Guest User

Untitled

a guest
May 24th, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.72 KB | Source Code | 0 0
  1.  
  2. let path = {|/bin:/usr/bin:/home/user/horrible\:path|}
  3.  
  4. let should_escape char_stack c =
  5.     not (Stack.is_empty char_stack)
  6.     && Stack.top char_stack = "\\"
  7.  
  8. let a char_stack c =
  9.     Stack.push (
  10.         (  
  11.             if (should_escape char_stack c)
  12.             then (Stack.pop char_stack)
  13.             else ""
  14.         ) ^ (String.make 1 c)
  15.     )  char_stack ;
  16.     char_stack
  17.  
  18.  
  19. let proto_paths = String.fold_left a (Stack.create()) path
  20.  
  21. let b string_stack c =
  22.     Stack.push (
  23.        if c = ":"
  24.        then ""
  25.        else (Stack.pop string_stack) ^ c
  26.     ) string_stack ;
  27.     string_stack
  28.  
  29. let paths = Stack.fold b  (Stack.create()) proto_paths
  30.  
  31. let () = Stack.iter print_endline paths
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement