diff options
Diffstat (limited to 'stdlib/buffer.ml')
| -rw-r--r-- | stdlib/buffer.ml | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/stdlib/buffer.ml b/stdlib/buffer.ml index dcde111ecd..cafec4444c 100644 --- a/stdlib/buffer.ml +++ b/stdlib/buffer.ml @@ -11,6 +11,8 @@ (* *) (***********************************************************************) +(* $Id$ *) + (* Extensible buffers *) type t = @@ -27,6 +29,22 @@ let create n = let contents b = String.sub b.buffer 0 b.position +let sub b ofs len = + if ofs < 0 || len < 0 || ofs > b.position - len + then invalid_arg "Buffer.sub" + else begin + let r = String.create len in + String.blit b.buffer ofs r 0 len; + r + end +;; + +let nth b ofs = + if ofs < 0 || ofs >= b.position then + invalid_arg "Buffer.nth" + else String.get b.buffer ofs +;; + let length b = b.position let clear b = b.position <- 0 @@ -87,9 +105,9 @@ let closing = function | _ -> assert false;; (* opening and closing: open and close characters, typically ( and ) - k balance of opening and closing chars - s the string where we are searching - start the index where we start the search *) + k: balance of opening and closing chars + s: the string where we are searching + start: the index where we start the search. *) let advance_to_closing opening closing k s start = let rec advance k i lim = if i >= lim then raise Not_found else @@ -110,7 +128,7 @@ let advance_to_non_alpha s start = | _ -> i in advance start (String.length s);; -(* We are just at the beginning of an ident in s, starting at start *) +(* We are just at the beginning of an ident in s, starting at start. *) let find_ident s start = match s.[start] with (* Parenthesized ident ? *) |
