Commit 08a08517 authored by MARCHE Claude's avatar MARCHE Claude
Browse files

Wrap around deprecated string functions

parent 7f06b8be
......@@ -478,7 +478,7 @@ let read_old_proof =
Vernacular
end in
let len = pos_in ch - !start in
let s = String.create len in
let s = Strings.create len in
seek_in ch !start;
really_input ch s 0 len;
Query (name, k, s)
......
......@@ -1515,7 +1515,7 @@ exception SessionFileError of string
module ReadShapes (C:Compress.S) = struct
let shape = Buffer.create 97
let sum = String.create 32
let sum = Strings.create 32
let read_sum_and_shape ch =
let nsum = C.input ch sum 0 32 in
......@@ -1544,7 +1544,7 @@ let read_sum_and_shape ch =
with
| End_of_file ->
raise (ShapesFileError "shapes files corrupted (premature end of file), ignored");
| Exit -> String.copy sum, Buffer.contents shape
| Exit -> Strings.copy sum, Buffer.contents shape
let use_shapes = ref true
......
......@@ -43,9 +43,9 @@ let cmdline_split s =
| '\\' -> cstate := Escape
| c when is_blank c ->
let n = Queue.length cur_arg in
let s = String.create n in
let s = Strings.create n in
for i = 0 to pred n do
String.set s i (Queue.take cur_arg)
Strings.set s i (Queue.take cur_arg)
done;
argv := s :: !argv;
cstate := Blank
......@@ -104,4 +104,3 @@ let () = Exn_printer.register (fun fmt e -> match e with
| EmptyCommandLine ->
Format.fprintf fmt "empty command line"
| _ -> raise e)
......@@ -98,9 +98,9 @@ and string = parse
let nb = ref 0 in
String.iter (fun c -> if c = '_' then incr nb) s;
!nb in
let t = String.create (String.length s - count) in
let t = Strings.create (String.length s - count) in
let i = ref 0 in
String.iter (fun c -> if c <> '_' then (t.[!i] <-c; incr i)) s;
String.iter (fun c -> if c <> '_' then (Strings.set t !i c; incr i)) s;
t
end else s
}
......@@ -158,7 +158,7 @@ let simplify_max_int = BigInt.of_string "2147483646"
let remove_minus e =
if e.[0] = '-' then
(let e' = String.copy e in e'.[0] <- 'm'; e')
(let e' = Strings.copy e in Strings.set e' 0 'm'; e')
else e
let print_dec_int support fmt i =
......
......@@ -64,16 +64,16 @@ let escape_string s =
| _ -> 1)
done;
if !n = String.length s then s else begin
let s' = String.create !n in
let s' = Strings.create !n in
n := 0;
for i = 0 to String.length s - 1 do
let c = String.unsafe_get s i in
begin match c with
| ('"' | '\\' | '\n' | '\r' | '\t') ->
String.unsafe_set s' !n '\\'; incr n
Strings.set s' !n '\\'; incr n
| _ -> ()
end;
String.unsafe_set s' !n
Strings.set s' !n
(match c with '\n' -> 'n' | '\r' -> 'r' | '\t' -> 't' | _ -> c);
incr n
done;
......
......@@ -9,7 +9,12 @@
(* *)
(********************************************************************)
(* useful function on string *)
let create = String.create
let copy = String.copy
let set = String.set
let rev_split c s =
let rec aux acc i =
......@@ -33,11 +38,10 @@ let ends_with s suf =
let pad_right c s i =
let sl = String.length s in
if sl < i then
let p = String.create i in
let p = create i in
String.blit s 0 p 0 sl;
String.fill p sl (i-sl) c;
p
else if sl > i
then String.sub s 0 i
else s
......@@ -9,6 +9,12 @@
(* *)
(********************************************************************)
(** Wrappers for deprecated string functions of OCaml stdlib *)
val create : int -> string
val copy : string -> string
val set : string -> int -> char -> unit
(** Useful functions on string *)
val rev_split : char -> string -> string list
......@@ -20,4 +26,3 @@ val ends_with : string -> string -> bool
val pad_right : char -> string -> int -> string
(** chop or pad the given string on the right up to the given length *)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment