Created
July 6, 2010 20:20
-
-
Save baris/465858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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