adayaml_0.3.0_ab19e387/test/src/utils.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
--  part of AdaYaml, (c) 2017 Felix Krause
--  released under the terms of the MIT license, see the file "copying.txt"

with Ada.Directories;
with Ada.Direct_IO;

package body Utils is
   function File_Content (Path : String) return String is
      File_Size : constant Natural := Natural (Ada.Directories.Size (Path));

      subtype File_String    is String (1 .. File_Size);
      package File_String_IO is new Ada.Direct_IO (File_String);

      File     : File_String_IO.File_Type;
   begin
      File_String_IO.Open (File, File_String_IO.In_File, Path);
      return Contents : File_String do
         File_String_IO.Read  (File, Contents);
         File_String_IO.Close (File);
      end return;
   end File_Content;
end Utils;