| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
type t = string |
| 12 |
|
| 13 |
type char63 = Uint63.t |
| 14 |
|
| 15 |
|
| 16 |
let max_length_int : int = 16777211 |
| 17 |
|
| 18 |
let max_length : Uint63.t = Uint63.of_int max_length_int |
| 19 |
|
| 20 |
let to_string : t -> string = fun s -> s |
| 21 |
|
| 22 |
let of_string : string -> t option = fun s -> |
| 23 |
if String.length s <= max_length_int then Some s else None |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
let make : Uint63.t -> char63 -> t = fun i c -> |
| 28 |
let i = Uint63.to_int_min i max_length_int in |
| 29 |
let c = Uint63.l_and c (Uint63.of_int 255) in |
| 30 |
let c = Char.chr (Uint63.to_int_min c 255) in |
| 31 |
String.make i c |
| 32 |
|
| 33 |
let length : t -> Uint63.t = fun s -> |
| 34 |
Uint63.of_int (String.length s) |
| 35 |
|
| 36 |
|
| 37 |
let get : t -> Uint63.t -> char63 = fun s i -> |
| 38 |
let i = Uint63.to_int_min i max_length_int in |
| 39 |
if i < String.length s then |
| 40 |
Uint63.of_int (Char.code (String.get s i)) |
| 41 |
else |
| 42 |
Uint63.zero |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
let sub : t -> Uint63.t -> Uint63.t -> t = fun s off len -> |
| 48 |
let off = Uint63.to_int_min off max_int in |
| 49 |
let len = Uint63.to_int_min len max_int in |
| 50 |
let len_s = String.length s in |
| 51 |
if off < len_s then |
| 52 |
String.sub s off (min len (len_s - off)) |
| 53 |
else |
| 54 |
"" |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
let cat : t -> t -> t = fun s1 s2 -> |
| 59 |
let len1 = String.length s1 in |
| 60 |
let len2 = String.length s2 in |
| 61 |
if len1 + len2 <= max_length_int then |
| 62 |
s1 ^ s2 |
| 63 |
else |
| 64 |
s1 ^ String.sub s2 0 (max_length_int - len1) |
| 65 |
|
| 66 |
let compare : t -> t -> int = |
| 67 |
String.compare |
| 68 |
|
| 69 |
let equal : t -> t -> bool = |
| 70 |
String.equal |
| 71 |
|
| 72 |
let hash : t -> int = |
| 73 |
Hashtbl.hash |
| 74 |
|
| 75 |
let unsafe_of_string : string -> t = fun s -> s |
| 76 |
|
| 77 |
let compile : t -> string = |
| 78 |
Printf.sprintf "Pstring.unsafe_of_string %S" |