File: autosprintf.texi

package info (click to toggle)
gettext 0.23.1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 167,652 kB
  • sloc: ansic: 532,868; sh: 68,216; perl: 28,011; makefile: 9,046; lisp: 3,184; yacc: 1,055; java: 615; cs: 589; cpp: 397; objc: 343; sed: 79; tcl: 63; xml: 40; pascal: 11; awk: 7; php: 7
file content (258 lines) | stat: -rw-r--r-- 8,709 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
\input texinfo          @c -*-texinfo-*-
@c %**start of header
@setfilename autosprintf.info
@c The @ifset makeinfo ... @end ifset conditional evaluates to true in makeinfo
@c for info and html output, but to false in texi2html.
@ifnottex
@ifclear texi2html
@set makeinfo
@end ifclear
@end ifnottex
@settitle GNU @code{autosprintf}
@finalout
@c Indices:
@c   none
@c Unused predefined indices:
@c   cp = concept         @cindex
@c   fn = function        @findex
@c   vr = variable        @vindex
@c   ky = keystroke       @kindex
@c   pg = program         @pindex
@c   tp = type            @tindex
@ifclear texi2html
@firstparagraphindent insert
@end ifclear
@c %**end of header
@set VERSION 1.0

@ifinfo
@dircategory C++ libraries
@direntry
* autosprintf: (autosprintf).   Support for printf format strings in C++.
@end direntry
@end ifinfo

@ifinfo
This file provides documentation for GNU @code{autosprintf} library.

@copying
Copyright (C) 2002-2003, 2006-2007, 2018-2019 Free Software Foundation, Inc.

This manual is free documentation.  It is dually licensed under the
GNU FDL and the GNU GPL.  This means that you can redistribute this
manual under either of these two licenses, at your choice.

