ggformat

A string formatting library for C++
Log | Files | Refs

commit 71f504831f2395dafc0dc76aadb7999af3c97139
parent 7f9b957a61a6f2226d662ccefa6789804161f309
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun, 29 Oct 2017 22:48:31 +0200

Some docs and release v1.0

Diffstat:
README.md | 23++++++++++++++++++++---
ggformat.cc | 2++
ggformat.h | 13+++++++++++++
3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md @@ -1,9 +1,20 @@ -# ggformat +# ggformat v1.0 ggformat is a liberally licensed string formatting library for C++ that supports user defined types without blowing up your compile times. It is meant to be used as a replacement for printf and friends. +ggformat saves you time by reducing the amount of tedious boilerplate +code you have to write, without adding that time back onto the build. +ggformat has a trivial API and does not mind being mixed with other +formatting libraries, so it's easy to incrementally integrate with +existing software. In particular, it's easy to integrate ggformat with +your favourite string class, adding an extra convenience API on top of +the functionality you already use. ggformat does not allocate memory +unless you want it to, and it's easy to use your own allocators, making +it appropriate for use in long-lived applications and games where memory +fragmentation is a concern. + ggformat requires C++11 (variadic templates), and supports VS2015, GCC and clang out of the box. It should also work with VS2013 and VS2017 but I don't test against them. @@ -13,8 +24,14 @@ I don't test against them. I wrote ggformat because the existing string formatting options for C++ either do not support user defined types or bloat compile times too much. printf doesn't support user defined types. Streams bloat compile -times and IO manipulators are unreadable. [tinyformat](tinyformat) uses -streams under the hood and also bloats compile times. +times and IO manipulators are unreadable. + + +## Version history + +- __v1.0 29th Oct 2017__: variadic arguments are now passed by const + reference. You can now use ggformat with types that have deleted copy + constructors/assignment operators. ## Usage diff --git a/ggformat.cc b/ggformat.cc @@ -1,4 +1,6 @@ /* + * ggformat v1.0 + * * Copyright (c) 2017 Michael Savage <mike@mikejsavage.co.uk> * * Permission to use, copy, modify, and distribute this software for any diff --git a/ggformat.h b/ggformat.h @@ -1,4 +1,6 @@ /* + * ggformat v1.0 + * * Copyright (c) 2017 Michael Savage <mike@mikejsavage.co.uk> * * Permission to use, copy, modify, and distribute this software for any @@ -23,9 +25,20 @@ * prototypes of the functions you should be calling */ +/* + * `ggformat` writes at most `len` bytes to `buf`, and that always includes a + * null terminator. It returns the number of bytes that would have been written + * if `buf` were large enough, not including the null terminator, and can be + * larger than `len` (just like sprintf). +*/ template< typename... Rest > size_t ggformat( char * buf, size_t len, const char * fmt, const Rest & ... rest ); +/* + * `ggprint_to_file` does what you would expect, and `ggprint` writes to + * standard output. Both return `true` on success, or `false` if the write + * fails. + */ template< typename... Rest > bool ggprint_to_file( FILE * file, const char * fmt, const Rest & ... rest );