home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / docs / lovelace / ustrings.adb < prev    next >
Encoding:
Text File  |  1995-10-20  |  1.9 KB  |  77 lines

  1. package body Ustrings is
  2.  
  3.   Input_Line_Buffer_Length : constant := 1024;
  4.     -- If an input line is longer, Get_Line will recurse to read in the line.
  5.  
  6.  
  7.   procedure Swap(Left, Right : in out Unbounded_String) is
  8.     -- Implement Swap.  This is the portable but slow approach.
  9.     Temporary : Unbounded_String;
  10.   begin
  11.     Temporary := Left;
  12.     Left := Right;
  13.     Right := Temporary;
  14.   end Swap;
  15.  
  16.   function Empty(S : Unbounded_String) return Boolean is
  17.    -- returns True if Length(S)=0.
  18.   begin
  19.    return (Length(S) = 0);
  20.   end Empty;
  21.  
  22.  
  23.   -- Implement Unbounded_String I/O by calling Text_IO String routines.
  24.  
  25.  
  26.   -- Get_Line gets a line of text, limited only by the maximum number of
  27.   -- characters in an Unbounded_String.  It reads characters into a buffer
  28.   -- and if that isn't enough, recurses to read the rest.
  29.  
  30.   procedure Get_Line (File : in File_Type; Item : out Unbounded_String) is
  31.  
  32.     function More_Input return Unbounded_String is
  33.        Input : String (1 .. Input_Line_Buffer_Length);
  34.        Last  : Natural;
  35.     begin
  36.        Get_Line (File, Input, Last);
  37.        if Last < Input'Last then
  38.           return   To_Unbounded_String (Input(1..Last));
  39.        else
  40.           return   To_Unbounded_String (Input(1..Last)) & More_Input;
  41.        end if;
  42.     end More_Input;
  43.  
  44.   begin
  45.       Item := More_Input;
  46.   end Get_Line;
  47.  
  48.  
  49.   procedure Get_Line(Item : out Unbounded_String) is
  50.   begin
  51.     Get_Line(Current_Input, Item);
  52.   end Get_Line;
  53.  
  54.   procedure Put(File : in File_Type; Item : in Unbounded_String) is
  55.   begin
  56.     Put(File, To_String(Item));
  57.   end Put;
  58.  
  59.   procedure Put(Item : in Unbounded_String) is
  60.   begin
  61.     Put(Current_Output, To_String(Item));
  62.   end Put;
  63.  
  64.   procedure Put_Line(File : in File_Type; Item : in Unbounded_String) is
  65.   begin
  66.     Put(File, Item);
  67.     New_Line(File);
  68.   end Put_Line;
  69.  
  70.   procedure Put_Line(Item : in Unbounded_String) is
  71.   begin
  72.     Put(Current_Output, Item);
  73.     New_Line;
  74.   end Put_Line;
  75.  
  76. end Ustrings;
  77.