|
Packit Bot |
06c835 |
GNU libasprintf - automatic formatted output to strings
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
This package makes the C formatted output routines (fprintf et al.) usable
|
|
Packit Bot |
06c835 |
in C++ programs.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
Sample use
|
|
Packit Bot |
06c835 |
----------
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
char *pathname = autosprintf ("%s/%s", directory, filename);
|
|
Packit Bot |
06c835 |
cerr << autosprintf ("syntax error in %s:%d: %s", filename, line, errstring);
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
Benefits
|
|
Packit Bot |
06c835 |
--------
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
The benefits of autosprintf over the usual "piecewise meal" idiom
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
cerr << "syntax error in " << filename << ":" << line << ": " << errstring;
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
are:
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
- Reuses of the standard POSIX printf facility. Easy migration from C to C++.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
- English sentences are kept together.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
- Internationalization requires format strings, because
|
|
Packit Bot |
06c835 |
1. Internationalization requires the ability for the translator to change
|
|
Packit Bot |
06c835 |
the order of parts of a sentence. The POSIX printf formatted output
|
|
Packit Bot |
06c835 |
functions (and thus also autosprintf) support this through the %m$ and
|
|
Packit Bot |
06c835 |
*m$ syntax.
|
|
Packit Bot |
06c835 |
2. Translators are used to translate one string per sentence, not
|
|
Packit Bot |
06c835 |
multiple strings per sentence, and not C++ code statements.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
- Reduces the risk of programming errors due to forgotten state in the
|
|
Packit Bot |
06c835 |
output stream (e.g. 'cout << hex;' not followed by 'cout << dec;').
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
The benefits of autosprintf over C sprintf are:
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
- Autosprintf avoids buffer overruns and truncated results.
|
|
Packit Bot |
06c835 |
The C sprintf() function often leads to buffer overruns. On the other
|
|
Packit Bot |
06c835 |
hand, the C snprintf() function requires extra coding for an a priori
|
|
Packit Bot |
06c835 |
estimate of the result's size and truncates the result if the estimate
|
|
Packit Bot |
06c835 |
was too low.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
- Autosprintf avoids memory leaks.
|
|
Packit Bot |
06c835 |
Temporarily allocated memory is cleaned up automatically.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
Installation
|
|
Packit Bot |
06c835 |
------------
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
See INSTALL. Usually "./configure; make; make install" should work.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
The installed files are:
|
|
Packit Bot |
06c835 |
- An include file "autosprintf.h" which defines the class 'autosprintf',
|
|
Packit Bot |
06c835 |
in the namespace 'gnu'.
|
|
Packit Bot |
06c835 |
- A library libasprintf containing this class.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
Use
|
|
Packit Bot |
06c835 |
---
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
To use the class autosprintf, use
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
#include "autosprintf.h"
|
|
Packit Bot |
06c835 |
using gnu::autosprintf;
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
and link with the linker option
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
-lasprintf
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
Misc notes
|
|
Packit Bot |
06c835 |
----------
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
An instance of class 'autosprintf' contains the formatted output result;
|
|
Packit Bot |
06c835 |
this string is freed when the instance's destructor is run.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
The class name 'autosprintf' is meant to remind the C function sprintf(),
|
|
Packit Bot |
06c835 |
the GNU C library function asprintf(), and the C++ autoptr programming idiom.
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
Distribution
|
|
Packit Bot |
06c835 |
------------
|
|
Packit Bot |
06c835 |
http://www.haible.de/bruno/gnu/libasprintf-1.0.tar.gz
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
Homepage
|
|
Packit Bot |
06c835 |
--------
|
|
Packit Bot |
06c835 |
http://www.haible.de/bruno/packages-libasprintf.html
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
Bug reports to:
|
|
Packit Bot |
06c835 |
---------------
|
|
Packit Bot |
06c835 |
<bug-gnu-gettext@gnu.org>
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
Bruno Haible <brunoe@clisp.org>
|