1 ////////////////////////////////////////////////////////////////////////////////
3 // Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // http://www.opensource.org/licenses/mit-license.php
25 ////////////////////////////////////////////////////////////////////////////////
27 #ifndef INCLUDED_FORMAT
28 #define INCLUDED_FORMAT
35 const std::string format (std::string&);
36 const std::string format (const char*);
37 const std::string formatHex (int);
38 const std::string format (float, int, int);
39 const std::string format (double, int, int);
40 const std::string format (double);
42 void replace_positional (std::string&, const std::string&, const std::string&);
45 const std::string format (T value)
53 const std::string format (int fmt_num, const std::string& fmt, T arg)
55 std::string output = fmt;
56 replace_positional (output, '{' + format (fmt_num) + '}', format (arg));
60 template<typename T, typename... Args>
61 const std::string format (int fmt_num, const std::string& fmt, T arg, Args... args)
63 const std::string fmt_replaced (format (fmt_num, fmt, arg));
64 return format (fmt_num+1, fmt_replaced, args...);
67 template<typename... Args>
68 const std::string format (const std::string& fmt, Args... args)
70 return format (1, fmt, args...);
73 std::string leftJustify (const int, const int);
74 std::string leftJustify (const std::string&, const int);
75 std::string rightJustifyZero (const int, const int);
76 std::string rightJustify (const int, const int);
77 std::string rightJustify (const std::string&, const int);
79 std::string commify (const std::string&);
80 std::string formatBytes (size_t);
81 std::string formatTime (time_t);
82 std::string printable (const std::string&);
83 std::string printable (char);
85 std::string obfuscateText (const std::string&);