---------------------------------------------------------------- {{{ ---------- --: Copyright © 2020 … 2023 Martin Krischik «krischik@users.sourceforge.net» ------------------------------------------------------------------------------- --: This library is free software; you can redistribute it and/or modify it --: under the terms of the GNU Library General Public License as published by --: the Free Software Foundation; either version 2 of the License, or (at your --: option) any later version. --: --: This library is distributed in the hope that it will be useful, but WITHOUT --: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or --: FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public --: License for more details. --: --: You should have received a copy of the GNU Library General Public License --: along with this library; if not, write to the Free Software Foundation, --: Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ---------------------------------------------------------------- }}} ---------- pragma License (Modified_Gpl); pragma Ada_2022; with Ada.Text_IO; with Ada.Wide_Text_IO; with Ada.Strings.UTF_Encoding; with Ada.Strings.UTF_Encoding.Wide_Strings; with AdaCL.Trace; package body HP41CX_Tools.Vector_IO is use type AdaCL.Trace.Parameter_Vectors.Vector; function Read_File (File_Name : in String) return HP41CX_Tools.String_Vectors.Vector is pragma Debug (AdaCL.Trace.Entering (AdaCL.Trace.Parameter & File_Name'Image)); package IO renames Ada.Text_IO; Retval : HP41CX_Tools.String_Vectors.Vector; File : IO.File_Type; begin IO.Open (File, IO.In_File, File_Name, Form => "Encoding=UTF8,Text_Translation=U8TEXT,WCEM=8"); while not IO.End_Of_File (File) loop Retval.Append (IO.Get_Line (File)); end loop; IO.Close (File); pragma Debug (AdaCL.Trace.Exiting (Out_Parameter => Retval'Image)); return Retval; end Read_File; function Read_File (File_Name : in String) return HP41CX_Tools.Wide_String_Vectors.Vector is pragma Debug (AdaCL.Trace.Entering (AdaCL.Trace.Parameter & File_Name'Image)); package IO renames Ada.Text_IO; package Encoding renames Ada.Strings.UTF_Encoding; Retval : HP41CX_Tools.Wide_String_Vectors.Vector; File : IO.File_Type; begin IO.Open (File, IO.In_File, File_Name); while not IO.End_Of_File (File) loop declare UTF_8_Line : constant Encoding.UTF_8_String := IO.Get_Line (File); Line : constant Wide_String := Encoding.Wide_Strings.Decode (UTF_8_Line); begin Retval.Append (Line); end; end loop; IO.Close (File); pragma Debug (AdaCL.Trace.Exiting (Out_Parameter => Retval'Image)); return Retval; end Read_File; procedure Write_File (File_Name : in String; Text : in String_Vectors.Vector) is pragma Debug (AdaCL.Trace.Entering (AdaCL.Trace.Parameter & File_Name'Image)); package IO renames Ada.Text_IO; File : IO.File_Type; begin IO.Create (File, IO.Out_File, File_Name, Form => "Encoding=UTF8,Text_Translation=U8TEXT,WCEM=8"); for Line in Text.Iterate loop IO.Put_Line (File, Text (Line)); end loop; IO.Close (File); pragma Debug (AdaCL.Trace.Exiting); return; end Write_File; procedure Write_File (File_Name : in String; Text : in Wide_String_Vectors.Vector) is pragma Debug (AdaCL.Trace.Entering (AdaCL.Trace.Parameter & File_Name'Image)); package IO renames Ada.Wide_Text_IO; File : IO.File_Type; begin IO.Create (File, IO.Out_File, File_Name); for Line in Text.Iterate loop IO.Put_Line (File, Text (Line)); end loop; IO.Close (File); pragma Debug (AdaCL.Trace.Exiting); return; end Write_File; end HP41CX_Tools.Vector_IO; ---------------------------------------------------------------- {{{ ---------- --: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab : --: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr : --: vim: set spell spelllang=en_gb :