1 |
149 |
jeremybenn |
-- CXA4017.A
|
2 |
|
|
--
|
3 |
|
|
-- Grant of Unlimited Rights
|
4 |
|
|
--
|
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
|
14 |
|
|
-- to do so.
|
15 |
|
|
--
|
16 |
|
|
-- DISCLAIMER
|
17 |
|
|
--
|
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.
|
24 |
|
|
--*
|
25 |
|
|
--
|
26 |
|
|
-- OBJECTIVE:
|
27 |
|
|
-- Check that the subprograms defined in package Ada.Strings.Wide_Bounded
|
28 |
|
|
-- are available, and that they produce correct results. Specifically,
|
29 |
|
|
-- check the subprograms Append, Delete, Index, Insert , Length,
|
30 |
|
|
-- Overwrite, Replace_Slice, Slice, "&", To_Bounded_Wide_String,
|
31 |
|
|
-- To_Wide_String, Translate, and Trim.
|
32 |
|
|
--
|
33 |
|
|
-- TEST DESCRIPTION:
|
34 |
|
|
-- This test demonstrates the uses of a variety of the Wide_String
|
35 |
|
|
-- functions found in the package Ada.Strings.Wide_Bounded, simulating
|
36 |
|
|
-- the operations found in a text processing environment.
|
37 |
|
|
-- With bounded wide strings, the length of each "line" of text can vary
|
38 |
|
|
-- up 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 (wide strings).
|
41 |
|
|
-- Several subprograms are defined, all of which attempt to take
|
42 |
|
|
-- advantage of as many different bounded wide string utilities as
|
43 |
|
|
-- possible. Often, an operation that is being performed in a subprogram
|
44 |
|
|
-- using a certain bounded wide string utility could more efficiently be
|
45 |
|
|
-- performed using a different utility. However, in the interest of
|
46 |
|
|
-- including as broad coverage as possible, a mixture of utilities is
|
47 |
|
|
-- invoked in this test.
|
48 |
|
|
-- A simulated page of text is provided as a parameter to the test
|
49 |
|
|
-- defined subprograms, and the appropriate processing performed. The
|
50 |
|
|
-- processed page of text is then compared to a predefined "finished"
|
51 |
|
|
-- page, and test passage/failure is based on the results of this
|
52 |
|
|
-- comparison.
|
53 |
|
|
--
|
54 |
|
|
--
|
55 |
|
|
-- CHANGE HISTORY:
|
56 |
|
|
-- 06 Dec 94 SAIC ACVC 2.0
|
57 |
|
|
-- 06 Nov 95 SAIC Corrected initialization error for ACVC 2.0.1.
|
58 |
|
|
--
|
59 |
|
|
--!
|
60 |
|
|
|
61 |
|
|
with Ada.Strings;
|
62 |
|
|
with Ada.Strings.Wide_Bounded;
|
63 |
|
|
with Ada.Strings.Wide_Maps;
|
64 |
|
|
with Report;
|
65 |
|
|
|
66 |
|
|
procedure CXA4017 is
|
67 |
|
|
|
68 |
|
|
begin
|
69 |
|
|
|
70 |
|
|
Report.Test ("CXA4017", "Check that the subprograms defined in package " &
|
71 |
|
|
"Ada.Strings.Wide_Bounded are available, and " &
|
72 |
|
|
"that they produce correct results");
|
73 |
|
|
|
74 |
|
|
Test_Block:
|
75 |
|
|
declare
|
76 |
|
|
|
77 |
|
|
Characters_Per_Line : constant Positive := 40;
|
78 |
|
|
Lines_Per_Page : constant Natural := 4;
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
package BS_40 is new
|
82 |
|
|
Ada.Strings.Wide_Bounded.Generic_Bounded_Length(Characters_Per_Line);
|
83 |
|
|
|
84 |
|
|
use type BS_40.Bounded_Wide_String;
|
85 |
|
|
|
86 |
|
|
type Page_Type is array (1..Lines_Per_Page) of
|
87 |
|
|
BS_40.Bounded_Wide_String;
|
88 |
|
|
|
89 |
|
|
-- Note: Misspellings below are intentional.
|
90 |
|
|
|
91 |
|
|
Line1 : BS_40.Bounded_Wide_String :=
|
92 |
|
|
BS_40.To_Bounded_Wide_String
|
93 |
|
|
("ada is a progrraming language designed");
|
94 |
|
|
Line2 : BS_40.Bounded_Wide_String :=
|
95 |
|
|
BS_40.To_Bounded_Wide_String("to support the construction of long-");
|
96 |
|
|
Line3 : BS_40.Bounded_Wide_String :=
|
97 |
|
|
BS_40.To_Bounded_Wide_String("lived, highly reliabel software ");
|
98 |
|
|
Line4 : BS_40.Bounded_Wide_String :=
|
99 |
|
|
BS_40.To_Bounded_Wide_String("systems");
|
100 |
|
|
|
101 |
|
|
Page : Page_Type := (1 => Line1, 2 => Line2, 3 => Line3, 4 => Line4);
|
102 |
|
|
|
103 |
|
|
Finished_Page : Page_Type :=
|
104 |
|
|
(BS_40.To_Bounded_Wide_String
|
105 |
|
|
("Ada is a programming language designed"),
|
106 |
|
|
BS_40.To_Bounded_Wide_String("to support the construction of long-"),
|
107 |
|
|
BS_40.To_Bounded_Wide_String
|
108 |
|
|
("lived, HIGHLY RELIABLE software systems."),
|
109 |
|
|
BS_40.To_Bounded_Wide_String(""));
|
110 |
|
|
|
111 |
|
|
---
|
112 |
|
|
|
113 |
|
|
procedure Compress (Page : in out Page_Type) is
|
114 |
|
|
Clear_Line : Natural := Lines_Per_Page;
|
115 |
|
|
begin
|
116 |
|
|
-- If two consecutive lines on the page are together less than the
|
117 |
|
|
-- maximum line length, then append those two lines, move up all
|
118 |
|
|
-- lower lines on the page, and blank out the last line.
|
119 |
|
|
-- This algorithm works one time through the page, does not perform
|
120 |
|
|
-- repetitive compression, and is designed for use with this test
|
121 |
|
|
-- program only.
|
122 |
|
|
for i in 1..Lines_Per_Page - 1 loop
|
123 |
|
|
if BS_40.Length(Page(i)) + BS_40.Length(Page(i+1)) <=
|
124 |
|
|
BS_40.Max_Length
|
125 |
|
|
then
|
126 |
|
|
Page(i) := BS_40."&"(Page(i),
|
127 |
|
|
Page(i+1)); -- "&" (wd bnd, wd bnd)
|
128 |
|
|
|
129 |
|
|
for j in i+1..Lines_Per_Page - 1 loop
|
130 |
|
|
Page(j) :=
|
131 |
|
|
BS_40.To_Bounded_Wide_String
|
132 |
|
|
(BS_40.Slice(Page(j+1),
|
133 |
|
|
1,
|
134 |
|
|
BS_40.Length(Page(j+1))));
|
135 |
|
|
Clear_Line := j + 1;
|
136 |
|
|
end loop;
|
137 |
|
|
Page(Clear_Line) := BS_40.Null_Bounded_Wide_String;
|
138 |
|
|
end if;
|
139 |
|
|
end loop;
|
140 |
|
|
end Compress;
|
141 |
|
|
|
142 |
|
|
---
|
143 |
|
|
|
144 |
|
|
procedure Format (Page : in out Page_Type) is
|
145 |
|
|
Sm_Ada : BS_40.Bounded_Wide_String :=
|
146 |
|
|
BS_40.To_Bounded_Wide_String("ada");
|
147 |
|
|
Cap_Ada : constant Wide_String := "Ada";
|
148 |
|
|
Char_Pos : Natural := 0;
|
149 |
|
|
Finished : Boolean := False;
|
150 |
|
|
Line : Natural := Page_Type'Last;
|
151 |
|
|
begin
|
152 |
|
|
|
153 |
|
|
-- Add a period to the end of the last line.
|
154 |
|
|
while Line >= Page_Type'First and not Finished loop
|
155 |
|
|
if Page(Line) /= BS_40.Null_Bounded_Wide_String and
|
156 |
|
|
BS_40.Length(Page(Line)) <= BS_40.Max_Length
|
157 |
|
|
then
|
158 |
|
|
Page(Line) := BS_40.Append(Page(Line), '.');
|
159 |
|
|
Finished := True;
|
160 |
|
|
end if;
|
161 |
|
|
Line := Line - 1;
|
162 |
|
|
end loop;
|
163 |
|
|
|
164 |
|
|
-- Replace all occurrences of "ada" with "Ada".
|
165 |
|
|
for Line in Page_Type'First .. Page_Type'Last loop
|
166 |
|
|
Finished := False;
|
167 |
|
|
while not Finished loop
|
168 |
|
|
Char_Pos :=
|
169 |
|
|
BS_40.Index (Source => Page(Line),
|
170 |
|
|
Pattern => BS_40.To_Wide_String(Sm_Ada),
|
171 |
|
|
Going => Ada.Strings.Backward);
|
172 |
|
|
-- A zero is returned by function Index if no occurrences of
|
173 |
|
|
-- the pattern wide string are found.
|
174 |
|
|
Finished := (Char_Pos = 0);
|
175 |
|
|
if not Finished then
|
176 |
|
|
BS_40.Replace_Slice
|
177 |
|
|
(Source => Page(Line),
|
178 |
|
|
Low => Char_Pos,
|
179 |
|
|
High => Char_Pos + BS_40.Length(Sm_Ada) - 1,
|
180 |
|
|
By => Cap_Ada);
|
181 |
|
|
end if;
|
182 |
|
|
end loop; -- while loop
|
183 |
|
|
end loop; -- for loop
|
184 |
|
|
|
185 |
|
|
end Format;
|
186 |
|
|
|
187 |
|
|
---
|
188 |
|
|
|
189 |
|
|
procedure Spell_Check (Page : in out Page_Type) is
|
190 |
|
|
type Spelling_Type is (Incorrect, Correct);
|
191 |
|
|
type Word_Array_Type is array (Spelling_Type)
|
192 |
|
|
of BS_40.Bounded_Wide_String;
|
193 |
|
|
type Dictionary_Type is array (1..2) of Word_Array_Type;
|
194 |
|
|
|
195 |
|
|
-- Note that the "words" in the dictionary will require various
|
196 |
|
|
-- amounts of Trimming prior to their use in the bounded wide string
|
197 |
|
|
-- functions.
|
198 |
|
|
Dictionary : Dictionary_Type :=
|
199 |
|
|
(1 => (BS_40.To_Bounded_Wide_String(" reliabel "),
|
200 |
|
|
BS_40.To_Bounded_Wide_String(" reliable ")),
|
201 |
|
|
2 => (BS_40.To_Bounded_Wide_String(" progrraming "),
|
202 |
|
|
BS_40.To_Bounded_Wide_String(" programming ")));
|
203 |
|
|
|
204 |
|
|
Pos : Natural := Natural'First;
|
205 |
|
|
Finished : Boolean := False;
|
206 |
|
|
|
207 |
|
|
begin
|
208 |
|
|
|
209 |
|
|
for Line in Page_Type'Range loop
|
210 |
|
|
|
211 |
|
|
-- Search for the first incorrectly spelled word in the
|
212 |
|
|
-- Dictionary, if it is found, replace it with the correctly
|
213 |
|
|
-- spelled word, using the Overwrite function.
|
214 |
|
|
|
215 |
|
|
while not Finished loop
|
216 |
|
|
Pos :=
|
217 |
|
|
BS_40.Index(Page(Line),
|
218 |
|
|
BS_40.To_Wide_String
|
219 |
|
|
(BS_40.Trim(Dictionary(1)(Incorrect),
|
220 |
|
|
Ada.Strings.Both)),
|
221 |
|
|
Ada.Strings.Forward);
|
222 |
|
|
Finished := (Pos = 0);
|
223 |
|
|
if not Finished then
|
224 |
|
|
Page(Line) :=
|
225 |
|
|
BS_40.Overwrite(Page(Line),
|
226 |
|
|
Pos,
|
227 |
|
|
BS_40.To_Wide_String
|
228 |
|
|
(BS_40.Trim(Dictionary(1)(Correct),
|
229 |
|
|
Ada.Strings.Both)));
|
230 |
|
|
end if;
|
231 |
|
|
end loop;
|
232 |
|
|
|
233 |
|
|
Finished := False;
|
234 |
|
|
|
235 |
|
|
-- Search for the second incorrectly spelled word in the
|
236 |
|
|
-- Dictionary, if it is found, replace it with the correctly
|
237 |
|
|
-- spelled word, using the Delete procedure and Insert function.
|
238 |
|
|
|
239 |
|
|
while not Finished loop
|
240 |
|
|
Pos :=
|
241 |
|
|
BS_40.Index(Page(Line),
|
242 |
|
|
BS_40.To_Wide_String(
|
243 |
|
|
BS_40.Trim(Dictionary(2)(Incorrect),
|
244 |
|
|
Ada.Strings.Both)),
|
245 |
|
|
Ada.Strings.Forward);
|
246 |
|
|
|
247 |
|
|
Finished := (Pos = 0);
|
248 |
|
|
|
249 |
|
|
if not Finished then
|
250 |
|
|
BS_40.Delete
|
251 |
|
|
(Page(Line),
|
252 |
|
|
Pos,
|
253 |
|
|
Pos + BS_40.To_Wide_String
|
254 |
|
|
(BS_40.Trim(Dictionary(2)(Incorrect),
|
255 |
|
|
Ada.Strings.Both))'Length-1);
|
256 |
|
|
Page(Line) :=
|
257 |
|
|
BS_40.Insert(Page(Line),
|
258 |
|
|
Pos,
|
259 |
|
|
BS_40.To_Wide_String
|
260 |
|
|
(BS_40.Trim(Dictionary(2)(Correct),
|
261 |
|
|
Ada.Strings.Both)));
|
262 |
|
|
end if;
|
263 |
|
|
end loop;
|
264 |
|
|
|
265 |
|
|
Finished := False;
|
266 |
|
|
|
267 |
|
|
end loop;
|
268 |
|
|
end Spell_Check;
|
269 |
|
|
|
270 |
|
|
---
|
271 |
|
|
|
272 |
|
|
procedure Bold (Page : in out Page_Type) is
|
273 |
|
|
Key_Word : constant Wide_String := "highly reliable";
|
274 |
|
|
Bold_Mapping : constant
|
275 |
|
|
Ada.Strings.Wide_Maps.Wide_Character_Mapping :=
|
276 |
|
|
Ada.Strings.Wide_Maps.To_Mapping
|
277 |
|
|
(From => " abcdefghijklmnopqrstuvwxyz",
|
278 |
|
|
To => " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
279 |
|
|
Pos : Natural := Natural'First;
|
280 |
|
|
Finished : Boolean := False;
|
281 |
|
|
begin
|
282 |
|
|
-- This procedure is designed to change the case of the phrase
|
283 |
|
|
-- "highly reliable" into upper case (a type of "Bolding").
|
284 |
|
|
-- All instances of the phrase on all lines of the page will be
|
285 |
|
|
-- modified.
|
286 |
|
|
|
287 |
|
|
for Line in Page_Type'First .. Page_Type'Last loop
|
288 |
|
|
while not Finished loop
|
289 |
|
|
Pos := BS_40.Index(Page(Line), Key_Word);
|
290 |
|
|
Finished := (Pos = 0);
|
291 |
|
|
if not Finished then
|
292 |
|
|
|
293 |
|
|
BS_40.Overwrite
|
294 |
|
|
(Page(Line),
|
295 |
|
|
Pos,
|
296 |
|
|
BS_40.To_Wide_String
|
297 |
|
|
(BS_40.Translate
|
298 |
|
|
(BS_40.To_Bounded_Wide_String
|
299 |
|
|
(BS_40.Slice(Page(Line),
|
300 |
|
|
Pos,
|
301 |
|
|
Pos + Key_Word'Length - 1)),
|
302 |
|
|
Bold_Mapping)));
|
303 |
|
|
|
304 |
|
|
end if;
|
305 |
|
|
end loop;
|
306 |
|
|
Finished := False;
|
307 |
|
|
end loop;
|
308 |
|
|
end Bold;
|
309 |
|
|
|
310 |
|
|
|
311 |
|
|
begin
|
312 |
|
|
|
313 |
|
|
Compress(Page);
|
314 |
|
|
Format(Page);
|
315 |
|
|
Spell_Check(Page);
|
316 |
|
|
Bold(Page);
|
317 |
|
|
|
318 |
|
|
for i in 1..Lines_Per_Page loop
|
319 |
|
|
if BS_40.To_Wide_String(Page(i)) /=
|
320 |
|
|
BS_40.To_Wide_String(Finished_Page(i)) or
|
321 |
|
|
BS_40.Length(Page(i)) /=
|
322 |
|
|
BS_40.Length(Finished_Page(i))
|
323 |
|
|
then
|
324 |
|
|
Report.Failed("Incorrect modification of Page, Line " &
|
325 |
|
|
Integer'Image(i));
|
326 |
|
|
end if;
|
327 |
|
|
end loop;
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
exception
|
331 |
|
|
when others => Report.Failed ("Exception raised in Test_Block");
|
332 |
|
|
end Test_Block;
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
Report.Result;
|
336 |
|
|
|
337 |
|
|
end CXA4017;
|