Source

olfend / vmmisc.ml

let split_at_dot s =
  try 
    let pos = String.index s '.' in
    let prefix = String.sub s 0 pos in
    let postfix = String.sub s (pos+1) (String.length s - pos - 1) in
    try ignore (String.index postfix '.'); assert false with Not_found ->
      [ prefix;  postfix ]
  with
  | Not_found -> [ s ]

let load_via_sexp of_sexp ic = of_sexp (Sexplib.Sexp.input_sexp ic)
let save_via_sexp sexp_of oc v = Sexplib.Sexp.output_mach oc (sexp_of v)
let save_via_hum_sexp sexp_of oc v = Sexplib.Sexp.output_hum oc (sexp_of v)

let load_file load_channel path =
  let ic = open_in path in
  let res = load_channel ic in
  close_in ic;
  res

let save_file save_channel path v =
  let oc = open_out_bin path in
  save_channel oc v;
  close_out oc

let load_file_via_sexp c = load_file (load_via_sexp c)
(* let save_file_via_sexp c = save_file (save_via_sexp c) *)
let save_file_via_hum_sexp c = save_file (save_via_hum_sexp c)
let save_file_via_sexp = save_file_via_hum_sexp

let save_list_file_via_hum_sexp c path vs = 
  let oc = open_out_bin path in
  List.iter (fun v -> 
    save_via_hum_sexp c oc v;
    output_string oc "\n") vs;
  close_out oc

module Digest = struct
  include Digest
  open Sexplib.Conv
  let sexp_of_t = sexp_of_string
  let t_of_sexp = string_of_sexp
end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.