This manual is covered by the GNU FDL.  Permission is granted to copy,
distribute and/or modify this document under the terms of the
GNU Free Documentation License (FDL), either version 1.3 of the
License, or (at your option) any later version published by the
Free Software Foundation (FSF); with no Invariant Sections, with no
Front-Cover Text, and with no Back-Cover Texts.
A copy of the license is at @url{https://www.gnu.org/licenses/fdl.html}.

This manual is covered by the GNU GPL.  You can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL), either
version 2 of the License, or (at your option) any later version published
by the Free Software Foundation (FSF).
A copy of the license is at @url{https://www.gnu.org/licenses/gpl.html}.
@end copying
@end ifinfo

@titlepage
@title GNU autosprintf, version @value{VERSION}
@subtitle Formatted Output to Strings in C++
@author Bruno Haible

@ifnothtml
@page
@vskip 0pt plus 1filll
@c @insertcopying
Copyright (C) 2002-2003, 2006-2007, 2018-2019 Free Software Foundation, Inc.

This manual is free documentation.  It is dually licensed under the
GNU FDL and the GNU GPL.  This means that you can redistribute this
manual under either of these two licenses, at your choice.

This manual is covered by the GNU FDL.  Permission is granted to copy,
distribute and/or modify this document under the terms of the
GNU Free Documentation License (FDL), either version 1.2 of the
License, or (at your option) any later version published by the
Free Software Foundation (FSF); with no Invariant Sections, with no
Front-Cover Text, and with no Back-Cover Texts.
A copy of the license is at @url{https://www.gnu.org/licenses/fdl.html}.

This manual is covered by the GNU GPL.  You can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL), either
version 2 of the License, or (at your option) any later version published
by the Free Software Foundation (FSF).
A copy of the license is at @url{https://www.gnu.org/licenses/gpl.html}.
@end ifnothtml
@end titlepage

@c Table of Contents
@contents

@ifnottex
@node Top
@top GNU autosprintf

This manual documents the GNU autosprintf class, version @value{VERSION}.

@menu
* Introduction::                Introduction
* Class autosprintf::           The @code{autosprintf} class
* Using autosprintf::           Using @code{autosprintf} in own programs
* Licenses::
@end menu

@end ifnottex

@node Introduction
@chapter Introduction

This package makes the C formatted output routines (@code{fprintf} et al.)
usable in C++ programs, for use with the @code{<string>} strings and the
@code{<iostream>} streams.

It allows to write code like

@smallexample
cerr << autosprintf ("syntax error in %s:%d: %s", filename, line, errstring);
@end smallexample

@noindent
instead of

@smallexample
cerr << "syntax error in " << filename << ":" << line << ": " << errstring;
@end smallexample

The benefits of the autosprintf syntax are:

@itemize @bullet
@item
It reuses the standard POSIX printf facility. Easy migration from C to C++.

@item
English sentences are kept together.

@item
It makes internationalization possible. Internationalization requires format
strings, because in some cases the translator needs to change the order of a
sentence, and more generally it is easier for the translator to work with a
single string for a sentence than with multiple string pieces.

@item
It reduces the risk of programming errors due to forgotten state in the
output stream (e.g.@: @code{cout << hex;} not followed by @code{cout << dec;}).
@end itemize

@node Class autosprintf
@chapter The @code{autosprintf} class

An instance of class @code{autosprintf} just contains a string with the
formatted output result. Such an instance is usually allocated as an
automatic storage variable, i.e.@: on the stack, not with @code{new} on the
heap.

The constructor @code{autosprintf (const char *format, ...)} takes a format
string and additional arguments, like the C function @code{printf}.

Conversions to @code{char *} and @code{std::string} are defined that return
the encapsulated string.  The conversion to @code{char *} returns a freshly
allocated copy of the encapsulated string; it needs to be freed using
@code{delete[]}.  The conversion to @code{std::string} returns a copy of
the encapsulated string, with automatic memory management.

The destructor @code{~autosprintf ()} destroys the encapsulated string.

An @code{operator <<} is provided that outputs the encapsulated string to the
given @code{ostream}.

@node Using autosprintf
@chapter Using @code{autosprintf} in own programs

To use the @code{autosprintf} class in your programs, you need to add

@smallexample
#include "autosprintf.h"
using gnu::autosprintf;
@end smallexample

@noindent
to your source code.
The include file defines the class @code{autosprintf}, in a namespace called
@code{gnu}. The @samp{using} statement makes it possible to use the class
without the (otherwise natural) @code{gnu::} prefix.

When linking your program, you need to link with @code{libasprintf}, because
that's where the class is defined. In projects using GNU @code{autoconf},
this means adding @samp{AC_LIB_LINKFLAGS([asprintf])} to @code{configure.in}
or @code{configure.ac}, and using the @@LIBASPRINTF@@ Makefile variable that
it provides.

@node Licenses
@appendix Licenses
@cindex Licenses

The files of this package are covered by the licenses indicated in each
particular file or directory.  Here is a summary:

@itemize @bullet
@item
The @code{libasprintf} library is covered by the
GNU Lesser General Public License (LGPL), either version 2.1 of the
License, or (at your option) any later version published by the
Free Software Foundation (FSF).
A copy of the license is included in @ref{GNU LGPL}.

@item
This manual is free documentation.  It is dually licensed under the
GNU FDL and the GNU GPL.  This means that you can redistribute this
manual under either of these two licenses, at your choice.
@*
This manual is covered by the GNU FDL.  Permission is granted to copy,
distribute and/or modify this document under the terms of the
GNU Free Documentation License (FDL), either version 1.2 of the
License, or (at your option) any later version published by the
Free Software Foundation (FSF); with no Invariant Sections, with no
Front-Cover Text, and with no Back-Cover Texts.
A copy of the license is included in @ref{GNU FDL}.
@*
This manual is covered by the GNU GPL.  You can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL), either
version 2 of the License, or (at your option) any later version published
by the Free Software Foundation (FSF).
A copy of the license is included in @ref{GNU GPL}.
@end itemize

@menu
* GNU LGPL::                    GNU Lesser General Public License
* GNU GPL::                     GNU General Public License
* GNU FDL::                     GNU Free Documentation License
@end menu

@page
@node GNU LGPL
@appendixsec GNU LESSER GENERAL PUBLIC LICENSE
@cindex :GPL, GNU Lesser General Public License
@cindex License, GNU LGPL
@include lgpl.texi
@page
@node GNU GPL
@appendixsec GNU GENERAL PUBLIC LICENSE
@cindex GPL, GNU General Public License
@cindex License, GNU GPL
@include gpl.texi
@page
@node GNU FDL
@appendixsec GNU Free Documentation License
@cindex FDL, GNU Free Documentation License
@cindex License, GNU FDL
@include fdl.texi

@bye

@c Local variables:
@c texinfo-column-for-description: 32
@c End: