diff options
Diffstat (limited to 'stdlib/string.ml')
-rw-r--r-- | stdlib/string.ml | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/stdlib/string.ml b/stdlib/string.ml index be074fa10..0556b273e 100644 --- a/stdlib/string.ml +++ b/stdlib/string.ml @@ -136,3 +136,17 @@ let apply1 f s = let capitalize s = apply1 Char.uppercase s let uncapitalize s = apply1 Char.lowercase s + +let index s c = + let rec idx i = + if i >= String.length s then raise Not_found + else if s.[i] = c then i + else idx (i+1) + in idx 0 + +let rindex s c = + let rec idx i = + if i < 0 then raise Not_found + else if s.[i] = c then i + else idx (i-1) + in idx (String.length s - 1) |