| 1 |
From Coq Require Import NArith. |
| 2 |
From Coq Require Import Ascii. |
| 3 |
Require Import Crypto.Util.Notations. |
| 4 |
|
| 5 |
Local Open Scope bool_scope. |
| 6 |
Local Open Scope N_scope. |
| 7 |
Local Open Scope char_scope. |
| 8 |
|
| 9 |
(** Special characters *) |
| 10 |
|
| 11 |
Example Null := "000". |
| 12 |
Example Backspace := "008". |
| 13 |
Example Tab := "009". |
| 14 |
Example HorizontalTab := "009". |
| 15 |
Example LF := "010". |
| 16 |
Example NewLine := "010". |
| 17 |
Example VerticalTab := "011". |
| 18 |
Example NewPage := "012". |
| 19 |
Example FormFeed := "012". |
| 20 |
Example CR := "013". |
| 21 |
Example Escape := "027". |
| 22 |
|
| 23 |
Local Coercion N_of_ascii : ascii >-> N. |
| 24 |
Definition ltb (x y : ascii) : bool := N.ltb x y. |
| 25 |
Definition leb (x y : ascii) : bool := N.leb x y. |
| 26 |
Infix "<?" := ltb : char_scope. |
| 27 |
Infix "<=?" := leb : char_scope. |
| 28 |
|
| 29 |
Definition is_upper (ch : ascii) : bool |
| 30 |
:= ("A" <=? ch) && (ch <=? "Z"). |
| 31 |
Definition is_lower (ch : ascii) : bool |
| 32 |
:= ("a" <=? ch) && (ch <=? "z"). |
| 33 |
|
| 34 |
Definition to_lower (ch : ascii) : ascii |
| 35 |
:= if ("A" <=? ch) && (ch <=? "Z") |
| 36 |
then ascii_of_N ("a" + ch - "A") |
| 37 |
else ch. |
| 38 |
Definition to_upper (ch : ascii) : ascii |
| 39 |
:= if ("a" <=? ch) && (ch <=? "z") |
| 40 |
then ascii_of_N ("A" + ch - "a") |
| 41 |
else ch. |
| 42 |
|
| 43 |
Definition is_whitespace (x : ascii) : bool |
| 44 |
:= ((x =? " ") || (x =? NewPage) || (x =? LF) || (x =? CR) || (x =? Tab))%char%bool. |
| 45 |
|
| 46 |
Definition is_printable (x : ascii) : bool |
| 47 |
:= (" " <=? x) && (x <=? "~"). |