mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 03:05:29 -05:00
depend on bytes; compliant with -safe-string
This commit is contained in:
parent
d95495dc12
commit
0de04d0eb8
5 changed files with 22 additions and 6 deletions
1
.merlin
1
.merlin
|
|
@ -6,3 +6,4 @@ B _build/tests/
|
|||
B _build/bench/
|
||||
PKG oUnit
|
||||
PKG benchmark
|
||||
FLAG -safe-string
|
||||
|
|
|
|||
1
_oasis
1
_oasis
|
|
@ -30,6 +30,7 @@ Flag bigarray
|
|||
Library "sequence"
|
||||
Path: .
|
||||
Modules: Sequence
|
||||
BuildDepends: bytes
|
||||
|
||||
Library "invert"
|
||||
Path: invert
|
||||
|
|
|
|||
1
_tags
1
_tags
|
|
@ -28,3 +28,4 @@
|
|||
<bench/*.ml{,i}>: use_sequence
|
||||
# OASIS_STOP
|
||||
true: bin_annot
|
||||
true: safe_string
|
||||
|
|
|
|||
15
sequence.ml
15
sequence.ml
|
|
@ -751,7 +751,7 @@ module IO = struct
|
|||
fun k ->
|
||||
let ic = open_in_gen flags mode filename in
|
||||
try
|
||||
let buf = String.create size in
|
||||
let buf = Bytes.create size in
|
||||
let n = ref 0 in
|
||||
let stop = ref false in
|
||||
while not !stop do
|
||||
|
|
@ -763,7 +763,7 @@ module IO = struct
|
|||
if n' = 0 then stop := true else n := !n + n';
|
||||
done;
|
||||
if !n > 0
|
||||
then k (String.sub buf 0 !n)
|
||||
then k (Bytes.sub_string buf 0 !n)
|
||||
done;
|
||||
close_in ic
|
||||
with e ->
|
||||
|
|
@ -773,12 +773,19 @@ module IO = struct
|
|||
let write_to ?(mode=0o644) ?(flags=[Open_creat;Open_wronly]) filename seq =
|
||||
let oc = open_out_gen flags mode filename in
|
||||
try
|
||||
seq (fun s -> output oc s 0 (String.length s));
|
||||
seq (fun s -> output oc s 0 (Bytes.length s));
|
||||
close_out oc
|
||||
with e ->
|
||||
close_out oc;
|
||||
raise e
|
||||
|
||||
let write_str_to ?mode ?flags filename seq =
|
||||
write_to ?mode ?flags filename (map Bytes.unsafe_of_string seq)
|
||||
|
||||
let write_lines ?mode ?flags filename seq =
|
||||
write_to ?mode ?flags filename (snoc (intersperse "\n" seq) "\n")
|
||||
let ret = Bytes.unsafe_of_string "\n" in
|
||||
write_to ?mode ?flags filename (snoc (intersperse ret seq) ret)
|
||||
|
||||
let write_str_lines ?mode ?flags filename seq =
|
||||
write_lines ?mode ?flags filename (map Bytes.unsafe_of_string seq)
|
||||
end
|
||||
|
|
|
|||
10
sequence.mli
10
sequence.mli
|
|
@ -586,13 +586,19 @@ module IO : sig
|
|||
different iterations might return different results *)
|
||||
|
||||
val write_to : ?mode:int -> ?flags:open_flag list ->
|
||||
string -> string t -> unit
|
||||
string -> Bytes.t t -> unit
|
||||
(** [write_to filename seq] writes all strings from [seq] into the given
|
||||
file. It takes care of opening and closing the file.
|
||||
@param mode default [0o644]
|
||||
@param flags used by [open_out_gen]. Default: [[Open_creat;Open_wronly]]. *)
|
||||
|
||||
val write_str_to : ?mode:int -> ?flags:open_flag list ->
|
||||
string -> string t -> unit
|
||||
|
||||
val write_lines : ?mode:int -> ?flags:open_flag list ->
|
||||
string -> string t -> unit
|
||||
string -> Bytes.t t -> unit
|
||||
(** Same as {!write_to}, but intercales ['\n'] between each string *)
|
||||
|
||||
val write_str_lines : ?mode:int -> ?flags:open_flag list ->
|
||||
string -> string t -> unit
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue