1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200 | ------------------------------------------------------------------------------
-- --
-- ASIS Tester And iNTerpreter (ASIStant) COMPONENTS --
-- --
-- A S I S T A N T . S T R I N G _ H A N D L I N G --
-- --
-- B o d y --
-- --
-- Copyright (C) 1997-2013, Free Software Foundation, Inc. --
-- --
-- ASIStant is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIStant is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with GNAT; see file COPYING. If --
-- not, write to the Free Software Foundation, 59 Temple Place Suite 330, --
-- Boston, MA 02111-1307, USA. --
-- --
-- ASIStant is an evolution of ASIStint tool that was created by --
-- Vasiliy Fofanov as part of a collaboration between Software Engineering --
-- Laboratory of the Swiss Federal Institute of Technology in Lausanne, --
-- Switzerland, and the Scientific Research Computer Center of the Moscow --
-- University, Russia, supported by the Swiss National Science Foundation --
-- grant #7SUPJ048247, "Development of ASIS for GNAT with industry quality" --
-- --
-- ASIStant is distributed as a part of the ASIS implementation for GNAT --
-- (ASIS-for-GNAT) and is maintained by AdaCore (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with ASIStant.Common; use ASIStant.Common;
package body ASIStant.String_Handling is
--------------
-- Word_End --
--------------
function Word_End (Str : Wide_String; ID : Boolean := False)
return Integer is
P : Integer := Str'Last;
begin
for i in Str'First .. Str'Last loop
if ID and
(Str (i) in 'A' .. 'Z' or
Str (i) in 'a' .. 'z' or
Str (i) = '_' or
Str (i) in '0' .. '9')
then
P := i;
else
exit;
end if;
if Str (i) /= ' ' then
P := i;
else
exit;
end if;
end loop;
return P;
end Word_End;
--------------
-- Skip_Spc --
--------------
function Skip_Spc (Str : Wide_String) return Integer is
begin
for i in Str'First .. Str'Last loop
if Str (i) /= ' ' then
return i;
end if;
end loop;
return Str'Last;
end Skip_Spc;
-----------------
-- Skip_Symbol --
-----------------
function Skip_Symbol (Str : Wide_String; C : Wide_Character)
return Integer is
P : Integer;
begin
P := Skip_Spc (Str);
if P > 0 and then Str (P) = C then
P := P + 1;
else
P := 0;
end if;
return P;
end Skip_Symbol;
-----------------
-- Skip_Prefix --
-----------------
function Skip_Prefix (S : Wide_String; N : Natural := 4)
return Wide_String is
begin
return S (N + 1 .. S'Last);
end Skip_Prefix;
function Find_Symbol (Str : Wide_String; C : Wide_Character)
return Integer is
P : Integer := Str'First;
begin
while P <= Str'Last loop
if Str (P) = C then
return P;
else
P := P + 1;
end if;
end loop;
return 0;
end Find_Symbol;
------------------
-- Read_Integer --
------------------
procedure Read_Integer (S : Wide_String; Val, New1st : out Integer) is
begin
New1st := S'First;
Val := 0;
while S (New1st) in '0' .. '9' loop
Val := Val * 10 +
Wide_Character'Pos (S (New1st)) - Wide_Character'Pos ('0');
New1st := New1st + 1;
exit when New1st > S'Last;
end loop;
end Read_Integer;
--------------
-- To_Upper --
--------------
procedure To_Upper (S : in out Wide_String) is
I : Natural := S'First;
begin
loop
exit when I > S'Last;
if S (I) in 'a' .. 'z' then
S (I) := To_Wide_Character (To_Upper (To_Character (S (I))));
elsif S (I) = '"' then
I := Find_Symbol (S (I + 1 .. S'Last), '"');
if I = 0 then
Error (ERR_BADSTRING);
end if;
I := I + 1;
end if;
I := I + 1;
end loop;
end To_Upper;
---------------
-- To_Proper --
---------------
procedure To_Proper (S : in out Wide_String) is
Next_To_Upper : Boolean := True;
begin
for I in S'Range loop
if S (I) = '_' then
Next_To_Upper := True;
elsif Next_To_Upper and then
S (I) in 'a' .. 'z'
then
S (I) := To_Wide_Character (To_Upper (To_Character (S (I))));
Next_To_Upper := False;
elsif not Next_To_Upper and then
S (I) in 'A' .. 'Z'
then
S (I) := To_Wide_Character (To_Lower (To_Character (S (I))));
else
Next_To_Upper := False;
end if;
end loop;
end To_Proper;
---------------
-- To_Proper --
---------------
function To_Proper (S : Wide_String) return Wide_String is
SS : Wide_String := S;
begin
To_Proper (SS);
return SS;
end To_Proper;
end ASIStant.String_Handling;
|