summaryrefslogtreecommitdiff
path: root/src/string.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/string.hh')
-rw-r--r--src/string.hh22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/string.hh b/src/string.hh
index 5e90e98d..41dbccb8 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -5,6 +5,7 @@
#include "utf8.hh"
#include "hash.hh"
#include "vector.hh"
+#include "array_view.hh"
#include <string>
#include <climits>
@@ -276,6 +277,27 @@ String expand_tabs(StringView line, CharCount tabstop, CharCount col = 0);
Vector<StringView> wrap_lines(StringView text, CharCount max_width);
+namespace detail
+{
+
+template<typename T> using IsString = std::is_convertible<T, StringView>;
+
+template<typename T, class = typename std::enable_if<!IsString<T>::value>::type>
+String format_param(const T& val) { return to_string(val); }
+
+template<typename T, class = typename std::enable_if<IsString<T>::value>::type>
+StringView format_param(const T& val) { return val; }
+
+}
+
+String format(StringView fmt, ArrayView<const StringView> params);
+
+template<typename... Types>
+String format(StringView fmt, Types... params)
+{
+ return format(fmt, ArrayView<const StringView>{{detail::format_param(params)...}});
+}
+
}
#endif // string_hh_INCLUDED