X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FFormat.cpp;h=9ad5395e8f04f507c4496c9ed046a26622680148;hb=a123a11e30026dd9883f16fa3ad1baa2d9ecfeec;hp=db95ea24088f34aa4c57234cf37b90a76854253e;hpb=41365ea66d92749ba78f73d60325e5447beb04ab;p=folly.git diff --git a/folly/Format.cpp b/folly/Format.cpp index db95ea24..9ad5395e 100644 --- a/folly/Format.cpp +++ b/folly/Format.cpp @@ -16,7 +16,8 @@ #include -#include +#include +#include #include @@ -26,7 +27,7 @@ namespace detail { extern const FormatArg::Align formatAlignTable[]; extern const FormatArg::Sign formatSignTable[]; -} // namespace detail +} // namespace detail using namespace folly::detail; @@ -81,6 +82,7 @@ void FormatValue::formatHelper( switch (arg.presentation) { case '%': val *= 100; + FOLLY_FALLTHROUGH; case 'f': case 'F': { @@ -177,7 +179,9 @@ void FormatArg::initSlow() { if (*p == ':') { // parse format spec - if (++p == end) return; + if (++p == end) { + return; + } // fill/align, or just align Align a; @@ -187,30 +191,40 @@ void FormatArg::initSlow() { fill = *p; align = a; p += 2; - if (p == end) return; + if (p == end) { + return; + } } else if ((a = formatAlignTable[static_cast(*p)]) != Align::INVALID) { align = a; - if (++p == end) return; + if (++p == end) { + return; + } } Sign s; unsigned char uSign = static_cast(*p); if ((s = formatSignTable[uSign]) != Sign::INVALID) { sign = s; - if (++p == end) return; + if (++p == end) { + return; + } } if (*p == '#') { basePrefix = true; - if (++p == end) return; + if (++p == end) { + return; + } } if (*p == '0') { enforce(align == Align::DEFAULT, "alignment specified twice"); fill = '0'; align = Align::PAD_AFTER_SIGN; - if (++p == end) return; + if (++p == end) { + return; + } } auto readInt = [&] { @@ -225,20 +239,30 @@ void FormatArg::initSlow() { width = kDynamicWidth; ++p; - if (p == end) return; + if (p == end) { + return; + } - if (*p >= '0' && *p <= '9') widthIndex = readInt(); + if (*p >= '0' && *p <= '9') { + widthIndex = readInt(); + } - if (p == end) return; + if (p == end) { + return; + } } else if (*p >= '0' && *p <= '9') { width = readInt(); - if (p == end) return; + if (p == end) { + return; + } } if (*p == ',') { thousandsSeparator = true; - if (++p == end) return; + if (++p == end) { + return; + } } if (*p == '.') { @@ -256,11 +280,15 @@ void FormatArg::initSlow() { trailingDot = true; } - if (p == end) return; + if (p == end) { + return; + } } presentation = *p; - if (++p == end) return; + if (++p == end) { + return; + } } error("extra characters in format string"); @@ -326,6 +354,17 @@ void insertThousandsGroupingUnsafe(char* start_buffer, char** end_buffer) { remaining_digits -= current_group_size; } } -} // detail +} // namespace detail + +FormatKeyNotFoundException::FormatKeyNotFoundException(StringPiece key) + : std::out_of_range(kMessagePrefix.str() + key.str()) {} + +constexpr StringPiece const FormatKeyNotFoundException::kMessagePrefix; + +namespace detail { +[[noreturn]] void throwFormatKeyNotFoundException(StringPiece key) { + throw FormatKeyNotFoundException(key); +} +} // namespace detail -} // namespace folly +} // namespace folly