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, "*" (string constructor function),
30 -- Count, Trim, and Replace_Slice.
33 -- This test demonstrates how certain Fixed string functions are used
34 -- to eliminate specific substrings from portions of text. A procedure
35 -- is defined that will take as parameters a source string along with
36 -- a substring that is to be completely removed from the source string.
37 -- The source string is parsed using the Index function, and any substring
38 -- slices are replaced in the source string by a series of X's (based on
39 -- the length of the substring.)
40 -- Three lines of text are provided to this procedure, and the resulting
41 -- substitutions are compared with expected results to validate the
43 -- A global accumulator is updated with the number of occurrences of the
44 -- substring in the source string.
48 -- 06 Dec 94 SAIC ACVC 2.0
53 with Ada
.Strings
.Fixed
;
54 with Ada
.Strings
.Maps
;
61 Report
.Test
("CXA4002", "Check that the subprograms defined in package " &
62 "Ada.Strings.Fixed are available, and that " &
63 "they produce correct results");
68 TC_Total
: Natural := 0;
69 Number_Of_Lines
: constant := 3;
71 type Restricted_Words_Array_Type
is array (1..10) of String (1..10);
73 Restricted_Words
: Restricted_Words_Array_Type
:=
74 (" platoon", " marines ", " Marines ",
75 "north ", "south ", " east",
76 " beach ", " airport", "airfield ",
79 subtype Line_Of_Text_Type
is String(1..25);
80 type Page_Of_Text_Type
is array (1..Number_Of_Lines
)
83 Text_Page
: Page_Of_Text_Type
:= ("The platoon of Marines ",
84 "moved south on the south ",
85 "road to the airfield. ");
87 TC_Revised_Line_1
: constant String := "The XXXXXXX of XXXXXXX ";
88 TC_Revised_Line_2
: constant String := "moved XXXXX on the XXXXX ";
89 TC_Revised_Line_3
: constant String := "XXXX to the XXXXXXXX. ";
93 procedure Censor
(Source_String
: in out String;
94 Pattern_String
: in String) is
96 -- Create a replacement string that is the same length as the
97 -- pattern string being removed.
98 Replacement
: constant String := -- "*"
99 Ada
.Strings
.Fixed
."*"(Pattern_String
'Length, 'X');
101 Going
: Ada
.Strings
.Direction
:= Ada
.Strings
.Forward
;
102 Map
: constant Ada
.Strings
.Maps
.Character_Mapping
:=
103 Ada
.Strings
.Maps
.Identity
;
105 Index
: Natural := Source_String
'First;
110 -- Accumulate count of total replacement operations.
112 TC_Total
:= TC_Total
+ -- Count
113 Ada
.Strings
.Fixed
.Count
(Source
=> Source_String
,
114 Pattern
=> Pattern_String
,
118 Index
:= Ada
.Strings
.Fixed
.Index
-- Index
119 (Source_String
(Start_Pos
..Source_String
'Last),
124 exit when Index
= 0; -- No matches, exit loop.
126 -- if a match was found, modify the substring.
127 Ada
.Strings
.Fixed
.Replace_Slice
-- Replace_Slice
130 Index
+ Pattern_String
'Length - 1,
132 Start_Pos
:= Index
+ Pattern_String
'Length;
141 -- Invoke Censor subprogram to cleanse text.
142 -- Loop through each line of text, and check for the presence of each
144 -- Use the Trim function to eliminate leading or trailing blanks from
145 -- the restricted word parameters.
147 for Line
in 1..Number_Of_Lines
loop
148 for Word
in Restricted_Words
'Range loop
149 Censor
(Text_Page
(Line
),
150 Ada
.Strings
.Fixed
.Trim
(Restricted_Words
(Word
), -- Trim
158 if TC_Total
/= 6 then
159 Report
.Failed
("Incorrect number of substitutions performed");
162 if Text_Page
(1) /= TC_Revised_Line_1
then
163 Report
.Failed
("Incorrect substitutions on Line 1");
166 if Text_Page
(2) /= TC_Revised_Line_2
then
167 Report
.Failed
("Incorrect substitutions on Line 2");
170 if Text_Page
(3) /= TC_Revised_Line_3
then
171 Report
.Failed
("Incorrect substitutions on Line 3");
176 when others => Report
.Failed
("Exception raised in Test_Block");