1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- ADA.STRINGS.TEXT_BUFFERS.FORMATTING --
9 -- Copyright (C) 2020-2024, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Ada
.Strings
.Text_Buffers
.Utils
;
34 package Ada
.Strings
.Text_Buffers
.Formatting
is
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.
41 type Template
is new Utils
.UTF_8
;
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, ....
53 -- Note that the template is not type String, to avoid this sort of thing:
55 -- https://xkcd.com/327/
59 X1
, X2
, X3
, X4
, X5
, X6
, X7
, X8
, X9
: Utils
.UTF_8_Lines
:= "");
60 -- Sends to standard output
64 X1
, X2
, X3
, X4
, X5
, X6
, X7
, X8
, X9
: Utils
.UTF_8_Lines
:= "");
65 -- Sends to standard error
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
73 end Ada
.Strings
.Text_Buffers
.Formatting
;