diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
commit | 71d5a2540a98c81f5bcaeb48805e0e2881f530ef (patch) | |
tree | 5343938942df402b49ec7300a1c25a2d4ccd5821 /include/llvm/Support/FormatProviders.h | |
parent | 31bbf64f3a4974a2d6c8b3b27ad2f519caf74057 (diff) |
Diffstat (limited to 'include/llvm/Support/FormatProviders.h')
-rw-r--r-- | include/llvm/Support/FormatProviders.h | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/include/llvm/Support/FormatProviders.h b/include/llvm/Support/FormatProviders.h index 1f0768c3ab08..4e57034ff98e 100644 --- a/include/llvm/Support/FormatProviders.h +++ b/include/llvm/Support/FormatProviders.h @@ -18,6 +18,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/Twine.h" #include "llvm/Support/FormatVariadicDetails.h" #include "llvm/Support/NativeFormatting.h" @@ -45,9 +46,8 @@ struct is_cstring template <typename T> struct use_string_formatter - : public std::integral_constant< - bool, is_one_of<T, llvm::StringRef, std::string>::value || - is_cstring<T>::value> {}; + : public std::integral_constant<bool, + std::is_convertible<T, llvm::StringRef>::value> {}; template <typename T> struct use_pointer_formatter @@ -205,11 +205,22 @@ struct format_provider< if (!Style.empty() && Style.getAsInteger(10, N)) { assert(false && "Style is not a valid integer"); } - llvm::StringRef S(V); + llvm::StringRef S = V; Stream << S.substr(0, N); } }; +/// Implementation of format_provider<T> for llvm::Twine. +/// +/// This follows the same rules as the string formatter. + +template <> struct format_provider<Twine> { + static void format(const Twine &V, llvm::raw_ostream &Stream, + StringRef Style) { + format_provider<std::string>::format(V.str(), Stream, Style); + } +}; + /// Implementation of format_provider<T> for characters. /// /// The options string of a character type has the grammar: @@ -359,8 +370,7 @@ template <typename IterT> class format_provider<llvm::iterator_range<IterT>> { return Default; } - std::vector<const char *> Delims = {"[]", "<>", "()"}; - for (const char *D : Delims) { + for (const char *D : {"[]", "<>", "()"}) { if (Style.front() != D[0]) continue; size_t End = Style.find_first_of(D[1]); |