#include <folly/Exception.h>
#include <folly/FormatTraits.h>
+#include <folly/MapUtil.h>
#include <folly/Traits.h>
#include <folly/portability/Windows.h>
p = q;
if (p == end || *p != '}') {
- throw BadFormatArg("folly::format: single '}' in format string");
+ throwBadFormatArg("folly::format: single '}' in format string");
}
++p;
}
p = q + 1;
if (p == end) {
- throw BadFormatArg("folly::format: '}' at end of format string");
+ throwBadFormatArg("folly::format: '}' at end of format string");
}
// "{{" -> "{"
// Format string
q = static_cast<const char*>(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;
}
if (hasDefaultArgIndex && hasExplicitArgIndex) {
- throw BadFormatArg(
+ throwBadFormatArg(
"folly::format: may not have both default and explicit arg indexes");
}
template <class FormatCallback>
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 &&
struct KeyFromStringPiece<fbstring> : public FormatTraitsBase {
typedef fbstring key_type;
static fbstring convert(StringPiece s) {
- return s.toFbstring();
+ return s.to<fbstring>();
}
};
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<key_type>::convert(key));
+ if (auto ptr = get_ptr(map, KeyFromStringPiece<key_type>::convert(key))) {
+ return *ptr;
+ }
+ detail::throwFormatKeyNotFoundException(key);
}
static const value_type&
at(const T& map, StringPiece key, const value_type& dflt) {