3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
8 #ifndef MSP_STRINGS_FORMATTER_H_
9 #define MSP_STRINGS_FORMATTER_H_
12 #include "lexicalcast.h"
17 Printf-like string formatter class.
22 Formatter(const std::string &);
25 Extracts the next conversion from the format string and formats the given
26 value with it. Will throw if no more conversions are found.
29 Formatter &operator()(const T &a)
31 result+=lexical_cast(a, get_conversion());
36 const std::string &str() const;
39 std::string::iterator pos;
46 inline Formatter format(const std::string &f)
47 { return Formatter(f); }
50 inline std::string format(const std::string &f, const A1 &a1)
51 { return Formatter(f)(a1).str(); }
53 template<typename A1, typename A2>
54 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2)
55 { return Formatter(f)(a1)(a2).str(); }
57 template<typename A1, typename A2, typename A3>
58 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3)
59 { return Formatter(f)(a1)(a2)(a3).str(); }
61 template<typename A1, typename A2, typename A3, typename A4>
62 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
63 { return Formatter(f)(a1)(a2)(a3)(a4).str(); }
65 template<typename A1, typename A2, typename A3, typename A4, typename A5>
66 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
67 { return Formatter(f)(a1)(a2)(a3)(a4)(a5).str(); }