with Ada.Text_IO;
with Ada.Text_IO.Unbounded_IO;
with Ada.Strings.Unbounded;      use Ada.Strings.Unbounded;
with Ada.Containers.Vectors;     use Ada.Containers;
 
procedure Quotes is
   package IO renames Ada.Text_IO;
   package SUIO renames Ada.Text_IO.Unbounded_IO;
   package Quote_Container is new Vectors (Natural, Unbounded_String);
   use Quote_Container;
   Quotes    : Vector;
   Foo       : Vector;
   Bar       : Vector;
   Input     : IO.File_Type;
begin
   IO.Open (File => Input,
            Mode => IO.In_File,
            Name => "quotes.txt");
   while not IO.End_Of_File (File => Input) loop
      Quotes.Append (New_Item => SUIO.Get_Line (File => Input));
   end loop;
   IO.Close (Input);
 
   --  This is similar to: 
   --  Foo.Append (To_Unbounded_String ("Foo 1"));
   Foo := Foo & To_Unbounded_String ("Foo 1");
   for i in Foo.First_Index .. Foo.Last_Index loop
      SUIO.Put_Line (Item => Foo.Element (Index => i));
   end loop;
 
   IO.New_Line;
 
   --  This is similar to:
   --  Quotes.Append (Foo);
   Quotes := Quotes & Foo;
   for i in Quotes.First_Index .. Quotes.Last_Index loop
      SUIO.Put_Line (Item => Quotes.Element (Index => i));
   end loop;   
 
   IO.New_Line;
 
   --  This is similar to:
   --  Bar.Append (To_Unbounded_String ("Bar 1"));
   --  Bar.Append (To_Unbounded_String ("Bar 2"));
   Bar := To_Unbounded_String ("Bar 1") & To_Unbounded_String ("Bar 2");
   for i in Bar.First_Index .. Bar.Last_Index loop
      SUIO.Put_Line (Item => Bar.Element (Index => i));
   end loop;
 
   IO.New_Line;
 
   --  This is similar to:
   --  Foo.Prepend (To_Unbounded_String ("Foo 0"));
   Foo := To_Unbounded_String ("Foo 0") & Foo;
   for i in Foo.First_Index .. Foo.Last_Index loop
      SUIO.Put_Line (Item => Foo.Element (Index => i));
   end loop;
end Quotes;

Go back


Navigation