summaryrefslogtreecommitdiffstats
path: root/otherlibs/labltk/support/support.ml
diff options
context:
space:
mode:
authorJacques Garrigue <garrigue at math.nagoya-u.ac.jp>1999-11-16 10:22:42 +0000
committerJacques Garrigue <garrigue at math.nagoya-u.ac.jp>1999-11-16 10:22:42 +0000
commitdf8e31a8ae8fda0499f209ebd6efadbe544d4549 (patch)
tree6ad5d6bd60a5126b08d77b8c6c60671cba022ab1 /otherlibs/labltk/support/support.ml
parentfce433fa4ddf1ce57a29a00cf7d6c6c62ba85bff (diff)
This commit was generated by cvs2svn to compensate for changes in r2531,
which included commits to RCS files with non-trunk default branches. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2532 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/labltk/support/support.ml')
-rw-r--r--otherlibs/labltk/support/support.ml61
1 files changed, 61 insertions, 0 deletions
diff --git a/otherlibs/labltk/support/support.ml b/otherlibs/labltk/support/support.ml
new file mode 100644
index 000000000..4f67d62c7
--- /dev/null
+++ b/otherlibs/labltk/support/support.ml
@@ -0,0 +1,61 @@
+(* $Id$ *)
+
+(* Extensible buffers *)
+type extensible_buffer = {
+ mutable buffer : string;
+ mutable pos : int;
+ mutable len : int}
+
+let new_buffer () = {
+ buffer = String.create len:128;
+ pos = 0;
+ len = 128
+ }
+
+let print_in_buffer buf s =
+ let l = String.length s in
+ if buf.pos + l > buf.len then begin
+ buf.buffer <- buf.buffer ^ (String.create len:(l+128));
+ buf.len <- buf.len + 128 + l
+ end;
+ String.blit s pos:0 to:buf.buffer to_pos:buf.pos len:l;
+ buf.pos <- buf.pos + l
+
+let get_buffer buf =
+ String.sub buf.buffer pos:0 len:buf.pos
+
+
+
+(* Used by list converters *)
+let catenate_sep sep =
+ function
+ [] -> ""
+ | [x] -> x
+ | x::l ->
+ let b = new_buffer() in
+ print_in_buffer b x;
+ List.iter l
+ fun:(function s -> print_in_buffer b sep; print_in_buffer b s);
+ get_buffer b
+
+(* Parsing results of Tcl *)
+(* List.split a string according to char_sep predicate *)
+let split_str char_sep str =
+ let len = String.length str in
+ let rec skip_sep cur =
+ if cur >= len then cur
+ else if char_sep str.[cur] then skip_sep (succ cur)
+ else cur in
+ let rec split beg cur =
+ if cur >= len then
+ if beg = cur then []
+ else [String.sub str pos:beg len:(len - beg)]
+ else if char_sep str.[cur]
+ then
+ let nextw = skip_sep cur in
+ (String.sub str pos:beg len:(cur - beg))
+ ::(split nextw nextw)
+ else split beg (succ cur) in
+ let wstart = skip_sep 0 in
+ split wstart wstart
+