Skip to content

Instantly share code, notes, and snippets.

@baris
Created July 6, 2010 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baris/465858 to your computer and use it in GitHub Desktop.
Save baris/465858 to your computer and use it in GitHub Desktop.
let string_strip_dir s lst ~right =
let rec strip s lst' =
match lst' with
[] -> s
| hd::tail ->
let len = String.length s in
let index = if right then (len - 1) else 0 in
if (String.get s index) = hd then
let cropped = if right then String.sub s 0 index else String.sub s 1 (len-1) in
strip cropped lst
else
strip s tail
in
strip s lst
let string_lstrip s lst = string_strip_dir s lst ~right:false
let string_rstrip s lst = string_strip_dir s lst ~right:true
let string_strip s lst = string_lstrip (string_rstrip s lst) lst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment