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.Bounded are
28 -- available, and that they produce correct results. Specifically, check
29 -- the subprograms Length, Slice, "&", To_Bounded_String, Append, Index,
30 -- To_String, Replace_Slice, Trim, Overwrite, Delete, Insert, and
34 -- This test demonstrates the uses of a variety of the string functions
35 -- found in the package Ada.Strings.Bounded, simulating the operations
36 -- found in a text processing package.
37 -- With bounded strings, the length of each "line" of text can vary up
38 -- to the instantiated maximum, allowing one to view a page of text as
39 -- a series of expandable lines. This provides flexibility in text
40 -- formatting of individual lines (strings).
41 -- Several subprograms are defined, all of which attempt to take advantage
42 -- of as many different bounded string utilities as possible. Often,
43 -- an operation that is being performed in a subprogram using a certain
44 -- bounded string utility could more efficiently be performed using a
45 -- a different utility. However, in the interest of including as broad
46 -- coverage as possible, a mixture of utilities is invoked in this test.
47 -- A simulated page of text is provided as a parameter to the test
48 -- defined subprograms, and the appropriate processing performed. The
49 -- processed page of text is then compared to a predefined "finished"
50 -- page, and test passage/failure is based on the results of this
55 -- 06 Dec 94 SAIC ACVC 2.0
60 with Ada
.Strings
.Bounded
;
61 with Ada
.Strings
.Maps
;
68 Report
.Test
("CXA4006", "Check that the subprograms defined in package " &
69 "Ada.Strings.Bounded are available, and that " &
70 "they produce correct results");
75 Characters_Per_Line
: constant Positive := 40;
76 Lines_Per_Page
: constant Natural := 4;
79 Ada
.Strings
.Bounded
.Generic_Bounded_Length
(Characters_Per_Line
);
80 use type BS_40
.Bounded_String
;
82 type Page_Type
is array (1..Lines_Per_Page
) of BS_40
.Bounded_String
;
84 -- Note: Misspellings below are intentional.
86 Line1
: BS_40
.Bounded_String
:=
87 BS_40
.To_Bounded_String
("ada is a progrraming language designed");
88 Line2
: BS_40
.Bounded_String
:=
89 BS_40
.To_Bounded_String
("to support the construction of long-");
90 Line3
: BS_40
.Bounded_String
:=
91 BS_40
.To_Bounded_String
("lived, highly reliabel software ");
92 Line4
: BS_40
.Bounded_String
:=
93 BS_40
.To_Bounded_String
("systems");
95 Page
: Page_Type
:= (1 => Line1
, 2 => Line2
, 3 => Line3
, 4 => Line4
);
97 Finished_Page
: Page_Type
:=
98 (BS_40
.To_Bounded_String
("Ada is a programming language designed"),
99 BS_40
.To_Bounded_String
("to support the construction of long-"),
100 BS_40
.To_Bounded_String
("lived, HIGHLY RELIABLE software systems."),
101 BS_40
.To_Bounded_String
(""));
105 procedure Compress
(Page
: in out Page_Type
) is
106 Clear_Line
: Natural := Lines_Per_Page
;
108 -- If two consecutive lines on the page are together less than the
109 -- maximum line length, then append those two lines, move up all
110 -- lower lines on the page, and blank out the last line.
111 for i
in 1..Lines_Per_Page
- 1 loop
112 if BS_40
.Length
(Page
(i
)) + BS_40
.Length
(Page
(i
+1)) <=
115 Page
(i
) := BS_40
."&"(Page
(i
),
116 Page
(i
+1)); -- "&" (bounded, bounded)
118 for j
in i
+1..Lines_Per_Page
- 1 loop
120 BS_40
.To_Bounded_String
121 (BS_40
.Slice
(Page
(j
+1),
123 BS_40
.Length
(Page
(j
+1))));
126 Page
(Clear_Line
) := BS_40
.Null_Bounded_String
;
133 procedure Format
(Page
: in out Page_Type
) is
134 Sm_Ada
: BS_40
.Bounded_String
:= BS_40
.To_Bounded_String
("ada");
135 Cap_Ada
: constant String := "Ada";
136 Char_Pos
: Natural := 0;
137 Finished
: Boolean := False;
138 Line
: Natural := Page_Type
'Last;
141 -- Add a period to the end of the last line.
142 while Line
>= Page_Type
'First and not Finished
loop
143 if Page
(Line
) /= BS_40
.Null_Bounded_String
and
144 BS_40
.Length
(Page
(Line
)) <= BS_40
.Max_Length
146 Page
(Line
) := BS_40
.Append
(Page
(Line
), '.');
152 -- Replace all occurrences of "ada" with "Ada".
153 for Line
in Page_Type
'First .. Page_Type
'Last loop
155 while not Finished
loop
156 Char_Pos
:= BS_40
.Index
(Source
=> Page
(Line
),
157 Pattern
=> BS_40
.To_String
(Sm_Ada
),
158 Going
=> Ada
.Strings
.Backward
);
159 -- A zero is returned by function Index if no occurrences of
160 -- the pattern string are found.
161 Finished
:= (Char_Pos
= 0);
164 (Source
=> Page
(Line
),
166 High
=> Char_Pos
+ BS_40
.Length
(Sm_Ada
) - 1,
169 end loop; -- while loop
170 end loop; -- for loop
176 procedure Spell_Check
(Page
: in out Page_Type
) is
177 type Spelling_Type
is (Incorrect
, Correct
);
178 type Word_Array_Type
is array (Spelling_Type
)
179 of BS_40
.Bounded_String
;
180 type Dictionary_Type
is array (1..2) of Word_Array_Type
;
182 -- Note that the "words" in the dictionary will require various
183 -- amounts of Trimming prior to their use in the string functions.
184 Dictionary
: Dictionary_Type
:=
185 (1 => (BS_40
.To_Bounded_String
(" reliabel "),
186 BS_40
.To_Bounded_String
(" reliable ")),
187 2 => (BS_40
.To_Bounded_String
(" progrraming "),
188 BS_40
.To_Bounded_String
(" programming ")));
190 Pos
: Natural := Natural'First;
191 Finished
: Boolean := False;
195 for Line
in Page_Type
'Range loop
197 -- Search for the first incorrectly spelled word in the Dictionary,
198 -- if it is found, replace it with the correctly spelled word,
199 -- using the Overwrite function.
201 while not Finished
loop
203 BS_40
.Index
(Page
(Line
),
205 BS_40
.Trim
(Dictionary
(1)(Incorrect
),
207 Ada
.Strings
.Forward
);
208 Finished
:= (Pos
= 0);
211 BS_40
.Overwrite
(Page
(Line
),
214 (BS_40
.Trim
(Dictionary
(1)(Correct
),
221 -- Search for the second incorrectly spelled word in the
222 -- Dictionary, if it is found, replace it with the correctly
223 -- spelled word, using the Delete procedure and Insert function.
225 while not Finished
loop
227 BS_40
.Index
(Page
(Line
),
229 BS_40
.Trim
(Dictionary
(2)(Incorrect
),
231 Ada
.Strings
.Forward
);
233 Finished
:= (Pos
= 0);
239 Pos
+ BS_40
.To_String
240 (BS_40
.Trim
(Dictionary
(2)(Incorrect
),
241 Ada
.Strings
.Both
))'Length-1);
243 BS_40
.Insert
(Page
(Line
),
246 (BS_40
.Trim
(Dictionary
(2)(Correct
),
258 procedure Bold
(Page
: in out Page_Type
) is
259 Key_Word
: constant String := "highly reliable";
260 Bold_Mapping
: constant Ada
.Strings
.Maps
.Character_Mapping
:=
261 Ada
.Strings
.Maps
.To_Mapping
(From
=> " abcdefghijklmnopqrstuvwxyz",
262 To
=> " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
263 Pos
: Natural := Natural'First;
264 Finished
: Boolean := False;
266 -- This procedure is designed to change the case of the phrase
267 -- "highly reliable" into upper case (a type of "Bolding").
268 -- All instances of the phrase on all lines of the page will be
271 for Line
in Page_Type
'First .. Page_Type
'Last loop
272 while not Finished
loop
273 Pos
:= BS_40
.Index
(Page
(Line
), Key_Word
);
274 Finished
:= (Pos
= 0);
282 (BS_40
.To_Bounded_String
283 (BS_40
.Slice
(Page
(Line
),
285 Pos
+ Key_Word
'Length - 1)),
302 for i
in 1..Lines_Per_Page
loop
303 if BS_40
.To_String
(Page
(i
)) /= BS_40
.To_String
(Finished_Page
(i
)) or
304 BS_40
.Length
(Page
(i
)) /= BS_40
.Length
(Finished_Page
(i
))
306 Report
.Failed
("Incorrect modification of Page, Line " &
313 when others => Report
.Failed
("Exception raised in Test_Block");