]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/utility/string.ma
227f9f478d2cb285d09c501be7cc7e712ded1371
[helm.git] / helm / software / matita / contribs / ng_assembly / utility / string.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Cosimo Oliboni, oliboni@cs.unibo.it                   *)
19 (*     Cosimo Oliboni, oliboni@cs.unibo.it                                *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "utility/ascii.ma".
24 include "utility/utility.ma".
25
26 (* ************************ *)
27 (* MANIPOLAZIONE DI STRINGA *)
28 (* ************************ *)
29
30 (* tipo pubblico *)
31 ndefinition aux_str_type ≝ list ascii.
32
33 (* empty string *)
34 ndefinition empty_str ≝ nil ascii.
35
36 (* is empty ? *)
37 ndefinition isNull_str ≝
38 λstr:aux_str_type.match str with
39  [ nil ⇒ true | cons _ _ ⇒ false ].
40
41 (* strcmp *)
42 nlet rec eq_str (str,str':aux_str_type) ≝
43  match str with
44   [ nil ⇒ match str' with
45    [ nil => true
46    | cons _ _ => false ]
47   | cons h t ⇒ match str' with
48    [ nil ⇒ false
49    | cons h' t' ⇒ (eq_ascii h h')⊗(eq_str t t')
50    ]
51   ].
52
53 (* strcat *)
54 ndefinition strCat_str ≝
55 λstr,str':aux_str_type.str@str'.
56
57 (* strlen *)
58 ndefinition strLen_str ≝ len_list ascii.
59
60 (* ************ *)
61 (* STRINGA + ID *)
62 (* ************ *)
63
64 (* tipo pubblico *)
65 ninductive aux_strId_type : Type ≝
66  STR_ID: aux_str_type → nat → aux_strId_type.
67
68 ndefinition aux_strId_type_ind : ΠP:aux_strId_type → Prop.(Πl,n.P (STR_ID l n)) → Πa:aux_strId_type.P a ≝
69 λP:aux_strId_type → Prop.λf:Πl,n.P (STR_ID l n).λa:aux_strId_type.
70  match a with [ STR_ID l n ⇒ f l n ].
71
72 ndefinition aux_strId_type_rec : ΠP:aux_strId_type → Set.(Πl,n.P (STR_ID l n)) → Πa:aux_strId_type.P a ≝
73 λP:aux_strId_type → Set.λf:Πl,n.P (STR_ID l n).λa:aux_strId_type.
74  match a with [ STR_ID l n ⇒ f l n ].
75
76 ndefinition aux_strId_type_rect : ΠP:aux_strId_type → Type.(Πl,n.P (STR_ID l n)) → Πa:aux_strId_type.P a ≝
77 λP:aux_strId_type → Type.λf:Πl,n.P (STR_ID l n).λa:aux_strId_type.
78  match a with [ STR_ID l n ⇒ f l n ].
79
80 (* getter *)
81 ndefinition get_name_strId ≝ λsid:aux_strId_type.match sid with [ STR_ID n _ ⇒ n ].
82 ndefinition get_id_strId ≝ λsid:aux_strId_type.match sid with [ STR_ID _ d ⇒ d ].
83
84 (* confronto *)
85 ndefinition eq_strId ≝
86 λsid,sid':aux_strId_type.(eq_str (get_name_strId sid) (get_name_strId sid'))⊗(eq_nat (get_id_strId sid) (get_id_strId sid')).