summaryrefslogtreecommitdiff
path: root/stdlib/buffer.ml
diff options
context:
space:
mode:
authorJun FURUSE / 古瀬 淳 <jun.furuse@gmail.com>2004-06-18 05:04:14 +0000
committerJun FURUSE / 古瀬 淳 <jun.furuse@gmail.com>2004-06-18 05:04:14 +0000
commit5e1bf20850aaa9b1ceb86a971848609ee9e84c47 (patch)
treef3a6e5b5c38263fe527e6275ff95425f12637226 /stdlib/buffer.ml
parent8ec769214e067da9ee8b33d05f4ef275e9269dd5 (diff)
downloadocaml-gcaml.tar.gz
port to the latest ocaml (2004/06/18)gcaml
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/gcaml@6419 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'stdlib/buffer.ml')
-rw-r--r--stdlib/buffer.ml26
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 ? *)