1------------------------------------------------------------------------------ 2-- -- 3-- GNAT RUN-TIME COMPONENTS -- 4-- -- 5-- ADA.STRINGS.TEXT_BUFFERS.FORMATTING -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 2020-2021, Free Software Foundation, Inc. -- 10-- -- 11-- GNAT is free software; you can redistribute it and/or modify it under -- 12-- terms of the GNU General Public License as published by the Free Soft- -- 13-- ware Foundation; either version 3, or (at your option) any later ver- -- 14-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16-- or FITNESS FOR A PARTICULAR PURPOSE. -- 17-- -- 18-- As a special exception under Section 7 of GPL version 3, you are granted -- 19-- additional permissions described in the GCC Runtime Library Exception, -- 20-- version 3.1, as published by the Free Software Foundation. -- 21-- -- 22-- You should have received a copy of the GNU General Public License and -- 23-- a copy of the GCC Runtime Library Exception along with this program; -- 24-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25-- <http://www.gnu.org/licenses/>. -- 26-- -- 27-- GNAT was originally developed by the GNAT team at New York University. -- 28-- Extensive contributions were provided by Ada Core Technologies Inc. -- 29-- -- 30------------------------------------------------------------------------------ 31 32with Ada.Strings.Text_Buffers.Utils; 33 34package Ada.Strings.Text_Buffers.Formatting is 35 36 -- Template-based output, based loosely on C's printf family. Unlike 37 -- printf, it is type safe. We don't support myriad formatting options; the 38 -- caller is expected to call 'Image, or other functions that might have 39 -- various formatting capabilities. 40 41 type Template is new Utils.UTF_8; 42 43 procedure Put 44 (S : in out Root_Buffer_Type'Class; T : Template; 45 X1, X2, X3, X4, X5, X6, X7, X8, X9 : Utils.UTF_8_Lines := ""); 46 -- Prints the template as is, except for the following escape sequences: 47 -- "\n" is end of line. 48 -- "\i" indents by the default amount, and "\o" outdents. 49 -- "\I" indents by one space, and "\O" outdents. 50 -- "\1" is replaced with X1, and similarly for 2, 3, .... 51 -- "\\" is "\". 52 53 -- Note that the template is not type String, to avoid this sort of thing: 54 -- 55 -- https://xkcd.com/327/ 56 57 procedure Put 58 (T : Template; 59 X1, X2, X3, X4, X5, X6, X7, X8, X9 : Utils.UTF_8_Lines := ""); 60 -- Sends to standard output 61 62 procedure Err 63 (T : Template; 64 X1, X2, X3, X4, X5, X6, X7, X8, X9 : Utils.UTF_8_Lines := ""); 65 -- Sends to standard error 66 67 function Format 68 (T : Template; 69 X1, X2, X3, X4, X5, X6, X7, X8, X9 : Utils.UTF_8_Lines := "") 70 return Utils.UTF_8_Lines; 71 -- Returns a UTF-8-encoded String 72 73end Ada.Strings.Text_Buffers.Formatting; 74