String composition library

Overview

The idea behind the compose library is to provide the following syntax: String::compose("Price of %1: %2", item, price) -> "Price of knife: 15.0".

The main reason it's not a good idea to this manually, e.g. with boost::lexical_cast, is that the program is then very difficult to localize properly, i.e. your translators job will become close to impossible. It's also inconvenient and error-prone since it's easy to get the spacing wrong.

The compose library defines a set of functions on the form String::compose(format_string, arg1, arg2, etc...) where the types of arg1, arg2, etc. are templatized to support arbitrary objects. The format_string has embedded %1, %2,... specifications that are replaced by the stringified representations of arg1, arg2,...,.

So its capabilities are close to those of the functions in the C printf family, but without the type and memory insafety and inconvience. Note that the library consists of a single header file that you can easily include in your source code.

Latest version

The latest version of compose.tar.gz is v. 1.0.5.

Documentation is included in the tarball, and also available here. If you're dealing with Glib::ustrings from glibmm/gtkmm, the ucompose.hpp header defines String::ucompose(fmt, args...) that work with ustrings (using the ordinary String::compose functions will silently corrupt the UTF-8 in the ustrings).

What has been changed:

Back to home.