added Unicode_To_Utf8 converter

This commit is contained in:
2014-01-14 14:22:06 +00:00
parent d839e8c41a
commit bcf50fe381
10 changed files with 195 additions and 36 deletions

View File

@ -6,7 +6,6 @@ with Stream;
with Ada.Text_IO;
with Ada.Unchecked_Deallocation;
procedure scheme is
--package S renames H2.Scheme;
--package S is new H2.Scheme (Wide_Character, Wide_String);
@ -43,8 +42,13 @@ begin
);
File_Stream.Name := File_Name'Unchecked_Access;
S.Set_Input_Stream (SI, File_Stream); -- specify main input stream
--S.Set_Input_Stream (SI, String_Stream);
begin
S.Set_Input_Stream (SI, File_Stream); -- specify main input stream
--S.Set_Input_Stream (SI, String_Stream);
exception
when others =>
Ada.Text_IO.Put_Line ("Cannot open Input Stream");
end;
--S.Set_Output_Stream (SI, Stream); -- specify main output stream.
Ada.Text_IO.Put_Line ("-------------------------------------------");

View File

@ -23,7 +23,7 @@ project Scheme is
package Compiler is
for Default_Switches ("Ada") use (
"-gnata", "-gnato", "-gnatN", "-gnatwl", "-gnat95",
"-gnata", "-gnato", "-gnatN", "-gnatwl", "-gnat95", "-gnatW8",
"-I@abs_srcdir@/../lib"
);
end Compiler;

View File

@ -1,7 +1,8 @@
with H2.Pool;
with Ada.Characters.Conversions;
with Ada.Unchecked_Conversion;
with Ada.Text_IO; -- for debugging
package body Stream is
------------------------------------------------------------------
@ -9,13 +10,13 @@ package body Stream is
procedure Open (Stream: in out String_Input_Stream_Record) is
begin
Ada.Wide_Text_IO.Put_Line ("****** OPEN STRING STREAM ******");
Ada.Text_IO.Put_Line ("****** OPEN STRING STREAM ******");
Stream.Pos := 0;
end Open;
procedure Close (Stream: in out String_Input_Stream_Record) is
begin
Ada.Wide_Text_IO.Put_Line ("****** CLOSE STRING STREAM ******");
Ada.Text_IO.Put_Line ("****** CLOSE STRING STREAM ******");
Stream.Pos := Stream.Str'Last;
end Close;
@ -50,18 +51,18 @@ Ada.Wide_Text_IO.Put_Line ("****** CLOSE STRING STREAM ******");
------------------------------------------------------------------
procedure Open (Stream: in out File_Stream_Record) is
subtype Wide_String is Standard.Wide_String(1 .. Standard.Natural(Stream.Name'Length));
function To_Wide_String is new Ada.Unchecked_Conversion (S.Object_String, Wide_String);
begin
Ada.Wide_Text_IO.Put_Line (">>>>> OPEN File STREAM <<<<< " & To_Wide_String(Stream.Name.all));
Ada.Wide_Text_IO.Open (Stream.Handle, Ada.Wide_Text_IO.In_File, Ada.Characters.Conversions.To_String(To_Wide_String(Stream.Name.all)));
Ada.Text_IO.Put_Line (">>>>> OPEN File STREAM <<<<< " & Standard.String(UTF8.Unicode_To_Utf8(UTF8.Unicode_String(Stream.Name.all))));
--Ada.Wide_Text_IO.Open (Stream.Handle, Ada.Wide_Text_IO.In_File, Ada.Characters.Conversions.To_String(Standard.Wide_String(Stream.Name.all)));
Ada.Wide_Text_IO.Open (Stream.Handle, Ada.Wide_Text_IO.In_File, Standard.String(UTF8.Unicode_To_Utf8(UTF8.Unicode_String(Stream.Name.all))));
end Open;
procedure Close (Stream: in out File_Stream_Record) is
subtype Wide_String is Standard.Wide_String(1 .. Standard.Natural(Stream.Name'Length));
function To_Wide_String is new Ada.Unchecked_Conversion (S.Object_String, Wide_String);
begin
Ada.Wide_Text_IO.Put_Line (">>>>> CLOSE File STREAM <<<<< " & To_Wide_String(Stream.Name.all));
--Ada.Wide_Text_IO.Put_Line (">>>>> CLOSE File STREAM <<<<< " & Standard.Wide_String(Stream.Name.all));
Ada.Text_IO.Put_Line (">>>>> CLOSE File STREAM <<<<< " & Standard.String(UTF8.Unicode_To_Utf8(UTF8.Unicode_String(Stream.Name.all))));
Ada.Wide_Text_IO.Close (Stream.Handle);
end Close;
@ -71,6 +72,10 @@ Ada.Wide_Text_IO.Put_Line (">>>>> CLOSE File STREAM <<<<< " & To_Wide_String(Str
begin
for I in Data'First .. Data'Last loop
begin
if Ada.Wide_Text_IO.End_Of_File (Stream.Handle) then
Last := I - 1;
return;
end if;
Ada.Wide_Text_IO.Get_Immediate (Stream.Handle, Data(I));
exception
when Ada.Wide_Text_IO.End_Error =>

View File

@ -1,9 +1,11 @@
with H2.Scheme;
with H2.UTF8;
with Ada.Wide_Text_IO;
package Stream is
package S is new H2.Scheme (Standard.Wide_Character);
package UTF8 is new H2.UTF8 (Standard.Wide_Character, Standard.Character);
------------------------------------------------------------
--type Object_String_Pointer is access all S.Object_String;