The Ada Program: unbounded.adb
1 -- unbounded.adb: illustrating access to String
2
3 procedure Unbounded is
4
5 type Unbounded_String_Type is access String;
6
7 function "<" (Left, Right: Unbounded_String_Type)
8 return Boolean is
9 begin
10 return (Left.all < Right.all);
11 end "<";
12
13 function "&" (Left, Right: Unbounded_String_Type)
14 return Unbounded_String_Type is
15 begin
16 return (new String'(Left.all & Right.all));
17 end "&";
18
19 W, X, Y, Z : Unbounded_String_Type;
20
21 begin
22
23 W := new String (1..0); -- empty string
24 W := new String (1..20); -- allocate 20 characters
25 X := new String'("Hello");
26 Y := new String'(1..10=>'J');
27 Z := new String'(X.all & ' ' & "Mildred"); -- "Hello Mildred"
28
29 W := X; -- now W points to 5 characters
30
31 W := new String'(X.all); -- allocate new string and copy
32
33 end Unbounded;