Annotation of OpenXM_contrib/PHC/Ada/Math_Lib/Numbers/characters_and_numbers.adb, Revision 1.1.1.1
1.1 maekawa 1: package body Characters_and_Numbers is
2:
3: function Convert ( c : character ) return natural is
4:
5: -- DESCRIPTION :
6: -- Returns 10 if the character does not represent a number
7: -- between 0 and 9, otherwise returns the corresponding number.
8:
9: begin
10: case c is
11: when '0' => return 0;
12: when '1' => return 1;
13: when '2' => return 2;
14: when '3' => return 3;
15: when '4' => return 4;
16: when '5' => return 5;
17: when '6' => return 6;
18: when '7' => return 7;
19: when '8' => return 8;
20: when '9' => return 9;
21: when others => return 10;
22: end case;
23: end Convert;
24:
25: function Convert_Decimal ( n : natural ) return character is
26:
27: -- DESCRIPTION :
28: -- For n in 0..9, the corresponding character representation is returned.
29:
30: begin
31: case n is
32: when 0 => return '0';
33: when 1 => return '1';
34: when 2 => return '2';
35: when 3 => return '3';
36: when 4 => return '4';
37: when 5 => return '5';
38: when 6 => return '6';
39: when 7 => return '7';
40: when 8 => return '8';
41: when 9 => return '9';
42: when others => return '0';
43: end case;
44: end Convert_Decimal;
45:
46: function Convert_Hexadecimal ( c : character ) return natural is
47: begin
48: case c is
49: when '0' => return 0;
50: when '1' => return 1;
51: when '2' => return 2;
52: when '3' => return 3;
53: when '4' => return 4;
54: when '5' => return 5;
55: when '6' => return 6;
56: when '7' => return 7;
57: when '8' => return 8;
58: when '9' => return 9;
59: when 'A' => return 10;
60: when 'B' => return 11;
61: when 'C' => return 12;
62: when 'D' => return 13;
63: when 'E' => return 14;
64: when 'F' => return 15;
65: when others => return 16;
66: end case;
67: end Convert_Hexadecimal;
68:
69: function Convert_Hexadecimal ( n : natural ) return character is
70: begin
71: if n < 10
72: then return Convert_Decimal(n);
73: else case n is
74: when 10 => return 'A';
75: when 11 => return 'B';
76: when 12 => return 'C';
77: when 13 => return 'D';
78: when 14 => return 'E';
79: when 15 => return 'F';
80: when others => return '0';
81: end case;
82: end if;
83: end Convert_Hexadecimal;
84:
85: function Convert ( s : String ) return natural is
86:
87: acc : natural := 0;
88: cvn : natural;
89:
90: begin
91: for i in s'range loop
92: cvn := Convert(s(i));
93: if cvn < 10
94: then acc := acc*10 + cvn;
95: end if;
96: end loop;
97: return acc;
98: end Convert;
99:
100: function Convert ( n : natural ) return String is
101: begin
102: if n < 10
103: then declare
104: res : String(1..1);
105: begin
106: res(1) := Convert_Decimal(n);
107: return res;
108: end;
109: else declare
110: rest : natural := n mod 10;
111: head : natural := n/10;
112: headstr : constant string := Convert(head);
113: res : String(1..headstr'last+1);
114: begin
115: res(headstr'range) := headstr;
116: res(res'last) := Convert_Decimal(rest);
117: return res;
118: end;
119: end if;
120: end Convert;
121:
122: procedure Skip_Spaces ( file : in file_type; c : in out character ) is
123: begin
124: get(file,c);
125: while c = ' ' and not End_of_Line(file) loop
126: get(file,c);
127: end loop;
128: end Skip_Spaces;
129:
130: procedure Skip_Underscores ( file : in file_type; c : in out character ) is
131: begin
132: get(file,c);
133: while c = '_' and not End_of_Line(file) loop
134: get(file,c);
135: end loop;
136: end Skip_Underscores;
137:
138: end Characters_and_Numbers;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>