diff options
-rw-r--r-- | llvm/include/llvm/Support/FormatProviders.h | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/llvm/include/llvm/Support/FormatProviders.h b/llvm/include/llvm/Support/FormatProviders.h index bf489e2..b7d2e2e 100644 --- a/llvm/include/llvm/Support/FormatProviders.h +++ b/llvm/include/llvm/Support/FormatProviders.h @@ -76,19 +76,19 @@ protected: return Result; } - static bool consumeHexStyle(StringRef &Str, HexPrintStyle &Style) { + static std::optional<HexPrintStyle> consumeHexStyle(StringRef &Str) { if (!Str.starts_with_insensitive("x")) - return false; + return std::nullopt; if (Str.consume_front("x-")) - Style = HexPrintStyle::Lower; - else if (Str.consume_front("X-")) - Style = HexPrintStyle::Upper; - else if (Str.consume_front("x+") || Str.consume_front("x")) - Style = HexPrintStyle::PrefixLower; - else if (Str.consume_front("X+") || Str.consume_front("X")) - Style = HexPrintStyle::PrefixUpper; - return true; + return HexPrintStyle::Lower; + if (Str.consume_front("X-")) + return HexPrintStyle::Upper; + if (Str.consume_front("x+") || Str.consume_front("x")) + return HexPrintStyle::PrefixLower; + if (!Str.consume_front("X+")) + Str.consume_front("X"); + return HexPrintStyle::PrefixUpper; } static size_t consumeNumHexDigits(StringRef &Str, HexPrintStyle Style, @@ -132,11 +132,10 @@ struct format_provider< private: public: static void format(const T &V, llvm::raw_ostream &Stream, StringRef Style) { - HexPrintStyle HS; size_t Digits = 0; - if (consumeHexStyle(Style, HS)) { - Digits = consumeNumHexDigits(Style, HS, 0); - write_hex(Stream, V, HS, Digits); + if (std::optional<HexPrintStyle> HS = consumeHexStyle(Style)) { + Digits = consumeNumHexDigits(Style, *HS, 0); + write_hex(Stream, V, *HS, Digits); return; } @@ -182,7 +181,8 @@ private: public: static void format(const T &V, llvm::raw_ostream &Stream, StringRef Style) { HexPrintStyle HS = HexPrintStyle::PrefixUpper; - consumeHexStyle(Style, HS); + if (std::optional<HexPrintStyle> consumed = consumeHexStyle(Style)) + HS = *consumed; size_t Digits = consumeNumHexDigits(Style, HS, sizeof(void *) * 2); write_hex(Stream, reinterpret_cast<std::uintptr_t>(V), HS, Digits); } |