Skip to content
Browse files

[feature] libbase: Added add_substring to Buf.

  • Loading branch information...
1 parent 315e351 commit 732d845b46f85fb30b901ac1f5c16f0314658c77 @nrs135 nrs135 committed
Showing with 7 additions and 4 deletions.
  1. +6 −4 libbase/buf.ml
  2. +1 −0 libbase/buf.mli
View
10 libbase/buf.ml
@@ -56,7 +56,7 @@ let set buf i ch =
let unsafe_set buf i ch = String.unsafe_set buf.str i ch
let sub buf base len =
- if base < 0 || base + len >= buf.i then invalid_arg (Printf.sprintf "Buf.sub index out of bounds %d %d" base len);
+ if base < 0 || base + len > buf.i then invalid_arg (Printf.sprintf "Buf.sub index out of bounds %d %d" base len);
String.sub buf.str base len
let add_char buf ch =
@@ -64,11 +64,13 @@ let add_char buf ch =
buf.str.[buf.i] <- ch;
buf.i <- buf.i + 1
-let append buf str len =
- if String.length buf.str - buf.i < len then invalid_arg (Printf.sprintf "Buf.add_stringn %s" str);
- String.unsafe_blit str 0 buf.str buf.i len;
+let add_substring buf str base len =
+ if String.length buf.str - buf.i < len then invalid_arg (Printf.sprintf "Buf.add_substring %s %d %d" str base len);
+ String.unsafe_blit str base buf.str buf.i len;
buf.i <- buf.i + len
+let append buf str len = add_substring buf str 0 len
+
let extend buf len =
if String.length buf.str - buf.i < len then invalid_arg (Printf.sprintf "Buf.extend %d" len);
buf.i <- buf.i + len
View
1 libbase/buf.mli
@@ -43,6 +43,7 @@ val clear : buf -> unit
val reset : buf -> unit
val add_char : buf -> char -> unit
val add_string : buf -> string -> unit
+val add_substring : buf -> string -> int -> int -> unit
val contents : buf -> string
(** Specifics **)

0 comments on commit 732d845

Please sign in to comment.
Something went wrong with that request. Please try again.