Commit 798a9055 by Robert Dewar Committed by Arnaud Charlet

a-stzunb.adb, [...]: Move Realloc_For_Chunk to private part of package.

2005-03-08  Robert Dewar  <dewar@adacore.com>

	* a-stzunb.adb, a-stzunb.adb a-stzunb.ads, a-stzunb.ads,
	a-stwiun.ads, a-stwiun.adb, a-strunb.ads, a-strunb.adb: Move
	Realloc_For_Chunk to private part of package.
	New subprograms for AI-301

	* a-szuzti.adb, a-suteio.adb, a-swuwti.adb: Improve efficiency of
	Get_Line procedure.
	Avoid unnecessary use of Get/Set_Wide_String

From-SVN: r96487
parent f122ea71
......@@ -39,16 +39,6 @@ package body Ada.Strings.Unbounded is
use Ada.Finalization;
procedure Realloc_For_Chunk
(Source : in out Unbounded_String;
Chunk_Size : Natural);
pragma Inline (Realloc_For_Chunk);
-- Adjust the size allocated for the string. Add at least Chunk_Size so it
-- is safe to add a string of this size at the end of the current content.
-- The real size allocated for the string is Chunk_Size + x of the current
-- string size. This buffered handling makes the Append unbounded string
-- routines very fast.
---------
-- "&" --
---------
......@@ -202,7 +192,7 @@ package body Ada.Strings.Unbounded is
Result.Reference := new String (1 .. Result.Last);
K := 1;
for I in 1 .. Left loop
for J in 1 .. Left loop
Result.Reference (K .. K + Len - 1) :=
Right.Reference (1 .. Right.Last);
K := K + Len;
......@@ -363,7 +353,7 @@ package body Ada.Strings.Unbounded is
procedure Adjust (Object : in out Unbounded_String) is
begin
-- Copy string, except we do not copy the statically allocated null
-- string, since it can never be deallocated. Note that we do not copy
-- string since it can never be deallocated. Note that we do not copy
-- extra string room here to avoid dragging unused allocated memory.
if Object.Reference /= Null_String'Access then
......
......@@ -405,18 +405,31 @@ private
pragma Stream_Convert (Unbounded_String, To_Unbounded, To_String);
pragma Finalize_Storage_Only (Unbounded_String);
-- Finalization is required only for freeing storage
procedure Initialize (Object : in out Unbounded_String);
procedure Adjust (Object : in out Unbounded_String);
procedure Finalize (Object : in out Unbounded_String);
-- Note: the following declaration is illegal since library level
-- controlled objects are not allowed in preelaborated units. See
-- AI-161 for a discussion of this issue and an attempt to address it.
-- Meanwhile, what happens in GNAT is that this check is omitted for
-- internal implementation units (see check in sem_cat.adb).
procedure Realloc_For_Chunk
(Source : in out Unbounded_String;
Chunk_Size : Natural);
pragma Inline (Realloc_For_Chunk);
-- Adjust the size allocated for the string. Add at least Chunk_Size so it
-- is safe to add a string of this size at the end of the current content.
-- The real size allocated for the string is Chunk_Size + x of the current
-- string size. This buffered handling makes the Append unbounded string
-- routines very fast. This spec is in the private part so that it can be
-- accessed from children (e.g. from Unbounded.Text_IO).
Null_Unbounded_String : constant Unbounded_String :=
(AF.Controlled with Reference => Null_String'Access, Last => 0);
(AF.Controlled with
Reference => Null_String'Access,
Last => 0);
-- Note: this declaration is illegal since library level controlled
-- objects are not allowed in preelaborated units. See AI-161 for a
-- discussion of this issue and an attempt to address it. Meanwhile,
-- what happens in GNAT is that this check is omitted for internal
-- implementation units (see check in sem_cat.adb).
end Ada.Strings.Unbounded;
......@@ -40,7 +40,6 @@ with Ada.Finalization;
package Ada.Strings.Wide_Unbounded is
pragma Preelaborate (Wide_Unbounded);
type Unbounded_Wide_String is private;
Null_Unbounded_Wide_String : constant Unbounded_Wide_String;
......@@ -62,7 +61,13 @@ pragma Preelaborate (Wide_Unbounded);
(Length : Natural) return Unbounded_Wide_String;
function To_Wide_String
(Source : Unbounded_Wide_String) return Wide_String;
(Source : Unbounded_Wide_String)
return Wide_String;
procedure Set_Unbounded_Wide_String
(Target : out Unbounded_Wide_String;
Source : Wide_String);
pragma Ada_05 (Set_Unbounded_Wide_String);
procedure Append
(Source : in out Unbounded_Wide_String;
......@@ -77,7 +82,8 @@ pragma Preelaborate (Wide_Unbounded);
New_Item : Wide_Character);
function "&"
(Left, Right : Unbounded_Wide_String) return Unbounded_Wide_String;
(Left : Unbounded_Wide_String;
Right : Unbounded_Wide_String) return Unbounded_Wide_String;
function "&"
(Left : Unbounded_Wide_String;
......@@ -109,6 +115,19 @@ pragma Preelaborate (Wide_Unbounded);
Low : Positive;
High : Natural) return Wide_String;
function Unbounded_Slice
(Source : Unbounded_Wide_String;
Low : Positive;
High : Natural) return Unbounded_Wide_String;
pragma Ada_05 (Unbounded_Slice);
procedure Unbounded_Slice
(Source : Unbounded_Wide_String;
Target : out Unbounded_Wide_String;
Low : Positive;
High : Natural);
pragma Ada_05 (Unbounded_Slice);
function "="
(Left : Unbounded_Wide_String;
Right : Unbounded_Wide_String) return Boolean;
......@@ -192,10 +211,41 @@ pragma Preelaborate (Wide_Unbounded);
Test : Membership := Inside;
Going : Direction := Forward) return Natural;
function Index
(Source : Unbounded_Wide_String;
Pattern : Wide_String;
From : Positive;
Going : Direction := Forward;
Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
return Natural;
pragma Ada_05 (Index);
function Index
(Source : Unbounded_Wide_String;
Pattern : Wide_String;
From : Positive;
Going : Direction := Forward;
Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
pragma Ada_05 (Index);
function Index
(Source : Unbounded_Wide_String;
Set : Wide_Maps.Wide_Character_Set;
From : Positive;
Test : Membership := Inside;
Going : Direction := Forward) return Natural;
pragma Ada_05 (Index);
function Index_Non_Blank
(Source : Unbounded_Wide_String;
Going : Direction := Forward) return Natural;
function Index_Non_Blank
(Source : Unbounded_Wide_String;
From : Positive;
Going : Direction := Forward) return Natural;
pragma Ada_05 (Index_Non_Blank);
function Count
(Source : Unbounded_Wide_String;
Pattern : Wide_String;
......@@ -219,12 +269,13 @@ pragma Preelaborate (Wide_Unbounded);
Last : out Natural);
------------------------------------
-- Wide_String Translation Subprograms --
-- String Translation Subprograms --
------------------------------------
function Translate
(Source : Unbounded_Wide_String;
Mapping : Wide_Maps.Wide_Character_Mapping) return Unbounded_Wide_String;
Mapping : Wide_Maps.Wide_Character_Mapping)
return Unbounded_Wide_String;
procedure Translate
(Source : in out Unbounded_Wide_String;
......@@ -240,7 +291,7 @@ pragma Preelaborate (Wide_Unbounded);
Mapping : Wide_Maps.Wide_Character_Mapping_Function);
---------------------------------------
-- Wide_String Transformation Subprograms --
-- String Transformation Subprograms --
---------------------------------------
function Replace_Slice
......@@ -250,10 +301,10 @@ pragma Preelaborate (Wide_Unbounded);
By : Wide_String) return Unbounded_Wide_String;
procedure Replace_Slice
(Source : in out Unbounded_Wide_String;
Low : Positive;
High : Natural;
By : Wide_String);
(Source : in out Unbounded_Wide_String;
Low : Positive;
High : Natural;
By : Wide_String);
function Insert
(Source : Unbounded_Wide_String;
......@@ -271,9 +322,9 @@ pragma Preelaborate (Wide_Unbounded);
New_Item : Wide_String) return Unbounded_Wide_String;
procedure Overwrite
(Source : in out Unbounded_Wide_String;
Position : Positive;
New_Item : Wide_String);
(Source : in out Unbounded_Wide_String;
Position : Positive;
New_Item : Wide_String);
function Delete
(Source : Unbounded_Wide_String;
......@@ -361,12 +412,29 @@ private
(Unbounded_Wide_String, To_Unbounded_Wide, To_Wide_String);
pragma Finalize_Storage_Only (Unbounded_Wide_String);
-- Finalization is required only for freeing storage
procedure Initialize (Object : in out Unbounded_Wide_String);
procedure Adjust (Object : in out Unbounded_Wide_String);
procedure Finalize (Object : in out Unbounded_Wide_String);
procedure Realloc_For_Chunk
(Source : in out Unbounded_Wide_String;
Chunk_Size : Natural);
-- Adjust the size allocated for the string. Add at least Chunk_Size so it
-- is safe to add a string of this size at the end of the current content.
-- The real size allocated for the string is Chunk_Size + x of the current
-- string size. This buffered handling makes the Append unbounded string
-- routines very fast.
Null_Unbounded_Wide_String : constant Unbounded_Wide_String :=
(AF.Controlled with Reference => Null_Wide_String'Access, Last => 0);
(AF.Controlled with
Reference => Null_Wide_String'Access,
Last => 0);
-- Note: this declaration is illegal since library level controlled
-- objects are not allowed in preelaborated units. See AI-161 for a
-- discussion of this issue and an attempt to address it. Meanwhile,
-- what happens in GNAT is that this check is omitted for internal
-- implementation units (see check in sem_cat.adb).
end Ada.Strings.Wide_Unbounded;
......@@ -40,7 +40,6 @@ with Ada.Finalization;
package Ada.Strings.Wide_Wide_Unbounded is
pragma Preelaborate (Wide_Wide_Unbounded);
type Unbounded_Wide_Wide_String is private;
Null_Unbounded_Wide_Wide_String : constant Unbounded_Wide_Wide_String;
......@@ -64,6 +63,11 @@ pragma Preelaborate (Wide_Wide_Unbounded);
function To_Wide_Wide_String
(Source : Unbounded_Wide_Wide_String) return Wide_Wide_String;
procedure Set_Unbounded_Wide_Wide_String
(Target : out Unbounded_Wide_Wide_String;
Source : Wide_Wide_String);
pragma Ada_05 (Set_Unbounded_Wide_Wide_String);
procedure Append
(Source : in out Unbounded_Wide_Wide_String;
New_Item : Unbounded_Wide_Wide_String);
......@@ -77,8 +81,8 @@ pragma Preelaborate (Wide_Wide_Unbounded);
New_Item : Wide_Wide_Character);
function "&"
(Left, Right : Unbounded_Wide_Wide_String)
return Unbounded_Wide_Wide_String;
(Left : Unbounded_Wide_Wide_String;
Right : Unbounded_Wide_Wide_String) return Unbounded_Wide_Wide_String;
function "&"
(Left : Unbounded_Wide_Wide_String;
......@@ -110,6 +114,19 @@ pragma Preelaborate (Wide_Wide_Unbounded);
Low : Positive;
High : Natural) return Wide_Wide_String;
function Unbounded_Slice
(Source : Unbounded_Wide_Wide_String;
Low : Positive;
High : Natural) return Unbounded_Wide_Wide_String;
pragma Ada_05 (Unbounded_Slice);
procedure Unbounded_Slice
(Source : Unbounded_Wide_Wide_String;
Target : out Unbounded_Wide_Wide_String;
Low : Positive;
High : Natural);
pragma Ada_05 (Unbounded_Slice);
function "="
(Left : Unbounded_Wide_Wide_String;
Right : Unbounded_Wide_Wide_String) return Boolean;
......@@ -179,7 +196,8 @@ pragma Preelaborate (Wide_Wide_Unbounded);
Pattern : Wide_Wide_String;
Going : Direction := Forward;
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
Wide_Wide_Maps.Identity) return Natural;
Wide_Wide_Maps.Identity)
return Natural;
function Index
(Source : Unbounded_Wide_Wide_String;
......@@ -194,15 +212,49 @@ pragma Preelaborate (Wide_Wide_Unbounded);
Test : Membership := Inside;
Going : Direction := Forward) return Natural;
function Index
(Source : Unbounded_Wide_Wide_String;
Pattern : Wide_Wide_String;
From : Positive;
Going : Direction := Forward;
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
Wide_Wide_Maps.Identity)
return Natural;
pragma Ada_05 (Index);
function Index
(Source : Unbounded_Wide_Wide_String;
Pattern : Wide_Wide_String;
From : Positive;
Going : Direction := Forward;
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
return Natural;
pragma Ada_05 (Index);
function Index
(Source : Unbounded_Wide_Wide_String;
Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
From : Positive;
Test : Membership := Inside;
Going : Direction := Forward) return Natural;
pragma Ada_05 (Index);
function Index_Non_Blank
(Source : Unbounded_Wide_Wide_String;
Going : Direction := Forward) return Natural;
function Index_Non_Blank
(Source : Unbounded_Wide_Wide_String;
From : Positive;
Going : Direction := Forward) return Natural;
pragma Ada_05 (Index_Non_Blank);
function Count
(Source : Unbounded_Wide_Wide_String;
Pattern : Wide_Wide_String;
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
Wide_Wide_Maps.Identity) return Natural;
Wide_Wide_Maps.Identity)
return Natural;
function Count
(Source : Unbounded_Wide_Wide_String;
......@@ -222,7 +274,7 @@ pragma Preelaborate (Wide_Wide_Unbounded);
Last : out Natural);
------------------------------------
-- Wide_Wide_String Translation Subprograms --
-- String Translation Subprograms --
------------------------------------
function Translate
......@@ -244,7 +296,7 @@ pragma Preelaborate (Wide_Wide_Unbounded);
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function);
---------------------------------------
-- Wide_Wide_String Transformation Subprograms --
-- String Transformation Subprograms --
---------------------------------------
function Replace_Slice
......@@ -254,10 +306,10 @@ pragma Preelaborate (Wide_Wide_Unbounded);
By : Wide_Wide_String) return Unbounded_Wide_Wide_String;
procedure Replace_Slice
(Source : in out Unbounded_Wide_Wide_String;
Low : Positive;
High : Natural;
By : Wide_Wide_String);
(Source : in out Unbounded_Wide_Wide_String;
Low : Positive;
High : Natural;
By : Wide_Wide_String);
function Insert
(Source : Unbounded_Wide_Wide_String;
......@@ -275,9 +327,9 @@ pragma Preelaborate (Wide_Wide_Unbounded);
New_Item : Wide_Wide_String) return Unbounded_Wide_Wide_String;
procedure Overwrite
(Source : in out Unbounded_Wide_Wide_String;
Position : Positive;
New_Item : Wide_Wide_String);
(Source : in out Unbounded_Wide_Wide_String;
Position : Positive;
New_Item : Wide_Wide_String);
function Delete
(Source : Unbounded_Wide_Wide_String;
......@@ -351,11 +403,11 @@ private
function To_Unbounded_Wide
(S : Wide_Wide_String) return Unbounded_Wide_Wide_String
renames To_Unbounded_Wide_Wide_String;
renames To_Unbounded_Wide_Wide_String;
type Unbounded_Wide_Wide_String is new AF.Controlled with record
Reference : Wide_Wide_String_Access := Null_Wide_Wide_String'Access;
Last : Natural := 0;
Last : Natural := 0;
end record;
-- The Unbounded_Wide_Wide_String is using a buffered implementation to
......@@ -369,12 +421,29 @@ private
(Unbounded_Wide_Wide_String, To_Unbounded_Wide, To_Wide_Wide_String);
pragma Finalize_Storage_Only (Unbounded_Wide_Wide_String);
-- Finalization is required only for freeing storage
procedure Initialize (Object : in out Unbounded_Wide_Wide_String);
procedure Adjust (Object : in out Unbounded_Wide_Wide_String);
procedure Finalize (Object : in out Unbounded_Wide_Wide_String);
procedure Realloc_For_Chunk
(Source : in out Unbounded_Wide_Wide_String;
Chunk_Size : Natural);
-- Adjust the size allocated for the string. Add at least Chunk_Size so it
-- is safe to add a string of this size at the end of the current content.
-- The real size allocated for the string is Chunk_Size + x of the current
-- string size. This buffered handling makes the Append unbounded string
-- routines very fast.
Null_Unbounded_Wide_Wide_String : constant Unbounded_Wide_Wide_String :=
(AF.Controlled with Reference => Null_Wide_Wide_String'Access, Last => 0);
(AF.Controlled with
Reference =>
Null_Wide_Wide_String'Access,
Last => 0);
-- Note: this declaration is illegal since library level controlled
-- objects are not allowed in preelaborated units. See AI-161 for a
-- discussion of this issue and an attempt to address it. Meanwhile,
-- what happens in GNAT is that this check is omitted for internal
-- implementation units (see check in sem_cat.adb).
end Ada.Strings.Wide_Wide_Unbounded;
......@@ -31,8 +31,7 @@
-- --
------------------------------------------------------------------------------
with Ada.Strings.Unbounded.Aux; use Ada.Strings.Unbounded.Aux;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO; use Ada.Text_IO;
package body Ada.Strings.Unbounded.Text_IO is
......@@ -57,7 +56,8 @@ package body Ada.Strings.Unbounded.Text_IO is
Str1 := Str2;
end loop;
Set_String (Result, Str1);
Result.Reference := Str1;
Result.Last := Str1'Length;
return Result;
end Get_Line;
......@@ -78,49 +78,52 @@ package body Ada.Strings.Unbounded.Text_IO is
Str1 := Str2;
end loop;
Set_String (Result, Str1);
Result.Reference := Str1;
Result.Last := Str1'Length;
return Result;
end Get_Line;
procedure Get_Line (Item : out Unbounded_String) is
Buffer : String (1 .. 1000);
Last : Natural;
Str1 : String_Access;
Str2 : String_Access;
begin
Get_Line (Buffer, Last);
Str1 := new String'(Buffer (1 .. Last));
while Last = Buffer'Last loop
Get_Line (Buffer, Last);
Str2 := new String'(Str1.all & Buffer (1 .. Last));
Free (Str1);
Str1 := Str2;
end loop;
Set_String (Item, Str1);
Get_Line (Current_Input, Item);
end Get_Line;
procedure Get_Line
(File : Ada.Text_IO.File_Type;
Item : out Unbounded_String)
is
Buffer : String (1 .. 1000);
Last : Natural;
Str1 : String_Access;
Str2 : String_Access;
begin
Get_Line (File, Buffer, Last);
Str1 := new String'(Buffer (1 .. Last));
while Last = Buffer'Last loop
Get_Line (Buffer, Last);
Str2 := new String'(Str1.all & Buffer (1 .. Last));
Free (Str1);
Str1 := Str2;
end loop;
-- We are going to read into the string that is already there and
-- allocated. Hopefully it is big enough now, if not, we will extend
-- it in the usual manner using Realloc_For_Chunk.
Set_String (Item, Str1);
-- Make sure we start with at least 80 characters
if Item.Reference'Last < 80 then
Realloc_For_Chunk (Item, 80);
end if;
-- Loop to read data, filling current string as far as possible.
-- Item.Last holds the number of characters read so far.
Item.Last := 0;
loop
Get_Line
(File,
Item.Reference (Item.Last + 1 .. Item.Reference'Last),
Item.Last);
-- If we hit the end of the line before the end of the buffer, then
-- we are all done, and the result length is properly set.
if Item.Last < Item.Reference'Last then
return;
end if;
-- If not enough room, double it and keep reading
Realloc_For_Chunk (Item, Item.Last);
end loop;
end Get_Line;
---------
......@@ -129,12 +132,12 @@ package body Ada.Strings.Unbounded.Text_IO is
procedure Put (U : Unbounded_String) is
begin
Put (Get_String (U).all);
Put (U.Reference (1 .. U.Last));
end Put;
procedure Put (File : File_Type; U : Unbounded_String) is
begin
Put (File, Get_String (U).all);
Put (File, U.Reference (1 .. U.Last));
end Put;
--------------
......@@ -143,12 +146,12 @@ package body Ada.Strings.Unbounded.Text_IO is
procedure Put_Line (U : Unbounded_String) is
begin
Put_Line (Get_String (U).all);
Put_Line (U.Reference (1 .. U.Last));
end Put_Line;
procedure Put_Line (File : File_Type; U : Unbounded_String) is
begin
Put_Line (File, Get_String (U).all);
Put_Line (File, U.Reference (1 .. U.Last));
end Put_Line;
end Ada.Strings.Unbounded.Text_IO;
......@@ -31,8 +31,7 @@
-- --
------------------------------------------------------------------------------
with Ada.Strings.Wide_Unbounded.Aux; use Ada.Strings.Wide_Unbounded.Aux;
with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
package body Ada.Strings.Wide_Unbounded.Wide_Text_IO is
......@@ -57,7 +56,8 @@ package body Ada.Strings.Wide_Unbounded.Wide_Text_IO is
Str1 := Str2;
end loop;
Set_Wide_String (Result, Str1);
Result.Reference := Str1;
Result.Last := Str1'Length;
return Result;
end Get_Line;
......@@ -81,49 +81,52 @@ package body Ada.Strings.Wide_Unbounded.Wide_Text_IO is
Str1 := Str2;
end loop;
Set_Wide_String (Result, Str1);
Result.Reference := Str1;
Result.Last := Str1'Length;
return Result;
end Get_Line;
procedure Get_Line (Item : out Unbounded_Wide_String) is
Buffer : Wide_String (1 .. 1000);
Last : Natural;
Str1 : Wide_String_Access;
Str2 : Wide_String_Access;
begin
Get_Line (Buffer, Last);
Str1 := new Wide_String'(Buffer (1 .. Last));
while Last = Buffer'Last loop
Get_Line (Buffer, Last);
Str2 := new Wide_String'(Str1.all & Buffer (1 .. Last));
Free (Str1);
Str1 := Str2;
end loop;
Set_Wide_String (Item, Str1);
Get_Line (Current_Input, Item);
end Get_Line;
procedure Get_Line
(File : Ada.Wide_Text_IO.File_Type;
Item : out Unbounded_Wide_String)
is
Buffer : Wide_String (1 .. 1000);
Last : Natural;
Str1 : Wide_String_Access;
Str2 : Wide_String_Access;
begin
Get_Line (File, Buffer, Last);
Str1 := new Wide_String'(Buffer (1 .. Last));
while Last = Buffer'Last loop
Get_Line (Buffer, Last);
Str2 := new Wide_String'(Str1.all & Buffer (1 .. Last));
Free (Str1);
Str1 := Str2;
end loop;
-- We are going to read into the string that is already there and
-- allocated. Hopefully it is big enough now, if not, we will extend
-- it in the usual manner using Realloc_For_Chunk.
Set_Wide_String (Item, Str1);
-- Make sure we start with at least 80 characters
if Item.Reference'Last < 80 then
Realloc_For_Chunk (Item, 80);
end if;
-- Loop to read data, filling current string as far as possible.
-- Item.Last holds the number of characters read so far.
Item.Last := 0;
loop
Get_Line
(File,
Item.Reference (Item.Last + 1 .. Item.Reference'Last),
Item.Last);
-- If we hit the end of the line before the end of the buffer, then
-- we are all done, and the result length is properly set.
if Item.Last < Item.Reference'Last then
return;
end if;
-- If not enough room, double it and keep reading
Realloc_For_Chunk (Item, Item.Last);
end loop;
end Get_Line;
---------
......@@ -132,12 +135,12 @@ package body Ada.Strings.Wide_Unbounded.Wide_Text_IO is
procedure Put (U : Unbounded_Wide_String) is
begin
Put (Get_Wide_String (U).all);
Put (U.Reference (1 .. U.Last));
end Put;
procedure Put (File : File_Type; U : Unbounded_Wide_String) is
begin
Put (File, Get_Wide_String (U).all);
Put (File, U.Reference (1 .. U.Last));
end Put;
--------------
......@@ -146,12 +149,12 @@ package body Ada.Strings.Wide_Unbounded.Wide_Text_IO is
procedure Put_Line (U : Unbounded_Wide_String) is
begin
Put_Line (Get_Wide_String (U).all);
Put_Line (U.Reference (1 .. U.Last));
end Put_Line;
procedure Put_Line (File : File_Type; U : Unbounded_Wide_String) is
begin
Put_Line (File, Get_Wide_String (U).all);
Put_Line (File, U.Reference (1 .. U.Last));
end Put_Line;
end Ada.Strings.Wide_Unbounded.Wide_Text_IO;
......@@ -31,10 +31,7 @@
-- --
------------------------------------------------------------------------------
with Ada.Strings.Wide_Wide_Unbounded.Aux;
use Ada.Strings.Wide_Wide_Unbounded.Aux;
with Ada.Wide_Wide_Text_IO;
use Ada.Wide_Wide_Text_IO;
with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO;
package body Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Text_IO is
......@@ -59,13 +56,13 @@ package body Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Text_IO is
Str1 := Str2;
end loop;
Set_Wide_Wide_String (Result, Str1);
Result.Reference := Str1;
Result.Last := Str1'Length;
return Result;
end Get_Line;
function Get_Line
(File : Ada.Wide_Wide_Text_IO.File_Type)
return Unbounded_Wide_Wide_String
(File : Ada.Wide_Wide_Text_IO.File_Type) return Unbounded_Wide_Wide_String
is
Buffer : Wide_Wide_String (1 .. 1000);
Last : Natural;
......@@ -84,49 +81,52 @@ package body Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Text_IO is
Str1 := Str2;
end loop;
Set_Wide_Wide_String (Result, Str1);
Result.Reference := Str1;
Result.Last := Str1'Length;
return Result;
end Get_Line;
procedure Get_Line (Item : out Unbounded_Wide_Wide_String) is
Buffer : Wide_Wide_String (1 .. 1000);
Last : Natural;
Str1 : Wide_Wide_String_Access;
Str2 : Wide_Wide_String_Access;
begin
Get_Line (Buffer, Last);
Str1 := new Wide_Wide_String'(Buffer (1 .. Last));
while Last = Buffer'Last loop
Get_Line (Buffer, Last);
Str2 := new Wide_Wide_String'(Str1.all & Buffer (1 .. Last));
Free (Str1);
Str1 := Str2;
end loop;
Set_Wide_Wide_String (Item, Str1);
Get_Line (Current_Input, Item);
end Get_Line;
procedure Get_Line
(File : Ada.Wide_Wide_Text_IO.File_Type;
Item : out Unbounded_Wide_Wide_String)
is
Buffer : Wide_Wide_String (1 .. 1000);
Last : Natural;
Str1 : Wide_Wide_String_Access;
Str2 : Wide_Wide_String_Access;
begin
Get_Line (File, Buffer, Last);
Str1 := new Wide_Wide_String'(Buffer (1 .. Last));
while Last = Buffer'Last loop
Get_Line (Buffer, Last);
Str2 := new Wide_Wide_String'(Str1.all & Buffer (1 .. Last));
Free (Str1);
Str1 := Str2;
end loop;
-- We are going to read into the string that is already there and
-- allocated. Hopefully it is big enough now, if not, we will extend
-- it in the usual manner using Realloc_For_Chunk.
Set_Wide_Wide_String (Item, Str1);
-- Make sure we start with at least 80 characters
if Item.Reference'Last < 80 then
Realloc_For_Chunk (Item, 80);
end if;
-- Loop to read data, filling current string as far as possible.
-- Item.Last holds the number of characters read so far.
Item.Last := 0;
loop
Get_Line
(File,
Item.Reference (Item.Last + 1 .. Item.Reference'Last),
Item.Last);
-- If we hit the end of the line before the end of the buffer, then
-- we are all done, and the result length is properly set.
if Item.Last < Item.Reference'Last then
return;
end if;
-- If not enough room, double it and keep reading
Realloc_For_Chunk (Item, Item.Last);
end loop;
end Get_Line;
---------
......@@ -135,12 +135,12 @@ package body Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Text_IO is
procedure Put (U : Unbounded_Wide_Wide_String) is
begin
Put (Get_Wide_Wide_String (U).all);
Put (U.Reference (1 .. U.Last));
end Put;
procedure Put (File : File_Type; U : Unbounded_Wide_Wide_String) is
begin
Put (File, Get_Wide_Wide_String (U).all);
Put (File, U.Reference (1 .. U.Last));
end Put;
--------------
......@@ -149,12 +149,12 @@ package body Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Text_IO is
procedure Put_Line (U : Unbounded_Wide_Wide_String) is
begin
Put_Line (Get_Wide_Wide_String (U).all);
Put_Line (U.Reference (1 .. U.Last));
end Put_Line;
procedure Put_Line (File : File_Type; U : Unbounded_Wide_Wide_String) is
begin
Put_Line (File, Get_Wide_Wide_String (U).all);
Put_Line (File, U.Reference (1 .. U.Last));
end Put_Line;
end Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Text_IO;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment