1----------------------------------------------------------------------- 2-- Util.Streams.Files -- File Stream utilities 3-- Copyright (C) 2010, 2011, 2012, 2015 Stephane Carrez 4-- Written by Stephane Carrez (Stephane.Carrez@gmail.com) 5-- 6-- Licensed under the Apache License, Version 2.0 (the "License"); 7-- you may not use this file except in compliance with the License. 8-- You may obtain a copy of the License at 9-- 10-- http://www.apache.org/licenses/LICENSE-2.0 11-- 12-- Unless required by applicable law or agreed to in writing, software 13-- distributed under the License is distributed on an "AS IS" BASIS, 14-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15-- See the License for the specific language governing permissions and 16-- limitations under the License. 17----------------------------------------------------------------------- 18with Ada.Strings.Unbounded; 19with Util.Streams.Buffered; 20with Util.Texts.Transforms; 21with Ada.Characters.Handling; 22with Ada.Calendar; 23with GNAT.Calendar.Time_IO; 24package Util.Streams.Texts is 25 26 -- ----------------------- 27 -- Print stream 28 -- ----------------------- 29 -- The <b>Print_Stream</b> is an output stream which provides helper methods 30 -- for writing text streams. 31 type Print_Stream is new Buffered.Buffered_Stream with private; 32 type Print_Stream_Access is access all Print_Stream'Class; 33 34 procedure Initialize (Stream : in out Print_Stream; 35 To : in Output_Stream_Access); 36 37 -- Write an integer on the stream. 38 procedure Write (Stream : in out Print_Stream; 39 Item : in Integer); 40 41 -- Write an integer on the stream. 42 procedure Write (Stream : in out Print_Stream; 43 Item : in Long_Long_Integer); 44 45 -- Write a string on the stream. 46 procedure Write (Stream : in out Print_Stream; 47 Item : in Ada.Strings.Unbounded.Unbounded_String); 48 49 -- Write a date on the stream. 50 procedure Write (Stream : in out Print_Stream; 51 Item : in Ada.Calendar.Time; 52 Format : in GNAT.Calendar.Time_IO.Picture_String 53 := GNAT.Calendar.Time_IO.ISO_Date); 54 55 -- Get the output stream content as a string. 56 function To_String (Stream : in Buffered.Buffered_Stream) return String; 57 58 59 package TR is 60 new Util.Texts.Transforms (Stream => Buffered.Buffered_Stream, 61 Char => Character, 62 Input => String, 63 Put => Buffered.Write, 64 To_Upper => Ada.Characters.Handling.To_Upper, 65 To_Lower => Ada.Characters.Handling.To_Lower); 66 67 -- ----------------------- 68 -- Reader stream 69 -- ----------------------- 70 -- The <b>Reader_Stream</b> is an input stream which provides helper methods 71 -- for reading text streams. 72 type Reader_Stream is new Buffered.Buffered_Stream with private; 73 type Reader_Stream_Access is access all Reader_Stream'Class; 74 75 -- Initialize the reader to read the input from the input stream given in <b>From</b>. 76 procedure Initialize (Stream : in out Reader_Stream; 77 From : in Input_Stream_Access); 78 79 -- Read an input line from the input stream. The line is terminated by ASCII.LF. 80 -- When <b>Strip</b> is set, the line terminators (ASCII.CR, ASCII.LF) are removed. 81 procedure Read_Line (Stream : in out Reader_Stream; 82 Into : out Ada.Strings.Unbounded.Unbounded_String; 83 Strip : in Boolean := False); 84 85 86private 87 88 type Print_Stream is new Buffered.Buffered_Stream with null record; 89 90 type Reader_Stream is new Buffered.Buffered_Stream with null record; 91 92end Util.Streams.Texts; 93