| 1 |
From Corelib Require Import BinNums PosDef IntDef ListDef. |
| 2 |
From Corelib Require Export PrimInt63 Uint63Axioms. |
| 3 |
From Corelib Require Export PrimString. |
| 4 |
|
| 5 |
Definition char63_valid (c : char63) := |
| 6 |
PrimInt63.land c 255%uint63 = c. |
| 7 |
|
| 8 |
(** * Conversion to / from lists *) |
| 9 |
|
| 10 |
Abbreviation of_nat n := (of_Z (Z.of_nat n)). |
| 11 |
Abbreviation to_nat i := (Z.to_nat (to_Z i)). |
| 12 |
|
| 13 |
Definition to_list (s : string) : list char63 := |
| 14 |
ListDef.map (fun i => get s (of_nat i)) (ListDef.seq 0 (to_nat (length s))). |
| 15 |
|
| 16 |
Fixpoint of_list (cs : list char63) : string := |
| 17 |
match cs with |
| 18 |
| nil => ""%pstring |
| 19 |
| cons c cs => cat (make 1 c) (of_list cs) |
| 20 |
end. |
| 21 |
|
| 22 |
Axiom of_to_list : |
| 23 |
forall (s : string), |
| 24 |
of_list (to_list s) = s. |
| 25 |
|
| 26 |
Axiom to_list_length : |
| 27 |
forall (s : string), |
| 28 |
Datatypes.length (to_list s) <= to_nat max_length. |
| 29 |
|
| 30 |
Axiom to_list_char63_valid : |
| 31 |
forall (s : string), |
| 32 |
ListDef.Forall char63_valid (to_list s). |
| 33 |
|
| 34 |
(** * Axioms relating string operations with list operations *) |
| 35 |
|
| 36 |
Axiom length_spec : |
| 37 |
forall (s : string), |
| 38 |
to_nat (length s) = Datatypes.length (to_list s). |
| 39 |
|
| 40 |
Axiom get_spec : |
| 41 |
forall (s : string) (i : int), |
| 42 |
get s i = ListDef.nth (to_nat i) (to_list s) 0%uint63. |
| 43 |
|
| 44 |
Axiom make_spec : |
| 45 |
forall (i : int) (c : char63), |
| 46 |
to_list (make i c) = |
| 47 |
ListDef.repeat (PrimInt63.land c 255%uint63) |
| 48 |
(Nat.min (to_nat i) (to_nat max_length)). |
| 49 |
|
| 50 |
Axiom sub_spec : |
| 51 |
forall (s : string) (off len : int), |
| 52 |
to_list (sub s off len) = |
| 53 |
ListDef.firstn (to_nat len) (ListDef.skipn (to_nat off) (to_list s)). |
| 54 |
|
| 55 |
Axiom cat_spec : |
| 56 |
forall (s1 s2 : string), |
| 57 |
to_list (cat s1 s2) = |
| 58 |
ListDef.firstn (to_nat max_length) (to_list s1 ++ to_list s2). |
| 59 |
|
| 60 |
Abbreviation char63_compare := PrimInt63.compare (only parsing). |
| 61 |
|
| 62 |
Axiom compare_spec : |
| 63 |
forall (s1 s2 : string), |
| 64 |
compare s1 s2 = |
| 65 |
ListDef.list_compare char63_compare (to_list s1) (to_list s2). |