3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
27 -- Check that the subprograms defined in package Ada.Strings.Fixed are
28 -- available, and that they produce correct results. Specifically,
29 -- check the subprograms Index, Index_Non_Blank, Head, Tail, Translate,
30 -- Find_Token, Move, Overwrite, and Replace_Slice.
33 -- This test demonstrates how certain fixed string operations could be
34 -- used in string information processing. A procedure is defined that
35 -- will extract portions of a 50 character string that correspond to
36 -- certain data items (i.e., name, address, state, zip code). These
37 -- parsed items will then be added to the appropriate fields of data
38 -- base elements. These data base elements are then compared for
39 -- accuracy against a similar set of predefined data base elements.
41 -- A variety of fixed string processing subprograms are used in this
42 -- test. Each parsing operation uses a different combination
43 -- of the available subprograms to accomplish the same goal, therefore
44 -- continuity of approach to string parsing is not seen in this test.
45 -- However, a wide variety of possible approaches are demonstrated, while
46 -- exercising a large number of the total predefined subprograms of
47 -- package Ada.Strings.Fixed.
51 -- 06 Dec 94 SAIC ACVC 2.0
55 with Ada
.Strings
.Fixed
;
56 with Ada
.Strings
.Maps
;
63 Report
.Test
("CXA4003", "Check that the subprograms defined in package " &
64 "Ada.Strings.Fixed are available, and that they " &
65 "produce correct results");
70 Number_Of_Info_Strings
: constant Natural := 3;
71 DB_Size
: constant Natural := Number_Of_Info_Strings
;
73 Finished_Processing
: Boolean := False;
74 Blank_String
: constant String := " ";
76 subtype Info_String_Type
is String (1..50);
77 type Info_String_Storage_Type
is
78 array (1..Number_Of_Info_Strings
) of Info_String_Type
;
81 subtype Name_Type
is String (1..10);
82 subtype Street_Number_Type
is String (1..5);
83 subtype Street_Name_Type
is String (1..10);
84 subtype City_Type
is String (1..10);
85 subtype State_Type
is String (1..2);
86 subtype Zip_Code_Type
is String (1..5);
88 type Data_Base_Element_Type
is
90 Name
: Name_Type
:= (others => ' ');
91 Street_Number
: Street_Number_Type
:= (others => ' ');
92 Street_Name
: Street_Name_Type
:= (others => ' ');
93 City
: City_Type
:= (others => ' ');
94 State
: State_Type
:= (others => ' ');
95 Zip_Code
: Zip_Code_Type
:= (others => ' ');
98 type Data_Base_Type
is array (1..DB_Size
) of Data_Base_Element_Type
;
100 Data_Base
: Data_Base_Type
;
104 Info_String_1
: Info_String_Type
:=
105 "Joe_Jones 123 Sixth_St San_Diego CA 98765";
107 Info_String_2
: Info_String_Type
:=
108 "Sam_Smith 56789 S._Seventh Carlsbad CA 92177";
110 Info_String_3
: Info_String_Type
:=
111 "Jane_Brown 1219 Info_Lane Tuscon AZ 85643";
114 Info_Strings
: Info_String_Storage_Type
:= (1 => Info_String_1
,
120 TC_DB_Element_1
: Data_Base_Element_Type
:=
121 ("Joe Jones ", "123 ", "Sixth St ", "San Diego ", "CA", "98765");
123 TC_DB_Element_2
: Data_Base_Element_Type
:=
124 ("Sam Smith ", "56789", "S. Seventh", "Carlsbad ", "CA", "92177");
126 TC_DB_Element_3
: Data_Base_Element_Type
:=
127 ("Jane Brown", "1219 ", "Info Lane ", "Tuscon ", "AZ", "85643");
129 TC_Data_Base
: Data_Base_Type
:= (TC_DB_Element_1
,
136 procedure Store_Information
137 (Info_String
: in Info_String_Type
;
138 DB_Record
: in out Data_Base_Element_Type
) is
140 package AS
renames Ada
.Strings
;
141 use type AS
.Maps
.Character_Set
;
143 UnderScore
: AS
.Maps
.Character_Sequence
:= "_";
144 Blank
: AS
.Maps
.Character_Sequence
:= " ";
149 Underscore_to_Blank_Map
: constant AS
.Maps
.Character_Mapping
:=
150 AS
.Maps
.To_Mapping
(From
=> UnderScore
,
153 Numeric_Set
: constant AS
.Maps
.Character_Set
:=
154 AS
.Maps
.To_Set
("0123456789");
156 Cal
: constant AS
.Maps
.Character_Sequence
:= "CA";
157 California_Set
: constant AS
.Maps
.Character_Set
:=
159 Arizona_Set
: constant AS
.Maps
.Character_Set
:=
160 AS
.Maps
.To_Set
("AZ");
161 Nevada_Set
: constant AS
.Maps
.Character_Set
:=
162 AS
.Maps
.To_Set
("NV");
166 -- Find the starting position of the name field (first non-blank),
167 -- then, from that position, find the end of the name field (first
170 Start
:= AS
.Fixed
.Index_Non_Blank
(Info_String
);
171 Stop
:= AS
.Fixed
.Index
(Info_String
(Start
..Info_String
'Length),
176 -- Store the name field in the data base element field for "Name".
178 DB_Record
.Name
:= AS
.Fixed
.Head
(Info_String
(1..Stop
),
179 DB_Record
.Name
'Length);
181 -- Replace any underscore characters in the name field
182 -- that were used to separate first/middle/last names.
184 AS
.Fixed
.Translate
(DB_Record
.Name
, Underscore_to_Blank_Map
);
187 -- Continue the extraction process; now find the position of
188 -- the street number in the string.
192 AS
.Fixed
.Find_Token
(Info_String
(Start
..Info_String
'Length),
198 -- Store the street number field in the appropriate data base
200 -- No modification of the default parameters of procedure Move
203 AS
.Fixed
.Move
(Source
=> Info_String
(Start
..Stop
),
204 Target
=> DB_Record
.Street_Number
);
207 -- Continue the extraction process; find the street name in the
208 -- info string. Skip blanks to the start of the street name, then
209 -- search for the index of the next blank character in the string.
212 AS
.Fixed
.Index_Non_Blank
(Info_String
(Stop
+1..Info_String
'Length));
215 AS
.Fixed
.Index
(Info_String
(Start
..Info_String
'Length),
218 -- Store the street name in the appropriate data base element field.
220 AS
.Fixed
.Overwrite
(DB_Record
.Street_Name
,
222 Info_String
(Start
..Stop
));
224 -- Replace any underscore characters in the street name field
225 -- that were used as word separation.
227 DB_Record
.Street_Name
:= AS
.Fixed
.Translate
(DB_Record
.Street_Name
,
228 Underscore_to_Blank_Map
);
231 -- Continue the extraction; remove the city name from the string.
234 AS
.Fixed
.Index_Non_Blank
(Info_String
(Stop
+1..Info_String
'Length));
237 AS
.Fixed
.Index
(Info_String
(Start
..Info_String
'Length),
240 -- Store the city name field in the appropriate data base element.
242 AS
.Fixed
.Replace_Slice
(DB_Record
.City
,
244 DB_Record
.City
'Length,
245 Info_String
(Start
..Stop
));
247 -- Replace any underscore characters in the city name field
248 -- that were used as word separation.
250 AS
.Fixed
.Translate
(DB_Record
.City
, Underscore_to_Blank_Map
);
253 -- Continue the extraction; remove the state identifier from the
258 AS
.Fixed
.Find_Token
(Info_String
(Start
..Info_String
'Length),
259 AS
.Maps
."OR"(California_Set
,
260 AS
.Maps
."OR"(Nevada_Set
, Arizona_Set
)),
265 -- Store the state indicator into the data base element.
267 AS
.Fixed
.Move
(Source
=> Info_String
(Start
..Stop
),
268 Target
=> DB_Record
.State
,
269 Drop
=> Ada
.Strings
.Right
,
270 Justify
=> Ada
.Strings
.Left
,
274 -- Continue the extraction process; remove the final data item in
275 -- the info string, the zip code, and place it into the
276 -- corresponding data base element.
278 DB_Record
.Zip_Code
:= AS
.Fixed
.Tail
(Info_String
,
279 DB_Record
.Zip_Code
'Length);
282 when AS
.Length_Error
=>
283 Report
.Failed
("Length_Error raised in procedure");
284 when AS
.Pattern_Error
=>
285 Report
.Failed
("Pattern_Error raised in procedure");
286 when AS
.Translation_Error
=>
287 Report
.Failed
("Translation_Error raised in procedure");
289 Report
.Failed
("Exception raised in procedure");
290 end Store_Information
;
295 -- Loop thru the information strings, extract the name and address
296 -- information, place this info into elements of the data base.
298 while not Finished_Processing
loop
302 Store_Information
(Info_Strings
(Count
), Data_Base
(Count
));
304 Finished_Processing
:= (Count
= Number_Of_Info_Strings
);
309 -- Verify that the string processing was successful.
311 for i
in 1..DB_Size
loop
312 if Data_Base
(i
) /= TC_Data_Base
(i
) then
314 ("Data processing error on record " & Integer'Image(i
));
320 when others => Report
.Failed
("Exception raised in Test_Block");