X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FFormat-inl.h;h=ec5eb3569c245e22eba2fab1041d121ace459537;hp=7cea87a4b5e07cc2f4ab39a7adbb206898d07ea9;hb=2a4ad2c8ddc1eb1be8b7ffb607de954ccc2b666e;hpb=2734e379f411f7d9757f9b8d13c020249a6c2dd6 diff --git a/folly/Format-inl.h b/folly/Format-inl.h index 7cea87a4..ec5eb356 100644 --- a/folly/Format-inl.h +++ b/folly/Format-inl.h @@ -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. @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -180,7 +181,7 @@ void BaseFormatter::operator()( p = q; if (p == end || *p != '}') { - throw BadFormatArg("folly::format: single '}' in format string"); + throwBadFormatArg("folly::format: single '}' in format string"); } ++p; } @@ -202,7 +203,7 @@ void BaseFormatter::operator()( p = q + 1; if (p == end) { - throw BadFormatArg("folly::format: '}' at end of format string"); + throwBadFormatArg("folly::format: '}' at end of format string"); } // "{{" -> "{" @@ -215,7 +216,7 @@ void BaseFormatter::operator()( // Format string q = static_cast(memchr(p, '}', size_t(end - p))); if (q == nullptr) { - throw BadFormatArg("folly::format: missing ending '}'"); + throwBadFormatArg("folly::format: missing ending '}'"); } FormatArg arg(StringPiece(p, q)); p = q + 1; @@ -264,7 +265,7 @@ void BaseFormatter::operator()( } if (hasDefaultArgIndex && hasExplicitArgIndex) { - throw BadFormatArg( + throwBadFormatArg( "folly::format: may not have both default and explicit arg indexes"); } @@ -290,10 +291,10 @@ namespace format_value { template void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) { if (arg.width != FormatArg::kDefaultWidth && arg.width < 0) { - throw BadFormatArg("folly::format: invalid width"); + throwBadFormatArg("folly::format: invalid width"); } if (arg.precision != FormatArg::kDefaultPrecision && arg.precision < 0) { - throw BadFormatArg("folly::format: invalid precision"); + throwBadFormatArg("folly::format: invalid precision"); } if (arg.precision != FormatArg::kDefaultPrecision && @@ -931,7 +932,7 @@ template <> struct KeyFromStringPiece : public FormatTraitsBase { typedef fbstring key_type; static fbstring convert(StringPiece s) { - return s.toFbstring(); + return s.to(); } }; @@ -950,7 +951,10 @@ struct KeyableTraitsAssoc : public FormatTraitsBase { typedef typename T::key_type key_type; typedef typename T::value_type::second_type value_type; static const value_type& at(const T& map, StringPiece key) { - return map.at(KeyFromStringPiece::convert(key)); + if (auto ptr = get_ptr(map, KeyFromStringPiece::convert(key))) { + return *ptr; + } + detail::throwFormatKeyNotFoundException(key); } static const value_type& at(const T& map, StringPiece key, const value_type& dflt) {