X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FFormat.cpp;h=aed192bfac142dd36ad4a4b762256c42cedb002d;hp=bbcd2d004dec69f155331f26652c8ab3d963e616;hb=afde52ff7655ba79759eafdbee14b3fe47428fce;hpb=6d7c6d55f0f4b7b75607608ef9037db58083368f diff --git a/folly/Format.cpp b/folly/Format.cpp index bbcd2d00..aed192bf 100644 --- a/folly/Format.cpp +++ b/folly/Format.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2012-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -179,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; @@ -189,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 = [&] { @@ -227,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 == '.') { @@ -258,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"); @@ -330,4 +356,15 @@ void insertThousandsGroupingUnsafe(char* start_buffer, char** end_buffer) { } } // 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